|
@@ -1,158 +1,158 @@ |
1 |
|
- |
/* |
2 |
|
- |
* Copyright 2008 Google Inc. |
3 |
|
- |
* |
4 |
|
- |
* Licensed under the Apache License, Version 2.0 (the "License"); you may not |
5 |
|
- |
* use this file except in compliance with the License. You may obtain a copy of |
6 |
|
- |
* the License at |
7 |
|
- |
* |
8 |
|
- |
* http://www.apache.org/licenses/LICENSE-2.0 |
9 |
|
- |
* |
10 |
|
- |
* Unless required by applicable law or agreed to in writing, software |
11 |
|
- |
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
12 |
|
- |
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
13 |
|
- |
* License for the specific language governing permissions and limitations under |
14 |
|
- |
* the License. |
15 |
|
- |
*/ |
16 |
|
- |
package com.google.gwt.gen2.event.shared; |
17 |
|
- |
|
18 |
|
- |
/** |
19 |
|
- |
* Root of all gwt events. All gwt events are considered dead and should no |
20 |
|
- |
* longer be accessed once the {@link HandlerManager} which originally fired the |
21 |
|
- |
* event finishes with it. |
22 |
|
- |
* |
23 |
|
- |
* @deprecated use the com.google.gwt.event.shared classes instead |
24 |
|
- |
*/ |
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> { |
39 |
|
- |
|
40 |
|
- |
private int index; |
41 |
|
- |
|
42 |
|
- |
/** |
43 |
|
- |
* Constructor. |
44 |
|
- |
*/ |
45 |
|
- |
public Type() { |
46 |
|
- |
index = HandlerManager.createKeyIndex(); |
47 |
|
- |
} |
48 |
|
- |
|
49 |
|
- |
// We override hash code to make it as efficient as possible. |
50 |
|
- |
@Override |
51 |
|
- |
public final int hashCode() { |
52 |
|
- |
return index; |
53 |
|
- |
} |
54 |
|
- |
|
55 |
|
- |
/** |
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 |
|
- |
} |
158 |
|
- |
} |
|
1 |
+ |
/* |
|
2 |
+ |
* Copyright 2008 Google Inc. |
|
3 |
+ |
* |
|
4 |
+ |
* Licensed under the Apache License, Version 2.0 (the "License"); you may not |
|
5 |
+ |
* use this file except in compliance with the License. You may obtain a copy of |
|
6 |
+ |
* the License at |
|
7 |
+ |
* |
|
8 |
+ |
* http://www.apache.org/licenses/LICENSE-2.0 |
|
9 |
+ |
* |
|
10 |
+ |
* Unless required by applicable law or agreed to in writing, software |
|
11 |
+ |
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
|
12 |
+ |
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
|
13 |
+ |
* License for the specific language governing permissions and limitations under |
|
14 |
+ |
* the License. |
|
15 |
+ |
*/ |
|
16 |
+ |
package com.google.gwt.gen2.event.shared; |
|
17 |
+ |
|
|
18 |
+ |
/** |
|
19 |
+ |
* Root of all gwt events. All gwt events are considered dead and should no |
|
20 |
+ |
* longer be accessed once the {@link HandlerManager} which originally fired the |
|
21 |
+ |
* event finishes with it. |
|
22 |
+ |
* |
|
23 |
+ |
* @deprecated use the com.google.gwt.event.shared classes instead |
|
24 |
+ |
*/ |
|
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> { |
|
39 |
+ |
|
|
40 |
+ |
private int index; |
|
41 |
+ |
|
|
42 |
+ |
/** |
|
43 |
+ |
* Constructor. |
|
44 |
+ |
*/ |
|
45 |
+ |
public Type() { |
|
46 |
+ |
index = HandlerManager.createKeyIndex(); |
|
47 |
+ |
} |
|
48 |
+ |
|
|
49 |
+ |
// We override hash code to make it as efficient as possible. |
|
50 |
+ |
@Override |
|
51 |
+ |
public final int hashCode() { |
|
52 |
+ |
return index; |
|
53 |
+ |
} |
|
54 |
+ |
|
|
55 |
+ |
/** |
|
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 |
+ |
} |
|
158 |
+ |
} |