1 /* 2 * Copyright (c) 2010, 2013, 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 filter that produces a sepia tone effect, similar to antique photographs. 42 * 43 * <p> 44 * Example: 45 * <pre><code> 46 * SepiaTone sepiaTone = new SepiaTone(); 47 * sepiaTone.setLevel(0.7); 48 * 49 * Image image = new Image("boat.jpg"); 50 * ImageView imageView = new ImageView(image); 51 * imageView.setFitWidth(200); 52 * imageView.setPreserveRatio(true); 53 * imageView.setEffect(sepiaTone); 54 * </pre></code> 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/sepiatone.png"/> 62 * </p> 63 * @since JavaFX 2.0 64 */ 65 public class SepiaTone extends Effect { 66 /** 67 * Creates a new instance of SepiaTone with default parameters. 68 */ 69 public SepiaTone() {} 70 71 /** 72 * Creates a new instance of SepiaTone with the specified level. 73 * @param level the level value, which controls the intensity of the effect 74 * @since JavaFX 2.1 75 */ 76 public SepiaTone(double level) { 77 setLevel(level); 78 } 79 80 @Override 81 com.sun.scenario.effect.SepiaTone impl_createImpl() { 82 return new com.sun.scenario.effect.SepiaTone(); 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 sepia effect. 121 * <pre> 122 * Min: 0.0f 123 * Max: 1.0f 124 * Default: 1.0f 125 * Identity: 0.0f 126 * </pre> 127 * @defaultValue 1.0f 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 ? 1 : level.get(); 138 } 139 140 public final DoubleProperty levelProperty() { 141 if (level == null) { 142 level = new DoublePropertyBase(1) { 143 144 @Override 145 public void invalidated() { 146 markDirty(EffectDirtyBits.EFFECT_DIRTY); 147 } 148 149 @Override 150 public Object getBean() { 151 return SepiaTone.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.SepiaTone peer = 171 (com.sun.scenario.effect.SepiaTone) 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 SepiaTone st = new SepiaTone(this.getLevel()); 197 st.setInput(this.getInput()); 198 return st; 199 200 } 201 }