Browse Source

Added NotificationListeners to frame containers

git-svn-id: http://svn.dmdirc.com/trunk@2472 00569f92-eb28-0410-84fd-f71c24880f
tags/0.5.5
Chris Smith 17 years ago
parent
commit
d43af86264

+ 49
- 28
src/com/dmdirc/FrameContainer.java View File

@@ -23,6 +23,7 @@
23 23
 package com.dmdirc;
24 24
 
25 25
 import com.dmdirc.config.ConfigManager;
26
+import com.dmdirc.interfaces.NotificationListener;
26 27
 import com.dmdirc.logger.ErrorLevel;
27 28
 import com.dmdirc.logger.Logger;
28 29
 import com.dmdirc.ui.interfaces.Window;
@@ -31,6 +32,7 @@ import java.awt.Color;
31 32
 import java.beans.PropertyVetoException;
32 33
 
33 34
 import javax.swing.Icon;
35
+import javax.swing.event.EventListenerList;
34 36
 
35 37
 /**
36 38
  * The frame container implements basic methods that should be present in
@@ -39,44 +41,47 @@ import javax.swing.Icon;
39 41
  * @author chris
40 42
  */
41 43
 public abstract class FrameContainer {
42
-    
44
+
43 45
     /** The colour of our frame's notifications. */
44 46
     protected Color notification = Color.BLACK;
45
-    
47
+
48
+    /** A list of listeners for this containers's events. */
49
+    protected final EventListenerList listeners = new EventListenerList();
50
+
46 51
     /** The icon being used for this container's frame. */
47 52
     protected Icon icon;
48
-    
53
+
49 54
     /** Instantiate new frame container. */
50 55
     public FrameContainer() {
51 56
         //Do nothing
52 57
     }
53
-    
58
+
54 59
     /**
55 60
      * Returns the internal frame associated with this object.
56 61
      *
57 62
      * @return The internal frame associated with this object
58 63
      */
59 64
     public abstract Window getFrame();
60
-    
65
+
61 66
     /**
62 67
      * Returns a string identifier for this object/its frame.
63 68
      *
64 69
      * @return String identifier
65 70
      */
66 71
     public abstract String toString();
67
-    
72
+
68 73
     /**
69 74
      * Closes this container (and it's associated frame).
70 75
      */
71 76
     public abstract void close();
72
-    
77
+
73 78
     /**
74 79
      * Returns the server instance associated with this container.
75 80
      *
76 81
      * @return the associated server connection
77 82
      */
78 83
     public abstract Server getServer();
79
-    
84
+
80 85
     /**
81 86
      * Retrieves the icon used by this container's window.
82 87
      *
@@ -85,7 +90,7 @@ public abstract class FrameContainer {
85 90
     public Icon getIcon() {
86 91
         return icon;
87 92
     }
88
-    
93
+
89 94
     /**
90 95
      * Returns the config manager for this container.
91 96
      *
@@ -98,22 +103,30 @@ public abstract class FrameContainer {
98 103
             return getServer().getConfigManager();
99 104
         }
100 105
     }
101
-    
106
+
102 107
     /**
103 108
      * Requests that this object's frame be activated.
104 109
      */
105 110
     public void activateFrame() {
106 111
         Main.getUI().getMainWindow().setActiveFrame(getFrame());
107 112
     }
108
-    
113
+
109 114
     /**
110 115
      * Clears any outstanding notifications this frame has set.
111 116
      */
112 117
     protected void clearNotification() {
118
+        // TODO: This should default ot something colour independent
113 119
         notification = Color.BLACK;
114
-        Main.getUI().getMainWindow().getFrameManager().clearNotification(this);
120
+
121
+        final Object[] listenerList = listeners.getListenerList();
122
+        for (int i = 0; i < listenerList.length; i += 2) {
123
+            if (listenerList[i] == NotificationListener.class) {
124
+                ((NotificationListener) listenerList[i + 1])
125
+                        .notificationCleared(getFrame());
126
+             }
127
+        }        
115 128
     }
116
-    
129
+
117 130
     /**
118 131
      * Sends a notification to the frame manager if this fame isn't active.
119 132
      *
@@ -121,12 +134,20 @@ public abstract class FrameContainer {
121 134
      */
122 135
     public void sendNotification(final Color colour) {
123 136
         final Window activeFrame = Main.getUI().getMainWindow().getActiveFrame();
124
-        if (activeFrame != null && !activeFrame.equals(getFrame())) {
137
+        if (activeFrame != null && !activeFrame.equals(getFrame())
138
+                && !colour.equals(notification)) {
125 139
             notification = colour;
126
-            Main.getUI().getMainWindow().getFrameManager().showNotification(this, colour);
140
+
141
+            final Object[] listenerList = listeners.getListenerList();
142
+            for (int i = 0; i < listenerList.length; i += 2) {
143
+                if (listenerList[i] == NotificationListener.class) {
144
+                    ((NotificationListener) listenerList[i + 1])
145
+                            .notificationSet(getFrame(), colour);
146
+                }
147
+            }
127 148
         }
128 149
     }
129
-    
150
+
130 151
     /**
131 152
      * Retrieves the current notification colour of this channel.
132 153
      *
@@ -135,7 +156,7 @@ public abstract class FrameContainer {
135 156
     public Color getNotification() {
136 157
         return notification;
137 158
     }
138
-    
159
+
139 160
     /**
140 161
      * Determines if the specified frame is owned by this object.
141 162
      *
@@ -145,7 +166,7 @@ public abstract class FrameContainer {
145 166
     public boolean ownsFrame(final Window target) {
146 167
         return getFrame().equals(target);
147 168
     }
148
-    
169
+
149 170
     /**
150 171
      * Invoked when our window has been opened.
151 172
      */
@@ -153,7 +174,7 @@ public abstract class FrameContainer {
153 174
         if (getServer() == null || getConfigManager() == null || getFrame() == null) {
154 175
             return;
155 176
         }
156
-        
177
+
157 178
         final boolean pref = getConfigManager().getOptionBool("ui", "maximisewindows", false);
158 179
         if (pref || Main.getUI().getMainWindow().getMaximised()) {
159 180
             try {
@@ -163,21 +184,21 @@ public abstract class FrameContainer {
163 184
             }
164 185
         }
165 186
     }
166
-    
187
+
167 188
     /**
168 189
      * Invoked when our window is closing.
169 190
      */
170 191
     public void windowClosing() {
171 192
         close();
172 193
     }
173
-    
194
+
174 195
     /**
175 196
      * Invoked when our window has been closed.
176 197
      */
177 198
     public void windowClosed() {
178 199
         // Ignore.
179 200
     }
180
-    
201
+
181 202
     /**
182 203
      * Invoked when our window is activated.
183 204
      */
@@ -185,7 +206,7 @@ public abstract class FrameContainer {
185 206
         if (getFrame() == null) {
186 207
             return;
187 208
         }
188
-        
209
+
189 210
         if (Main.getUI().getMainWindow().getMaximised()) {
190 211
             try {
191 212
                 getFrame().setMaximum(true);
@@ -195,19 +216,19 @@ public abstract class FrameContainer {
195 216
         }
196 217
         Main.getUI().getMainWindow().getFrameManager().setSelected(this);
197 218
         clearNotification();
198
-        
219
+
199 220
         if (getServer() != null) {
200 221
             getServer().setActiveFrame(this);
201 222
         }
202 223
     }
203
-    
224
+
204 225
     /**
205 226
      * Invoked when our window is deactivated.
206 227
      */
207 228
     public void windowDeactivated() {
208 229
         // Do nothing.
209 230
     }
210
-    
231
+
211 232
     /**
212 233
      * Adds a line to this container's window. If the window is null for some
213 234
      * reason, the line is silently discarded.
@@ -220,7 +241,7 @@ public abstract class FrameContainer {
220 241
             getFrame().addLine(type, args);
221 242
         }
222 243
     }
223
-    
244
+
224 245
     /**
225 246
      * Adds a line to this container's window. If the window is null for some
226 247
      * reason, the line is silently discarded.
@@ -233,5 +254,5 @@ public abstract class FrameContainer {
233 254
             getFrame().addLine(type, args);
234 255
         }
235 256
     }
236
-    
257
+
237 258
 }

+ 0
- 3
src/com/dmdirc/Server.java View File

@@ -124,9 +124,6 @@ public final class Server extends WritableFrameContainer implements Serializable
124 124
     /** A list of outstanding invites. */
125 125
     private final List<Invite> invites = new ArrayList<Invite>();
126 126
     
127
-    /** A list of listeners for this server's events. */
128
-    private final EventListenerList listeners = new EventListenerList();
129
-    
130 127
     /**
131 128
      * Creates a new instance of Server.
132 129
      *

+ 1
- 0
src/com/dmdirc/interfaces/InviteListener.java View File

@@ -24,6 +24,7 @@ package com.dmdirc.interfaces;
24 24
 
25 25
 import com.dmdirc.Invite;
26 26
 import com.dmdirc.Server;
27
+
27 28
 import java.util.EventListener;
28 29
 
29 30
 /**

+ 52
- 0
src/com/dmdirc/interfaces/NotificationListener.java View File

@@ -0,0 +1,52 @@
1
+/*
2
+ * Copyright (c) 2006-2007 Chris Smith, Shane Mc Cormack, Gregory Holmes
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in
12
+ * all copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ */
22
+
23
+package com.dmdirc.interfaces;
24
+
25
+import com.dmdirc.ui.interfaces.Window;
26
+
27
+import java.awt.Color;
28
+import java.util.EventListener;
29
+
30
+/**
31
+ * Defines the methods that should be implemented by classes which wish to
32
+ * receive information about notification changes.
33
+ *
34
+ * @author Chris
35
+ */
36
+public interface NotificationListener extends EventListener {
37
+
38
+    /**
39
+     * Called when the notification colour has been changed.
40
+     *
41
+     * @param window The window whose notification has changed
42
+     * @param colour The new colour of the notification
43
+     */
44
+    void notificationSet(final Window window, final Color colour);
45
+
46
+    /**
47
+     * Called when a notification has been cleared.
48
+     *
49
+     * @param window The window whose notification has been cleared
50
+     */
51
+    void notificationCleared(final Window window);
52
+}

Loading…
Cancel
Save