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 filter that produces a sepia tone effect, similar to antique photographs.
043 * 
044 * <p>
045 * Example:
046 * <pre><code>
047 * SepiaTone sepiaTone = new SepiaTone();
048 * sepiaTone.setLevel(0.7);
049 *
050 * Image image = new Image("boat.jpg");
051 * ImageView imageView = new ImageView(image);
052 * imageView.setFitWidth(200);
053 * imageView.setPreserveRatio(true);
054 * imageView.setEffect(sepiaTone);
055 * </pre></code> 
056 * <p> The code above applied on this image: </p>
057 * <p>
058 * <img src="doc-files/photo.png"/>
059 * </p>
060 * <p> produces the following: </p>
061 * <p>
062 * <img src="doc-files/sepiatone.png"/>
063 * </p>
064 */
065public class SepiaTone extends Effect {
066    /**
067     * Creates a new instance of SepiaTone with default parameters.
068     */
069    public SepiaTone() {}
070
071    /**
072     * Creates a new instance of SepiaTone with the specified level.
073     * @param level the level value, which controls the intensity of the effect
074     */
075    public SepiaTone(double level) {
076        setLevel(level);
077    }
078
079    @Override
080    com.sun.scenario.effect.SepiaTone impl_createImpl() {
081        return new com.sun.scenario.effect.SepiaTone();
082    };
083    /**
084     * The input for this {@code Effect}.
085     * If set to {@code null}, or left unspecified, a graphical image of
086     * the {@code Node} to which the {@code Effect} is attached will be
087     * used as the input.
088     * @defaultValue null
089     */
090    private ObjectProperty<Effect> input;
091
092
093    public final void setInput(Effect value) {
094        inputProperty().set(value);
095    }
096
097    public final Effect getInput() {
098        return input == null ? null : input.get();
099    }
100
101    public final ObjectProperty<Effect> inputProperty() {
102        if (input == null) {
103            input = new EffectInputProperty("input");
104        }
105        return input;
106    }
107
108    @Override
109    boolean impl_checkChainContains(Effect e) {
110        Effect localInput = getInput();
111        if (localInput == null)
112            return false;
113        if (localInput == e)
114            return true;
115        return localInput.impl_checkChainContains(e);
116    }
117
118    /**
119     * The level value, which controls the intensity of the sepia effect.
120     * <pre>
121     *       Min: 0.0f
122     *       Max: 1.0f
123     *   Default: 1.0f
124     *  Identity: 0.0f
125     * </pre>
126     * @defaultValue 1.0f
127     */
128    private DoubleProperty level;
129
130
131    public final void setLevel(double value) {
132        levelProperty().set(value);
133    }
134
135    public final double getLevel() {
136        return level == null ? 1 : level.get();
137    }
138
139    public final DoubleProperty levelProperty() {
140        if (level == null) {
141            level = new DoublePropertyBase(1) {
142
143                @Override
144                public void invalidated() {
145                    markDirty(EffectDirtyBits.EFFECT_DIRTY);
146                }
147
148                @Override
149                public Object getBean() {
150                    return SepiaTone.this;
151                }
152
153                @Override
154                public String getName() {
155                    return "level";
156                }
157            };
158        }
159        return level;
160    }
161
162    @Override
163    void impl_update() {
164        Effect localInput = getInput();
165        if (localInput != null) {
166            localInput.impl_sync();
167        }
168
169        com.sun.scenario.effect.SepiaTone peer =
170                (com.sun.scenario.effect.SepiaTone) impl_getImpl();
171        peer.setInput(localInput == null ? null : localInput.impl_getImpl());
172        peer.setLevel((float)Utils.clamp(0, getLevel(), 1));
173    }
174
175    /**
176     * @treatAsPrivate implementation detail
177     * @deprecated This is an internal API that is not intended for use and will be removed in the next version
178     */
179    @Deprecated
180    @Override
181    public BaseBounds impl_getBounds(BaseBounds bounds,
182                                     BaseTransform tx,
183                                     Node node,
184                                     BoundsAccessor boundsAccessor) {
185        return EffectUtils.getInputBounds(bounds, tx,
186                                          node, boundsAccessor,
187                                          getInput());
188    }
189
190    /**
191     * 
192     * @treatAsPrivate implementation detail
193     * @deprecated This is an internal API that is not intended for use and will be removed in the next version
194     */
195    @Deprecated
196    @Override
197    public Effect impl_copy() {
198        SepiaTone st = new SepiaTone(this.getLevel());
199        st.setInput(this.getInput());        
200        return st;
201        
202    }
203}