KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > columba > core > gui > docking > DockableRegistry


1 package org.columba.core.gui.docking;
2
3 import java.util.Enumeration JavaDoc;
4 import java.util.Hashtable JavaDoc;
5
6 import javax.swing.event.EventListenerList JavaDoc;
7
8 import org.columba.core.gui.docking.event.DockableEvent;
9 import org.columba.core.gui.docking.event.IDockableListener;
10 import org.flexdock.docking.Dockable;
11
12 public class DockableRegistry {
13
14     private Hashtable JavaDoc<String JavaDoc,Dockable> hashtable = new Hashtable JavaDoc<String JavaDoc,Dockable>();
15
16     private static DockableRegistry instance = new DockableRegistry();
17
18     protected EventListenerList JavaDoc listenerList = new EventListenerList JavaDoc();
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 JavaDoc 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 JavaDoc[] 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 }
61
Popular Tags