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.image.Image;
034
035import com.sun.javafx.effect.EffectDirtyBits;
036import com.sun.javafx.effect.EffectUtils;
037import com.sun.javafx.geom.BaseBounds;
038import com.sun.javafx.geom.RectBounds;
039import com.sun.javafx.geom.transform.BaseTransform;
040import com.sun.javafx.scene.BoundsAccessor;
041import com.sun.javafx.tk.Toolkit;
042
043
044/**
045 * A type of source effect that simply passes the given {@code Image}
046 * through, unmodified, as an input to another {@code Effect}.
047 */
048public class ImageInput extends Effect {
049    /**
050     * Creates a new instance of ImageInput with default parameters.
051     */
052    public ImageInput() {}
053
054    /**
055     * Creates a new instance of ImageInput with the specified source.
056     * @param source the source {@code Image}.
057     */
058    public ImageInput(Image source) {
059        setSource(source);
060    }
061
062    /**
063     * Creates a new instance of ImageInput with the specified source, x and y.
064     * @param source the source {@code Image}.
065     * @param x the x location of the source image
066     * @param y the y location of the source image
067     */
068    public ImageInput(Image source, double x, double y) {
069        setSource(source);
070        setX(x);
071        setY(y);
072    }
073
074    @Override
075    com.sun.scenario.effect.Identity impl_createImpl() {
076        return new com.sun.scenario.effect.Identity(null);
077    };
078    /**
079     * The source {@code Image}.
080     */
081    private ObjectProperty<Image> source;
082
083
084    public final void setSource(Image value) {
085        sourceProperty().set(value);
086    }
087
088    public final Image getSource() {
089        return source == null ? null : source.get();
090    }
091
092    public final ObjectProperty<Image> sourceProperty() {
093        if (source == null) {
094            source = new ObjectPropertyBase<Image>() {
095
096                @Override
097                public void invalidated() {
098                    markDirty(EffectDirtyBits.EFFECT_DIRTY);
099                    effectBoundsChanged();
100                }
101
102                @Override
103                public Object getBean() {
104                    return ImageInput.this;
105                }
106
107                @Override
108                public String getName() {
109                    return "source";
110                }
111            };
112        }
113        return source;
114    }
115
116    /**
117     * Sets the x location of the source image, relative to the
118     * local coordinate space of the content {@code Node}.
119     * <pre>
120     *       Min: n/a
121     *       Max: n/a
122     *   Default: 0.0
123     *  Identity: 0.0
124     * </pre>
125     * @defaultValue 0.0
126     */
127    private DoubleProperty x;
128
129
130    public final void setX(double value) {
131        xProperty().set(value);
132    }
133
134    public final double getX() {
135        return x == null ? 0.0 : x.get();
136    }
137
138    public final DoubleProperty xProperty() {
139        if (x == null) {
140            x = new DoublePropertyBase() {
141
142                @Override
143                public void invalidated() {
144                    markDirty(EffectDirtyBits.EFFECT_DIRTY);
145                    effectBoundsChanged();
146                }
147
148                @Override
149                public Object getBean() {
150                    return ImageInput.this;
151                }
152
153                @Override
154                public String getName() {
155                    return "x";
156                }
157            };
158        }
159        return x;
160    }
161
162    /**
163     * Sets the y location of the source image, relative to the
164     * local coordinate space of the content {@code Node}.
165     * <pre>
166     *       Min: n/a
167     *       Max: n/a
168     *   Default: 0.0
169     *  Identity: 0.0
170     * </pre>
171     * @defaultValue 0.0
172     */
173    private DoubleProperty y;
174
175
176    public final void setY(double value) {
177        yProperty().set(value);
178    }
179
180    public final double getY() {
181        return y == null ? 0.0 : y.get();
182    }
183
184    public final DoubleProperty yProperty() {
185        if (y == null) {
186            y = new DoublePropertyBase() {
187
188                @Override
189                public void invalidated() {
190                    markDirty(EffectDirtyBits.EFFECT_DIRTY);
191                    effectBoundsChanged();
192                }
193
194                @Override
195                public Object getBean() {
196                    return ImageInput.this;
197                }
198
199                @Override
200                public String getName() {
201                    return "y";
202                }
203            };
204        }
205        return y;
206    }
207
208    @Override
209    void impl_update() {
210        com.sun.scenario.effect.Identity peer =
211                (com.sun.scenario.effect.Identity) impl_getImpl();
212        Image localSource = getSource();
213        if (localSource != null && localSource.impl_getPlatformImage() != null) {
214            peer.setSource(Toolkit.getToolkit().toFilterable(localSource));
215        } else {
216            peer.setSource(null);
217        }
218        peer.setLocation(new com.sun.javafx.geom.Point2D((float)getX(), (float)getY()));
219    }
220
221    @Override
222    boolean impl_checkChainContains(Effect e) {
223        return false;
224    }
225
226    /**
227     * @treatAsPrivate implementation detail
228     * @deprecated This is an internal API that is not intended for use and will be removed in the next version
229     */
230    @Deprecated
231    @Override
232    public BaseBounds impl_getBounds(BaseBounds bounds,
233                                     BaseTransform tx,
234                                     Node node,
235                                     BoundsAccessor boundsAccessor) {
236        Image localSource = getSource();
237        if (localSource != null && localSource.impl_getPlatformImage() != null) {
238            float localX = (float) getX();
239            float localY = (float) getY();
240            float localWidth = (float) localSource.getWidth();
241            float localHeight = (float) localSource.getHeight();
242            BaseBounds r = new RectBounds(
243                    localX, localY,
244                    localX + localWidth, localY + localHeight);
245            return EffectUtils.transformBounds(tx, r);
246        } else {
247            return new RectBounds();
248        }
249    }
250
251    /**
252     * 
253     * @treatAsPrivate implementation detail
254     * @deprecated This is an internal API that is not intended for use and will be removed in the next version
255     */
256    @Deprecated
257    @Override
258    public Effect impl_copy() {
259        return new ImageInput(this.getSource(), this.getX(), this.getY());
260    }
261}