< prev index next >

modules/graphics/src/main/java/javafx/scene/canvas/Canvas.java

Print this page




  68 gc.fillRect(75,75,100,100);
  69 
  70 root.getChildren().add(canvas);
  71  * </pre>
  72  * </p>
  73  *
  74  * @since JavaFX 2.2
  75  */
  76 public class Canvas extends Node {
  77     static {
  78         CanvasHelper.setCanvasAccessor(new CanvasHelper.CanvasAccessor() {
  79             @Override
  80             public NGNode doCreatePeer(Node node) {
  81                 return ((Canvas) node).doCreatePeer();
  82             }
  83 
  84             @Override
  85             public void doUpdatePeer(Node node) {
  86                 ((Canvas) node).doUpdatePeer();
  87             }
















  88         });
  89     }
  90     static final int DEFAULT_VAL_BUF_SIZE = 1024;
  91     static final int DEFAULT_OBJ_BUF_SIZE = 32;
  92     private static final int SIZE_HISTORY = 5;
  93 
  94     private GrowableDataBuffer current;
  95     private boolean rendererBehind;
  96     private int recentvalsizes[];
  97     private int recentobjsizes[];
  98     private int lastsizeindex;
  99 
 100     private GraphicsContext theContext;
 101 
 102     {
 103         // To initialize the class helper at the begining each constructor of this class
 104         CanvasHelper.initHelper(this);
 105     }
 106 
 107     /**


 164      * @profile common
 165      * @defaultvalue 0.0
 166      */
 167     private DoubleProperty width;
 168 
 169     public final void setWidth(double value) {
 170         widthProperty().set(value);
 171     }
 172 
 173     public final double getWidth() {
 174         return width == null ? 0.0 : width.get();
 175     }
 176 
 177     public final DoubleProperty widthProperty() {
 178         if (width == null) {
 179             width = new DoublePropertyBase() {
 180 
 181                 @Override
 182                 public void invalidated() {
 183                     NodeHelper.markDirty(Canvas.this, DirtyBits.NODE_GEOMETRY);
 184                     impl_geomChanged();
 185                     if (theContext != null) {
 186                         theContext.updateDimensions();
 187                     }
 188                 }
 189 
 190                 @Override
 191                 public Object getBean() {
 192                     return Canvas.this;
 193                 }
 194 
 195                 @Override
 196                 public String getName() {
 197                     return "width";
 198                 }
 199             };
 200         }
 201         return width;
 202     }
 203 
 204     /**


 207      * @profile common
 208      * @defaultvalue 0.0
 209      */
 210     private DoubleProperty height;
 211 
 212     public final void setHeight(double value) {
 213         heightProperty().set(value);
 214     }
 215 
 216     public final double getHeight() {
 217         return height == null ? 0.0 : height.get();
 218     }
 219 
 220     public final DoubleProperty heightProperty() {
 221         if (height == null) {
 222             height = new DoublePropertyBase() {
 223 
 224                 @Override
 225                 public void invalidated() {
 226                     NodeHelper.markDirty(Canvas.this, DirtyBits.NODE_GEOMETRY);
 227                     impl_geomChanged();
 228                     if (theContext != null) {
 229                         theContext.updateDimensions();
 230                     }
 231                 }
 232 
 233                 @Override
 234                 public Object getBean() {
 235                     return Canvas.this;
 236                 }
 237 
 238                 @Override
 239                 public String getName() {
 240                     return "height";
 241                 }
 242             };
 243         }
 244         return height;
 245     }
 246 
 247     private NGNode doCreatePeer() {


 254     private void doUpdatePeer() {
 255         if (NodeHelper.isDirty(this, DirtyBits.NODE_GEOMETRY)) {
 256             NGCanvas peer = NodeHelper.getPeer(this);
 257             peer.updateBounds((float)getWidth(),
 258                               (float)getHeight());
 259         }
 260         if (NodeHelper.isDirty(this, DirtyBits.NODE_CONTENTS)) {
 261             NGCanvas peer = NodeHelper.getPeer(this);
 262             if (current != null && !current.isEmpty()) {
 263                 if (--lastsizeindex < 0) {
 264                     lastsizeindex = SIZE_HISTORY - 1;
 265                 }
 266                 recentvalsizes[lastsizeindex] = current.writeValuePosition();
 267                 recentobjsizes[lastsizeindex] = current.writeObjectPosition();
 268                 rendererBehind = peer.updateRendering(current);
 269                 current = null;
 270             }
 271         }
 272     }
 273 
 274     /**
 275      * @treatAsPrivate implementation detail
 276      * @deprecated This is an internal API that is not intended for use and will be removed in the next version
 277      */
 278     @Deprecated
 279     @Override
 280     protected boolean impl_computeContains(double localX, double localY) {
 281         double w = getWidth();
 282         double h = getHeight();
 283         return (w > 0 && h > 0 &&
 284                 localX >= 0 && localY >= 0 &&
 285                 localX <  w && localY <  h);
 286     }
 287 
 288     /**
 289      * @treatAsPrivate implementation detail
 290      * @deprecated This is an internal API that is not intended for use and will be removed in the next version
 291      */
 292     @Deprecated
 293     @Override
 294     public BaseBounds impl_computeGeomBounds(BaseBounds bounds, BaseTransform tx) {
 295         bounds = new RectBounds(0f, 0f, (float) getWidth(), (float) getHeight());
 296         bounds = tx.transform(bounds, bounds);
 297         return bounds;
 298     }
 299 
 300     /**
 301      * @treatAsPrivate implementation detail
 302      * @deprecated This is an internal API that is not intended for use and will be removed in the next version
 303      */
 304     @Deprecated
 305     @Override
 306     public Object impl_processMXNode(MXNodeAlgorithm alg,
 307                                      MXNodeAlgorithmContext ctx) {
 308         return alg.processLeafNode(this, ctx);
 309     }
 310 }


  68 gc.fillRect(75,75,100,100);
  69 
  70 root.getChildren().add(canvas);
  71  * </pre>
  72  * </p>
  73  *
  74  * @since JavaFX 2.2
  75  */
  76 public class Canvas extends Node {
  77     static {
  78         CanvasHelper.setCanvasAccessor(new CanvasHelper.CanvasAccessor() {
  79             @Override
  80             public NGNode doCreatePeer(Node node) {
  81                 return ((Canvas) node).doCreatePeer();
  82             }
  83 
  84             @Override
  85             public void doUpdatePeer(Node node) {
  86                 ((Canvas) node).doUpdatePeer();
  87             }
  88 
  89             @Override
  90             public BaseBounds doComputeGeomBounds(Node node,
  91             BaseBounds bounds, BaseTransform tx) {
  92                 return ((Canvas) node).doComputeGeomBounds(bounds, tx);
  93             }
  94 
  95             @Override
  96             public boolean doComputeContains(Node node, double localX, double localY) {
  97                 return ((Canvas) node).doComputeContains(localX, localY);
  98             }
  99 
 100             @Override
 101             public Object doProcessMXNode(Node node, MXNodeAlgorithm alg, MXNodeAlgorithmContext ctx) {
 102                 return ((Canvas) node).doProcessMXNode(alg, ctx);
 103             }
 104         });
 105     }
 106     static final int DEFAULT_VAL_BUF_SIZE = 1024;
 107     static final int DEFAULT_OBJ_BUF_SIZE = 32;
 108     private static final int SIZE_HISTORY = 5;
 109 
 110     private GrowableDataBuffer current;
 111     private boolean rendererBehind;
 112     private int recentvalsizes[];
 113     private int recentobjsizes[];
 114     private int lastsizeindex;
 115 
 116     private GraphicsContext theContext;
 117 
 118     {
 119         // To initialize the class helper at the begining each constructor of this class
 120         CanvasHelper.initHelper(this);
 121     }
 122 
 123     /**


 180      * @profile common
 181      * @defaultvalue 0.0
 182      */
 183     private DoubleProperty width;
 184 
 185     public final void setWidth(double value) {
 186         widthProperty().set(value);
 187     }
 188 
 189     public final double getWidth() {
 190         return width == null ? 0.0 : width.get();
 191     }
 192 
 193     public final DoubleProperty widthProperty() {
 194         if (width == null) {
 195             width = new DoublePropertyBase() {
 196 
 197                 @Override
 198                 public void invalidated() {
 199                     NodeHelper.markDirty(Canvas.this, DirtyBits.NODE_GEOMETRY);
 200                     NodeHelper.geomChanged(Canvas.this);
 201                     if (theContext != null) {
 202                         theContext.updateDimensions();
 203                     }
 204                 }
 205 
 206                 @Override
 207                 public Object getBean() {
 208                     return Canvas.this;
 209                 }
 210 
 211                 @Override
 212                 public String getName() {
 213                     return "width";
 214                 }
 215             };
 216         }
 217         return width;
 218     }
 219 
 220     /**


 223      * @profile common
 224      * @defaultvalue 0.0
 225      */
 226     private DoubleProperty height;
 227 
 228     public final void setHeight(double value) {
 229         heightProperty().set(value);
 230     }
 231 
 232     public final double getHeight() {
 233         return height == null ? 0.0 : height.get();
 234     }
 235 
 236     public final DoubleProperty heightProperty() {
 237         if (height == null) {
 238             height = new DoublePropertyBase() {
 239 
 240                 @Override
 241                 public void invalidated() {
 242                     NodeHelper.markDirty(Canvas.this, DirtyBits.NODE_GEOMETRY);
 243                     NodeHelper.geomChanged(Canvas.this);
 244                     if (theContext != null) {
 245                         theContext.updateDimensions();
 246                     }
 247                 }
 248 
 249                 @Override
 250                 public Object getBean() {
 251                     return Canvas.this;
 252                 }
 253 
 254                 @Override
 255                 public String getName() {
 256                     return "height";
 257                 }
 258             };
 259         }
 260         return height;
 261     }
 262 
 263     private NGNode doCreatePeer() {


 270     private void doUpdatePeer() {
 271         if (NodeHelper.isDirty(this, DirtyBits.NODE_GEOMETRY)) {
 272             NGCanvas peer = NodeHelper.getPeer(this);
 273             peer.updateBounds((float)getWidth(),
 274                               (float)getHeight());
 275         }
 276         if (NodeHelper.isDirty(this, DirtyBits.NODE_CONTENTS)) {
 277             NGCanvas peer = NodeHelper.getPeer(this);
 278             if (current != null && !current.isEmpty()) {
 279                 if (--lastsizeindex < 0) {
 280                     lastsizeindex = SIZE_HISTORY - 1;
 281                 }
 282                 recentvalsizes[lastsizeindex] = current.writeValuePosition();
 283                 recentobjsizes[lastsizeindex] = current.writeObjectPosition();
 284                 rendererBehind = peer.updateRendering(current);
 285                 current = null;
 286             }
 287         }
 288     }
 289 
 290     /*
 291      * Note: This method MUST only be called via its accessor method.

 292      */
 293     private boolean doComputeContains(double localX, double localY) {


 294         double w = getWidth();
 295         double h = getHeight();
 296         return (w > 0 && h > 0 &&
 297                 localX >= 0 && localY >= 0 &&
 298                 localX <  w && localY <  h);
 299     }
 300 
 301     /*
 302      * Note: This method MUST only be called via its accessor method.

 303      */
 304     private BaseBounds doComputeGeomBounds(BaseBounds bounds, BaseTransform tx) {


 305         bounds = new RectBounds(0f, 0f, (float) getWidth(), (float) getHeight());
 306         bounds = tx.transform(bounds, bounds);
 307         return bounds;
 308     }
 309 
 310     /*
 311      * Note: This method MUST only be called via its accessor method.

 312      */
 313     private Object doProcessMXNode(MXNodeAlgorithm alg,


 314                                      MXNodeAlgorithmContext ctx) {
 315         return alg.processLeafNode(this, ctx);
 316     }
 317 }
< prev index next >