001: /*
002: * Copyright (c) 2006-2007 Valerio Proietti
003: *
004: * Permission is hereby granted, free of charge, to any person obtaining a copy
005: * of this software and associated documentation files (the "Software"), to deal
006: * in the Software without restriction, including without limitation the rights
007: * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
008: * copies of the Software, and to permit persons to whom the Software is
009: * furnished to do so, subject to the following conditions:
010: *
011: * The above copyright notice and this permission notice shall be included in
012: * all copies or substantial portions of the Software.
013: *
014: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
015: * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
016: * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
017: * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
018: * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
019: * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
020: * THE SOFTWARE.
021: *
022: * Contributors:
023: * Valerio Proietti - initial API and implementation
024: * MyGWT - derived implementation
025: */
026: package net.mygwt.ui.client.fx;
027:
028: import net.mygwt.ui.client.MyDOM;
029: import net.mygwt.ui.client.util.Rectangle;
030:
031: import com.google.gwt.user.client.Element;
032:
033: /**
034: * Effect for changing a single css style property for a given element.
035: *
036: * <p>
037: * This code is based on code from the MooTools Project by Valerio Proietti.
038: * </p>
039: *
040: * <dl>
041: * <dt><b>Events:</b></dt>
042: *
043: * <dd><b>EffectStart</b> : (source)<br>
044: * <div>Fires after a effect is started.</div>
045: * <ul>
046: * <li>source : this</li>
047: * </ul>
048: * </dd>
049: *
050: * <dd><b>EffecCancel</b> : (source)<br>
051: * <div>Fires after an effect has been cancelled.</div>
052: * <ul>
053: * <li>source : this</li>
054: * </ul>
055: * </dd>
056: *
057: * <dd><b>EffecComplete</b> : (source)<br>
058: * <div>Fires after an effect has been completed.</div>
059: * <ul>
060: * <li>source : this</li>
061: * </ul>
062: * </dd>
063: * </dl>
064: * <dl>
065: */
066: public class FXStyle extends FX {
067:
068: protected String style;
069: protected Element elem;
070:
071: /**
072: * Creates a new instance.
073: *
074: * @param element the animation element
075: */
076: public FXStyle(Element element) {
077: this .elem = element;
078: }
079:
080: /**
081: * Blinks the element.
082: */
083: public void blink() {
084: if (running)
085: return;
086: fps = 20;
087: start(new Effect.Blink(elem));
088: }
089:
090: /**
091: * Fades the element in.
092: */
093: public void fadeIn() {
094: if (running)
095: return;
096: Effect e = new Effect.FadeIn(elem);
097: start(e);
098: }
099:
100: /**
101: * Changes the size of the element.
102: *
103: * @param width the new width
104: * @param height the new height
105: */
106: public void size(int width, int height) {
107: if (running)
108: return;
109: Effect we = new Effect(elem, "width", MyDOM.getWidth(elem),
110: width);
111: Effect he = new Effect(elem, "height", MyDOM.getHeight(elem),
112: height);
113: start(new Effect[] { we, he });
114: }
115:
116: /**
117: * Fades out the element.
118: */
119: public void fadeOut() {
120: if (running)
121: return;
122: Effect e = new Effect.FadeOut(elem);
123: start(e);
124: }
125:
126: /**
127: * Fades the element in or out.
128: */
129: public void fadeToggle() {
130: if (running)
131: return;
132: if (MyDOM.isVisibility(elem)) {
133: fadeOut();
134: } else {
135: fadeIn();
136: }
137: }
138:
139: /**
140: * Moves a element to a new location.
141: *
142: * @param x the end x coordinate
143: * @param y the end y coordinate
144: */
145: public void move(int x, int y) {
146: if (running)
147: return;
148: Rectangle r = MyDOM.getBounds(elem, false);
149: Effect xe = new Effect(elem, "x", r.x, x);
150: Effect ye = new Effect(elem, "y", r.y, y);
151: start(new Effect[] { xe, ye });
152: }
153:
154: /**
155: * Moves and sizes the element.
156: *
157: * @param x the new x coordinate
158: * @param y the new y coordinate
159: * @param width the new width
160: * @param height the new height
161: */
162: public void zoom(int x, int y, int width, int height) {
163: if (running)
164: return;
165: Effect xe = new Effect(elem, "left", MyDOM.getX(elem), x);
166: Effect ye = new Effect(elem, "top", MyDOM.getY(elem), y);
167: Effect we = new Effect(elem, "width", MyDOM.getWidth(elem),
168: width);
169: Effect he = new Effect(elem, "height", MyDOM.getHeight(elem),
170: height);
171: start(new Effect[] { xe, ye, we, he });
172: }
173:
174: /**
175: * Slides the element in.
176: *
177: * @param dir the direction
178: */
179: public void slideIn(int dir) {
180: if (running)
181: return;
182: start(new Effect.SlideIn(dir, elem));
183: }
184:
185: /**
186: * Slides the element out.
187: *
188: * @param dir the direction
189: */
190: public void slideOut(int dir) {
191: if (running)
192: return;
193: start(new Effect.SlideOut(dir, elem));
194: }
195:
196: /**
197: * Creates and starts a new effect.
198: *
199: * @param style the css style being modified
200: * @param from the start value
201: * @param to the end value
202: */
203: public void start(String style, double from, double to) {
204: Effect e = new Effect(elem, style, from, to);
205: start(e);
206: }
207:
208: }
|