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.scene.Node;
032
033import com.sun.javafx.Utils;
034import com.sun.javafx.effect.EffectDirtyBits;
035import com.sun.javafx.effect.EffectUtils;
036import com.sun.javafx.geom.BaseBounds;
037import com.sun.javafx.geom.transform.BaseTransform;
038import com.sun.javafx.scene.BoundsAccessor;
039
040
041/**
042 * A blur effect using a Gaussian convolution kernel, with a configurable
043 * radius.
044 *
045 * <p>
046 * Example:
047 * <pre><code>
048 * Text text = new Text();
049 * text.setText("Blurry Text!");
050 * text.setFill(Color.web("0x3b596d"));
051 * text.setFont(Font.font(null, FontWeight.BOLD, 50));
052 * text.setX(10);
053 * text.setY(50);
054 *
055 * text.setEffect(new GaussianBlur());
056 * </pre></code>
057 * <p>
058 * The code above produces the following:
059 * </p>
060 * <p>
061 * <img src="doc-files/gaussianblur.png"/>
062 * </p>
063 */
064public class GaussianBlur extends Effect {
065    /**
066     * Creates a new instance of GaussianBlur with default parameters.
067     */
068    public GaussianBlur() {}
069
070    /**
071     * Creates a new instance of GaussianBlur with the specified radius.
072     * @param radius the radius of the blur kernel
073     */
074    public GaussianBlur(double radius) {
075        setRadius(radius);
076    }
077
078    @Override
079    com.sun.scenario.effect.GaussianBlur impl_createImpl() {
080        return new com.sun.scenario.effect.GaussianBlur();
081    };
082    /**
083     * The input for this {@code Effect}.
084     * If set to {@code null}, or left unspecified, a graphical image of
085     * the {@code Node} to which the {@code Effect} is attached will be
086     * used as the input.
087     * @defaultValue null
088     */
089    private ObjectProperty<Effect> input;
090
091
092    public final void setInput(Effect value) {
093        inputProperty().set(value);
094    }
095
096    public final Effect getInput() {
097        return input == null ? null : input.get();
098    }
099
100    public final ObjectProperty<Effect> inputProperty() {
101        if (input == null) {
102            input = new EffectInputProperty("input");
103        }
104        return input;
105    }
106
107    @Override
108    boolean impl_checkChainContains(Effect e) {
109        Effect localInput = getInput();
110        if (localInput == null)
111            return false;
112        if (localInput == e)
113            return true;
114        return localInput.impl_checkChainContains(e);
115    }
116
117    /**
118     * The radius of the blur kernel.
119     * <pre>
120     *       Min:  0.0
121     *       Max: 63.0
122     *   Default: 10.0
123     *  Identity:  0.0
124     * </pre>
125     * @defaultValue 10.0
126     */
127    private DoubleProperty radius;
128
129
130    public final void setRadius(double value) {
131        radiusProperty().set(value);
132    }
133
134    public final double getRadius() {
135        return radius == null ? 10 : radius.get();
136    }
137
138    public final DoubleProperty radiusProperty() {
139        if (radius == null) {
140            radius = new DoublePropertyBase(10) {
141
142                @Override
143                public void invalidated() {
144                    markDirty(EffectDirtyBits.EFFECT_DIRTY);
145                    effectBoundsChanged();
146                }
147
148                @Override
149                public Object getBean() {
150                    return GaussianBlur.this;
151                }
152
153                @Override
154                public String getName() {
155                    return "radius";
156                }
157            };
158        }
159        return radius;
160    }
161
162    private float getClampedRadius() {
163        return (float) Utils.clamp(0, getRadius(), 63);
164    }
165
166    @Override
167    void impl_update() {
168        Effect localInput = getInput();
169        if (localInput != null) {
170            localInput.impl_sync();
171        }
172
173        com.sun.scenario.effect.GaussianBlur peer =
174                (com.sun.scenario.effect.GaussianBlur) impl_getImpl();
175        peer.setRadius(getClampedRadius());
176        peer.setInput(localInput == null ? null : localInput.impl_getImpl());
177    }
178
179    /**
180     * @treatAsPrivate implementation detail
181     * @deprecated This is an internal API that is not intended for use and will be removed in the next version
182     */
183    @Deprecated
184    @Override
185    public BaseBounds impl_getBounds(BaseBounds bounds,
186                                     BaseTransform tx,
187                                     Node node,
188                                     BoundsAccessor boundsAccessor) {
189        bounds = EffectUtils.getInputBounds(bounds,
190                                            BaseTransform.IDENTITY_TRANSFORM,
191                                            node, boundsAccessor,
192                                            getInput());
193        float r = getClampedRadius();
194        bounds = bounds.deriveWithPadding(r, r, 0);
195        return EffectUtils.transformBounds(tx, bounds);
196    }
197
198    /**
199     * 
200     * @treatAsPrivate implementation detail
201     * @deprecated This is an internal API that is not intended for use and will be removed in the next version
202     */
203    @Deprecated
204    @Override
205    public Effect impl_copy() {
206        return new GaussianBlur(this.getRadius());
207    }
208}