Browse Source

Fixes issue 617: window closing procedure

git-svn-id: http://svn.dmdirc.com/trunk@3115 00569f92-eb28-0410-84fd-f71c24880f
tags/0.6
Chris Smith 16 years ago
parent
commit
4d4040f520

+ 20
- 31
src/com/dmdirc/Channel.java View File

@@ -342,44 +342,33 @@ public final class Channel extends MessageTarget
342 342
         window.updateNames(new ArrayList<ChannelClientInfo>());
343 343
     }
344 344
     
345
-    /**
346
-     * Parts the channel and then closes the window.
347
-     */
345
+    /** {@inheritDoc} */
348 346
     @Override
349
-    public void close() {
347
+    public void windowClosing() {
348
+        // 1: Make the window non-visible
349
+        window.setVisible(false);
350
+        
351
+        // 2: Remove any callbacks or listeners
352
+        eventHandler.unregisterCallbacks();
353
+        
354
+        // 3: Trigger any actions neccessary
350 355
         part(configManager.getOption("general", "partmessage"));
351
-        closeWindow();
352
-    }
353
-    
354
-    /**
355
-     * Closes the window without parting the channel.
356
-     */
357
-    public void closeWindow() {
358
-        closeWindow(true);
359
-    }
360
-    
361
-    /**
362
-     * Closes the window without parting the channel.
363
-     *
364
-     * @param shouldRemove Whether we should remove the window from the server
365
-     */
366
-    public void closeWindow(final boolean shouldRemove) {
367
-        if (server.getParser() != null) {
368
-            server.getParser().getCallbackManager().delAllCallback(eventHandler);
369
-        }
370 356
         
357
+        // 4: Trigger action for the window closing
371 358
         ActionManager.processEvent(CoreActionType.CHANNEL_CLOSED, null, this);
372 359
         
373
-        if (shouldRemove) {
374
-            server.delChannel(channelInfo.getName());
375
-        }
360
+        // 5: Inform any parents that the window is closing
361
+        server.delChannel(channelInfo.getName());
376 362
         
377
-        window.setVisible(false);
378
-        Main.getUI().getMainWindow().delChild(window);
363
+        // 6: Remove the window from the window manager
379 364
         WindowManager.removeWindow(window);
380
-        window.close();
381
-        window = null;
382
-        server = null;
365
+        if (server.getParser() != null) {
366
+            server.getParser().getCallbackManager().delAllCallback(eventHandler);
367
+        }
368
+        
369
+        // 7: Remove any references to the window and parents
370
+        window = null; // NOPMD
371
+        server = null; // NOPMD
383 372
     }
384 373
     
385 374
     /**

+ 11
- 4
src/com/dmdirc/CustomWindow.java View File

@@ -93,14 +93,21 @@ public class CustomWindow extends FrameContainer {
93 93
 
94 94
     /** {@inheritDoc} */
95 95
     @Override
96
-    public void close() {
96
+    public void windowClosing() {
97
+        // 1: Make the window non-visible
97 98
         window.setVisible(false);
98
-
99
+        
100
+        // 2: Remove any callbacks or listeners
101
+        // 3: Trigger any actions neccessary
102
+        // 4: Trigger action for the window closing
103
+        // 5: Inform any parents that the window is closing
104
+        
105
+        // 6: Remove the window from the window manager
99 106
         WindowManager.removeWindow(window);
100
-        Main.getUI().getMainWindow().delChild(window);
101 107
         
102
-        window.close();
108
+        // 7: Remove any references to the window and parents
103 109
         window = null; // NOPMD
110
+        parent = null; // NOPMD
104 111
     }
105 112
 
106 113
     /** {@inheritDoc} */

+ 8
- 1
src/com/dmdirc/EventHandler.java View File

@@ -56,7 +56,14 @@ public abstract class EventHandler implements ICallbackInterface {
56 56
             Logger.appError(ErrorLevel.FATAL, "Unable to register callbacks",
57 57
                     exception);
58 58
         }
59
-    }    
59
+    }
60
+    
61
+    /**
62
+     * Unregisters all callbacks that have been registered by this event handler.
63
+     */
64
+    public void unregisterCallbacks() {
65
+        getParser().getCallbackManager().delAllCallback(this);
66
+    }
60 67
     
61 68
     /**
62 69
      * Adds a callback to this event handler.

+ 8
- 4
src/com/dmdirc/FrameContainer.java View File

@@ -77,7 +77,13 @@ public abstract class FrameContainer {
77 77
     /**
78 78
      * Closes this container (and it's associated frame).
79 79
      */
80
-    public abstract void close();
80
+    public final void close() {
81
+        if (getFrame() == null) {
82
+            throw new IllegalStateException("No frame associated with this container!");
83
+        } else {
84
+            getFrame().close();
85
+        }
86
+    }
81 87
 
82 88
     /**
83 89
      * Returns the server instance associated with this container.
@@ -179,9 +185,7 @@ public abstract class FrameContainer {
179 185
     /**
180 186
      * Invoked when our window is closing.
181 187
      */
182
-    public void windowClosing() {
183
-        close();
184
-    }
188
+    public abstract void windowClosing();
185 189
 
