123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107 |
- package grafikchat.model;
-
- import java.awt.Point;
- import java.io.Serializable;
- import java.util.ArrayList;
- import java.util.List;
-
- /**
- * Implementation of a list of figures
- *
- * @author marian
- */
- public class Figures implements Serializable
- {
- private ArrayList<Figure> figureList;
- private Figure lastFigure;
- private Point lastPoint;
- private Point secondToLastPoint;
- private static final long serialVersionUID = 8582433437601788990L;
-
-
- /**
- * Constructor, initialize variables
- */
- public Figures()
- {
- figureList = new ArrayList<>();
- lastFigure = null;
- lastPoint = null;
- secondToLastPoint = null;
- }
-
- /**
- * Add point to latest figure
- * @param p new point to add
- */
- public void addPoint(Point p)
- {
- lastFigure.addPoint(p);
- secondToLastPoint = lastPoint;
- lastPoint = p;
- }
-
- /**
- * Create new figure
- */
- public void newFigure()
- {
- Figure f = new Figure();
- figureList.add(f);
- lastFigure = f;
-
- lastPoint = null;
- secondToLastPoint = null;
- }
-
- /**
- * Get the last two points of the latest figure
- * @return last two points of latest figure
- * @throws Exception if not yet available
- */
- public List<Point> getLastTwoPoints() throws Exception
- {
- if (secondToLastPoint == null || lastPoint == null) {
- throw new Exception("Not enough points available");
- }
-
- ArrayList<Point> p = new ArrayList<>();
- p.add(lastPoint);
- p.add(secondToLastPoint);
-
- return p;
- }
-
- /**
- * Get latest figure
- * @return latest figure
- * @throws Exception if not yet available
- */
- private List<Point> getFigure() throws Exception
- {
- if (lastFigure == null) {
- throw new Exception("No figure available");
- }
-
- return lastFigure.getPoints();
- }
-
- /**
- * Set new figures
- * @param f
- */
- public void setFigures(ArrayList<Figure> f)
- {
- figureList = f;
- }
-
- /**
- * Get all current figures
- * @return
- */
- public ArrayList<Figure> getFigures()
- {
- return figureList;
- }
-
- }
|