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 high-level effect that makes the input image appear to glow, 043 * based on a configurable threshold. 044 * 045 * <p> 046 * Example: 047 * <pre><code> 048 * Image image = new Image("boat.jpg"); 049 * ImageView imageView = new ImageView(image); 050 * imageView.setFitWidth(200); 051 * imageView.setPreserveRatio(true); 052 * 053 * imageView.setEffect(new Glow(0.8)); 054 * </pre></code> 055 * <p> 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/glow.png"/> 063 * </p> 064 */ 065public class Glow extends Effect { 066 /** 067 * Creates a new instance of Glow with default parameters. 068 */ 069 public Glow() {} 070 071 /** 072 * Creates a new instance of Glow with specified level. 073 * @param level the level value, which controls the intensity 074 * of the glow effect 075 */ 076 public Glow(double level) { 077 setLevel(level); 078 } 079 080 @Override 081 com.sun.scenario.effect.Glow impl_createImpl() { 082 return new com.sun.scenario.effect.Glow(); 083 }; 084 /** 085 * The input for this {@code Effect}. 086 * If set to {@code null}, or left unspecified, a graphical image of 087 * the {@code Node} to which the {@code Effect} is attached will be 088 * used as the input. 089 * @defaultValue null 090 */ 091 private ObjectProperty<Effect> input; 092 093 094 public final void setInput(Effect value) { 095 inputProperty().set(value); 096 } 097 098 public final Effect getInput() { 099 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 EffectUtils.getInputBounds(bounds, tx, 187 node, boundsAccessor, 188 getInput()); 189 } 190 191 /** 192 * 193 * @treatAsPrivate implementation detail 194 * @deprecated This is an internal API that is not intended for use and will be removed in the next version 195 */ 196 @Deprecated 197 @Override 198 public Effect impl_copy() { 199 return new Glow(this.getLevel()); 200 } 201}