186 190
     /**
187 191
      * Invoked when our window has been closed.

+ 24
- 3
src/com/dmdirc/GlobalWindow.java View File

@@ -61,34 +61,55 @@ public class GlobalWindow extends WritableFrameContainer {
61 61
         window.open();
62 62
     }
63 63
 
64
+    /** {@inheritDoc} */
65
+    @Override    
64 66
     public InputWindow getFrame() {
65 67
         return window;
66 68
     }
67 69
 
70
+    /** {@inheritDoc} */
71
+    @Override
68 72
     public String toString() {
69 73
         return "Global";
70 74
     }
71 75
 
72
-    public void close() {
76
+    /** {@inheritDoc} */
77
+    @Override    
78
+    public void windowClosing() {
79
+        // 1: Make the window non-visible
73 80
         window.setVisible(false);
74
-        window.close();
81
+        
82
+        // 2: Remove any callbacks or listeners
83
+        // 3: Trigger any actions neccessary
84
+        // 4: Trigger action for the window closing
85
+        // 5: Inform any parents that the window is closing
86
+        
87
+        // 6: Remove the window from the window manager
75 88
         WindowManager.removeWindow(window);
76
-        Main.getUI().getMainWindow().delChild(window);
89
+        
90
+        // 7: Remove any references to the window and parents        
77 91
     }
78 92
 
93
+    /** {@inheritDoc} */
94
+    @Override    
79 95
     public Server getServer() {
80 96
         return null;
81 97
     }
82 98
 
99
+    /** {@inheritDoc} */
100
+    @Override    
83 101
     public void sendLine(final String line) {
84 102
         GlobalCommandParser.getGlobalCommandParser().parseCommand(window, 
85 103
                 CommandManager.getCommandChar() + line);
86 104
     }
87 105
 
106
+    /** {@inheritDoc} */
107
+    @Override    
88 108
     public int getMaxLineLength() {
89 109
         return 0;
90 110
     }
91 111
     
112
+    /** {@inheritDoc} */
92 113
     @Override
93 114
     public ConfigManager getConfigManager() {
94 115
         return IdentityManager.getGlobalConfig();

+ 87
- 98
src/com/dmdirc/Query.java View File

@@ -54,26 +54,26 @@ import java.io.Serializable;
54 54
  */
55 55
 public final class Query extends MessageTarget implements
56 56
         IPrivateAction, IPrivateMessage, INickChanged, IQuit, Serializable {
57
-    
57
+
58 58
     /**
59 59
      * A version number for this class. It should be changed whenever the class
60 60
      * structure is changed (or anything else that would prevent serialized
61 61
      * objects being unserialized with the new class).
62 62
      */
63 63
     private static final long serialVersionUID = 1;
64
-    
64
+
65 65
     /** The Server this Query is on. */
66 66
     private Server server;
67
-    
67
+
68 68
     /** The QueryWindow used for this Query. */
69 69
     private QueryWindow window;
70
-    
70
+
71 71
     /** The full host of the client associated with this Query. */
72 72
     private String host;
73
-    
73
+
74 74
     /** The tab completer for the query window. */
75 75
     private final TabCompleter tabCompleter;
76
-    
76
+
77 77
     /**
78 78
      * Creates a new instance of Query.
79 79
      *
@@ -82,46 +82,46 @@ public final class Query extends MessageTarget implements
82 82
      */
83 83
     public Query(final Server newServer, final String newHost) {
84 84
         super();
85
-        
85
+
86 86
         this.server = newServer;
87 87
         this.host = newHost;
88
-        
88
+
89 89
         icon = IconManager.getIconManager().getIcon("query");
90
-        
90
+
91 91
         window = Main.getUI().getQuery(this);
92 92
         WindowManager.addWindow(server.getFrame(), window);
93
-        
93
+
94 94
         ActionManager.processEvent(CoreActionType.QUERY_OPENED, null, this);
95
-        
95
+
96 96
         window.setFrameIcon(icon);
97
-        
97
+
98 98
         if (!server.getConfigManager().getOptionBool("general", "hidequeries", false)) {
99 99
             window.open();
100 100
         }
101
-        
101
+
102 102
         tabCompleter = new TabCompleter(server.getTabCompleter());
103 103
         tabCompleter.addEntries(CommandManager.getCommandNames(CommandType.TYPE_QUERY));
104 104
         tabCompleter.addEntries(CommandManager.getCommandNames(CommandType.TYPE_CHAT));
105 105
         window.getInputHandler().setTabCompleter(tabCompleter);
106
-        
106
+
107 107
         reregister();
108
-        
108
+
109 109
         updateTitle();
110 110
     }
111
-    
111
+
112 112
     /**
113 113
      * Shows this query's window.
114 114
      */
115 115
     public void show() {
116 116
         window.open();
117 117
     }
118
-    
118
+
119 119
     /** {@inheritDoc} */
120 120
     @Override
121 121
     public InputWindow getFrame() {
122 122
         return window;
123 123
     }
124
-    
124
+
125 125
     /**
126 126
      * Returns the tab completer for this query.
127 127
      *
@@ -130,7 +130,7 @@ public final class Query extends MessageTarget implements
130 130
     public TabCompleter getTabCompleter() {
131 131
         return tabCompleter;
132 132
     }
133
-    
133
+
134 134
     /** {@inheritDoc} */
135 135
     @Override
136 136
     public void sendLine(final String line) {
@@ -138,24 +138,24 @@ public final class Query extends MessageTarget implements
138 138
             Toolkit.getDefaultToolkit().beep();
139 139
             return;
140 140
         }
141
-        
141
+
142 142
         if (line.indexOf('\n') > -1) {
143 143
             for (String part : line.split("\n")) {
144 144
                 sendLine(part);
145 145
             }
146
-            
146
+
147 147
             return;
148 148
         }
149 149
 
150 150
         final ClientInfo client = server.getParser().getMyself();
151
-        
151
+
152 152
         if (line.length() <= getMaxLineLength()) {
153 153
             server.getParser().sendMessage(ClientInfo.parseHost(host), window.getTranscoder().encode(line));
154
-            
154
+
155 155
             final StringBuffer buff = new StringBuffer("querySelfMessage");
156
-            
156
+
157 157
             ActionManager.processEvent(CoreActionType.QUERY_SELF_MESSAGE, buff, this, line);
158
-            
158
+
159 159
             addLine(buff, client.getNickname(), client.getIdent(),
160 160
                     client.getHost(), window.getTranscoder().encode(line));
161 161
         } else {
@@ -163,13 +163,13 @@ public final class Query extends MessageTarget implements
163 163
             sendLine(line.substring(getMaxLineLength()));
164 164
         }
165 165
     }
166
-    
166
+
167 167
     /** {@inheritDoc} */
168 168
     @Override
169 169
     public int getMaxLineLength() {
170 170
         return server.getParser().getMaxLength("PRIVMSG", host);
171 171
     }
172
-    
172
+
173 173
     /**
174 174
      * Sends a private action to the remote user.
175 175
      *
@@ -181,24 +181,24 @@ public final class Query extends MessageTarget implements
181 181
             Toolkit.getDefaultToolkit().beep();
182 182
             return;
183 183
         }
184
-        
184
+
185 185
         final ClientInfo client = server.getParser().getMyself();
186 186
         final int maxLineLength = server.getParser().getMaxLength("PRIVMSG", host);
187
-        
187
+
188 188
         if (maxLineLength >= action.length() + 2) {
189 189
             server.getParser().sendAction(ClientInfo.parseHost(host), window.getTranscoder().encode(action));
190
-            
190
+
191 191
             final StringBuffer buff = new StringBuffer("querySelfAction");
192
-            
192
+
193 193
             ActionManager.processEvent(CoreActionType.QUERY_SELF_ACTION, buff, this, action);
194
-            
194
+
195 195
             addLine(buff, client.getNickname(), client.getIdent(),
196 196
                     client.getHost(), window.getTranscoder().encode(action));
197 197
         } else {
198 198
             addLine("actionTooLong", action.length());
199 199
         }
200 200
     }
201
-    
201
+
202 202
     /**
203 203
      * Handles a private message event from the parser.
204 204
      *
@@ -210,14 +210,14 @@ public final class Query extends MessageTarget implements
210 210
     public void onPrivateMessage(final IRCParser parser, final String message,
211 211
             final String remoteHost) {
212 212
         final String[] parts = ClientInfo.parseHostFull(remoteHost);
213
-        
213
+
214 214
         final StringBuffer buff = new StringBuffer("queryMessage");
215
-        
215
+
216 216
         ActionManager.processEvent(CoreActionType.QUERY_MESSAGE, buff, this, message);
217
-        
217
+
218 218
         addLine(buff, parts[0], parts[1], parts[2], message);
219 219
     }
220
-    
220
+
221 221
     /**
222 222
      * Handles a private action event from the parser.
223 223
      *
@@ -229,33 +229,33 @@ public final class Query extends MessageTarget implements
229 229
     public void onPrivateAction(final IRCParser parser, final String message,
230 230
             final String remoteHost) {
231 231
         final String[] parts = ClientInfo.parseHostFull(host);
232
-        
232
+
233 233
         final StringBuffer buff = new StringBuffer("queryAction");
234
-        
234
+
235 235
         ActionManager.processEvent(CoreActionType.QUERY_ACTION, buff, this, message);
236
-        
236
+
237 237
         addLine(buff, parts[0], parts[1], parts[2], message);
238 238
     }
239
-    
239
+
240 240
     /**
241 241
      * Updates the QueryWindow's title.
242 242
      */
243 243
     private void updateTitle() {
244 244
         final String title = ClientInfo.parseHost(host);
245
-        
245
+
246 246
         window.setTitle(title);
247
-        
247
+
248 248
         if (window.isMaximum() && window.equals(Main.getUI().getMainWindow().getActiveFrame())) {
249 249
             Main.getUI().getMainWindow().setTitle(Main.getUI().getMainWindow().getTitlePrefix() + " - " + title);
250 250
         }
251 251
     }
252
-    
252
+
253 253
     /**
254 254
      * Reregisters query callbacks. Called when reconnecting to the server.
255 255
      */
256 256
     public void reregister() {
257 257
         final CallbackManager callbackManager = server.getParser().getCallbackManager();
258
-        
258
+
259 259
         try {
260 260
             callbackManager.addCallback("onPrivateAction", this, ClientInfo.parseHost(host));
261 261
             callbackManager.addCallback("onPrivateMessage", this, ClientInfo.parseHost(host));
@@ -265,38 +265,38 @@ public final class Query extends MessageTarget implements
265 265
             Logger.appError(ErrorLevel.HIGH, "Unable to get query events", ex);
266 266
         }
267 267
     }
268
-    
268
+
269 269
     /** {@inheritDoc} */
270 270
     @Override
271 271
     public void onNickChanged(final IRCParser tParser, final ClientInfo cClient,
272 272
             final String sOldNick) {
273 273
         if (sOldNick.equals(ClientInfo.parseHost(host))) {
274 274
             final CallbackManager callbackManager = server.getParser().getCallbackManager();
275
-            
275
+
276 276
             callbackManager.delCallback("onPrivateAction", this);
277 277
             callbackManager.delCallback("onPrivateMessage", this);
278
-            
278
+
279 279
             try {
280 280
                 callbackManager.addCallback("onPrivateAction", this, cClient.getNickname());
281 281
                 callbackManager.addCallback("onPrivateMessage", this, cClient.getNickname());
282 282
             } catch (CallbackNotFoundException ex) {
283 283
                 Logger.appError(ErrorLevel.HIGH, "Unable to get query events", ex);
284 284
             }
285
-            
285
+
286 286
             final StringBuffer format = new StringBuffer("queryNickChanged");
287
-            
287
+
288 288
             ActionManager.processEvent(CoreActionType.QUERY_NICKCHANGE, format, this, sOldNick);
289
-            
289
+
290 290
             server.getTabCompleter().removeEntry(sOldNick);
291 291
             server.getTabCompleter().addEntry(cClient.getNickname());
292
-            
292
+
293 293
             addLine(format, sOldNick, cClient.getIdent(),
294 294
                     cClient.getHost(), cClient.getNickname());
295 295
             host = cClient.getNickname() + "!" + cClient.getIdent() + "@" + cClient.getHost();
296 296
             updateTitle();
297 297
         }
298 298
     }
299
-    
299
+
300 300
     /** {@inheritDoc} */
301 301
     @Override
302 302
     public void onQuit(final IRCParser tParser, final ClientInfo cClient,
@@ -304,14 +304,14 @@ public final class Query extends MessageTarget implements
304 304
         if (cClient.getNickname().equals(ClientInfo.parseHost(host))) {
305 305
             final StringBuffer format = new StringBuffer(sReason.isEmpty() ?
306 306
                 "queryQuit" : "queryQuitReason");
307
-            
307
+
308 308
             ActionManager.processEvent(CoreActionType.QUERY_QUIT, format, this, sReason);
309
-            
309
+
310 310
             addLine(format, cClient.getNickname(),
311 311
                     cClient.getIdent(), cClient.getHost(), sReason);
312 312
         }
313 313
     }
314
-    
314
+
315 315
     /**
316 316
      * Returns the Server assocaited with this query.
317 317
      *
@@ -321,45 +321,34 @@ public final class Query extends MessageTarget implements
321 321
     public Server getServer() {
322 322
         return server;
323 323
     }
324
-    
325
-    /**
326
-     * Closes the query and associated window.
327
-     */
324
+
325
+    /** {@inheritDoc} */
328 326
     @Override
329
-    public void close() {
330
-        close(true);
331
-    }
332
-    
333
-    /**
334
-     * Closes the query and associated window.
335
-     *
336
-     * @param shouldRemove Whether or not we should remove the window from the server.
337
-     */
338
-    public void close(final boolean shouldRemove) {
327
+    public void windowClosing() {
328
+        // 1: Make the window non-visible
329
+        window.setVisible(false);
330
+
331
+        // 2: Remove any callbacks or listeners
339 332
         if (server != null && server.getParser() != null) {
340
-            server.getParser().getCallbackManager().delCallback("onPrivateAction", this);
341
-            server.getParser().getCallbackManager().delCallback("onPrivateMessage", this);
342
-            server.getParser().getCallbackManager().delCallback("onNickChanged", this);
343
-            server.getParser().getCallbackManager().delCallback("onQuit", this);
333
+            server.getParser().getCallbackManager().delAllCallback(this);
344 334
         }
345
-        
335
+
336
+        // 3: Trigger any actions neccessary
337
+
338
+        // 4: Trigger action for the window closing
346 339
         ActionManager.processEvent(CoreActionType.QUERY_CLOSED, null, this);
347
-        
348
-        if (server != null && shouldRemove) {
349
-            server.delQuery(this);
350
-        }
351
-        
352
-        if (window != null) {
353
-            Main.getUI().getMainWindow().delChild(window);
354
-            WindowManager.removeWindow(window);
355
-            window.close();
356
-            window.setVisible(false);
357
-        }
358
-        
340
+
341
+        // 5: Inform any parents that the window is closing
342
+        server.delQuery(this);
343
+
344
+        // 6: Remove the window from the window manager
345
+        WindowManager.removeWindow(window);
346
+
347
+        // 7: Remove any references to the window and parents
359 348
         window = null;
360 349
         server = null;
361 350
     }
362
-    
351
+
363 352
     /**
364 353
      * Returns this query's name.
365 354
      *
@@ -369,7 +358,7 @@ public final class Query extends MessageTarget implements
369 358
     public String toString() {
370 359
         return ClientInfo.parseHost(host);
371 360
     }
372
-    
361
+
373 362
     /**
374 363
      * Returns the host that this query is with.
375 364
      *
@@ -378,30 +367,30 @@ public final class Query extends MessageTarget implements
378 367
     public String getHost() {
379 368
         return host;
380 369
     }
381
-    
370
+
382 371
     /**
383 372
      * Returns the current nickname of the user that this query is with.
384
-     * 
373
+     *
385 374
      * @return The nickname of this query's user
386 375
      */
387 376
     public String getNickname() {
388 377
         return ClientInfo.parseHost(host);
389 378
     }
390
-    
379
+
391 380
     /** {@inheritDoc} */
392 381
     @Override
393 382
     public void activateFrame() {
394 383
         if (window == null) {
395 384
             return;
396 385
         }
397
-        
386
+
398 387
         if (!window.isVisible()) {
399 388
             show();
400 389
         }
401
-        
390
+
402 391
         Main.getUI().getMainWindow().setActiveFrame(window);
403 392
     }
404
-    
393
+
405 394
     /** {@inheritDoc} */
406 395
     @Override
407 396
     public ConfigManager getConfigManager() {
@@ -410,8 +399,8 @@ public final class Query extends MessageTarget implements
410 399
                     " from a query with no server", new IllegalStateException("My host: " + host));
411 400
             return IdentityManager.getGlobalConfig();
412 401
         }
413
-        
402
+
414 403
         return server.getConfigManager();
415
-    }    
416
-    
404
+    }
405
+
417 406
 }

