1 /*
   2  * Copyright (c) 2010, 2015, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package javafx.scene.effect;
  27 
  28 import javafx.beans.property.DoubleProperty;
  29 import javafx.beans.property.DoublePropertyBase;
  30 import javafx.beans.property.ObjectProperty;
  31 import javafx.scene.Node;
  32 
  33 import com.sun.javafx.util.Utils;
  34 import com.sun.javafx.effect.EffectDirtyBits;
  35 import com.sun.javafx.geom.BaseBounds;
  36 import com.sun.javafx.geom.transform.BaseTransform;
  37 import com.sun.javafx.scene.BoundsAccessor;
  38 
  39 
  40 /**
  41  * A high-level effect that makes the input image appear to glow,
  42  * based on a configurable threshold.
  43  *
  44  * <p>
  45  * Example:
  46  * <pre><code>
  47  * Image image = new Image("boat.jpg");
  48  * ImageView imageView = new ImageView(image);
  49  * imageView.setFitWidth(200);
  50  * imageView.setPreserveRatio(true);
  51  *
  52  * imageView.setEffect(new Glow(0.8));
  53  * </pre></code>
  54  * <p>
  55  * <p> The code above applied on this image: </p>
  56  * <p>
  57  * <img src="doc-files/photo.png"/>
  58  * </p>
  59  * <p> produces the following: </p>
  60  * <p>
  61  * <img src="doc-files/glow.png"/>
  62  * </p>
  63  * @since JavaFX 2.0
  64  */
  65 public class Glow extends Effect {
  66     /**
  67      * Creates a new instance of Glow with default parameters.
  68      */
  69     public Glow() {}
  70 
  71     /**
  72      * Creates a new instance of Glow with specified level.
  73      * @param level the level value, which controls the intensity
  74      * of the glow effect
  75      */
  76     public Glow(double level) {
  77         setLevel(level);
  78     }
  79 
  80     @Override
  81     com.sun.scenario.effect.Glow impl_createImpl() {
  82         return new com.sun.scenario.effect.Glow();
  83     };
  84     /**
  85      * The input for this {@code Effect}.
  86      * If set to {@code null}, or left unspecified, a graphical image of
  87      * the {@code Node} to which the {@code Effect} is attached will be
  88      * used as the input.
  89      * @defaultValue null
  90      */
  91     private ObjectProperty<Effect> input;
  92 
  93 
  94     public final void setInput(Effect value) {
  95         inputProperty().set(value);
  96     }
  97 
  98     public final Effect getInput() {
  99         return input == null ? null : input.get();
 100     }
 101 
 102     public final ObjectProperty<Effect> inputProperty() {
 103         if (input == null) {
 104             input = new EffectInputProperty("input");
 105         }
 106         return input;
 107     }
 108 
 109     @Override
 110     boolean impl_checkChainContains(Effect e) {
 111         Effect localInput = getInput();
 112         if (localInput == null)
 113             return false;
 114         if (localInput == e)
 115             return true;
 116         return localInput.impl_checkChainContains(e);
 117     }
 118 
 119     /**
 120      * The level value, which controls the intensity of the glow effect.
 121      * <pre>
 122      *       Min: 0.0
 123      *       Max: 1.0
 124      *   Default: 0.3
 125      *  Identity: 0.0
 126      * </pre>
 127      * @defaultValue 0.3
 128      */
 129     private DoubleProperty level;
 130 
 131 
 132     public final void setLevel(double value) {
 133         levelProperty().set(value);
 134     }
 135 
 136     public final double getLevel() {
 137         return level == null ? 0.3 : level.get();
 138     }
 139 
 140     public final DoubleProperty levelProperty() {
 141         if (level == null) {
 142             level = new DoublePropertyBase(0.3) {
 143 
 144                 @Override
 145                 public void invalidated() {
 146                     markDirty(EffectDirtyBits.EFFECT_DIRTY);
 147                 }
 148 
 149                 @Override
 150                 public Object getBean() {
 151                     return Glow.this;
 152                 }
 153 
 154                 @Override
 155                 public String getName() {
 156                     return "level";
 157                 }
 158             };
 159         }
 160         return level;
 161     }
 162 
 163     @Override
 164     void impl_update() {
 165         Effect localInput = getInput();
 166         if (localInput != null) {
 167             localInput.impl_sync();
 168         }
 169 
 170         com.sun.scenario.effect.Glow peer =
 171                 (com.sun.scenario.effect.Glow) impl_getImpl();
 172         peer.setInput(localInput == null ? null : localInput.impl_getImpl());
 173         peer.setLevel((float)Utils.clamp(0, getLevel(), 1));
 174     }
 175 
 176     /**
 177      * @treatAsPrivate implementation detail
 178      * @deprecated This is an internal API that is not intended for use and will be removed in the next version
 179      */
 180     @Deprecated
 181     @Override
 182     public BaseBounds impl_getBounds(BaseBounds bounds,
 183                                      BaseTransform tx,
 184                                      Node node,
 185                                      BoundsAccessor boundsAccessor) {
 186         return getInputBounds(bounds, tx, node, boundsAccessor, getInput());
 187     }
 188 
 189     /**
 190      * @treatAsPrivate implementation detail
 191      * @deprecated This is an internal API that is not intended for use and will be removed in the next version
 192      */
 193     @Deprecated
 194     @Override
 195     public Effect impl_copy() {
 196         return new Glow(this.getLevel());
 197     }
 198 }