|
@@ -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
|
}
|