< prev index next >

modules/graphics/src/main/java/javafx/scene/shape/Polygon.java

Print this page




  54     0.0, 0.0,
  55     20.0, 10.0,
  56     10.0, 20.0 });
  57 </PRE>
  58  * @since JavaFX 2.0
  59  */
  60 public  class Polygon extends Shape {
  61     static {
  62         PolygonHelper.setPolygonAccessor(new PolygonHelper.PolygonAccessor() {
  63             @Override
  64             public NGNode doCreatePeer(Node node) {
  65                 return ((Polygon) node).doCreatePeer();
  66             }
  67 
  68             @Override
  69             public void doUpdatePeer(Node node) {
  70                 ((Polygon) node).doUpdatePeer();
  71             }
  72 
  73             @Override






  74             public com.sun.javafx.geom.Shape doConfigShape(Shape shape) {
  75                 return ((Polygon) shape).doConfigShape();
  76             }
  77         });
  78     }
  79 
  80     private final Path2D shape = new Path2D();
  81 
  82     {
  83         // To initialize the class helper at the begining each constructor of this class
  84         PolygonHelper.initHelper(this);
  85     }
  86 
  87     /**
  88      * Creates an empty instance of Polygon.
  89      */
  90     public Polygon() {
  91     }
  92 
  93     /**
  94      * Creates a new instance of Polygon.
  95      * @param points the coordinates of the polygon vertices
  96      */
  97     public Polygon(double... points) {
  98         if (points != null) {
  99             for (double p : points) {
 100                 this.getPoints().add(p);
 101             }
 102         }
 103     }
 104 
 105     /**
 106      * Defines the coordinates of the polygon vertices.
 107      *
 108      * @defaultValue empty
 109      */
 110     private final ObservableList<Double> points = new TrackableObservableList<Double>() {
 111         @Override
 112         protected void onChanged(Change<Double> c) {
 113             NodeHelper.markDirty(Polygon.this, DirtyBits.NODE_GEOMETRY);
 114             impl_geomChanged();
 115         }
 116     };
 117 
 118     /**
 119      * Gets the coordinates of the {@code Polygon} vertices.
 120      * @return An observable list of vertices of this {@code Polygon}
 121      */
 122     public final ObservableList<Double> getPoints() { return points; }
 123 
 124     /*
 125      * Note: This method MUST only be called via its accessor method.
 126      */
 127     private NGNode doCreatePeer() {
 128         return new NGPolygon();
 129     }
 130 
 131     /**
 132      * @treatAsPrivate implementation detail
 133      * @deprecated This is an internal API that is not intended for use and will be removed in the next version
 134      */
 135     @Deprecated
 136     public BaseBounds impl_computeGeomBounds(BaseBounds bounds, BaseTransform tx) {
 137         if (getMode() == NGShape.Mode.EMPTY || getPoints().size() <= 1) {
 138             return bounds.makeEmpty();
 139         }
 140 
 141         if (getPoints().size() == 2) {
 142             if (getMode() == NGShape.Mode.FILL || getStrokeType() == StrokeType.INSIDE) {
 143                 return bounds.makeEmpty();
 144             }
 145             double upad = getStrokeWidth();
 146             if (getStrokeType() == StrokeType.CENTERED) {
 147                 upad /= 2.0f;
 148             }
 149             return computeBounds(bounds, tx, upad, 0.5f,
 150                 getPoints().get(0), getPoints().get(1), 0.0f, 0.0f);
 151         } else {
 152             return computeShapeBounds(bounds, tx, ShapeHelper.configShape(this));
 153         }
 154     }
 155 
 156     /*




  54     0.0, 0.0,
  55     20.0, 10.0,
  56     10.0, 20.0 });
  57 </PRE>
  58  * @since JavaFX 2.0
  59  */
  60 public  class Polygon extends Shape {
  61     static {
  62         PolygonHelper.setPolygonAccessor(new PolygonHelper.PolygonAccessor() {
  63             @Override
  64             public NGNode doCreatePeer(Node node) {
  65                 return ((Polygon) node).doCreatePeer();
  66             }
  67 
  68             @Override
  69             public void doUpdatePeer(Node node) {
  70                 ((Polygon) node).doUpdatePeer();
  71             }
  72 
  73             @Override
  74             public BaseBounds doComputeGeomBounds(Node node,
  75             BaseBounds bounds, BaseTransform tx) {
  76                 return ((Polygon) node).doComputeGeomBounds(bounds, tx);
  77             }
  78 
  79             @Override
  80             public com.sun.javafx.geom.Shape doConfigShape(Shape shape) {
  81                 return ((Polygon) shape).doConfigShape();
  82             }
  83         });
  84     }
  85 
  86     private final Path2D shape = new Path2D();
  87 
  88     {
  89         // To initialize the class helper at the begining each constructor of this class
  90         PolygonHelper.initHelper(this);
  91     }
  92 
  93     /**
  94      * Creates an empty instance of Polygon.
  95      */
  96     public Polygon() {
  97     }
  98 
  99     /**
 100      * Creates a new instance of Polygon.
 101      * @param points the coordinates of the polygon vertices
 102      */
 103     public Polygon(double... points) {
 104         if (points != null) {
 105             for (double p : points) {
 106                 this.getPoints().add(p);
 107             }
 108         }
 109     }
 110 
 111     /**
 112      * Defines the coordinates of the polygon vertices.
 113      *
 114      * @defaultValue empty
 115      */
 116     private final ObservableList<Double> points = new TrackableObservableList<Double>() {
 117         @Override
 118         protected void onChanged(Change<Double> c) {
 119             NodeHelper.markDirty(Polygon.this, DirtyBits.NODE_GEOMETRY);
 120             NodeHelper.geomChanged(Polygon.this);
 121         }
 122     };
 123 
 124     /**
 125      * Gets the coordinates of the {@code Polygon} vertices.
 126      * @return An observable list of vertices of this {@code Polygon}
 127      */
 128     public final ObservableList<Double> getPoints() { return points; }
 129 
 130     /*
 131      * Note: This method MUST only be called via its accessor method.
 132      */
 133     private NGNode doCreatePeer() {
 134         return new NGPolygon();
 135     }
 136 
 137     /*
 138      * Note: This method MUST only be called via its accessor method.

 139      */
 140     private BaseBounds doComputeGeomBounds(BaseBounds bounds, BaseTransform tx) {

 141         if (getMode() == NGShape.Mode.EMPTY || getPoints().size() <= 1) {
 142             return bounds.makeEmpty();
 143         }
 144 
 145         if (getPoints().size() == 2) {
 146             if (getMode() == NGShape.Mode.FILL || getStrokeType() == StrokeType.INSIDE) {
 147                 return bounds.makeEmpty();
 148             }
 149             double upad = getStrokeWidth();
 150             if (getStrokeType() == StrokeType.CENTERED) {
 151                 upad /= 2.0f;
 152             }
 153             return computeBounds(bounds, tx, upad, 0.5f,
 154                 getPoints().get(0), getPoints().get(1), 0.0f, 0.0f);
 155         } else {
 156             return computeShapeBounds(bounds, tx, ShapeHelper.configShape(this));
 157         }
 158     }
 159 
 160     /*


< prev index next >