-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDnDEventMulticaster.java
More file actions
231 lines (212 loc) · 7.2 KB
/
Copy pathDnDEventMulticaster.java
File metadata and controls
231 lines (212 loc) · 7.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
/*
* Copyright (c) 2001, 2013, Oracle and/or its affiliates. All rights reserved.
* ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*/
package java.awt.dnd;
import java.awt.AWTEventMulticaster;
import java.io.ObjectOutputStream;
import java.io.IOException;
import java.util.EventListener;
/**
* A class extends <code>AWTEventMulticaster</code> to implement efficient and
* thread-safe multi-cast event dispatching for the drag-and-drop events defined
* in the java.awt.dnd package.
*
* @since 1.4
* @see AWTEventMulticaster
*/
class DnDEventMulticaster extends AWTEventMulticaster
implements DragSourceListener, DragSourceMotionListener {
/**
* Creates an event multicaster instance which chains listener-a
* with listener-b. Input parameters <code>a</code> and <code>b</code>
* should not be <code>null</code>, though implementations may vary in
* choosing whether or not to throw <code>NullPointerException</code>
* in that case.
*
* @param a listener-a
* @param b listener-b
*/
protected DnDEventMulticaster(EventListener a, EventListener b) {
super(a,b);
}
/**
* Handles the <code>DragSourceDragEvent</code> by invoking
* <code>dragEnter</code> on listener-a and listener-b.
*
* @param dsde the <code>DragSourceDragEvent</code>
*/
public void dragEnter(DragSourceDragEvent dsde) {
((DragSourceListener)a).dragEnter(dsde);
((DragSourceListener)b).dragEnter(dsde);
}
/**
* Handles the <code>DragSourceDragEvent</code> by invoking
* <code>dragOver</code> on listener-a and listener-b.
*
* @param dsde the <code>DragSourceDragEvent</code>
*/
public void dragOver(DragSourceDragEvent dsde) {
((DragSourceListener)a).dragOver(dsde);
((DragSourceListener)b).dragOver(dsde);
}
/**
* Handles the <code>DragSourceDragEvent</code> by invoking
* <code>dropActionChanged</code> on listener-a and listener-b.
*
* @param dsde the <code>DragSourceDragEvent</code>
*/
public void dropActionChanged(DragSourceDragEvent dsde) {
((DragSourceListener)a).dropActionChanged(dsde);
((DragSourceListener)b).dropActionChanged(dsde);
}
/**
* Handles the <code>DragSourceEvent</code> by invoking
* <code>dragExit</code> on listener-a and listener-b.
*
* @param dse the <code>DragSourceEvent</code>
*/
public void dragExit(DragSourceEvent dse) {
((DragSourceListener)a).dragExit(dse);
((DragSourceListener)b).dragExit(dse);
}
/**
* Handles the <code>DragSourceDropEvent</code> by invoking
* <code>dragDropEnd</code> on listener-a and listener-b.
*
* @param dsde the <code>DragSourceDropEvent</code>
*/
public void dragDropEnd(DragSourceDropEvent dsde) {
((DragSourceListener)a).dragDropEnd(dsde);
((DragSourceListener)b).dragDropEnd(dsde);
}
/**
* Handles the <code>DragSourceDragEvent</code> by invoking
* <code>dragMouseMoved</code> on listener-a and listener-b.
*
* @param dsde the <code>DragSourceDragEvent</code>
*/
public void dragMouseMoved(DragSourceDragEvent dsde) {
((DragSourceMotionListener)a).dragMouseMoved(dsde);
((DragSourceMotionListener)b).dragMouseMoved(dsde);
}
/**
* Adds drag-source-listener-a with drag-source-listener-b and
* returns the resulting multicast listener.
*
* @param a drag-source-listener-a
* @param b drag-source-listener-b
*/
public static DragSourceListener add(DragSourceListener a,
DragSourceListener b) {
return (DragSourceListener)addInternal(a, b);
}
/**
* Adds drag-source-motion-listener-a with drag-source-motion-listener-b and
* returns the resulting multicast listener.
*
* @param a drag-source-motion-listener-a
* @param b drag-source-motion-listener-b
*/
public static DragSourceMotionListener add(DragSourceMotionListener a,
DragSourceMotionListener b) {
return (DragSourceMotionListener)addInternal(a, b);
}
/**
* Removes the old drag-source-listener from drag-source-listener-l
* and returns the resulting multicast listener.
*
* @param l drag-source-listener-l
* @param oldl the drag-source-listener being removed
*/
public static DragSourceListener remove(DragSourceListener l,
DragSourceListener oldl) {
return (DragSourceListener)removeInternal(l, oldl);
}
/**
* Removes the old drag-source-motion-listener from
* drag-source-motion-listener-l and returns the resulting multicast
* listener.
*
* @param l drag-source-motion-listener-l
* @param ol the drag-source-motion-listener being removed
*/
public static DragSourceMotionListener remove(DragSourceMotionListener l,
DragSourceMotionListener ol) {
return (DragSourceMotionListener)removeInternal(l, ol);
}
/**
* Returns the resulting multicast listener from adding listener-a
* and listener-b together.
* If listener-a is null, it returns listener-b;
* If listener-b is null, it returns listener-a
* If neither are null, then it creates and returns
* a new AWTEventMulticaster instance which chains a with b.
* @param a event listener-a
* @param b event listener-b
*/
protected static EventListener addInternal(EventListener a, EventListener b) {
if (a == null) return b;
if (b == null) return a;
return new DnDEventMulticaster(a, b);
}
/**
* Removes a listener from this multicaster and returns the
* resulting multicast listener.
* @param oldl the listener to be removed
*/
protected EventListener remove(EventListener oldl) {
if (oldl == a) return b;
if (oldl == b) return a;
EventListener a2 = removeInternal(a, oldl);
EventListener b2 = removeInternal(b, oldl);
if (a2 == a && b2 == b) {
return this; // it's not here
}
return addInternal(a2, b2);
}
/**
* Returns the resulting multicast listener after removing the
* old listener from listener-l.
* If listener-l equals the old listener OR listener-l is null,
* returns null.
* Else if listener-l is an instance of AWTEventMulticaster,
* then it removes the old listener from it.
* Else, returns listener l.
* @param l the listener being removed from
* @param oldl the listener being removed
*/
protected static EventListener removeInternal(EventListener l, EventListener oldl) {
if (l == oldl || l == null) {
return null;
} else if (l instanceof DnDEventMulticaster) {
return ((DnDEventMulticaster)l).remove(oldl);
} else {
return l; // it's not here
}
}
protected static void save(ObjectOutputStream s, String k, EventListener l)
throws IOException {
AWTEventMulticaster.save(s, k, l);
}
}