001: /*
002: * Copyright (c) 2001-2006 JGoodies Karsten Lentzsch. All Rights Reserved.
003: *
004: * Redistribution and use in source and binary forms, with or without
005: * modification, are permitted provided that the following conditions are met:
006: *
007: * o Redistributions of source code must retain the above copyright notice,
008: * this list of conditions and the following disclaimer.
009: *
010: * o Redistributions in binary form must reproduce the above copyright notice,
011: * this list of conditions and the following disclaimer in the documentation
012: * and/or other materials provided with the distribution.
013: *
014: * o Neither the name of JGoodies Karsten Lentzsch nor the names of
015: * its contributors may be used to endorse or promote products derived
016: * from this software without specific prior written permission.
017: *
018: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
019: * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
020: * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
021: * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
022: * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
023: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
024: * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
025: * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
026: * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
027: * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
028: * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
029: */
030:
031: package com.jgoodies.animation;
032:
033: /**
034: * Describes events appropriate for animations: started or stopped.
035: *
036: * @author Karsten Lentzsch
037: * @version $Revision: 1.1 $
038: *
039: * @see AnimationListener
040: */
041: public final class AnimationEvent {
042:
043: /**
044: * The animation event type for an animation that has been started.
045: */
046: public static final Type STARTED = new Type("Started");
047:
048: /**
049: * The animation event type for an animation that has been stopped.
050: */
051: public static final Type STOPPED = new Type("Stopped");
052:
053: /**
054: * The animation that has been started or stopped.
055: */
056: private final Animation source;
057:
058: /**
059: * Describes the state change of the animation: started or stopped.
060: */
061: private final Type type;
062:
063: /**
064: * Describes when the event has been created.
065: */
066: private final long time;
067:
068: // Instance Creation ******************************************************
069:
070: /**
071: * Constructs an <code>AnimationEvent</code> for the
072: * initiating animation, event type, and time.
073: *
074: * @param source the <code>Animation</code> that has originated the event
075: * @param type the event type: start or stop
076: * @param time the time the event has happened, which is likely
077: * before the event has been created
078: */
079: AnimationEvent(Animation source, Type type, long time) {
080: this .source = source;
081: this .type = type;
082: this .time = time;
083: }
084:
085: // ************************************************************************
086:
087: /**
088: * Returns the animation the has originated this event.
089: *
090: * @return the animation that has originated this event
091: */
092: public Animation getSource() {
093: return source;
094: }
095:
096: /**
097: * Returns the event type: started or stopped.
098: *
099: * @return the event type: started or stopped
100: */
101: public Type type() {
102: return type;
103: }
104:
105: /**
106: * Returns the time when this event has been created.
107: *
108: * @return the event creation time
109: */
110: public long time() {
111: return time;
112: }
113:
114: /**
115: * Returns an appropriate string representation.
116: *
117: * @return a string representation for this event
118: */
119: public String toString() {
120: return "[type= " + type + "; time= " + time + "; source="
121: + source + ']';
122: }
123:
124: // Helper Class ***********************************************************
125:
126: /**
127: * A typesafe enumeration for the event types.
128: */
129: private static final class Type {
130:
131: private final String name;
132:
133: private Type(String name) {
134: this .name = name;
135: }
136:
137: public String toString() {
138: return name;
139: }
140:
141: }
142:
143: }
|