Bladeren bron

Rework how window closing works

Fixes CLIENT-82

Change-Id: I4ea9fbf6c939a5b16f15ade230255b948e210c2c
Depends-On: I97f44a9269288f876a7a71b412302cec4238d9d4
Reviewed-on: http://gerrit.dmdirc.com/1600
Reviewed-by: Greg Holmes <greg@dmdirc.com>
Automatic-Compile: DMDirc Local Commits <dmdirc@googlemail.com>
tags/0.6.5b1
Chris Smith 13 jaren geleden
bovenliggende
commit
675c52357b

+ 0
- 8
src/com/dmdirc/Channel.java Bestand weergeven

@@ -327,11 +327,6 @@ public class Channel extends MessageTarget<ChannelWindow> implements ConfigChang
327 327
     /** {@inheritDoc} */
328 328
     @Override
329 329
     public void windowClosing() {
330
-        // 1: Make the window non-visible
331
-        for (ChannelWindow window : getWindows()) {
332
-            window.setVisible(false);
333
-        }
334
-
335 330
         // 2: Remove any callbacks or listeners
336 331
         eventHandler.unregisterCallbacks();
337 332
 
@@ -349,9 +344,6 @@ public class Channel extends MessageTarget<ChannelWindow> implements ConfigChang
349 344
 
350 345
         // 5: Inform any parents that the window is closing
351 346
         server.delChannel(channelInfo.getName());
352
-
353
-        // 6: Remove the window from the window manager
354
-        WindowManager.removeWindow(this);
355 347
     }
356 348
 
357 349
     /** {@inheritDoc} */

+ 0
- 8
src/com/dmdirc/CustomWindow.java Bestand weergeven

