Spec-Zone .ru
спецификации, руководства, описания, API
|
001/* 002 * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. 003 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 004 * 005 * This code is free software; you can redistribute it and/or modify it 006 * under the terms of the GNU General Public License version 2 only, as 007 * published by the Free Software Foundation. Oracle designates this 008 * particular file as subject to the "Classpath" exception as provided 009 * by Oracle in the LICENSE file that accompanied this code. 010 * 011 * This code is distributed in the hope that it will be useful, but WITHOUT 012 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 013 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 014 * version 2 for more details (a copy is included in the LICENSE file that 015 * accompanied this code). 016 * 017 * You should have received a copy of the GNU General Public License version 018 * 2 along with this work; if not, write to the Free Software Foundation, 019 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 020 * 021 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 022 * or visit www.oracle.com if you need additional information or have any 023 * questions. 024 */ 025 026package javafx.scene.effect; 027 028import javafx.beans.property.DoubleProperty; 029import javafx.beans.property.DoublePropertyBase; 030import javafx.beans.property.ObjectProperty; 031import javafx.beans.property.ObjectPropertyBase; 032import javafx.scene.Node; 033import javafx.scene.paint.Color; 034import javafx.scene.paint.Paint; 035 036import com.sun.javafx.effect.EffectDirtyBits; 037import com.sun.javafx.effect.EffectUtils; 038import com.sun.javafx.geom.BaseBounds; 039import com.sun.javafx.geom.RectBounds; 040import com.sun.javafx.geom.transform.BaseTransform; 041import com.sun.javafx.scene.BoundsAccessor; 042import com.sun.javafx.tk.Toolkit; 043 044 045/** 046 * An effect that renders a rectangular region that is filled ("flooded") 047 * with the given {@code Paint}. This is equivalent to rendering a 048 * filled rectangle into an image and using an {@code ImageInput} effect, 049 * except that it is more convenient and potentially much more efficient. 050 */ 051public class ColorInput extends Effect { 052 /** 053 * Creates a new instance of ColorInput with default parameters. 054 */ 055 public ColorInput() {} 056 057 /** 058 * Creates a new instance of ColorInput with the specified x, y, width, 059 * height, and paint. 060 * @param x the x location of the region to be flooded 061 * @param y the y location of the region to be flooded 062 * @param width the width of the region to be flooded 063 * @param height the height of the region to be flooded 064 * @param paint the {@code Paint} used to flood the region 065 */ 066 public ColorInput(double x, 067 double y, 068 double width, 069 double height, 070 Paint paint) { 071 setX(x); 072 setY(y); 073 setWidth(width); 074 setHeight(height); 075 setPaint(paint); 076 } 077 078 @Override 079 com.sun.scenario.effect.Flood impl_createImpl() { 080 return new com.sun.scenario.effect.Flood( 081 Toolkit.getPaintAccessor().getPlatformPaint(Color.RED)); 082 }; 083 /** 084 * The {@code Paint} used to flood the region. 085 * <pre> 086 * Min: n/a 087 * Max: n/a 088 * Default: Color.RED 089 * Identity: n/a 090 * </pre> 091 * @defaultValue RED 092 */ 093 private ObjectProperty<Paint> paint; 094 095 096 public final void setPaint(Paint value) { 097 paintProperty().set(value); 098 } 099 100 public final Paint getPaint() { 101 return paint == null ? Color.RED : paint.get(); 102 } 103 104 public final ObjectProperty<Paint> paintProperty() { 105 if (paint == null) { 106 paint = new ObjectPropertyBase<Paint>(Color.RED) { 107 108 @Override 109 public void invalidated() { 110 markDirty(EffectDirtyBits.EFFECT_DIRTY); 111 } 112 113 @Override 114 public Object getBean() { 115 return ColorInput.this; 116 } 117 118 @Override 119 public String getName() { 120 return "paint"; 121 } 122 }; 123 } 124 return paint; 125 } 126 127 /** 128 * Sets the x location of the region to be flooded, relative to the 129 * local coordinate space of the content {@code Node}. 130 * <pre> 131 * Min: n/a 132 * Max: n/a 133 * Default: 0.0 134 * Identity: 0.0 135 * </pre> 136 * @defaultValue 0.0 137 */ 138 private DoubleProperty x; 139 140 141 public final void setX(double value) { 142 xProperty().set(value); 143 } 144 145 public final double getX() { 146 return x == null ? 0 : x.get(); 147 } 148 149 public final DoubleProperty xProperty() { 150 if (x == null) { 151 x = new DoublePropertyBase() { 152 153 @Override 154 public void invalidated() { 155 markDirty(EffectDirtyBits.EFFECT_DIRTY); 156 effectBoundsChanged(); 157 } 158 159 @Override 160 public Object getBean() { 161 return ColorInput.this; 162 } 163 164 @Override 165 public String getName() { 166 return "x"; 167 } 168 }; 169 } 170 return x; 171 } 172 173 /** 174 * Sets the y location of the region to be flooded, relative to the 175 * local coordinate space of the content {@code Node}. 176 * <pre> 177 * Min: n/a 178 * Max: n/a 179 * Default: 0.0 180 * Identity: 0.0 181 * </pre> 182 * @defaultValue 0.0 183 */ 184 private DoubleProperty y; 185 186 187 public final void setY(double value) { 188 yProperty().set(value); 189 } 190 191 public final double getY() { 192 return y == null ? 0 : y.get(); 193 } 194 195 public final DoubleProperty yProperty() { 196 if (y == null) { 197 y = new DoublePropertyBase() { 198 199 @Override 200 public void invalidated() { 201 markDirty(EffectDirtyBits.EFFECT_DIRTY); 202 effectBoundsChanged(); 203 } 204 205 @Override 206 public Object getBean() { 207 return ColorInput.this; 208 } 209 210 @Override 211 public String getName() { 212 return "y"; 213 } 214 }; 215 } 216 return y; 217 } 218 219 /** 220 * Sets the width of the region to be flooded, relative to the 221 * local coordinate space of the content {@code Node}. 222 * <pre> 223 * Min: n/a 224 * Max: n/a 225 * Default: 0.0 226 * Identity: 0.0 227 * </pre> 228 * @defaultValue 0.0 229 */ 230 private DoubleProperty width; 231 232 233 public final void setWidth(double value) { 234 widthProperty().set(value); 235 } 236 237 public final double getWidth() { 238 return width == null ? 0 : width.get(); 239 } 240 241 public final DoubleProperty widthProperty() { 242 if (width == null) { 243 width = new DoublePropertyBase() { 244 245 @Override 246 public void invalidated() { 247 markDirty(EffectDirtyBits.EFFECT_DIRTY); 248 effectBoundsChanged(); 249 } 250 251 @Override 252 public Object getBean() { 253 return ColorInput.this; 254 } 255 256 @Override 257 public String getName() { 258 return "width"; 259 } 260 }; 261 } 262 return width; 263 } 264 265 /** 266 * Sets the height of the region to be flooded, relative to the 267 * local coordinate space of the content {@code Node}. 268 * <pre> 269 * Min: n/a 270 * Max: n/a 271 * Default: 0.0 272 * Identity: 0.0 273 * </pre> 274 * @defaultValue 0.0 275 */ 276 private DoubleProperty height; 277 278 279 public final void setHeight(double value) { 280 heightProperty().set(value); 281 } 282 283 public final double getHeight() { 284 return height == null ? 0 : height.get(); 285 } 286 287 public final DoubleProperty heightProperty() { 288 if (height == null) { 289 height = new DoublePropertyBase() { 290 291 @Override 292 public void invalidated() { 293 markDirty(EffectDirtyBits.EFFECT_DIRTY); 294 effectBoundsChanged(); 295 } 296 297 @Override 298 public Object getBean() { 299 return ColorInput.this; 300 } 301 302 @Override 303 public String getName() { 304 return "height"; 305 } 306 }; 307 } 308 return height; 309 } 310 311 private Paint getPaintInternal() { 312 Paint p = getPaint(); 313 return p == null ? Color.RED : p; 314 } 315 316 @Override 317 void impl_update() { 318 com.sun.scenario.effect.Flood peer = 319 (com.sun.scenario.effect.Flood) impl_getImpl(); 320 peer.setPaint(Toolkit.getPaintAccessor().getPlatformPaint(getPaintInternal())); 321 peer.setFloodBounds(new RectBounds( 322 (float)getX(), (float)getY(), 323 (float)(getX() + getWidth()), 324 (float)(getY() + getHeight()))); 325 } 326 327 @Override 328 boolean impl_checkChainContains(Effect e) { 329 return false; 330 } 331 332 /** 333 * @treatAsPrivate implementation detail 334 * @deprecated This is an internal API that is not intended for use and will be removed in the next version 335 */ 336 @Deprecated 337 @Override 338 public BaseBounds impl_getBounds(BaseBounds bounds, 339 BaseTransform tx, 340 Node node, 341 BoundsAccessor boundsAccessor) { 342 RectBounds ret = new RectBounds( 343 (float)getX(), (float)getY(), 344 (float)(getX() + getWidth()), 345 (float)(getY() + getHeight())); 346 return EffectUtils.transformBounds(tx, ret); 347 } 348 349 /** 350 * 351 * @treatAsPrivate implementation detail 352 * @deprecated This is an internal API that is not intended for use and will be removed in the next version 353 */ 354 @Deprecated 355 @Override 356 public Effect impl_copy() { 357 return new ColorInput(this.getX(), this.getY(), this.getWidth(), this.getHeight(), this.getPaint()); 358 } 359}