+ 22
- 8
src/com/dmdirc/Raw.java View File

@@ -92,54 +92,68 @@ public final class Raw extends WritableFrameContainer implements IDataIn,
92 92
     
93 93
     /** {@inheritDoc} */
94 94
     @Override
95
-    public void close() {
96
-        if (server.getParser() != null) {
97
-            server.getParser().getCallbackManager().delCallback("OnDataIn", this);
98
-            server.getParser().getCallbackManager().delCallback("OnDataOut", this);
95
+    public void windowClosing() {
96
+        // 1: Make the window non-visible
97
+        window.setVisible(false);
98
+        
99
+        // 2: Remove any callbacks or listeners
100
+        if (server != null && server.getParser() != null) {
101
+            server.getParser().getCallbackManager().delAllCallback(this);
99 102
         }
100 103
         
101
-        window.setVisible(false);
102
-        WindowManager.removeWindow(window);
103
-        Main.getUI().getMainWindow().delChild(window);
104
+        // 3: Trigger any actions neccessary
105
+        // 4: Trigger action for the window closing
104 106
         
107
+        // 5: Inform any parents that the window is closing
105 108
         server.delRaw();
106
-        window.close();
109
+        
110
+        // 6: Remove the window from the window manager
111
+        WindowManager.removeWindow(window);
112
+        
113
+        // 7: Remove any references to the window and parents
107 114
         window = null;
108 115
         server = null;
109 116
     }
110 117
     
111 118
     /** {@inheritDoc} */
119
+    @Override
112 120
     public InputWindow getFrame() {
113 121
         return window;
114 122
     }
115 123
     
116 124
     /** {@inheritDoc} */
125
+    @Override
117 126
     public void onDataIn(final IRCParser tParser, final String sData) {
118 127
         addLine("rawIn", sData);
119 128
     }
120 129
     
121 130
     /** {@inheritDoc} */
131
+    @Override
122 132
     public void onDataOut(final IRCParser tParser, final String sData,
123 133
             final boolean bFromParser) {
124 134
         addLine("rawOut", sData);
125 135
     }
126 136
     
127 137
     /** {@inheritDoc} */
138
+    @Override
128 139
     public String toString() {
129 140
         return "Raw";
130 141
     }
131 142
     
132 143
     /** {@inheritDoc} */
144
+    @Override
133 145
     public Server getServer() {
134 146
         return server;
135 147
     }
136 148
     
137 149
     /** {@inheritDoc} */
150
+    @Override
138 151
     public void sendLine(final String line) {
139 152
         server.sendLine(window.getTranscoder().encode(line));
140 153
     }
141 154
     
142 155
     /** {@inheritDoc} */
156
+    @Override
143 157
     public int getMaxLineLength() {
144 158
         return server.getMaxLineLength();
145 159
     }

+ 32
- 38
src/com/dmdirc/Server.java View File

@@ -296,6 +296,13 @@ public final class Server extends WritableFrameContainer implements Serializable
296 296
     public void reconnect() {
297 297
         reconnect(configManager.getOption(DOMAIN_GENERAL, "reconnectmessage"));
298 298
     }
299
+    
300
+    /**
301
+     * Disconnects from the server with the default quit message.
302
+     */
303
+    public void disconnect() {
304
+        disconnect(configManager.getOption(DOMAIN_GENERAL, "quitmessage"));
305
+    }
299 306
 
300 307
     /**
301 308
      * Disconnects from the server.
@@ -800,61 +807,50 @@ public final class Server extends WritableFrameContainer implements Serializable
800 807
         return myState;
801 808
     }
802 809
 
803
-    /**
804
-     * Closes this server connection and associated windows.
805
-     *
806
-     * @param reason reason for closing
807
-     */
808
-    public void close(final String reason) {
810
+    /** {@inheritDoc} */
811
+    @Override
812
+    public void windowClosing() {
813
+        // 1: Make the window non-visible
814
+        window.setVisible(false);
815
+        
816
+        // 2: Remove any callbacks or listeners
809 817
         if (parser != null) {
810
-            // Unregister parser callbacks
811 818
             parser.getCallbackManager().delAllCallback(eventHandler);
812 819
         }
813
-
814
-        // Disconnect from the server
815
-        disconnect(reason);
816
-
820
+        
821
+        // 3: Trigger any actions neccessary
822
+        if (parser != null && parser.isReady()) {
823
+            disconnect();
824
+        }
825
+        
817 826
         myState = ServerState.CLOSING;
818
-
819
-        // Close all channel windows
820 827
         closeChannels();
821
-        // Close all query windows
822 828
         closeQueries();
823
-        // Close the raw window
829
+
824 830
         if (raw != null) {
825 831
             raw.close();
826 832
         }
827 833
         
828
-        // Unregister ourselves with the server manager
834
+        
835
+        // 4: Trigger action for the window closing
836
+        // 5: Inform any parents that the window is closing
829 837
         ServerManager.getServerManager().unregisterServer(this);
830
-
831
-        if (window != null) {
832
-            window.setVisible(false);
833
-            WindowManager.removeWindow(window);
834
-            Main.getUI().getMainWindow().delChild(window);
835
-            window.close();
836
-            window = null; //NOPMD
837
-        }
838
-
839
-        // Ditch the parser
838
+        
839
+        // 6: Remove the window from the window manager
840
+        WindowManager.removeWindow(window);
841
+        
842
+        // 7: Remove any references to the window and parents
843
+        window = null; //NOPMD
840 844
         parser = null; //NOPMD
841 845
     }
842 846
 
843
-    /** {@inheritDoc} */
844
-    @Override
845
-    public void close() {
846
-        close(configManager.getOption(DOMAIN_GENERAL, "quitmessage"));
847
-    }
848
-
849 847
     /**
850 848
      * Closes all open channel windows associated with this server.
851 849
      */
852 850
     private void closeChannels() {
853 851
         for (Channel channel : new ArrayList<Channel>(channels.values())) {
854
-            channel.closeWindow(false);
852
+            channel.close();
855 853
         }
856
-
857
-        channels.clear();
858 854
     }
859 855
 
860 856
     /**
@@ -871,10 +867,8 @@ public final class Server extends WritableFrameContainer implements Serializable
871 867
      */
872 868
     private void closeQueries() {
873 869
         for (Query query : new ArrayList<Query>(queries)) {
874
-            query.close(false);
870
+            query.close();
875 871
         }
876
-
877
-        queries.clear();
878 872
     }
879 873
 
880 874
     /**

+ 8
- 20
src/com/dmdirc/ServerManager.java View File

@@ -23,7 +23,6 @@
23 23
 package com.dmdirc;
24 24
 
25 25
 import com.dmdirc.config.IdentityManager;
26
-import com.dmdirc.ui.WindowManager;
27 26
 import com.dmdirc.ui.interfaces.Window;
28 27
 
29 28
 import java.util.ArrayList;
@@ -40,12 +39,6 @@ public final class ServerManager {
40 39
     /** Singleton instance of ServerManager. */
41 40
     private static ServerManager me;
42 41
     
43
-    /**
44
-     * Indicates that the server manager is in the process of closing all
45
-     * servers. Used to prevent concurrent access to the servers property.
46
-     */
47
-    private boolean closing;
48
-    
49 42
     /** All servers that currently exist. */
50 43
     private final List<Server> servers = new ArrayList<Server>();
51 44
     
@@ -83,9 +76,7 @@ public final class ServerManager {
83 76
      * @param server The server to be unregistered
84 77
      */
85 78
     public void unregisterServer(final Server server) {
86
-        if (!closing) {
87
-            servers.remove(server);
88
-        }
79
+        servers.remove(server);
89 80
     }
90 81
     
91 82
     /**
@@ -112,12 +103,10 @@ public final class ServerManager {
112 103
      * Closes all servers with a default quit message.
113 104
      */
114 105
     public void closeAll() {
115
-        closing = true;
116
-        for (Server server : servers) {
117
-            server.close(server.getConfigManager().getOption("general", "quitmessage"));
106
+        for (Server server : new ArrayList<Server>(servers)) {
107
+            server.disconnect();
108
+            server.close();
118 109
         }
119
-        closing = false;
120
-        servers.clear();
121 110
     }
122 111
     
123 112
     /**
@@ -126,12 +115,10 @@ public final class ServerManager {
126 115
      * @param message The quit message to send to the IRC servers
127 116
      */
128 117
     public void closeAll(final String message) {
129
-        closing = true;
130
-        for (Server server : servers) {
131
-            server.close(message);
118
+        for (Server server : new ArrayList<Server>(servers)) {
119
+            server.disconnect(message);
120
+            server.close();
132 121
         }
133
-        closing = false;
134
-        servers.clear();
135 122
     }
136 123
     
137 124
     /**
@@ -155,6 +142,7 @@ public final class ServerManager {
155 142
                 return server;
156 143
             }
157 144
         }
145
+        
158 146
         return null;
159 147
     }
160 148
     

+ 3
- 2
src/com/dmdirc/addons/dcc/DCCChatWindow.java View File

@@ -110,8 +110,9 @@ public class DCCChatWindow extends DCCFrame implements DCCChatInterface {
110 110
 	/**
111 111
 	 * Closes this container (and it's associated frame).
112 112
 	 */
113
-	public void close() {
113
+        @Override
114
+	public void windowClosing() {
114 115
 		dcc.close();
115
-		super.close();
116
+		super.windowClosing();
116 117
 	}
117 118
 }

+ 27
- 19
src/com/dmdirc/addons/dcc/DCCFrame.java View File

@@ -22,21 +22,19 @@
22 22
 
23 23
 package com.dmdirc.addons.dcc;
24 24
 
25
+import com.dmdirc.IconManager;
26
+import com.dmdirc.Server;
25 27
 import com.dmdirc.WritableFrameContainer;
26
-import com.dmdirc.config.ConfigManager;
27
-import com.dmdirc.config.IdentityManager;
28
-import com.dmdirc.ui.swing.components.InputTextFrame;
29
-import com.dmdirc.Main;
30 28
 import com.dmdirc.commandparser.CommandManager;
31
-import com.dmdirc.commandparser.parsers.GlobalCommandParser;
32
-import com.dmdirc.commandparser.parsers.CommandParser;
33 29
 import com.dmdirc.commandparser.commands.Command;
34 30
 import com.dmdirc.commandparser.commands.GlobalCommand;
35
-
36
-import com.dmdirc.IconManager;
37
-import com.dmdirc.Server;
31
+import com.dmdirc.commandparser.parsers.CommandParser;
32
+import com.dmdirc.commandparser.parsers.GlobalCommandParser;
33
+import com.dmdirc.config.ConfigManager;
34
+import com.dmdirc.config.IdentityManager;
38 35
 import com.dmdirc.ui.WindowManager;
39 36
 import com.dmdirc.ui.interfaces.InputWindow;
37
+import com.dmdirc.ui.swing.components.InputTextFrame;
40 38
 
41 39
 /**
42 40
  * This class links DCC objects to a window.
@@ -81,6 +79,7 @@ public abstract class DCCFrame extends WritableFrameContainer {
81 79
 		private static final long serialVersionUID = 200711271;
82 80
 		
83 81
 		/** Loads the relevant commands into the parser. */
82
+        @Override
84 83
 		protected void loadCommands() { CommandManager.loadGlobalCommands(this); }
85 84
 		
86 85
 		/**
@@ -91,6 +90,7 @@ public abstract class DCCFrame extends WritableFrameContainer {
91 90
 		 * @param command The command to be executed
92 91
 		 * @param args The arguments to the command
93 92
 		 */
93
+        @Override
94 94
 		protected void executeCommand(final InputWindow origin, final boolean isSilent, final Command command, final String... args) {
95 95
 			((GlobalCommand) command).execute(origin, isSilent, args);
96 96
 		}
@@ -103,6 +103,7 @@ public abstract class DCCFrame extends WritableFrameContainer {
103 103
 		 * @param origin The window in which the command was typed
104 104
 		 * @param line The line input by the user
105 105
 		 */
106
+        @Override
106 107
 		protected void handleNonCommand(final InputWindow origin, final String line) {
107 108
 			if (origin.getContainer() instanceof WritableFrameContainer) {
108 109
 				((WritableFrameContainer)origin.getContainer()).sendLine(line);
@@ -225,16 +226,23 @@ public abstract class DCCFrame extends WritableFrameContainer {
225 226
 		return null;
226 227
 	}
227 228
 	
228
-	/**
229
-	 * Closes this container (and it's associated frame).
230
-	 */
229
+	/** {@inheritDoc} */
231 230
 	@Override
232
-	public void close() {
233
-		plugin.delWindow(this);
234
-		myWindow.setVisible(false);
235
-		Main.getUI().getMainWindow().delChild(myWindow);
236
-		WindowManager.removeWindow(myWindow);
237
-                myWindow.close();
238
-                myWindow = null;
231
+	public void windowClosing() {
232
+                // 1: Make the window non-visible
233
+                myWindow.setVisible(false);
234
+
235
+                // 2: Remove any callbacks or listeners
236
+                // 3: Trigger any actions neccessary
237
+                // 4: Trigger action for the window closing
238
+                
239
+                // 5: Inform any parents that the window is closing
240
+                plugin.delWindow(this);
241
+
242
+                // 6: Remove the window from the window manager
243
+                WindowManager.removeWindow(myWindow);
244
+
245
+                // 7: Remove any references to the window and parents
246
+                myWindow = null; // NOPMD
239 247
 	}   
240 248
 }

+ 4
- 7
src/com/dmdirc/addons/dcc/DCCSendWindow.java View File

@@ -22,14 +22,11 @@
22 22
 
23 23
 package com.dmdirc.addons.dcc;
24 24
 
25
-import com.dmdirc.WritableFrameContainer;
26
-import com.dmdirc.IconManager;
27
-import com.dmdirc.Main;
28
-import com.dmdirc.Server;
29
-import com.dmdirc.config.IdentityManager;
30 25
 import com.dmdirc.ui.swing.JWrappingLabel;
31 26
 import com.dmdirc.ui.swing.components.TextFrame;
27
+
32 28
 import javax.swing.SwingConstants;
29
+
33 30
 /**
34 31
  * This class links DCC Send objects to a window.
35 32
  *
@@ -89,8 +86,8 @@ public class DCCSendWindow extends DCCFrame implements DCCSendInterface {
89 86
 	/**
90 87
 	 * Closes this container (and it's associated frame).
91 88
 	 */
92
-	public void close() {
89
+	public void windowClosing() {
93 90
 		dcc.close();
94
-		super.close();
91
+		super.windowClosing();
95 92
 	}
96 93
 }

+ 30
- 16
src/com/dmdirc/addons/logging/HistoryWindow.java View File

@@ -44,10 +44,10 @@ public class HistoryWindow extends FrameContainer {
44 44
     private final String title;
45 45
        
46 46
     /** The window we're using. */
47
-    private Window myWindow;
47
+    private Window window;
48 48
     
49 49
     /** Our parent window. */
50
-    private final Window parent;
50
+    private Window parent;
51 51
     
52 52
     /**
53 53
      * Creates a new HistoryWindow.
@@ -64,41 +64,55 @@ public class HistoryWindow extends FrameContainer {
64 64
         
65 65
         icon = IconManager.getIconManager().getIcon("raw");
66 66
         
67
-        myWindow = Main.getUI().getWindow(this);
67
+        window = Main.getUI().getWindow(this);
68 68
         
69
-        WindowManager.addWindow(parent, myWindow);
69
+        WindowManager.addWindow(parent, window);
70 70
         
71
-        myWindow.setTitle(title);
72
-        myWindow.setFrameIcon(icon);
73
-        myWindow.setVisible(true);
71
+        window.setTitle(title);
72
+        window.setFrameIcon(icon);
73
+        window.setVisible(true);
74 74
         
75 75
         final Stack<String> lines = reader.getLines(
76
-                IdentityManager.getGlobalConfig().getOptionInt("plugin-Logging", "history.lines", 50000));
76
+                IdentityManager.getGlobalConfig().getOptionInt("plugin-Logging",
77
+                "history.lines", 50000));
77 78
         while (lines.size() > 0) {
78
-            myWindow.addLine(lines.pop(), false);
79
+            window.addLine(lines.pop(), false);
79 80
         }
80 81
     }
81 82
     
82 83
     /** {@inheritDoc} */
84
+    @Override
83 85
     public Window getFrame() {
84
-        return myWindow;
86
+        return window;
85 87
     }
86 88
     
87 89
     /** {@inheritDoc} */
90
+    @Override
88 91
     public String toString() {
89 92
         return title;
90 93
     }
91 94
     
92 95
     /** {@inheritDoc} */
93
-    public void close() {
94
-        myWindow.setVisible(false);
95
-        Main.getUI().getMainWindow().delChild(myWindow);
96
-        WindowManager.removeWindow(myWindow);
97
-        myWindow.close();
98
-        myWindow = null;
96
+    @Override
97
+    public void windowClosing() {
98
+        // 1: Make the window non-visible
99
+        window.setVisible(false);
100
+        
101
+        // 2: Remove any callbacks or listeners
102
+        // 3: Trigger any actions neccessary
103
+        // 4: Trigger action for the window closing
104
+        // 5: Inform any parents that the window is closing
105
+        
106
+        // 6: Remove the window from the window manager
107
+        WindowManager.removeWindow(window);
108
+        
109
+        // 7: Remove any references to the window and parents
110
+        window = null; // NOPMD
111
+        parent = null; // NOPMD
99 112
     }
100 113
     
101 114
     /** {@inheritDoc} */
115
+    @Override
102 116
     public Server getServer() {
103 117
         return parent.getContainer().getServer();
104 118
     }

+ 1
- 1
src/com/dmdirc/commandparser/commands/channel/Part.java View File

@@ -47,7 +47,7 @@ public final class Part extends ChannelCommand {
47 47
             final Channel channel, final boolean isSilent, final String... args) {
48 48
         channel.part(args.length > 0 ? implodeArgs(args)
49 49
                 : origin.getConfigManager().getOption("general", "partmessage"));
50
-        channel.closeWindow();
50
+        channel.close();
51 51
     }
52 52
     
53 53
     /** {@inheritDoc} */

Loading…
Cancel
Save