Advertisement
Guest User

Path

a guest
Jun 21st, 2016
198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.29 KB | None | 0 0
  1. import java.awt.geom.Point2D;
  2. import java.io.IOException;
  3. import java.util.ArrayList;
  4. import java.util.Iterator;
  5. import java.util.List;
  6.  
  7. public class Path implements Iterable<SubPath>
  8. {
  9.     public int getWindingRule()
  10.     {
  11.         return windingRule;
  12.     }
  13.  
  14.     void complete(int windingRule)
  15.     {
  16.         finishSubPath();
  17.         this.windingRule = windingRule;
  18.     }
  19.  
  20.     void appendRectangle(Point2D.Float p0, Point2D.Float p1, Point2D.Float p2, Point2D.Float p3) throws IOException
  21.     {
  22.         finishSubPath();
  23.         currentSubPath = new Rectangle(p0, p1, p2, p3);
  24.         finishSubPath();
  25.     }
  26.  
  27.     void moveTo(float x, float y) throws IOException
  28.     {
  29.         finishSubPath();
  30.         currentSubPath = new SubPath(new Point2D.Float(x, y));
  31.     }
  32.  
  33.     void lineTo(float x, float y) throws IOException
  34.     {
  35.         currentSubPath.lineTo(x, y);
  36.     }
  37.  
  38.     void curveTo(float x1, float y1, float x2, float y2, float x3, float y3) throws IOException
  39.     {
  40.         currentSubPath.curveTo(x1, y1, x2, y2, x3, y3);
  41.     }
  42.  
  43.     Point2D.Float getCurrentPoint() throws IOException
  44.     {
  45.         return currentSubPath.currentPoint;
  46.     }
  47.  
  48.     void closePath() throws IOException
  49.     {
  50.         currentSubPath.closePath();
  51.         finishSubPath();
  52.     }
  53.  
  54.     void finishSubPath()
  55.     {
  56.         if (currentSubPath != null)
  57.         {
  58.             subPaths.add(currentSubPath);
  59.             currentSubPath = null;
  60.         }
  61.     }
  62.  
  63.     public List<SubPath> getSubPaths()
  64.     {
  65.         return subPaths;
  66.     }
  67.     //
  68.     // Iterable<Path.SubPath> implementation
  69.     //
  70.     public Iterator<SubPath> iterator()
  71.     {
  72.         return subPaths.iterator();
  73.     }
  74.  
  75.     //
  76.     // Object override
  77.     //
  78.     @Override
  79.     public String toString()
  80.     {
  81.         StringBuilder builder = new StringBuilder();
  82.         builder.append("{\n  Winding: ")
  83.                 .append(windingRule)
  84.                 .append('\n');
  85.         System.out.println("printing path");
  86.         for (SubPath subPath : subPaths)
  87.             builder.append(subPath);
  88.         builder.append("}\n");
  89.         return builder.toString();
  90.     }
  91.  
  92.     //Point2D.Float currentPoint = null;
  93.     SubPath currentSubPath = null;
  94.     int windingRule = -1;
  95.     final List<SubPath> subPaths = new ArrayList<>();
  96. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement