View Javadoc

1   // Copyright 2001 FreeHEP.
2   package org.freehep.graphicsio;
3   
4   import java.awt.geom.Point2D;
5   import java.io.IOException;
6   import java.util.Vector;
7   
8   /**
9    * @author Mark Donszelmann
10   * @version $Id: PolylinePathConstructor.java 8584 2006-08-10 23:06:37Z duns $
11   */
12  public abstract class PolylinePathConstructor extends
13          CubicToLinePathConstructor {
14      private Vector polyline;
15  
16      protected boolean closed;
17  
18      protected boolean fill;
19  
20      public PolylinePathConstructor(boolean fill) {
21          this(fill, 0.025);
22      }
23  
24      public PolylinePathConstructor(boolean fill, double resolution) {
25          super(resolution);
26          closed = false;
27          this.fill = fill;
28      }
29  
30      public void move(double x, double y) throws IOException {
31          writePolyline();
32          polyline = new Vector();
33          polyline.add(new Point2D.Double(x, y));
34          super.move(x, y);
35      }
36  
37      public void line(double x, double y) throws IOException {
38          // System.out.println("Line "+x+" "+y);
39          polyline.add(new Point2D.Double(x, y));
40          super.line(x, y);
41      }
42  
43      public void closePath(double x0, double y0) throws IOException {
44          closed = true;
45          writePolyline();
46          super.closePath(x0, y0);
47      }
48  
49      public void writePolyline() throws IOException {
50          if (polyline != null)
51              writePolyline(polyline);
52          closed = false;
53          polyline = null;
54      }
55  
56      protected abstract void writePolyline(Vector polyline) throws IOException;
57  }