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