1
2 package hep.wired.util;
3
4
5
6
7
8
9
10
11
12
13
14
15
16 import java.awt.*;
17
18 import java.util.*;
19
20 import javax.swing.event.*;
21 import javax.swing.tree.*;
22
23
24 /***
25 * source http://www.fawcette.com/archives/premier/mgznarch/javapro/2001/01jan01/vc0101/vc0101.asp
26 *
27 * @author Mark Donszelmann
28 * @version $Id: SwingEventMulticaster.java 385 2004-08-04 00:27:33Z duns $
29 */
30 public class SwingEventMulticaster extends AWTEventMulticaster
31 implements AncestorListener, CaretListener, CellEditorListener,
32 ChangeListener, DocumentListener, HyperlinkListener,
33 InternalFrameListener, ListDataListener,
34 ListSelectionListener, MenuDragMouseListener,
35 MenuKeyListener, MenuListener, PopupMenuListener,
36 TableColumnModelListener, TableModelListener,
37 TreeExpansionListener, TreeModelListener,
38 TreeSelectionListener, TreeWillExpandListener,
39 UndoableEditListener {
40
41 protected SwingEventMulticaster(EventListener a, EventListener b) {
42 super(a, b);
43 }
44
45
46
47
48 public void ancestorAdded(AncestorEvent event) {
49 ((AncestorListener) a).ancestorAdded(event);
50 ((AncestorListener) b).ancestorAdded(event);
51 }
52
53 public void ancestorRemoved(AncestorEvent event) {
54 ((AncestorListener) a).ancestorRemoved(event);
55 ((AncestorListener) b).ancestorRemoved(event);
56 }
57
58 public void ancestorMoved(AncestorEvent event) {
59 ((AncestorListener) a).ancestorMoved(event);
60 ((AncestorListener) b).ancestorMoved(event);
61 }
62
63 public static AncestorListener add(AncestorListener a,
64 AncestorListener b) {
65 return(AncestorListener) addInternal(a, b);
66 }
67
68 public static AncestorListener remove(AncestorListener l,
69 AncestorListener oldl) {
70 return(AncestorListener) removeInternal(l, oldl);
71 }
72
73
74
75
76 public void caretUpdate(CaretEvent event) {
77 ((CaretListener) a).caretUpdate(event);
78 ((CaretListener) b).caretUpdate(event);
79 }
80
81 public static CaretListener add(CaretListener a, CaretListener b) {
82 return(CaretListener) addInternal(a, b);
83 }
84
85 public static CaretListener remove(CaretListener l, CaretListener oldl) {
86 return(CaretListener) removeInternal(l, oldl);
87 }
88
89
90
91
92 public void editingCanceled(ChangeEvent event) {
93 ((CellEditorListener) a).editingCanceled(event);
94 ((CellEditorListener) b).editingCanceled(event);
95 }
96
97 public void editingStopped(ChangeEvent event) {
98 ((CellEditorListener) a).editingStopped(event);
99 ((CellEditorListener) b).editingStopped(event);
100 }
101
102 public static CellEditorListener add(CellEditorListener a,
103 CellEditorListener b) {
104 return(CellEditorListener) addInternal(a, b);
105 }
106
107 public static CellEditorListener remove(CellEditorListener l,
108 CellEditorListener oldl) {
109 return(CellEditorListener) removeInternal(l, oldl);
110 }
111
112
113
114
115 public void stateChanged(ChangeEvent event) {
116 ((ChangeListener) a).stateChanged(event);
117 ((ChangeListener) b).stateChanged(event);
118 }
119
120 public static ChangeListener add(ChangeListener a, ChangeListener b) {
121 return(ChangeListener) addInternal(a, b);
122 }
123
124 public static ChangeListener remove(ChangeListener l,
125 ChangeListener oldl) {
126 return(ChangeListener) removeInternal(l, oldl);
127 }
128
129
130
131
132 public void insertUpdate(DocumentEvent event) {
133 ((DocumentListener) a).insertUpdate(event);
134 ((DocumentListener) b).insertUpdate(event);
135 }
136
137 public void removeUpdate(DocumentEvent event) {
138 ((DocumentListener) a).removeUpdate(event);
139 ((DocumentListener) b).removeUpdate(event);
140 }
141
142 public void changedUpdate(DocumentEvent event) {
143 ((DocumentListener) a).changedUpdate(event);
144 ((DocumentListener) b).changedUpdate(event);
145 }
146
147 public static DocumentListener add(DocumentListener a,
148 DocumentListener b) {
149 return(DocumentListener) addInternal(a, b);
150 }
151
152 public static DocumentListener remove(DocumentListener l,
153 DocumentListener oldl) {
154 return(DocumentListener) removeInternal(l, oldl);
155 }
156
157
158
159
160 public void hyperlinkUpdate(HyperlinkEvent event) {
161 ((HyperlinkListener) a).hyperlinkUpdate(event);
162 ((HyperlinkListener) b).hyperlinkUpdate(event);
163 }
164
165 public static HyperlinkListener add(HyperlinkListener a,
166 HyperlinkListener b) {
167 return(HyperlinkListener) addInternal(a, b);
168 }
169
170 public static HyperlinkListener remove(HyperlinkListener l,
171 HyperlinkListener oldl) {
172 return(HyperlinkListener) removeInternal(l, oldl);
173 }
174
175
176
177
178 public void internalFrameOpened(InternalFrameEvent event) {
179 ((InternalFrameListener) a).internalFrameOpened(event);
180 ((InternalFrameListener) b).internalFrameOpened(event);
181 }
182
183 public void internalFrameClosing(InternalFrameEvent event) {
184 ((InternalFrameListener) a).internalFrameClosing(event);
185 ((InternalFrameListener) b).internalFrameClosing(event);
186 }
187
188 public void internalFrameClosed(InternalFrameEvent event) {
189 ((InternalFrameListener) a).internalFrameClosed(event);
190 ((InternalFrameListener) b).internalFrameClosed(event);
191 }
192
193 public void internalFrameIconified(InternalFrameEvent event) {
194 ((InternalFrameListener) a).internalFrameIconified(event);
195 ((InternalFrameListener) b).internalFrameIconified(event);
196 }
197
198 public void internalFrameDeiconified(InternalFrameEvent event) {
199 ((InternalFrameListener) a).internalFrameDeiconified(event);
200 ((InternalFrameListener) b).internalFrameDeiconified(event);
201 }
202
203 public void internalFrameActivated(InternalFrameEvent event) {
204 ((InternalFrameListener) a).internalFrameActivated(event);
205 ((InternalFrameListener) b).internalFrameActivated(event);
206 }
207
208 public void internalFrameDeactivated(InternalFrameEvent event) {
209 ((InternalFrameListener) a).internalFrameDeactivated(event);
210 ((InternalFrameListener) b).internalFrameDeactivated(event);
211 }
212
213 public static InternalFrameListener add(InternalFrameListener a,
214 InternalFrameListener b) {
215 return(InternalFrameListener) addInternal(a, b);
216 }
217
218 public static InternalFrameListener remove(InternalFrameListener l,
219 InternalFrameListener oldl) {
220 return(InternalFrameListener) removeInternal(l, oldl);
221 }
222
223
224
225
226 public void intervalAdded(ListDataEvent event) {
227 ((ListDataListener) a).intervalAdded(event);
228 ((ListDataListener) b).intervalAdded(event);
229 }
230
231 public void intervalRemoved(ListDataEvent event) {
232 ((ListDataListener) a).intervalRemoved(event);
233 ((ListDataListener) b).intervalRemoved(event);
234 }
235
236 public void contentsChanged(ListDataEvent event) {
237 ((ListDataListener) a).contentsChanged(event);
238 ((ListDataListener) b).contentsChanged(event);
239 }
240
241 public static ListDataListener add(ListDataListener a,
242 ListDataListener b) {
243 return(ListDataListener) addInternal(a, b);
244 }
245
246 public static ListDataListener remove(ListDataListener l,
247 ListDataListener oldl) {
248 return(ListDataListener) removeInternal(l, oldl);
249 }
250
251
252
253
254 public void valueChanged(ListSelectionEvent event) {
255 ((ListSelectionListener) a).valueChanged(event);
256 ((ListSelectionListener) b).valueChanged(event);
257 }
258
259 public static ListSelectionListener add(ListSelectionListener a,
260 ListSelectionListener b) {
261 return(ListSelectionListener) addInternal(a, b);
262 }
263
264 public static ListSelectionListener remove(ListSelectionListener l,
265 ListSelectionListener oldl) {
266 return(ListSelectionListener) removeInternal(l, oldl);
267 }
268
269
270
271
272 public void menuDragMouseEntered(MenuDragMouseEvent event) {
273 ((MenuDragMouseListener) a).menuDragMouseEntered(event);
274 ((MenuDragMouseListener) b).menuDragMouseEntered(event);
275 }
276
277 public void menuDragMouseExited(MenuDragMouseEvent event) {
278 ((MenuDragMouseListener) a).menuDragMouseExited(event);
279 ((MenuDragMouseListener) b).menuDragMouseExited(event);
280 }
281
282 public void menuDragMouseDragged(MenuDragMouseEvent event) {
283 ((MenuDragMouseListener) a).menuDragMouseDragged(event);
284 ((MenuDragMouseListener) b).menuDragMouseDragged(event);
285 }
286
287 public void menuDragMouseReleased(MenuDragMouseEvent event) {
288 ((MenuDragMouseListener) a).menuDragMouseReleased(event);
289 ((MenuDragMouseListener) b).menuDragMouseReleased(event);
290 }
291
292 public static MenuDragMouseListener add(MenuDragMouseListener a,
293 MenuDragMouseListener b) {
294 return(MenuDragMouseListener) addInternal(a, b);
295 }
296
297 public static MenuDragMouseListener remove(MenuDragMouseListener l,
298 MenuDragMouseListener oldl) {
299 return(MenuDragMouseListener) removeInternal(l, oldl);
300 }
301
302
303
304
305 public void menuKeyTyped(MenuKeyEvent event) {
306 ((MenuKeyListener) a).menuKeyTyped(event);
307 ((MenuKeyListener) b).menuKeyTyped(event);
308 }
309
310 public void menuKeyPressed(MenuKeyEvent event) {
311 ((MenuKeyListener) a).menuKeyPressed(event);
312 ((MenuKeyListener) b).menuKeyPressed(event);
313 }
314
315 public void menuKeyReleased(MenuKeyEvent event) {
316 ((MenuKeyListener) a).menuKeyReleased(event);
317 ((MenuKeyListener) b).menuKeyReleased(event);
318 }
319
320 public static MenuKeyListener add(MenuKeyListener a, MenuKeyListener b) {
321 return(MenuKeyListener) addInternal(a, b);
322 }
323
324 public static MenuKeyListener remove(MenuKeyListener l,
325 MenuKeyListener oldl) {
326 return(MenuKeyListener) removeInternal(l, oldl);
327 }
328
329
330
331
332 public void menuSelected(MenuEvent event) {
333 ((MenuListener) a).menuSelected(event);
334 ((MenuListener) b).menuSelected(event);
335 }
336
337 public void menuDeselected(MenuEvent event) {
338 ((MenuListener) a).menuDeselected(event);
339 ((MenuListener) b).menuDeselected(event);
340 }
341
342 public void menuCanceled(MenuEvent event) {
343 ((MenuListener) a).menuCanceled(event);
344 ((MenuListener) b).menuCanceled(event);
345 }
346
347 public static MenuListener add(MenuListener a, MenuListener b) {
348 return(MenuListener) addInternal(a, b);
349 }
350
351 public static MenuListener remove(MenuListener l, MenuListener oldl) {
352 return(MenuListener) removeInternal(l, oldl);
353 }
354
355
356
357
358 public void popupMenuWillBecomeVisible(PopupMenuEvent event) {
359 ((PopupMenuListener) a).popupMenuWillBecomeVisible(event);
360 ((PopupMenuListener) b).popupMenuWillBecomeVisible(event);
361 }
362
363 public void popupMenuWillBecomeInvisible(PopupMenuEvent event) {
364 ((PopupMenuListener) a).popupMenuWillBecomeInvisible(event);
365 ((PopupMenuListener) b).popupMenuWillBecomeInvisible(event);
366 }
367
368 public void popupMenuCanceled(PopupMenuEvent event) {
369 ((PopupMenuListener) a).popupMenuCanceled(event);
370 ((PopupMenuListener) b).popupMenuCanceled(event);
371 }
372
373 public static PopupMenuListener add(PopupMenuListener a,
374 PopupMenuListener b) {
375 return(PopupMenuListener) addInternal(a, b);
376 }
377
378 public static PopupMenuListener remove(PopupMenuListener l,
379 PopupMenuListener oldl) {
380 return(PopupMenuListener) removeInternal(l, oldl);
381 }
382
383
384
385
386 public void columnAdded(TableColumnModelEvent event) {
387 ((TableColumnModelListener) a).columnAdded(event);
388 ((TableColumnModelListener) b).columnAdded(event);
389 }
390
391 public void columnRemoved(TableColumnModelEvent event) {
392 ((TableColumnModelListener) a).columnRemoved(event);
393 ((TableColumnModelListener) b).columnRemoved(event);
394 }
395
396 public void columnMoved(TableColumnModelEvent event) {
397 ((TableColumnModelListener) a).columnMoved(event);
398 ((TableColumnModelListener) b).columnMoved(event);
399 }
400
401 public void columnMarginChanged(ChangeEvent event) {
402 ((TableColumnModelListener) a).columnMarginChanged(event);
403 ((TableColumnModelListener) b).columnMarginChanged(event);
404 }
405
406 public void columnSelectionChanged(ListSelectionEvent event) {
407 ((TableColumnModelListener) a).columnSelectionChanged(event);
408 ((TableColumnModelListener) b).columnSelectionChanged(event);
409 }
410
411 public static TableColumnModelListener add(TableColumnModelListener a,
412 TableColumnModelListener b) {
413 return(TableColumnModelListener) addInternal(a, b);
414 }
415
416 public static TableColumnModelListener remove(TableColumnModelListener l,
417 TableColumnModelListener oldl) {
418 return(TableColumnModelListener) removeInternal(l, oldl);
419 }
420
421
422
423
424 public void tableChanged(TableModelEvent event) {
425 ((TableModelListener) a).tableChanged(event);
426 ((TableModelListener) b).tableChanged(event);
427 }
428
429 public static TableModelListener add(TableModelListener a,
430 TableModelListener b) {
431 return(TableModelListener) addInternal(a, b);
432 }
433
434 public static TableModelListener remove(TableModelListener l,
435 TableModelListener oldl) {
436 return(TableModelListener) removeInternal(l, oldl);
437 }
438
439
440
441
442 public void treeExpanded(TreeExpansionEvent event) {
443 ((TreeExpansionListener) a).treeExpanded(event);
444 ((TreeExpansionListener) b).treeExpanded(event);
445 }
446
447 public void treeCollapsed(TreeExpansionEvent event) {
448 ((TreeExpansionListener) a).treeCollapsed(event);
449 ((TreeExpansionListener) b).treeCollapsed(event);
450 }
451
452 public static TreeExpansionListener add(TreeExpansionListener a,
453 TreeExpansionListener b) {
454 return(TreeExpansionListener) addInternal(a, b);
455 }
456
457 public static TreeExpansionListener remove(TreeExpansionListener l,
458 TreeExpansionListener oldl) {
459 return(TreeExpansionListener) removeInternal(l, oldl);
460 }
461
462
463
464
465 public void treeNodesChanged(TreeModelEvent event) {
466 ((TreeModelListener) a).treeNodesChanged(event);
467 ((TreeModelListener) b).treeNodesChanged(event);
468 }
469
470 public void treeNodesInserted(TreeModelEvent event) {
471 ((TreeModelListener) a).treeNodesInserted(event);
472 ((TreeModelListener) b).treeNodesInserted(event);
473 }
474
475 public void treeNodesRemoved(TreeModelEvent event) {
476 ((TreeModelListener) a).treeNodesRemoved(event);
477 ((TreeModelListener) b).treeNodesRemoved(event);
478 }
479
480 public void treeStructureChanged(TreeModelEvent event) {
481 ((TreeModelListener) a).treeStructureChanged(event);
482 ((TreeModelListener) b).treeStructureChanged(event);
483 }
484
485 public static TreeModelListener add(TreeModelListener a,
486 TreeModelListener b) {
487 return(TreeModelListener) addInternal(a, b);
488 }
489
490 public static TreeModelListener remove(TreeModelListener l,
491 TreeModelListener oldl) {
492 return(TreeModelListener) removeInternal(l, oldl);
493 }
494
495
496
497
498 public void valueChanged(TreeSelectionEvent event) {
499 ((TreeSelectionListener) a).valueChanged(event);
500 ((TreeSelectionListener) b).valueChanged(event);
501 }
502
503 public static TreeSelectionListener add(TreeSelectionListener a,
504 TreeSelectionListener b) {
505 return(TreeSelectionListener) addInternal(a, b);
506 }
507
508 public static TreeSelectionListener remove(TreeSelectionListener l,
509 TreeSelectionListener oldl) {
510 return(TreeSelectionListener) removeInternal(l, oldl);
511 }
512
513
514
515
516 public void treeWillExpand(TreeExpansionEvent event)
517 throws ExpandVetoException {
518 ((TreeWillExpandListener) a).treeWillExpand(event);
519 ((TreeWillExpandListener) b).treeWillExpand(event);
520 }
521
522 public void treeWillCollapse(TreeExpansionEvent event)
523 throws ExpandVetoException {
524 ((TreeWillExpandListener) a).treeWillCollapse(event);
525 ((TreeWillExpandListener) b).treeWillCollapse(event);
526 }
527
528 public static TreeWillExpandListener add(TreeWillExpandListener a,
529 TreeWillExpandListener b) {
530 return(TreeWillExpandListener) addInternal(a, b);
531 }
532
533 public static TreeWillExpandListener remove(TreeWillExpandListener l,
534 TreeWillExpandListener oldl) {
535 return(TreeWillExpandListener) removeInternal(l, oldl);
536 }
537
538
539
540
541 public void undoableEditHappened(UndoableEditEvent event) {
542 ((UndoableEditListener) a).undoableEditHappened(event);
543 ((UndoableEditListener) b).undoableEditHappened(event);
544 }
545
546 public static UndoableEditListener add(UndoableEditListener a,
547 UndoableEditListener b) {
548 return(UndoableEditListener) addInternal(a, b);
549 }
550
551 public static UndoableEditListener remove(UndoableEditListener l,
552 UndoableEditListener oldl) {
553 return(UndoableEditListener) removeInternal(l, oldl);
554 }
555
556
557
558
559 protected static EventListener addInternal(EventListener a,
560 EventListener b) {
561
562 if(a == null) {
563 return b;
564 }
565
566 if(b == null) {
567 return a;
568 }
569
570 return new SwingEventMulticaster(a, b);
571 }
572
573 protected static EventListener removeInternal(EventListener l,
574 EventListener oldl) {
575
576 if((l == oldl) || (l == null)) {
577 return null;
578 } else if(l instanceof SwingEventMulticaster) {
579 return((SwingEventMulticaster) l).remove(oldl);
580 } else {
581 return l;
582 }
583 }
584 }
585
586
587