01: package org.swingml.event;
02:
03: import java.awt.Window;
04: import java.util.*;
05:
06: /**
07: * TODO: ttolle - Look at the construction here and modify for standards and naming
08: * @author ttolle - CrossLogic Corporation
09: */
10: public class WindowNotificationRegistrar {
11: // The single instance
12: private static WindowNotificationRegistrar sole;
13: // The registered window notification listeners
14: private List listeners = null;
15:
16: /**
17: * Private constructor to protect from arbitrary creation
18: */
19: private WindowNotificationRegistrar() {
20: super ();
21: }
22:
23: /**
24: * Retrieves the only created instance of the registrar
25: * @return
26: */
27: public static synchronized WindowNotificationRegistrar sole() {
28: if (sole == null) {
29: sole = new WindowNotificationRegistrar();
30: }
31: return sole;
32: }
33:
34: public synchronized boolean register(
35: WindowNotificationListener listener) {
36: boolean result = false;
37: if (listener != null) {
38: if (listeners == null) {
39: listeners = new ArrayList();
40: }
41: result = listeners.add(listener);
42: }
43: return result;
44: }
45:
46: public synchronized boolean unregister(
47: WindowNotificationListener listener) {
48: boolean result = false;
49: if (listener != null) {
50: result = listeners.remove(listener);
51: }
52: return result;
53: }
54:
55: public void windowAdded(Window window) {
56: if (listeners != null) {
57: List clone = new ArrayList(listeners);
58: Iterator iterator = clone.iterator();
59: while (iterator.hasNext()) {
60: ((WindowNotificationListener) iterator.next())
61: .windowAdded(window);
62: }
63: }
64: }
65:
66: public void windowRemoved(Window window) {
67: if (listeners != null) {
68: List clone = new ArrayList(listeners);
69: Iterator iterator = clone.iterator();
70: while (iterator.hasNext()) {
71: ((WindowNotificationListener) iterator.next())
72: .windowRemoved(window);
73: }
74: }
75: }
76:
77: }
|