@@ -62,18 +62,10 @@ public class CustomWindow extends FrameContainer<Window> {
62 62
     /** {@inheritDoc} */
63 63
     @Override
64 64
     public void windowClosing() {
65
-        // 1: Make the window non-visible
66
-        for (Window window : getWindows()) {
67
-            window.setVisible(false);
68
-        }
69
-
70 65
         // 2: Remove any callbacks or listeners
71 66
         // 3: Trigger any actions neccessary
72 67
         // 4: Trigger action for the window closing
73 68
         // 5: Inform any parents that the window is closing
74
-
75
-        // 6: Remove the window from the window manager
76
-        WindowManager.removeWindow(this);
77 69
     }
78 70
 
79 71
     /** {@inheritDoc} */

+ 51
- 10
src/com/dmdirc/FrameContainer.java Bestand weergeven

@@ -26,6 +26,7 @@ import com.dmdirc.actions.ActionManager;
26 26
 import com.dmdirc.actions.CoreActionType;
27 27
 import com.dmdirc.config.ConfigManager;
28 28
 import com.dmdirc.interfaces.ConfigChangeListener;
29
+import com.dmdirc.interfaces.FrameCloseListener;
29 30
 import com.dmdirc.interfaces.FrameInfoListener;
30 31
 import com.dmdirc.interfaces.NotificationListener;
31 32
 import com.dmdirc.interfaces.SelectionListener;
@@ -89,10 +90,10 @@ public abstract class FrameContainer<T extends Window> {
89 90
 
90 91
     /** The transcoder to use for this container. */
91 92
     private final StringTranscoder transcoder;
92
-    
93
+
93 94
     /** The config manager for this container. */
94 95
     private final ConfigManager config;
95
-    
96
+
96 97
     /** The IconChanger for this container. */
97 98
     private final IconChanger changer = new IconChanger();
98 99
 
@@ -101,7 +102,7 @@ public abstract class FrameContainer<T extends Window> {
101 102
 
102 103
     /**
103 104
      * Instantiate new frame container.
104
-     * 
105
+     *
105 106
      * @param icon The icon to use for this container
106 107
      * @param name The name of this container
107 108
      * @param title The title of this container
@@ -129,7 +130,7 @@ public abstract class FrameContainer<T extends Window> {
129 130
             tempTranscoder = new StringTranscoder(Charset.forName("UTF-8"));
130 131
         }
131 132
         transcoder = tempTranscoder;
132
-        
133
+
133 134
         setIcon(icon);
134 135
     }
135 136
 
@@ -317,18 +318,18 @@ public abstract class FrameContainer<T extends Window> {
317 318
 
318 319
     /**
319 320
      * Sets the icon to be used by this frame container.
320
-     * 
321
+     *
321 322
      * @param icon The new icon to be used
322 323
      */
323 324
     public final void setIcon(final String icon) {
324 325
         this.icon = icon;
325
-        
326
+
326 327
         iconUpdated();
327
-        
328
+
328 329
         config.removeListener(changer);
329 330
         config.addChangeListener("icon", icon, changer);
330 331
     }
331
-    
332
+
332 333
     /**
333 334
      * Called when this container's icon is updated.
334 335
      */
@@ -454,6 +455,12 @@ public abstract class FrameContainer<T extends Window> {
454 455
      *      {@link WindowManager#removeWindow(com.dmdirc.ui.interfaces.Window)}</li>
455 456
      * </ol>
456 457
      * <p>
458
+     * <strong>NB:</strong> As of DMDirc 0.6.5, points 1 and 6 (making windows
459
+     * non-visible and removing the window from the window manager) are handled
460
+     * by the caller of this method, and should <strong>not</strong> be
461
+     * implemented by subclasses.
462
+     * </p>
463
+     * <p>
457 464
      * While resources may be relinquished in step three, references MUST NOT
458 465
      * be removed yet. That is, if a window holds a resource, the resource may
459 466
      * be closed, but the relevant object MUST still be available for
@@ -464,7 +471,21 @@ public abstract class FrameContainer<T extends Window> {
464 471
      * on its frame, parser, etc. The resources should be completely freed in
465 472
      * the {@link #windowClosed()} method.
466 473
      */
467
-    public abstract void windowClosing();
474
+    protected abstract void windowClosing();
475
+
476
+    /**
477
+     * Handles the closing of this container. This should be called by UI
478
+     * components when the user is attempting to close a corresponding window.
479
+     */
480
+    public void handleWindowClosing() {
481
+        for (FrameCloseListener listener : listeners.get(FrameCloseListener.class)) {
482
+            listener.windowClosing(this);
483
+        }
484
+
485
+        windowClosing();
486
+
487
+        WindowManager.removeWindow(this);
488
+    }
468 489
 
469 490
     /**
470 491
      * Invoked when our window has been closed.
@@ -614,6 +635,26 @@ public abstract class FrameContainer<T extends Window> {
614 635
         listeners.remove(NotificationListener.class, listener);
615 636
     }
616 637
 
638
+    /**
639
+     * Adds a close listener for this frame container.
640
+     *
641
+     * @since 0.6.5
642
+     * @param listener The listener to be added
643
+     */
644
+    public void addCloseListener(final FrameCloseListener listener) {
645
+        listeners.add(FrameCloseListener.class, listener);
646
+    }
647
+
648
+    /**
649
+     * Removes a close listener from this frame container.
650
+     *
651
+     * @since 0.6.5
652
+     * @param listener The listener to be removed
653
+     */
654
+    public void removeCloseListener(final FrameCloseListener listener) {
655
+        listeners.remove(FrameCloseListener.class, listener);
656
+    }
657
+
617 658
     /**
618 659
      * Adds a selection listener for this frame container.
619 660
      *
@@ -701,6 +742,6 @@ public abstract class FrameContainer<T extends Window> {
701 742
         public void configChanged(final String domain, final String key) {
702 743
             iconUpdated();
703 744
         }
704
-        
745
+
705 746
     }
706 747
 }

+ 0
- 8
src/com/dmdirc/GlobalWindow.java Bestand weergeven

@@ -64,18 +64,10 @@ public class GlobalWindow extends WritableFrameContainer<InputWindow> {
64 64
     /** {@inheritDoc} */
65 65
     @Override
66 66
     public void windowClosing() {
67
-        // 1: Make the window non-visible
68
-        for (InputWindow window : getWindows()) {
69
-            window.setVisible(false);
70
-        }
71
-
72 67
         // 2: Remove any callbacks or listeners
73 68
         // 3: Trigger any actions neccessary
74 69
         // 4: Trigger action for the window closing
75 70
         // 5: Inform any parents that the window is closing
76
-
77
-        // 6: Remove the window from the window manager
78
-        WindowManager.removeWindow(this);
79 71
     }
80 72
 
81 73
     /** {@inheritDoc} */

+ 0
- 8
src/com/dmdirc/Query.java Bestand weergeven

@@ -300,11 +300,6 @@ public class Query extends MessageTarget<QueryWindow> implements PrivateActionLi
300 300
     /** {@inheritDoc} */
301 301
     @Override
302 302
     public void windowClosing() {
303
-        // 1: Make the window non-visible
304
-        for (QueryWindow window : getWindows()) {
305
-            window.setVisible(false);
306
-        }
307
-
308 303
         // 2: Remove any callbacks or listeners
309 304
         if (server != null && server.getParser() != null) {
310 305
             server.getParser().getCallbackManager().delAllCallback(this);
@@ -319,9 +314,6 @@ public class Query extends MessageTarget<QueryWindow> implements PrivateActionLi
319 314
         if (server != null) {
320 315
             server.delQuery(this);
321 316
         }
322
-
323
-        // 6: Remove the window from the window manager
324
-        WindowManager.removeWindow(this);
325 317
     }
326 318
 
327 319
     /** {@inheritDoc} */

+ 0
- 8
src/com/dmdirc/Raw.java Bestand weergeven

@@ -77,11 +77,6 @@ public final class Raw extends WritableFrameContainer<InputWindow>
77 77
     /** {@inheritDoc} */
78 78
     @Override
79 79
     public void windowClosing() {
80
-        // 1: Make the window non-visible
81
-        for (InputWindow window : getWindows()) {
82
-            window.setVisible(false);
83
-        }
84
-
85 80
         // 2: Remove any callbacks or listeners
86 81
         if (server.getParser() != null) {
87 82
             server.getParser().getCallbackManager().delAllCallback(this);
@@ -92,9 +87,6 @@ public final class Raw extends WritableFrameContainer<InputWindow>
92 87
 
93 88
         // 5: Inform any parents that the window is closing
94 89
         server.delRaw();
95
-
96
-        // 6: Remove the window from the window manager
97
-        WindowManager.removeWindow(this);
98 90
     }
99 91
 
100 92
     /** {@inheritDoc} */

+ 0
- 8
src/com/dmdirc/Server.java Bestand weergeven

@@ -1167,11 +1167,6 @@ public class Server extends WritableFrameContainer<ServerWindow> implements Conf
1167 1167
     @Override
1168 1168
     public void windowClosing() {
1169 1169
         synchronized (myStateLock) {
1170
-            // 1: Make the window non-visible
1171
-            for (Window window : getWindows()) {
1172
-                window.setVisible(false);
1173
-            }
1174
-
1175 1170
             // 2: Remove any callbacks or listeners
1176 1171
             eventHandler.unregisterCallbacks();
1177 1172
 
@@ -1192,9 +1187,6 @@ public class Server extends WritableFrameContainer<ServerWindow> implements Conf
1192 1187
         // 4: Trigger action for the window closing
1193 1188
         // 5: Inform any parents that the window is closing
1194 1189
         ServerManager.getServerManager().unregisterServer(this);
1195
-
1196
-        // 6: Remove the window from the window manager
1197
-        WindowManager.removeWindow(this);
1198 1190
     }
1199 1191
 
1200 1192
     /** {@inheritDoc} */

+ 44
- 0
src/com/dmdirc/interfaces/FrameCloseListener.java Bestand weergeven

@@ -0,0 +1,44 @@
1
+/*
2
+ * Copyright (c) 2006-2010 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.FrameContainer;
26
+
27
+/**
28
+ * Defines methods that should be implemented by objects interested in the
29
+ * frame closing lifecycle of a {@link FrameContainer}.
30
+ *
31
+ * @since 0.6.5
32
+ * @author chris
33
+ */
34
+public interface FrameCloseListener {
35
+
36
+    /**
37
+     * Called when a window is starting the closing process and should be
38
+     * hidden from users.
39
+     *
40
+     * @param window The window which is being closed
41
+     */
42
+    void windowClosing(final FrameContainer<?> window);
43
+
44
+}

+ 2
- 0
src/com/dmdirc/ui/interfaces/Window.java Bestand weergeven

@@ -93,6 +93,7 @@ public interface Window {
93 93
      *
94 94
      * @return boolean visibility
95 95
      */
96
+    @Deprecated
96 97
     boolean isVisible();
97 98
 
98 99
     /**
@@ -100,6 +101,7 @@ public interface Window {
100 101
      *
101 102
      * @param isVisible Whether the window should be visible or not
102 103
      */
104
+    @Deprecated
103 105
     void setVisible(boolean isVisible);
104 106
 
105 107
     /**

+ 0
- 1
test/com/dmdirc/harness/TestWritableFrameContainer.java Bestand weergeven

@@ -59,7 +59,6 @@ public class TestWritableFrameContainer<T extends InputWindow> extends WritableF
59 59
     @Override
60 60
     public void windowClosing() {
61 61
         System.out.println("windowClosing");
62
-        WindowManager.removeWindow(this);
63 62
     }
64 63
 
65 64
     @Override

Laden…
Annuleren
Opslaan