File Source: FrameContainer.java
/*
P/P * Method: com.dmdirc.FrameContainer$IconChanger__static_init
*/
1 /*
2 * Copyright (c) 2006-2009 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;
24
25 import com.dmdirc.config.ConfigManager;
26 import com.dmdirc.interfaces.ConfigChangeListener;
27 import com.dmdirc.interfaces.IconChangeListener;
28 import com.dmdirc.interfaces.NotificationListener;
29 import com.dmdirc.interfaces.SelectionListener;
30 import com.dmdirc.ui.IconManager;
31 import com.dmdirc.ui.interfaces.Window;
32 import com.dmdirc.util.ListenerList;
33
34 import java.awt.Color;
35
36 import javax.swing.Icon;
37
38 /**
39 * The frame container implements basic methods that should be present in
40 * all objects that handle a frame.
41 *
42 * @author chris
43 */
/*
P/P * Method: void access$100(FrameContainer)
*
* Preconditions:
* x0 != null
* init'ed(x0.icon)
* x0.listeners != null
*/
44 public abstract class FrameContainer {
45
46 /** Logger to use. */
/*
P/P * Method: com.dmdirc.FrameContainer__static_init
*
* Postconditions:
* init'ed(LOGGER)
*/
47 private static final java.util.logging.Logger LOGGER = java.util.logging
48 .Logger.getLogger(FrameContainer.class.getName());
49
50 /** The colour of our frame's notifications. */
51 protected Color notification = Color.BLACK;
52
53 /** A list of listeners for this containers's events. */
54 protected final ListenerList listeners = new ListenerList();
55
56 /** The name of the icon being used for this container's frame. */
57 private String icon;
58
59 /** The config manager for this container. */
60 private final ConfigManager config;
61
62 /** The IconChanger for this container. */
63 private final IconChanger changer = new IconChanger();
64
65 /**
66 * Instantiate new frame container.
67 *
68 * @param icon The icon to use for this container
69 * @param config The config manager for this container
70 */
/*
P/P * Method: void com.dmdirc.FrameContainer(String, ConfigManager)
*
* Preconditions:
* config != null
*
* Presumptions:
* init'ed(java.awt.Color.BLACK)
*
* Postconditions:
* this.changer == &new FrameContainer$IconChanger(FrameContainer#2)
* this.config == config
* this.config != null
* this.icon == icon
* init'ed(this.icon)
* this.listeners == &new ListenerList(FrameContainer#1)
* this.notification == java.awt.Color.BLACK
* init'ed(this.notification)
* new FrameContainer$IconChanger(FrameContainer#2) num objects == 1
* new ListenerList(FrameContainer#1) num objects == 1
*/
71 public FrameContainer(final String icon, final ConfigManager config) {
72 this.config = config;
73
74 setIcon(icon);
75 }
76
77 /**
78 * Returns the internal frame associated with this object.
79 *
80 * @return The internal frame associated with this object
81 */
82 public abstract Window getFrame();
83
84 /**
85 * Returns a string identifier for this object/its frame.
86 *
87 * @return String identifier
88 */
89 @Override
90 public abstract String toString();
91
92 /**
93 * Closes this container (and it's associated frame).
94 */
95 public void close() {
/*
P/P * Method: void close()
*
* Presumptions:
* getFrame(...)@96 != null
* getFrame(...)@99 != null
*/
96 if (getFrame() == null) {
97 throw new IllegalStateException("No frame associated with this container!");
98 } else {
99 getFrame().close();
100 }
101 }
102
103 /**
104 * Returns the server instance associated with this container.
105 *
106 * @return the associated server connection
107 */
108 public abstract Server getServer();
109
110 /**
111 * Sets the icon to be used by this frame container.
112 *
113 * @param icon The new icon to be used
114 */
115 public final void setIcon(final String icon) {
/*
P/P * Method: void setIcon(String)
*
* Preconditions:
* this.config != null
* this.listeners != null
*
* Postconditions:
* this.icon == icon
* init'ed(this.icon)
*/
116 this.icon = icon;
117
118 iconUpdated();
119
120 config.removeListener(changer);
121 config.addChangeListener("icon", icon, changer);
122 }
123
124 /**
125 * Called when this container's icon is updated.
126 */
127 private void iconUpdated() {
/*
P/P * Method: void iconUpdated()
*
* Preconditions:
* init'ed(this.icon)
* this.listeners != null
*
* Presumptions:
* com.dmdirc.util.ListenerList:get(...)@131 != null
* java.util.Iterator:next(...)@131 != null
*
* Test Vectors:
* java.util.Iterator:hasNext(...)@131: {1}, {0}
*/
128 final Icon newIcon = getIcon();
129
130 synchronized (listeners) {
131 for (IconChangeListener listener : listeners.get(IconChangeListener.class)) {
132 listener.iconChanged(getFrame(), newIcon);
133 }
134 }
135 }
136
137 /**
138 * Retrieves the icon used by this container's window.
139 *
140 * @return This container's icon
141 */
142 public final Icon getIcon() {
/*
P/P * Method: Icon getIcon()
*
* Preconditions:
* init'ed(this.icon)
*
* Presumptions:
* com.dmdirc.ui.IconManager:getIconManager(...)@143 != null
*
* Postconditions:
* init'ed(return_value)
*/
143 return IconManager.getIconManager().getIcon(icon);
144 }
145
146 /**
147 * Returns the config manager for this container.
148 *
149 * @return the associated config manager
150 */
151 public final ConfigManager getConfigManager() {
/*
P/P * Method: ConfigManager getConfigManager()
*
* Postconditions:
* return_value == this.config
* init'ed(return_value)
*/
152 return config;
153 }
154
155 /**
156 * Requests that this object's frame be activated.
157 */
158 public void activateFrame() {
/*
P/P * Method: void activateFrame()
*
* Presumptions:
* getFrame(...)@159 != null
*/
159 getFrame().activateFrame();
160 }
161
162 /**
163 * Clears any outstanding notifications this frame has set.
164 */
165 protected void clearNotification() {
/*
P/P * Method: void clearNotification()
*
* Preconditions:
* this.listeners != null
*
* Presumptions:
* com.dmdirc.util.ListenerList:get(...)@173 != null
* getFrame(...)@166 != null
* init'ed(java.awt.Color.BLACK)
* java.lang.Object:getClass(...)@166 != null
* java.util.Iterator:next(...)@173 != null
* ...
*
* Postconditions:
* this.notification == java.awt.Color.BLACK
* init'ed(this.notification)
*
* Test Vectors:
* java.util.Iterator:hasNext(...)@173: {1}, {0}
*/
166 LOGGER.finer(toString() + ": clearNotification(): frame = "
167 + (getFrame() == null ? null : getFrame().getClass().getName()));
168
169 // TODO: This should default ot something colour independent
170 notification = Color.BLACK;
171
172 synchronized (listeners) {
173 for (NotificationListener listener : listeners.get(NotificationListener.class)) {
174 listener.notificationCleared(getFrame());
175 }
176 }
177 }
178
179 /**
180 * Sends a notification to the frame manager if this fame isn't active.
181 *
182 * @param colour The colour to use for the notification
183 */
184 public void sendNotification(final Color colour) {
/*
P/P * Method: void sendNotification(Color)
*
* Preconditions:
* com/dmdirc/Main.controller != null
* (soft) colour != null
* (soft) init'ed(this.notification)
* (soft) this.listeners != null
*
* Presumptions:
* com.dmdirc.util.ListenerList:get(...)@192 != null
* java.util.Iterator:next(...)@192 != null
*
* Postconditions:
* this.notification == One-of{old this.notification, colour}
* init'ed(this.notification)
*
* Test Vectors:
* com.dmdirc.ui.interfaces.UIController:getActiveWindow(...)@185: Addr_Set{null}, Inverse{null}
* java.awt.Color:equals(...)@187: {1}, {0}
* java.lang.Object:equals(...)@187: {1}, {0}
*/
185 final Window activeFrame = Main.getUI().getActiveWindow();
186
187 if (activeFrame != null && !activeFrame.equals(getFrame())
188 && !colour.equals(notification)) {
189 notification = colour;
190
191 synchronized (listeners) {
192 for (NotificationListener listener : listeners.get(NotificationListener.class)) {
193 listener.notificationSet(getFrame(), colour);
194 }
195 }
196 }
197 }
198
199 /**
200 * Retrieves the current notification colour of this channel.
201 *
202 * @return This channel's notification colour
203 */
204 public Color getNotification() {
/*
P/P * Method: Color getNotification()
*
* Preconditions:
* init'ed(this.notification)
*
* Postconditions:
* return_value == this.notification
* init'ed(return_value)
*/
205 return notification;
206 }
207
208 /**
209 * Determines if the specified frame is owned by this object.
210 *
211 * @param target Window to check ownership of
212 * @return True iff frame is owned by this container, false otherwise
213 */
214 public boolean ownsFrame(final Window target) {
/*
P/P * Method: bool ownsFrame(Window)
*
* Presumptions:
* getFrame(...)@215 != null
*
* Postconditions:
* init'ed(return_value)
*/
215 return getFrame().equals(target);
216 }
217
218 /**
219 * Invoked when our window has been opened.
220 */
221 public void windowOpened() {
/*
P/P * Method: void windowOpened()
*
* Test Vectors:
* this.config: Addr_Set{null}, Inverse{null}
* getFrame(...)@222: Inverse{null}, Addr_Set{null}
*/
222 if (config == null || getFrame() == null) {
223 return;
224 }
225 }
226
227 /**
228 * Invoked when our window is closing.
229 */
230 public abstract void windowClosing();
231
232 /**
233 * Invoked when our window has been closed.
234 */
235 public void windowClosed() {
236 // Ignore.
/*
P/P * Method: void windowClosed()
*/
237 }
238
239 /**
240 * Invoked when our window is activated.
241 */
242 public void windowActivated() {
/*
P/P * Method: void windowActivated()
*
* Preconditions:
* (soft) this.listeners != null
*
* Presumptions:
* com.dmdirc.util.ListenerList:get(...)@251 != null
* getFrame(...)@243 != null
* getServer(...)@259 != null
* java.lang.Object:getClass(...)@243 != null
* java.util.Iterator:next(...)@251 != null
* ...
*
* Postconditions:
* this.notification == One-of{old this.notification, java.awt.Color.BLACK}
*
* Test Vectors:
* getFrame(...)@246: Inverse{null}, Addr_Set{null}
* getServer(...)@258: Addr_Set{null}, Inverse{null}
* java.util.Iterator:hasNext(...)@251: {1}, {0}
*/
243 LOGGER.finer(toString() + ": windowActivated(): frame = "
244 + (getFrame() == null ? null : getFrame().getClass().getName()));
245
246 if (getFrame() == null) {
247 return;
248 }
249
250 synchronized (listeners) {
251 for (SelectionListener listener : listeners.get(SelectionListener.class)) {
252 listener.selectionChanged(getFrame());
253 }
254 }
255
256 clearNotification();
257
258 if (getServer() != null) {
259 getServer().setActiveFrame(this);
260 }
261 }
262
263 /**
264 * Invoked when our window is deactivated.
265 */
266 public void windowDeactivated() {
/*
P/P * Method: void windowDeactivated()
*
* Presumptions:
* getFrame(...)@267 != null
* java.lang.Object:getClass(...)@267 != null
* java.util.logging.Logger:getLogger(...)@47 != null
*/
267 LOGGER.finer(toString() + ": windowDeactivated(): frame = "
268 + (getFrame() == null ? null : getFrame().getClass().getName()));
269 }
270
271 /**
272 * Adds a line to this container's window. If the window is null for some
273 * reason, the line is silently discarded.
274 *
275 * @param type The message type to use
276 * @param args The message's arguments
277 */
278 protected void addLine(final String type, final Object ... args) {
/*
P/P * Method: void addLine(String, Object[])
*
* Presumptions:
* getFrame(...)@280 != null
*
* Test Vectors:
* getFrame(...)@279: Addr_Set{null}, Inverse{null}
*/
279 if (getFrame() != null) {
280 getFrame().addLine(type, args);
281 }
282 }
283
284 /**
285 * Adds a line to this container's window. If the window is null for some
286 * reason, the line is silently discarded.
287 *
288 * @param type The message type to use
289 * @param args The message's arguments
290 */
291 protected void addLine(final StringBuffer type, final Object ... args) {
/*
P/P * Method: void addLine(StringBuffer, Object[])
*
* Presumptions:
* getFrame(...)@293 != null
*
* Test Vectors:
* getFrame(...)@292: Addr_Set{null}, Inverse{null}
*/
292 if (getFrame() != null) {
293 getFrame().addLine(type, args);
294 }
295 }
296
297 /**
298 * Adds a notification listener for this frame container.
299 *
300 * @param listener The listener to be added
301 */
302 public void addNotificationListener(final NotificationListener listener) {
/*
P/P * Method: void addNotificationListener(NotificationListener)
*
* Preconditions:
* this.listeners != null
*/
303 synchronized (listeners) {
304 listeners.add(NotificationListener.class, listener);
305 }
306 }
307
308 /**
309 * Removes a notification listener from this frame container.
310 *
311 * @param listener The listener to be removed
312 */
313 public void removeNotificationListener(final NotificationListener listener) {
/*
P/P * Method: void removeNotificationListener(NotificationListener)
*
* Preconditions:
* this.listeners != null
*/
314 synchronized (listeners) {
315 listeners.remove(NotificationListener.class, listener);
316 }
317 }
318
319 /**
320 * Adds a selection listener for this frame container.
321 *
322 * @param listener The listener to be added
323 */
324 public void addSelectionListener(final SelectionListener listener) {
/*
P/P * Method: void addSelectionListener(SelectionListener)
*
* Preconditions:
* this.listeners != null
*/
325 synchronized (listeners) {
326 listeners.add(SelectionListener.class, listener);
327 }
328 }
329
330 /**
331 * Removes a selection listener from this frame container.
332 *
333 * @param listener The listener to be removed
334 */
335 public void removeSelectionListener(final SelectionListener listener) {
/*
P/P * Method: void removeSelectionListener(SelectionListener)
*
* Preconditions:
* this.listeners != null
*/
336 synchronized (listeners) {
337 listeners.remove(SelectionListener.class, listener);
338 }
339 }
340
341 /**
342 * Adds an icon change listener for this frame container.
343 *
344 * @param listener The listener to be added
345 */
346 public void addIconChangeListener(final IconChangeListener listener) {
/*
P/P * Method: void addIconChangeListener(IconChangeListener)
*
* Preconditions:
* this.listeners != null
*/
347 synchronized (listeners) {
348 listeners.add(IconChangeListener.class, listener);
349 }
350 }
351
352 /**
353 * Removes an icon change listener from this frame container.
354 *
355 * @param listener The listener to be removed
356 */
357 public void removeIconChangeListener(final IconChangeListener listener) {
/*
P/P * Method: void removeIconChangeListener(IconChangeListener)
*
* Preconditions:
* this.listeners != null
*/
358 synchronized (listeners) {
359 listeners.remove(IconChangeListener.class, listener);
360 }
361 }
362
363 /**
364 * Updates the icon of this frame if its config setting is changed.
365 */
/*
P/P * Method: void com.dmdirc.FrameContainer$IconChanger(FrameContainer, FrameContainer$1)
*/
366 private class IconChanger implements ConfigChangeListener {
367
368 /** {@inheritDoc} */
369 @Override
370 public void configChanged(final String domain, final String key) {
/*
P/P * Method: void configChanged(String, String)
*
* Preconditions:
* init'ed(this.icon)
* this.listeners != null
*/
371 iconUpdated();
372 }
373
374 }
375 }
SofCheck Inspector Build Version : 2.17854
| FrameContainer.java |
2009-Jun-25 01:54:24 |
| FrameContainer.class |
2009-Sep-02 17:04:11 |
| FrameContainer$1.class |
2009-Sep-02 17:04:11 |
| FrameContainer$IconChanger.class |
2009-Sep-02 17:04:11 |