01: package org.columba.core.gui.docking;
02:
03: import java.util.Enumeration;
04: import java.util.Hashtable;
05:
06: import javax.swing.event.EventListenerList;
07:
08: import org.columba.core.gui.docking.event.DockableEvent;
09: import org.columba.core.gui.docking.event.IDockableListener;
10: import org.flexdock.docking.Dockable;
11:
12: public class DockableRegistry {
13:
14: private Hashtable<String, Dockable> hashtable = new Hashtable<String, Dockable>();
15:
16: private static DockableRegistry instance = new DockableRegistry();
17:
18: protected EventListenerList listenerList = new EventListenerList();
19:
20: private DockableRegistry() {
21: super ();
22: }
23:
24: public static DockableRegistry getInstance() {
25: return instance;
26: }
27:
28: public void register(Dockable dockable) {
29: hashtable.put(dockable.getPersistentId(), dockable);
30:
31: fireDockableAdded(dockable);
32: }
33:
34: public Enumeration getDockableEnumeration() {
35: return hashtable.elements();
36: }
37:
38: public void addListener(IDockableListener l) {
39: listenerList.add(IDockableListener.class, l);
40: }
41:
42: public void removeListener(IDockableListener l) {
43: listenerList.remove(IDockableListener.class, l);
44: }
45:
46: public void fireDockableAdded(Dockable dockable) {
47: DockableEvent e = new DockableEvent(this , dockable);
48: // Guaranteed to return a non-null array
49: Object[] listeners = listenerList.getListenerList();
50:
51: // Process the listeners last to first, notifying
52: // those that are interested in this event
53: for (int i = listeners.length - 2; i >= 0; i -= 2) {
54: if (listeners[i] == IDockableListener.class) {
55: ((IDockableListener) listeners[i + 1]).dockableAdded(e);
56: }
57: }
58: }
59:
60: }
|