KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > jgoodies > animation > AnimationEvent


1 /*
2  * Copyright (c) 2001-2004 JGoodies Karsten Lentzsch. All Rights Reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are met:
6  *
7  * o Redistributions of source code must retain the above copyright notice,
8  * this list of conditions and the following disclaimer.
9  *
10  * o Redistributions in binary form must reproduce the above copyright notice,
11  * this list of conditions and the following disclaimer in the documentation
12  * and/or other materials provided with the distribution.
13  *
14  * o Neither the name of JGoodies Karsten Lentzsch nor the names of
15  * its contributors may be used to endorse or promote products derived
16  * from this software without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
20  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
22  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
25  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
27  * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
28  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  */

30
31 package com.jgoodies.animation;
32
33 /**
34  * Describes events appropriate for animations: started or stopped.
35  *
36  * @author Karsten Lentzsch
37  * @version $Revision: 1.3 $
38  *
39  * @see AnimationListener
40  */

41 public final class AnimationEvent {
42
43     /**
44      * The animation event type for an animation that has been started.
45      */

46     public static final Type STARTED = new Type("Started");
47     
48     /**
49      * The animation event type for an animation that has been stopped.
50      */

51     public static final Type STOPPED = new Type("Stopped");
52     
53     /**
54      * The animation that has been started or stopped.
55      */

56     private final Animation source;
57     
58     /**
59      * Describes the state change of the animation: started or stopped.
60      */

61     private final Type type;
62     
63     /**
64      * Describes when the event has been created.
65      */

66     private final long time;
67
68     
69     // Instance Creation ******************************************************
70

71     /**
72      * Constructs an <code>AnimationEvent</code> for the
73      * initiating animation, event type, and time.
74      *
75      * @param source the <code>Animation</code> that has originated the event
76      * @param type the event type: start or stop
77      * @param time the time the event has happened, which is likely
78      * before the event has been created
79      */

80     AnimationEvent(Animation source, Type type, long time) {
81         this.source = source;
82         this.type = type;
83         this.time = time;
84     }
85     
86     
87     // ************************************************************************
88

89     /**
90      * Returns the animation the has originated this event.
91      *
92      * @return the animation that has originated this event
93      */

94     public Animation getSource() {
95         return source;
96     }
97     
98
99     /**
100      * Returns the event type: started or stopped.
101      *
102      * @return the event type: started or stopped
103      */

104     public Type type() {
105         return type;
106     }
107
108     
109     /**
110      * Returns the time when this event has been created.
111      *
112      * @return the event creation time
113      */

114     public long time() {
115         return time;
116     }
117     
118
119     /**
120      * Returns an appropriate string representation.
121      *
122      * @return a string representation for this event
123      */

124     public String JavaDoc toString() {
125         return "[type= "
126             + type
127             + "; time= "
128             + time
129             + "; source="
130             + source
131             + ']';
132     }
133     
134     
135     // Helper Class ***********************************************************
136

137     /**
138      * A typesafe enumeration for the event types.
139      */

140     private static final class Type {
141         
142         private final String JavaDoc name;
143
144         private Type(String JavaDoc name) {
145             this.name = name;
146         }
147
148         public String JavaDoc toString() {
149             return name;
150         }
151
152     }
153
154     
155 }
Popular Tags