Subversion Repository Public Repository

litesoft

Diff Revisions 282 vs 475 for /trunk/Java/GWT/Client/src/com/google/gwt/gen2/event/shared/AbstractEvent.java

Diff revisions: vs.
  @@ -19,140 +19,153 @@
19 19 * Root of all gwt events. All gwt events are considered dead and should no
20 20 * longer be accessed once the {@link HandlerManager} which originally fired the
21 21 * event finishes with it.
22 - *
22 + *
23 23 * @deprecated use the com.google.gwt.event.shared classes instead
24 24 */
25 25 @Deprecated
26 - public abstract class AbstractEvent {
27 - /**
28 - * Type class used to register events with the {@link HandlerManager}.
29 - * <p>
30 - * Type is parameterized by the event and handler type in order to make the
31 - * addHandler method type safe and to avoid type-casts when implementing
32 - * {@link AbstractEvent.Type#fire(EventHandler, AbstractEvent)}.
33 - * </p>
34 - *
35 - * @param <EventType> event type
36 - * @param <HandlerType> handler type
37 - */
38 - public abstract static class Type<EventType extends AbstractEvent, HandlerType extends EventHandler> {
26 + public abstract class AbstractEvent
27 + {
28 + /**
29 + * Type class used to register events with the {@link HandlerManager}.
30 + * <p>
31 + * Type is parameterized by the event and handler type in order to make the
32 + * addHandler method type safe and to avoid type-casts when implementing
33 + * {@link AbstractEvent.Type#fire(EventHandler, AbstractEvent)}.
34 + * </p>
35 + *
36 + * @param <EventType> event type
37 + * @param <HandlerType> handler type
38 + */
39 + public abstract static class Type<EventType extends AbstractEvent, HandlerType extends EventHandler>
40 + {
41 +
42 + private int index;
43 +
44 + /**
45 + * Constructor.
46 + */
47 + public Type()
48 + {
49 + index = HandlerManager.createKeyIndex();
50 + }
51 +
52 + // We override hash code to make it as efficient as possible.
53 + @Override
54 + public final int hashCode()
55 + {
56 + return index;
57 + }
58 +
59 + /**
60 + * Fires the given handler on the supplied event.
61 + *
62 + * @param handler the handler to fire
63 + * @param event the event
64 + */
65 + protected abstract void fire( HandlerType handler, EventType event );
66 + }
39 67
40 - private int index;
68 + private boolean dead;
69 +
70 + private Object source;
41 71
42 72 /**
43 73 * Constructor.
44 74 */
45 - public Type() {
46 - index = HandlerManager.createKeyIndex();
75 + protected AbstractEvent()
76 + {
77 + }
78 +
79 + /**
80 + * Returns the source that last fired this event.
81 + *
82 + * @return object representing the source of this event
83 + */
84 + public Object getSource()
85 + {
86 + assertLive();
87 + return source;
47 88 }
48 89
49 - // We override hash code to make it as efficient as possible.
90 + /**
91 + * This is a method used primarily for debugging. It gives a string
92 + * representation of the event details. This does not override the toString
93 + * method because the compiler cannot always optimize toString out correctly.
94 + * Event types should override as desired.
95 + *
96 + * @return a string representing the event's specifics.
97 + */
98 + public String toDebugString()
99 + {
100 + String name = this.getClass().getName();
101 + name = name.substring( name.lastIndexOf( "." ) );
102 + return name + ": source = " + source;
103 + }
104 +
105 + /**
106 + * The toString() for abstract event is overridden to avoid accidently
107 + * including class literals in the the compiled output. Use
108 + * {@link AbstractEvent} #toDebugString to get more information about the
109 + * event.
110 + */
50 111 @Override
51 - public final int hashCode() {
52 - return index;
112 + public String toString()
113 + {
114 + return "An event type";
53 115 }
54 116
55 117 /**
56 - * Fires the given handler on the supplied event.
57 - *
58 - * @param handler the handler to fire
59 - * @param event the event
60 - */
61 - protected abstract void fire(HandlerType handler, EventType event);
62 - }
63 -
64 - private boolean dead;
65 -
66 - private Object source;
67 -
68 - /**
69 - * Constructor.
70 - */
71 - protected AbstractEvent() {
72 - }
73 -
74 - /**
75 - * Returns the source that last fired this event.
76 - *
77 - * @return object representing the source of this event
78 - */
79 - public Object getSource() {
80 - assertLive();
81 - return source;
82 - }
83 -
84 - /**
85 - * This is a method used primarily for debugging. It gives a string
86 - * representation of the event details. This does not override the toString
87 - * method because the compiler cannot always optimize toString out correctly.
88 - * Event types should override as desired.
89 - *
90 - * @return a string representing the event's specifics.
91 - */
92 - public String toDebugString() {
93 - String name = this.getClass().getName();
94 - name = name.substring(name.lastIndexOf("."));
95 - return name + ": source = " + source;
96 - }
97 -
98 - /**
99 - * The toString() for abstract event is overridden to avoid accidently
100 - * including class literals in the the compiled output. Use
101 - * {@link AbstractEvent} #toDebugString to get more information about the
102 - * event.
103 - */
104 - @Override
105 - public String toString() {
106 - return "An event type";
107 - }
108 -
109 - /**
110 - * Asserts that the event still should be accessed. All events are considered
111 - * to be "dead" after their original handler manager finishes firing them. An
112 - * event can be revived by calling {@link AbstractEvent#revive()}.
113 - */
114 - protected void assertLive() {
115 - assert (!dead) : "This event has already finished being processed by its original handler manager, so you can no longer access it";
116 - }
117 -
118 - /**
119 - * Returns the type used to register this event.
120 - *
121 - * @return the type
122 - */
123 - protected abstract Type getType();
124 -
125 - /**
126 - * Is the event current live?
127 - *
128 - * @return whether the event is live
129 - */
130 - protected boolean isLive() {
131 - return !dead;
132 - }
133 -
134 - /**
135 - * Revives the event. Used when recycling event instances.
136 - */
137 - protected void revive() {
138 - dead = false;
139 - }
140 -
141 - /**
142 - * Kills the event. Used when recycling event instances.
143 - */
144 - final void kill() {
145 - dead = true;
146 - source = null;
147 - }
148 -
149 - /**
150 - * Set the source that triggered this event.
151 - *
152 - * @param source the source of this event, should only be set by a
153 - * {@link HandlerManager}
154 - */
155 - void setSource(Object source) {
156 - this.source = source;
157 - }
118 + * Asserts that the event still should be accessed. All events are considered
119 + * to be "dead" after their original handler manager finishes firing them. An
120 + * event can be revived by calling {@link AbstractEvent#revive()}.
121 + */
122 + protected void assertLive()
123 + {
124 + assert (!dead) : "This event has already finished being processed by its original handler manager, so you can no longer access it";
125 + }
126 +
127 + /**
128 + * Returns the type used to register this event.
129 + *
130 + * @return the type
131 + */
132 + protected abstract Type getType();
133 +
134 + /**
135 + * Is the event current live?
136 + *
137 + * @return whether the event is live
138 + */
139 + protected boolean isLive()
140 + {
141 + return !dead;
142 + }
143 +
144 + /**
145 + * Revives the event. Used when recycling event instances.
146 + */
147 + protected void revive()
148 + {
149 + dead = false;
150 + }
151 +
152 + /**
153 + * Kills the event. Used when recycling event instances.
154 + */
155 + final void kill()
156 + {
157 + dead = true;
158 + source = null;
159 + }
160 +
161 + /**
162 + * Set the source that triggered this event.
163 + *
164 + * @param source the source of this event, should only be set by a
165 + * {@link HandlerManager}
166 + */
167 + void setSource( Object source )
168 + {
169 + this.source = source;
170 + }
158 171 }