Kaynağa Gözat

Major hackage of how closing windows works. Away listeners should be properly removed now. We need to take a better look at the closing process at some point in the future

git-svn-id: http://svn.dmdirc.com/trunk@2958 00569f92-eb28-0410-84fd-f71c24880f
tags/0.6
Chris Smith 16 yıl önce
ebeveyn
işleme
31dc28fbc1

+ 2
- 0
src/com/dmdirc/Channel.java Dosyayı Görüntüle

@@ -373,6 +373,8 @@ public final class Channel extends MessageTarget
373 373
         
374 374
         window.setVisible(false);
375 375
         Main.getUI().getMainWindow().delChild(window);
376
+        WindowManager.removeWindow(window);
377
+        window.close();
376 378
         window = null;
377 379
         server = null;
378 380
     }

+ 4
- 1
src/com/dmdirc/CustomWindow.java Dosyayı Görüntüle

@@ -39,7 +39,7 @@ public class CustomWindow extends FrameContainer {
39 39
     /** This custom window's title. */
40 40
     private final String title;
41 41
 
42
-    private final Window window;
42
+    private Window window;
43 43
 
44 44
     private Window parent = null;
45 45
 
@@ -98,6 +98,9 @@ public class CustomWindow extends FrameContainer {
98 98
 
99 99
         WindowManager.removeWindow(window);
100 100
         Main.getUI().getMainWindow().delChild(window);
101
+        
102
+        window.close();
103
+        window = null; // NOPMD
101 104
     }
102 105
 
103 106
     /** {@inheritDoc} */

+ 2
- 0
src/com/dmdirc/GlobalWindow.java Dosyayı Görüntüle

@@ -71,7 +71,9 @@ public class GlobalWindow extends WritableFrameContainer {
71 71
 
72 72
     public void close() {
73 73
         window.setVisible(false);
74
+        window.close();
74 75
         WindowManager.removeWindow(window);
76
+        Main.getUI().getMainWindow().delChild(window);
75 77
     }
76 78
 
77 79
     public Server getServer() {

+ 2
- 0
src/com/dmdirc/Query.java Dosyayı Görüntüle

@@ -349,6 +349,8 @@ public final class Query extends MessageTarget implements
349 349
         }
350 350
         
351 351
         Main.getUI().getMainWindow().delChild(window);
352
+        WindowManager.removeWindow(window);
353
+        window.close();
352 354
         
353 355
         window = null;
354 356
         server = null;

+ 3
- 1
src/com/dmdirc/Raw.java Dosyayı Görüntüle

@@ -55,6 +55,8 @@ public final class Raw extends WritableFrameContainer implements IDataIn,
55 55
     /** An InputWindow used for displaying the raw data.*/
56 56
     private InputWindow window;
57 57
     
58
+    private boolean isClosing = false;
59
+    
58 60
     /**
59 61
      * Creates a new instance of Raw.
60 62
      *
@@ -101,7 +103,7 @@ public final class Raw extends WritableFrameContainer implements IDataIn,
101 103
         Main.getUI().getMainWindow().delChild(window);
102 104
         
103 105
         server.delRaw();
104
-        
106
+        window.close();
105 107
         window = null;
106 108
         server = null;
107 109
     }

+ 3
- 5
src/com/dmdirc/Server.java Dosyayı Görüntüle

@@ -463,7 +463,6 @@ public final class Server extends WritableFrameContainer implements Serializable
463 463
      * closed).
464 464
      */
465 465
     public void delRaw() {
466
-        WindowManager.removeWindow(raw.getFrame());
467 466
         raw = null; //NOPMD
468 467
     }
469 468
 
@@ -474,8 +473,6 @@ public final class Server extends WritableFrameContainer implements Serializable
474 473
      */
475 474
     public void delChannel(final String chan) {
476 475
         tabCompleter.removeEntry(chan);
477
-        WindowManager.removeWindow(
478
-                channels.get(parser.toLowerCase(chan)).getFrame());
479 476
         channels.remove(parser.toLowerCase(chan));
480 477
     }
481 478
 
@@ -518,8 +515,6 @@ public final class Server extends WritableFrameContainer implements Serializable
518 515
      */
519 516
     public void delQuery(final String host) {
520 517
         tabCompleter.removeEntry(ClientInfo.parseHost(host));
521
-        WindowManager.removeWindow(
522
-                queries.get(parser.toLowerCase(ClientInfo.parseHost(host))).getFrame());
523 518
         queries.remove(parser.toLowerCase(ClientInfo.parseHost(host)));
524 519
     }
525 520
 
@@ -820,12 +815,15 @@ public final class Server extends WritableFrameContainer implements Serializable
820 815
         if (raw != null) {
821 816
             raw.close();
822 817
         }
818
+        
823 819
         // Unregister ourselves with the server manager
824 820
         ServerManager.getServerManager().unregisterServer(this);
825 821
 
826 822
         if (window != null) {
827 823
             window.setVisible(false);
824
+            WindowManager.removeWindow(window);
828 825
             Main.getUI().getMainWindow().delChild(window);
826
+            window.close();
829 827
             window = null; //NOPMD
830 828
         }
831 829
 

+ 0
- 2
src/com/dmdirc/ServerManager.java Dosyayı Görüntüle

@@ -86,8 +86,6 @@ public final class ServerManager {
86 86
         if (!closing) {
87 87
             servers.remove(server);
88 88
         }
89
-        
90
-        WindowManager.removeWindow(server.getFrame());
91 89
     }
92 90
     
93 91
     /**

+ 1
- 4
src/com/dmdirc/addons/dcc/DCCChatWindow.java Dosyayı Görüntüle

@@ -22,11 +22,8 @@
22 22
 
23 23
 package com.dmdirc.addons.dcc;
24 24
 
25
-import com.dmdirc.WritableFrameContainer;
26
-import com.dmdirc.IconManager;
27 25
 import com.dmdirc.Main;
28
-import com.dmdirc.Server;
29
-import com.dmdirc.config.IdentityManager;
26
+
30 27
 /**
31 28
  * This class links DCC Chat objects to a window.
32 29
  *

+ 2
- 0
src/com/dmdirc/addons/dcc/DCCFrame.java Dosyayı Görüntüle

@@ -234,5 +234,7 @@ public abstract class DCCFrame extends WritableFrameContainer {
234 234
 		myWindow.setVisible(false);
235 235
 		Main.getUI().getMainWindow().delChild(myWindow);
236 236
 		WindowManager.removeWindow(myWindow);
237
+                myWindow.close();
238
+                myWindow = null;
237 239
 	}   
238 240
 }

+ 0
- 2
src/com/dmdirc/addons/dcc/DCCPlugin.java Dosyayı Görüntüle

@@ -39,8 +39,6 @@ import com.dmdirc.interfaces.ActionListener;
39 39
 
40 40
 import java.util.List;
41 41
 import java.util.ArrayList;
42
-import java.util.Map;
43
-import java.util.HashMap;
44 42
 
45 43
 import javax.swing.SwingConstants;
46 44
 import javax.swing.JOptionPane;

+ 3
- 1
src/com/dmdirc/addons/logging/HistoryWindow.java Dosyayı Görüntüle

@@ -44,7 +44,7 @@ public class HistoryWindow extends FrameContainer {
44 44
     private final String title;
45 45
        
46 46
     /** The window we're using. */
47
-    private final Window myWindow;
47
+    private Window myWindow;
48 48
     
49 49
     /** Our parent window. */
50 50
     private final Window parent;
@@ -94,6 +94,8 @@ public class HistoryWindow extends FrameContainer {
94 94
         myWindow.setVisible(false);
95 95
         Main.getUI().getMainWindow().delChild(myWindow);
96 96
         WindowManager.removeWindow(myWindow);
97
+        myWindow.close();
98
+        myWindow = null;
97 99
     }
98 100
     
99 101
     /** {@inheritDoc} */

+ 24
- 0
src/com/dmdirc/addons/redirectplugin/FakeInputWindow.java Dosyayı Görüntüle

@@ -56,93 +56,117 @@ public class FakeInputWindow implements InputWindow {
56 56
     }
57 57
 
58 58
     /** {@inheritDoc} */
59
+    @Override
59 60
     public CommandParser getCommandParser() {
60 61
         return target.getFrame().getCommandParser();
61 62
     }
62 63
 
63 64
     /** {@inheritDoc} */
65
+    @Override
64 66
     public InputHandler getInputHandler() {
65 67
         return target.getFrame().getInputHandler();
66 68
     }
67 69
 
68 70
     /** {@inheritDoc} */
71
+    @Override
69 72
     public void setAwayIndicator(final boolean isAway) {
70 73
         // Do nothing
71 74
     }
72 75
 
73 76
     /** {@inheritDoc} */
77
+    @Override
74 78
     public void addLine(final String messageType, final Object... args) {
75 79
         target.sendLine(Formatter.formatMessage(messageType, args));
76 80
     }
77 81
 
78 82
     /** {@inheritDoc} */
83
+    @Override
79 84
     public void addLine(final StringBuffer messageType, final Object... args) {
80 85
         addLine(messageType.toString(), args);
81 86
     }
82 87
 
83 88
     /** {@inheritDoc} */
89
+    @Override
84 90
     public void addLine(final String line, final boolean timestamp) {
85 91
         target.sendLine(line);
86 92
     }
87 93
 
88 94
     /** {@inheritDoc} */
95
+    @Override
89 96
     public void clear() {
90 97
         // Do nothing
91 98
     }
92 99
 
93 100
     /** {@inheritDoc} */
101
+    @Override
94 102
     public ConfigManager getConfigManager() {
95 103
         return target.getFrame().getConfigManager();
96 104
     }
97 105
 
98 106
     /** {@inheritDoc} */
107
+    @Override
99 108
     public FrameContainer getContainer() {
100 109
         return target;
101 110
     }
102 111
 
103 112
     /** {@inheritDoc} */
113
+    @Override
104 114
     public boolean isVisible() {
105 115
         return false;
106 116
     }
107 117
 
108 118
     /** {@inheritDoc} */
119
+    @Override
109 120
     public void setVisible(final boolean isVisible) {
110 121
         // Do nothing
111 122
     }
112 123
 
113 124
     /** {@inheritDoc} */
125
+    @Override
114 126
     public String getTitle() {
115 127
         return "Fake window";
116 128
     }
117 129
 
118 130
     /** {@inheritDoc} */
131
+    @Override
119 132
     public boolean isMaximum() {
120 133
         return false;
121 134
     }
122 135
 
123 136
     /** {@inheritDoc} */
137
+    @Override
124 138
     public void setMaximum(final boolean b) throws PropertyVetoException {
125 139
         // Do nothing
126 140
     }
127 141
 
128 142
     /** {@inheritDoc} */
143
+    @Override
129 144
     public void setTitle(final String title) {
130 145
         // Do nothing
131 146
     }
132 147
 
133 148
     /** {@inheritDoc} */
149
+    @Override
134 150
     public void open() {
135 151
         // Do nothing
136 152
     }
137 153
 
138 154
     /** {@inheritDoc} */
155
+    @Override
139 156
     public void setFrameIcon(final Icon icon) {
140 157
         // Do nothing
141 158
     }
142 159
 
143 160
     /** {@inheritDoc} */
161
+    @Override
144 162
     public StringTranscoder getTranscoder() {
145 163
         return new StringTranscoder(Charset.defaultCharset());
146 164
     }
147 165
 
166
+    /** {@inheritDoc} */
167
+    @Override
168
+    public void close() {
169
+        /// Do nothing
170
+    }
171
+
148 172
 }

+ 7
- 5
src/com/dmdirc/ui/WindowManager.java Dosyayı Görüntüle

@@ -138,16 +138,18 @@ public class WindowManager {
138 138
     /**
139 139
      * Removes a window from the Window Manager. If the specified window
140 140
      * has child windows, they are recursively removed before the target window.
141
+     * If the window hasn't previously been added, the reques to remove it is
142
+     * ignored.
141 143
      *
142 144
      * @param window The window to be removed
143 145
      */
144
-    @Precondition({
145
-        "The specified Window is not null",
146
-        "The specified Window has already been added and not removed"
147
-    })
146
+    @Precondition("The specified Window is not null")
148 147
     public static void removeWindow(final Window window) {
149 148
         assert(window != null);
150
-        assert(childWindows.containsKey(window));
149
+        
150
+        if (!childWindows.containsKey(window)) {
151
+            return;
152
+        }
151 153
 
152 154
         if (childWindows.get(window) != null && !childWindows.get(window).isEmpty()) {
153 155
             for (Window child : new ArrayList<Window>(childWindows.get(window))) {

+ 6
- 0
src/com/dmdirc/ui/dummy/DummyChannelWindow.java Dosyayı Görüntüle

@@ -170,5 +170,11 @@ public final class DummyChannelWindow implements ChannelWindow {
170 170
     public StringTranscoder getTranscoder() {
171 171
         return new StringTranscoder(Charset.defaultCharset());
172 172
     }
173
+    
174
+    /** {@inheritDoc} */
175
+    @Override
176
+    public void close() {
177
+        // Do nothing
178
+    }    
173 179
 
174 180
 }

+ 6
- 0
src/com/dmdirc/ui/dummy/DummyInputWindow.java Dosyayı Görüntüle

@@ -151,5 +151,11 @@ public final class DummyInputWindow implements InputWindow {
151 151
     public StringTranscoder getTranscoder() {
152 152
         return new StringTranscoder(Charset.defaultCharset());
153 153
     }
154
+
155
+    /** {@inheritDoc} */
156
+    @Override
157
+    public void close() {
158
+        // Do nothing
159
+    }
154 160
     
155 161
 }

+ 6
- 0
src/com/dmdirc/ui/dummy/DummyServerWindow.java Dosyayı Görüntüle

@@ -153,4 +153,10 @@ public final class DummyServerWindow implements ServerWindow {
153 153
         return new StringTranscoder(Charset.defaultCharset());
154 154
     }
155 155
     
156
+    /** {@inheritDoc} */
157
+    @Override
158
+    public void close() {
159
+        // Do nothing
160
+    }    
161
+    
156 162
 }

+ 4
- 1
src/com/dmdirc/ui/interfaces/Window.java Dosyayı Görüntüle

@@ -113,7 +113,7 @@ public interface Window {
113 113
      * Sets the maximised state of this window.
114 114
      * 
115 115
      * @param b true if the frame should be maximised, false otherwise
116
-     * @throws PropertyVetoException if the change is vetoed
116
+     * @throws java.beans.PropertyVetoException if the change is vetoed
117 117
      */
118 118
     void setMaximum(boolean b) throws PropertyVetoException;
119 119
     
@@ -143,4 +143,7 @@ public interface Window {
143 143
      */
144 144
     StringTranscoder getTranscoder();
145 145
     
146
+    /** Closes this window. */
147
+    void close();
148
+    
146 149
 }

+ 5
- 2
src/com/dmdirc/ui/swing/ServerFrame.java Dosyayı Görüntüle

@@ -27,14 +27,12 @@ import com.dmdirc.Server;
27 27
 import com.dmdirc.ServerState;
28 28
 import com.dmdirc.commandparser.parsers.CommandParser;
29 29
 import com.dmdirc.commandparser.parsers.ServerCommandParser;
30
-import com.dmdirc.config.IdentityManager;
31 30
 import com.dmdirc.ui.input.InputHandler;
32 31
 import com.dmdirc.ui.interfaces.ServerWindow;
33 32
 import com.dmdirc.ui.swing.components.InputTextFrame;
34 33
 import com.dmdirc.ui.swing.dialogs.serversetting.ServerSettingsDialog;
35 34
 import static com.dmdirc.ui.swing.UIUtilities.SMALL_BORDER;
36 35
 
37
-import java.awt.BorderLayout;
38 36
 import java.awt.GridBagConstraints;
39 37
 import java.awt.GridBagLayout;
40 38
 import java.awt.Insets;
@@ -82,6 +80,7 @@ public final class ServerFrame extends InputTextFrame implements ServerWindow,
82 80
      * Retrieves the command Parser for this command window.
83 81
      * @return This window's command Parser
84 82
      */
83
+    @Override
85 84
     public CommandParser getCommandParser() {
86 85
         return commandParser;
87 86
     }
@@ -120,6 +119,7 @@ public final class ServerFrame extends InputTextFrame implements ServerWindow,
120 119
     }
121 120
     
122 121
     /** {@inheritDoc}. */
122
+    @Override
123 123
     public void actionPerformed(final ActionEvent actionEvent) {
124 124
         super.actionPerformed(actionEvent);
125 125
         if (actionEvent.getSource() == settingsMI) {
@@ -128,6 +128,7 @@ public final class ServerFrame extends InputTextFrame implements ServerWindow,
128 128
     }
129 129
 
130 130
     /** {@inheritDoc}. */
131
+    @Override
131 132
     public void popupMenuWillBecomeVisible(final PopupMenuEvent e) {
132 133
         if (getContainer().getServer().getState().equals(ServerState.CONNECTED)) {
133 134
             settingsMI.setEnabled(true);
@@ -137,11 +138,13 @@ public final class ServerFrame extends InputTextFrame implements ServerWindow,
137 138
     }
138 139
 
139 140
     /** {@inheritDoc}. */
141
+    @Override
140 142
     public void popupMenuWillBecomeInvisible(final PopupMenuEvent e) {
141 143
         //Ignore
142 144
     }
143 145
 
144 146
     /** {@inheritDoc}. */
147
+    @Override
145 148
     public void popupMenuCanceled(final PopupMenuEvent e) {
146 149
         //Ignore
147 150
     }

+ 11
- 1
src/com/dmdirc/ui/swing/components/InputTextFrame.java Dosyayı Görüntüle

@@ -555,5 +555,15 @@ public abstract class InputTextFrame extends TextFrame implements InputWindow,
555 555
     public void onBack() {
556 556
         setAwayIndicator(false);
557 557
     }
558
-    
558
+
559
+    /** {@inheritDoc} */
560
+    @Override
561
+    public void close() {
562
+        super.close();
563
+        
564
+        if (getContainer() != null && getContainer().getServer() != null) {
565
+            getContainer().getServer().removeAwayStateListener(this);
566
+        }
567
+    }
568
+
559 569
 }

+ 8
- 0
src/com/dmdirc/ui/swing/components/TextFrame.java Dosyayı Görüntüle

@@ -130,6 +130,8 @@ public abstract class TextFrame extends JInternalFrame implements Window,
130 130
     /** Quick copy? */
131 131
     private boolean quickCopy;
132 132
     
133
+    private boolean closing = false;
134
+    
133 135
     /**
134 136
      * Creates a new instance of Frame.
135 137
      *
@@ -629,7 +631,13 @@ public abstract class TextFrame extends JInternalFrame implements Window,
629 631
     }
630 632
     
631 633
     /** Closes this frame. */
634
+    @Override
632 635
     public void close() {
636
+        if (closing) {
637
+            return;
638
+        }
639
+        closing = true;
640
+        
633 641
         try {
634 642
             setClosed(true);
635 643
         } catch (PropertyVetoException ex) {

Loading…
İptal
Kaydet