< prev index next >

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

Print this page




  55 circle.setCenterY(100.0f);
  56 circle.setRadius(50.0f);
  57 }
  58 </PRE>
  59  * @since JavaFX 2.0
  60  */
  61 public class Circle extends Shape {
  62     static {
  63         CircleHelper.setCircleAccessor(new CircleHelper.CircleAccessor() {
  64             @Override
  65             public NGNode doCreatePeer(Node node) {
  66                 return ((Circle) node).doCreatePeer();
  67             }
  68 
  69             @Override
  70             public void doUpdatePeer(Node node) {
  71                 ((Circle) node).doUpdatePeer();
  72             }
  73 
  74             @Override






  75             public com.sun.javafx.geom.Shape doConfigShape(Shape shape) {
  76                 return ((Circle) shape).doConfigShape();
  77             }
  78         });
  79     }
  80 
  81     private final Ellipse2D shape = new Ellipse2D();
  82 
  83     {
  84         // To initialize the class helper at the begining each constructor of this class
  85         CircleHelper.initHelper(this);
  86     }
  87 
  88     /**
  89      * Creates a new instance of Circle with a specified radius.
  90      * @param radius the radius of the circle in pixels
  91      */
  92     public Circle(double radius) {
  93         setRadius(radius);
  94     }


 144 
 145 
 146 
 147     public final void setCenterX(double value) {
 148         if (centerX != null || value != 0.0) {
 149             centerXProperty().set(value);
 150         }
 151     }
 152 
 153     public final double getCenterX() {
 154         return centerX == null ? 0.0 : centerX.get();
 155     }
 156 
 157     public final DoubleProperty centerXProperty() {
 158         if (centerX == null) {
 159             centerX = new DoublePropertyBase(0.0) {
 160 
 161                 @Override
 162                 public void invalidated() {
 163                     NodeHelper.markDirty(Circle.this, DirtyBits.NODE_GEOMETRY);
 164                     impl_geomChanged();
 165                 }
 166 
 167                 @Override
 168                 public Object getBean() {
 169                     return Circle.this;
 170                 }
 171 
 172                 @Override
 173                 public String getName() {
 174                     return "centerX";
 175                 }
 176             };
 177         }
 178         return centerX;
 179     }
 180 
 181     /**
 182      * Defines the vertical position of the center of the circle in pixels.
 183      *
 184      * @defaultValue 0.0


 187 
 188 
 189 
 190     public final void setCenterY(double value) {
 191         if (centerY != null || value != 0.0) {
 192             centerYProperty().set(value);
 193         }
 194     }
 195 
 196     public final double getCenterY() {
 197         return centerY == null ? 0.0 : centerY.get();
 198     }
 199 
 200     public final DoubleProperty centerYProperty() {
 201         if (centerY == null) {
 202             centerY = new DoublePropertyBase(0.0) {
 203 
 204                 @Override
 205                 public void invalidated() {
 206                     NodeHelper.markDirty(Circle.this, DirtyBits.NODE_GEOMETRY);
 207                     impl_geomChanged();
 208                 }
 209 
 210                 @Override
 211                 public Object getBean() {
 212                     return Circle.this;
 213                 }
 214 
 215                 @Override
 216                 public String getName() {
 217                     return "centerY";
 218                 }
 219             };
 220         }
 221         return centerY;
 222     }
 223 
 224     /**
 225      * Defines the radius of the circle in pixels.
 226      *
 227      * @defaultValue 0.0
 228      */
 229     private final DoubleProperty radius = new DoublePropertyBase() {
 230 
 231         @Override
 232         public void invalidated() {
 233             NodeHelper.markDirty(Circle.this, DirtyBits.NODE_GEOMETRY);
 234             impl_geomChanged();
 235         }
 236 
 237         @Override
 238         public Object getBean() {
 239             return Circle.this;
 240         }
 241 
 242         @Override
 243         public String getName() {
 244             return "radius";
 245         }
 246     };
 247 
 248     public final void setRadius(double value) {
 249         radius.set(value);
 250     }
 251 
 252     public final double getRadius() {
 253         return radius.get();
 254     }


 267         // and also because it means we might have to pad the bounds to account
 268         // for this rare and unpredictable circumstance.
 269         // To avoid the problem, we set the Join style to BEVEL for any
 270         // circle.  The BEVEL join style is more predictable for
 271         // anomalous angles and is the simplest join style to compute in
 272         // the stroking code.
 273         // These problems do not necessarily happen for circles which have a
 274         // fixed and balanced aspect ratio, but why waste time computing a
 275         // conversion of a MITER join style when it has no advantage for
 276         // circles and technically requires more computation?
 277         return StrokeLineJoin.BEVEL;
 278     }
 279 
 280     /*
 281      * Note: This method MUST only be called via its accessor method.
 282      */
 283     private  NGNode doCreatePeer() {
 284         return new NGCircle();
 285     }
 286 
 287     /**
 288      * @treatAsPrivate implementation detail
 289      * @deprecated This is an internal API that is not intended for use and will be removed in the next version
 290      */
 291     @Deprecated
 292     @Override public BaseBounds impl_computeGeomBounds(BaseBounds bounds, BaseTransform tx) {
 293         // if there is no fill or stroke, then there are no bounds. The bounds
 294         // must be marked empty in this case to distinguish it from 0,0,0,0
 295         // which would actually contribute to the bounds of a group.
 296         if (getMode() == NGShape.Mode.EMPTY) {
 297             return bounds.makeEmpty();
 298         }
 299 
 300         final double cX = getCenterX();
 301         final double cY = getCenterY();
 302 
 303         if ((tx.getType() & ~(BaseTransform.TYPE_MASK_ROTATION | BaseTransform.TYPE_TRANSLATION)) == 0) {
 304 
 305             double tCX = cX * tx.getMxx() + cY * tx.getMxy() + tx.getMxt();
 306             double tCY = cX * tx.getMyx() + cY * tx.getMyy() + tx.getMyt();
 307             double r = getRadius();
 308 
 309             if (getMode() != NGShape.Mode.FILL && getStrokeType() != StrokeType.INSIDE) {
 310                 double upad = getStrokeWidth();
 311                 if (getStrokeType() == StrokeType.CENTERED) {
 312                     upad /= 2.0f;




  55 circle.setCenterY(100.0f);
  56 circle.setRadius(50.0f);
  57 }
  58 </PRE>
  59  * @since JavaFX 2.0
  60  */
  61 public class Circle extends Shape {
  62     static {
  63         CircleHelper.setCircleAccessor(new CircleHelper.CircleAccessor() {
  64             @Override
  65             public NGNode doCreatePeer(Node node) {
  66                 return ((Circle) node).doCreatePeer();
  67             }
  68 
  69             @Override
  70             public void doUpdatePeer(Node node) {
  71                 ((Circle) node).doUpdatePeer();
  72             }
  73 
  74             @Override
  75             public BaseBounds doComputeGeomBounds(Node node,
  76             BaseBounds bounds, BaseTransform tx) {
  77                 return ((Circle) node).doComputeGeomBounds(bounds, tx);
  78             }
  79 
  80             @Override
  81             public com.sun.javafx.geom.Shape doConfigShape(Shape shape) {
  82                 return ((Circle) shape).doConfigShape();
  83             }
  84         });
  85     }
  86 
  87     private final Ellipse2D shape = new Ellipse2D();
  88 
  89     {
  90         // To initialize the class helper at the begining each constructor of this class
  91         CircleHelper.initHelper(this);
  92     }
  93 
  94     /**
  95      * Creates a new instance of Circle with a specified radius.
  96      * @param radius the radius of the circle in pixels
  97      */
  98     public Circle(double radius) {
  99         setRadius(radius);
 100     }


 150 
 151 
 152 
 153     public final void setCenterX(double value) {
 154         if (centerX != null || value != 0.0) {
 155             centerXProperty().set(value);
 156         }
 157     }
 158 
 159     public final double getCenterX() {
 160         return centerX == null ? 0.0 : centerX.get();
 161     }
 162 
 163     public final DoubleProperty centerXProperty() {
 164         if (centerX == null) {
 165             centerX = new DoublePropertyBase(0.0) {
 166 
 167                 @Override
 168                 public void invalidated() {
 169                     NodeHelper.markDirty(Circle.this, DirtyBits.NODE_GEOMETRY);
 170                     NodeHelper.geomChanged(Circle.this);
 171                 }
 172 
 173                 @Override
 174                 public Object getBean() {
 175                     return Circle.this;
 176                 }
 177 
 178                 @Override
 179                 public String getName() {
 180                     return "centerX";
 181                 }
 182             };
 183         }
 184         return centerX;
 185     }
 186 
 187     /**
 188      * Defines the vertical position of the center of the circle in pixels.
 189      *
 190      * @defaultValue 0.0


 193 
 194 
 195 
 196     public final void setCenterY(double value) {
 197         if (centerY != null || value != 0.0) {
 198             centerYProperty().set(value);
 199         }
 200     }
 201 
 202     public final double getCenterY() {
 203         return centerY == null ? 0.0 : centerY.get();
 204     }
 205 
 206     public final DoubleProperty centerYProperty() {
 207         if (centerY == null) {
 208             centerY = new DoublePropertyBase(0.0) {
 209 
 210                 @Override
 211                 public void invalidated() {
 212                     NodeHelper.markDirty(Circle.this, DirtyBits.NODE_GEOMETRY);
 213                     NodeHelper.geomChanged(Circle.this);
 214                 }
 215 
 216                 @Override
 217                 public Object getBean() {
 218                     return Circle.this;
 219                 }
 220 
 221                 @Override
 222                 public String getName() {
 223                     return "centerY";
 224                 }
 225             };
 226         }
 227         return centerY;
 228     }
 229 
 230     /**
 231      * Defines the radius of the circle in pixels.
 232      *
 233      * @defaultValue 0.0
 234      */
 235     private final DoubleProperty radius = new DoublePropertyBase() {
 236 
 237         @Override
 238         public void invalidated() {
 239             NodeHelper.markDirty(Circle.this, DirtyBits.NODE_GEOMETRY);
 240             NodeHelper.geomChanged(Circle.this);
 241         }
 242 
 243         @Override
 244         public Object getBean() {
 245             return Circle.this;
 246         }
 247 
 248         @Override
 249         public String getName() {
 250             return "radius";
 251         }
 252     };
 253 
 254     public final void setRadius(double value) {
 255         radius.set(value);
 256     }
 257 
 258     public final double getRadius() {
 259         return radius.get();
 260     }


 273         // and also because it means we might have to pad the bounds to account
 274         // for this rare and unpredictable circumstance.
 275         // To avoid the problem, we set the Join style to BEVEL for any
 276         // circle.  The BEVEL join style is more predictable for
 277         // anomalous angles and is the simplest join style to compute in
 278         // the stroking code.
 279         // These problems do not necessarily happen for circles which have a
 280         // fixed and balanced aspect ratio, but why waste time computing a
 281         // conversion of a MITER join style when it has no advantage for
 282         // circles and technically requires more computation?
 283         return StrokeLineJoin.BEVEL;
 284     }
 285 
 286     /*
 287      * Note: This method MUST only be called via its accessor method.
 288      */
 289     private  NGNode doCreatePeer() {
 290         return new NGCircle();
 291     }
 292 
 293     /*
 294      * Note: This method MUST only be called via its accessor method.

 295      */
 296     private BaseBounds doComputeGeomBounds(BaseBounds bounds, BaseTransform tx) {

 297         // if there is no fill or stroke, then there are no bounds. The bounds
 298         // must be marked empty in this case to distinguish it from 0,0,0,0
 299         // which would actually contribute to the bounds of a group.
 300         if (getMode() == NGShape.Mode.EMPTY) {
 301             return bounds.makeEmpty();
 302         }
 303 
 304         final double cX = getCenterX();
 305         final double cY = getCenterY();
 306 
 307         if ((tx.getType() & ~(BaseTransform.TYPE_MASK_ROTATION | BaseTransform.TYPE_TRANSLATION)) == 0) {
 308 
 309             double tCX = cX * tx.getMxx() + cY * tx.getMxy() + tx.getMxt();
 310             double tCY = cX * tx.getMyx() + cY * tx.getMyy() + tx.getMyt();
 311             double r = getRadius();
 312 
 313             if (getMode() != NGShape.Mode.FILL && getStrokeType() != StrokeType.INSIDE) {
 314                 double upad = getStrokeWidth();
 315                 if (getStrokeType() == StrokeType.CENTERED) {
 316                     upad /= 2.0f;


< prev index next >