001 
002 /*
003  *  JScripter Standard 1.0 - To Script In Java
004  *  Copyright (C) 2008-2011  J.J.Liu<jianjunliu@126.com> <http://www.jscripter.org>
005  *  
006  *  This program is free software: you can redistribute it and/or modify
007  *  it under the terms of the GNU Affero General Public License as published by
008  *  the Free Software Foundation, either version 3 of the License, or
009  *  (at your option) any later version.
010  *  
011  *  This program is distributed in the hope that it will be useful,
012  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
013  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
014  *  GNU Affero General Public License for more details.
015  *  
016  *  You should have received a copy of the GNU Affero General Public License
017  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
018  */
019 
020 package jsx.ui.fx.event;
021 
022 import js.Id;
023 import js.Initializer;
024 import js.Js;
025 import js.ObjectLike;
026 import jsx.ui.Widget;
027 import jsx.ui.event.Style;
028 import jsx.ui.fx.Effects;
029 
030 /**
031  * <p>A type of high level events that may be fired from a source widget when 
032  * it is asked for a required animation or has finished an animation.</p>
033  * 
034  * @author <a href="mailto:jianjunliu@126.com">J.J.Liu (Jianjun Liu)</a> at <a href="http://www.jscripter.org" target="_blank">http://www.jscripter.org</a>
035  */
036 public final class Animation extends Widget.Event<OnAnimation>
037 {
038     /**
039      * <p>A global identifier for a configurable property of an {@link Animation} event.</p>
040      * <p>The identified configurable property of an {@link Animation} event 
041      * is a reference to a visual effects that how the animation animates.</p>
042      * @since 1.0
043      */
044     public final static Id<Class<? extends Effects>> FX =
045                     new Id<Class<? extends Effects>>();
046 
047     /**
048      * <p>Constructs an event of this type.</p>
049      * <p>This constructor simply invokes the default constructor of the superclass without 
050      * setting the configurable property {@link #FX}. The event constructed with this 
051      * constructor is expected to only be used as a notification of an animation.</p>
052      * <p>Note that, this constructor does not change the configurable properties 
053      * {@link jsx.Source.Event#BUBBLE} and {@link jsx.Source.Event#UPDATE} of this event object.</p>
054      * @since 1.0
055      */
056     public Animation() {}
057 
058     /**
059      * <p>Constructs an event of this type.</p>
060      * <p>This constructor simply invokes the default constructor of the superclass and sets 
061      * the configurable property {@link #FX} of this event to the specified visual effects. 
062      * The event constructed with this constructor is expected to be used as an animation 
063      * command asking for a specific visual effects.</p>
064      * <p>Note that, this constructor does not change the configurable properties 
065      * {@link jsx.Source.Event#BUBBLE} and {@link jsx.Source.Event#UPDATE} of this event.</p>
066      * @param fx A visual effects object that defines what the animation does.
067      * @since 1.0
068      */
069     public Animation(Class<? extends Effects> fx) {
070         ini(this).var(FX, fx);
071     }
072 
073     /**
074      * <p>Constructs an event of this type.</p>
075      * <p>This constructor simply invokes the default constructor of the superclass and sets 
076      * the configurable property {@link #FX} to the specified visual effects and {@link jsx.ui.event.Style#STYLE} 
077      * to the specified style object. The event constructed with this constructor is expected 
078      * to be used as an animation command asking for a specific visual effects and a critical 
079      * style the visual effects uses.</p>
080      * <p>Note that, this constructor does not change the configurable properties 
081      * {@link jsx.Source.Event#BUBBLE} and {@link jsx.Source.Event#UPDATE} of this event object.</p>
082      * @param fx A visual effects object that defines what the animation does.
083      * @param style A style object the visual effects wants.
084      * @since 1.0
085      */
086     public Animation(Class<? extends Effects> fx, ObjectLike style) {
087         this(fx);
088         ini(this).var(
089                 Style.STYLE,
090                 Js.apply(
091                         new Initializer().var(),
092                         style
093                 )
094         );
095     }
096 
097     /**
098      * <p>Constructs an event of this type.</p>
099      * <p>This constructor simply invokes the default constructor of the superclass and sets 
100      * the configurable property {@link jsx.ui.event.Style#STYLE} to the specified style 
101      * object. The event constructed with this constructor is expected to be used as an 
102      * animation command sending to event listeners of this type with the critical style 
103      * object.</p>
104      * <p>Note that, this constructor does not change the configurable properties 
105      * {@link jsx.Source.Event#BUBBLE} and {@link jsx.Source.Event#UPDATE} of this event object.</p>
106      * @param style A style object the event listeners can use.
107      * @since 1.0
108      */
109     public Animation(ObjectLike style) {
110         this(null, style);
111     }
112 
113     /**
114      * <p>Dispatches this event to the specified event listener to handle, by invoking the 
115      * handler method of the listener interface passing the event itself as the argument.</p>
116      * @param on The event listener that handles this event.
117      * @since 1.0
118      */
119     @Override
120     protected final void execute(OnAnimation on) {
121         on.onEvent(this);
122     }
123 }