001: /*
002: * This file is part of the Tucana Echo2 Library.
003: * Copyright (C) 2006.
004: *
005: * Version: MPL 1.1/GPL 2.0/LGPL 2.1
006: *
007: * The contents of this file are subject to the Mozilla Public License Version
008: * 1.1 (the "License"); you may not use this file except in compliance with
009: * the License. You may obtain a copy of the License at
010: * http://www.mozilla.org/MPL/
011: *
012: * Software distributed under the License is distributed on an "AS IS" basis,
013: * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
014: * for the specific language governing rights and limitations under the
015: * License.
016: *
017: * Alternatively, the contents of this file may be used under the terms of
018: * either the GNU General Public License Version 2 or later (the "GPL"), or
019: * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
020: * in which case the provisions of the GPL or the LGPL are applicable instead
021: * of those above. If you wish to allow use of your version of this file only
022: * under the terms of either the GPL or the LGPL, and not to allow others to
023: * use your version of this file under the terms of the MPL, indicate your
024: * decision by deleting the provisions above and replace them with the notice
025: * and other provisions required by the GPL or the LGPL. If you do not delete
026: * the provisions above, a recipient may use your version of this file under
027: * the terms of any one of the MPL, the GPL or the LGPL.
028: */
029:
030: package tucana.echo2.app;
031:
032: import nextapp.echo2.app.Color;
033: import nextapp.echo2.app.Component;
034: import nextapp.echo2.app.FloatingPane;
035: import nextapp.echo2.app.ImageReference;
036: import nextapp.echo2.app.ResourceImageReference;
037:
038: /**
039: * The ModalDimmer component a non-standard component intended to be added to an
040: * application only once. Once added, it will dim everything under to modal
041: * component (usually a windowpane).
042: *
043: * @author Jeremy Volkman
044: *
045: */
046: public class ModalDimmer extends Component implements FloatingPane {
047:
048: /**
049: *
050: */
051: private static final long serialVersionUID = 1L;
052:
053: /**
054: * The dimming type
055: *
056: * @see #DIM_TYPE_OPACITY
057: * @see #DIM_TYPE_IMAGE
058: */
059: public static final String PROPERTY_DIM_TYPE = "dimType";
060:
061: /**
062: * The overlay image to use
063: *
064: * @see #DIM_TYPE_IMAGE
065: */
066: public static final String PROPERTY_DIM_IMAGE = "dimImage";
067:
068: /**
069: * The final dim opacity
070: *
071: * @see #DIM_TYPE_OPACITY
072: */
073: public static final String PROPERTY_DIM_OPACITY = "dimOpacity";
074:
075: /**
076: * The color to use for opacity dimming.
077: *
078: * @see #DIM_TYPE_OPACITY
079: */
080: public static final String PROPERTY_DIM_COLOR = "dimColor";
081:
082: /**
083: * Whether or not dimming should be animated
084: *
085: * @see #DIM_TYPE_OPACITY
086: * @see #PROPERTY_DIM_ANIMATION_SPEED
087: */
088: public static final String PROPERTY_DIM_ANIMATED = "dimAnimated";
089:
090: /**
091: * The dimming speed. Higher numbers are faster.
092: *
093: * @see #DIM_TYPE_OPACITY
094: * @see #PROPERTY_DIM_ANIMATED
095: */
096: public static final String PROPERTY_DIM_ANIMATION_SPEED = "dimAnimationSpeed";
097:
098: /**
099: * Opacity dimming. Use a colored DIV and set an opacity value on it. This
100: * mode supports animated dimming.
101: */
102: public static final int DIM_TYPE_OPACITY = 0;
103:
104: /**
105: * Image dimming. Overlay an alpha-supporting image over the window. This
106: * mode does not support animated dimming.
107: */
108: public static final int DIM_TYPE_IMAGE = 1;
109:
110: /**
111: * Auto selection. This mode favors opacity dimming, but falls back to
112: * image based on browser support. This is probably the desired option.
113: */
114: public static final int DIM_TYPE_AUTO = 2;
115:
116: public ModalDimmer() {
117: setDimType(DIM_TYPE_AUTO);
118: setDimOpacity(0.6f);
119: setDimColor(Color.BLACK);
120: setDimAnimated(true);
121: setDimAnimationSpeed(0.38f);
122: setDimImage(new ResourceImageReference(
123: "tucana/echo2/app/resource/image/translucent_60_percent.png"));
124: }
125:
126: /**
127: * Set the dimming type.
128: * @param type The new dimming type.
129: *
130: * @see #DIM_TYPE_IMAGE
131: * @see #DIM_TYPE_OPACITY
132: */
133: public void setDimType(int type) {
134: if (type != DIM_TYPE_OPACITY && type != DIM_TYPE_IMAGE
135: && type != DIM_TYPE_AUTO) {
136: throw new IllegalArgumentException("Invalid dim type: "
137: + type);
138: }
139:
140: setProperty(PROPERTY_DIM_TYPE, new Integer(type));
141: }
142:
143: /**
144: * Return the current dim type.
145: * @return The current dim type, or <code>-1</code> if one is not set.
146: *
147: * @see #DIM_TYPE_IMAGE
148: * @see #DIM_TYPE_OPACITY
149: */
150: public int getDimType() {
151: Integer type = (Integer) getProperty(PROPERTY_DIM_TYPE);
152: if (type == null) {
153: return -1;
154: }
155:
156: return type.intValue();
157: }
158:
159: /**
160: * Set the dim image to use.
161: * @param dimImage The dim image to use
162: *
163: * @see #DIM_TYPE_IMAGE
164: */
165: public void setDimImage(ImageReference dimImage) {
166: setProperty(PROPERTY_DIM_IMAGE, dimImage);
167: }
168:
169: /**
170: * Get the current dim image.
171: * @return The current dim image, or <code>null</code> if one is not set.
172: */
173: public ImageReference getDimImage() {
174: return (ImageReference) getProperty(PROPERTY_DIM_IMAGE);
175: }
176:
177: /**
178: * Set the dim opacity. Valid values are between 0 and 1.
179: * @param opacity The dim opacity.
180: *
181: * @see #DIM_TYPE_OPACITY
182: */
183: public void setDimOpacity(float opacity) {
184: if (opacity < 0.0f || opacity > 1.0f) {
185: throw new IllegalArgumentException(
186: "Invalid opacity value: " + opacity);
187: }
188: setProperty(PROPERTY_DIM_OPACITY, new Float(opacity));
189: }
190:
191: /**
192: * Get the current dim opacity.
193: * @return The current opacity, or <code>-1.0f</code> if it is not set.
194: */
195: public float getDimOpacity() {
196: Float opacity = (Float) getProperty(PROPERTY_DIM_OPACITY);
197: if (opacity == null) {
198: return -1.0f;
199: }
200: return opacity.floatValue();
201: }
202:
203: /**
204: * Set the opacity dimming color
205: * @param color The opacity dimming color
206: *
207: * @see #DIM_TYPE_OPACITY
208: */
209: public void setDimColor(Color color) {
210: setProperty(PROPERTY_DIM_COLOR, color);
211: }
212:
213: /**
214: * Get the opacity dimming color
215: * @return The opacity dimming color, or <code>null</code> if none is set.
216: */
217: public Color getDimColor() {
218: return (Color) getProperty(PROPERTY_DIM_COLOR);
219: }
220:
221: /**
222: * Set the animation status
223: * @param animated Animation on/off status
224: *
225: * @see #DIM_TYPE_OPACITY
226: */
227: public void setDimAnimated(boolean animated) {
228: setProperty(PROPERTY_DIM_ANIMATED, new Boolean(animated));
229: }
230:
231: /**
232: * Return the current animation on/off status.
233: * @return The current animation on/off status, or <code>false</code>
234: * if it is not set.
235: *
236: * @see #DIM_TYPE_OPACITY
237: */
238: public boolean isDimAnimated() {
239: Boolean animated = (Boolean) getProperty(PROPERTY_DIM_ANIMATED);
240: if (animated == null) {
241: return false;
242: }
243: return animated.booleanValue();
244: }
245:
246: /**
247: * Set the dimming animation speed
248: * @param speed The speed
249: *
250: * @see #DIM_TYPE_OPACITY
251: */
252: public void setDimAnimationSpeed(float speed) {
253: setProperty(PROPERTY_DIM_ANIMATION_SPEED, new Float(speed));
254: }
255:
256: /**
257: * Return the current dim animation speed
258: * @return The current animation speed, or <code>-1.0f</code> if it is not set.
259: *
260: * @see #DIM_TYPE_OPACITY
261: */
262: public float getDimAnimationSpeed() {
263: Float speed = (Float) getProperty(PROPERTY_DIM_ANIMATION_SPEED);
264: if (speed == null) {
265: return -1.0f;
266: }
267: return speed.floatValue();
268: }
269:
270: /**
271: * Disallow the addition of children.
272: */
273: @Override
274: public void add(Component child, int n) {
275: throw new UnsupportedOperationException(
276: "Can't add a child to a ModalDimmer component");
277: }
278: }
|