1 19 package jcckit.graphic; 20 21 import java.util.Vector ; 22 23 28 public class Polygon extends BasicGraphicalElement { 29 private final Vector _points = new Vector (); 30 private final boolean _closed; 31 32 36 public Polygon(GraphicAttributes attributes, boolean closed) { 37 super(attributes); 38 _closed = closed; 39 } 40 41 42 public boolean isClosed() { 43 return _closed; 44 } 45 46 47 public int getNumberOfPoints() { 48 return _points.size(); 49 } 50 51 52 public GraphPoint getPoint(int index) { 53 return (GraphPoint) _points.elementAt(index); 54 } 55 56 57 public void addPoint(GraphPoint point) { 58 _points.addElement(point); 59 } 60 61 62 public void removeAllPoints() { 63 _points.removeAllElements(); 64 } 65 66 67 public void replacePointAt(int index, GraphPoint point) { 68 _points.setElementAt(point, index); 69 } 70 71 77 public void renderWith(Renderer renderer) { 78 if (renderer instanceof PolygonRenderer) { 79 ((PolygonRenderer) renderer).render(this); 80 } else { 81 throw new IllegalArgumentException (renderer 82 + " does not implements PolygonRenderer."); 83 } 84 } 85 } 86 | Popular Tags |