瀏覽代碼

fixing all the horrible bugs introduced removing singletones, fixes issue 2429

tags/0.6.3m1rc1
Gregory Holmes 15 年之前
父節點
當前提交
c307409b03

+ 0
- 2
src/com/dmdirc/Main.java 查看文件

@@ -108,8 +108,6 @@ public final class Main {
108 108
 
109 109
         loadUI(pm, IdentityManager.getGlobalConfig());
110 110
 
111
-        getUI().initUISettings();
112
-
113 111
         doFirstRun();
114 112
 
115 113
         ActionManager.init();

+ 1
- 0
src/com/dmdirc/addons/ui_swing/SwingController.java 查看文件

@@ -526,6 +526,7 @@ public final class SwingController extends Plugin implements UIController {
526 526
             /** {@inheritDoc} */
527 527
             @Override
528 528
             public void run() {
529
+                UIUtilities.initUISettings();
529 530
                 me = new MainFrame(SwingController.this);
530 531
                 statusBar = me.getStatusBar();
531 532
                 ErrorListDialog.getErrorListDialog(me, me.getStatusBar());

+ 14
- 3
src/com/dmdirc/addons/ui_swing/components/MDIBar.java 查看文件

@@ -35,6 +35,7 @@ import com.dmdirc.ui.interfaces.Window;
35 35
 import com.dmdirc.addons.ui_swing.MainFrame;
36 36
 import com.dmdirc.addons.ui_swing.UIUtilities;
37 37
 
38
+import com.dmdirc.interfaces.SelectionListener;
38 39
 import java.awt.event.ActionEvent;
39 40
 import java.awt.event.ActionListener;
40 41
 import java.beans.PropertyChangeEvent;
@@ -49,7 +50,7 @@ import net.miginfocom.swing.MigLayout;
49 50
 /**
50 51
  * Provides an MDI style bar for restore/minimise/close.
51 52
  */
52
-public class MDIBar extends JPanel implements FrameManager,
53
+public class MDIBar extends JPanel implements FrameManager, SelectionListener,
53 54
         PropertyChangeListener, ActionListener, ConfigChangeListener {
54 55
 
55 56
     private static final long serialVersionUID = -8028057596226636245L;
@@ -60,6 +61,8 @@ public class MDIBar extends JPanel implements FrameManager,
60 61
     private MainFrame mainFrame;
61 62
     private ConfigManager config;
62 63
     private String visibility;
64
+    /** Active frame. */
65
+    private Window activeFrame;
63 66
 
64 67
     /**
65 68
      * Instantiates a new MDI bar.
@@ -86,6 +89,7 @@ public class MDIBar extends JPanel implements FrameManager,
86 89
 
87 90
 
88 91
         WindowManager.addFrameManager(this);
92
+        WindowManager.addSelectionListener(this);
89 93
         closeButton.addActionListener(this);
90 94
         minimiseButton.addActionListener(this);
91 95
         restoreButton.addActionListener(this);
@@ -108,7 +112,10 @@ public class MDIBar extends JPanel implements FrameManager,
108 112
             @Override
109 113
             public void run() {
110 114
                 boolean show = true;
111
-                if ("alwaysShow".equalsIgnoreCase(visibility)) {
115
+                if (mainFrame == null) {
116
+                    show = false;
117
+                    return;
118
+                } else if ("alwaysShow".equalsIgnoreCase(visibility)) {
112 119
                     show = mainFrame.getDesktopPane().getAllFrames().length > 0;
113 120
                 } else if ("neverShow".equalsIgnoreCase(visibility)) {
114 121
                     show = false;
@@ -193,7 +200,6 @@ public class MDIBar extends JPanel implements FrameManager,
193 200
      */
194 201
     @Override
195 202
     public void actionPerformed(final ActionEvent e) {
196
-        final Window activeFrame = mainFrame.getActiveFrame();
197 203
         if (activeFrame == null) {
198 204
             return;
199 205
         }
@@ -212,4 +218,9 @@ public class MDIBar extends JPanel implements FrameManager,
212 218
         visibility = config.getOption("ui", "mdiBarVisibility");
213 219
         check();
214 220
     }
221
+
222
+    @Override
223
+    public void selectionChanged(Window window) {
224
+        activeFrame = window;
225
+    }
215 226
 }

+ 18
- 25
src/com/dmdirc/addons/ui_swing/components/statusbar/InviteLabel.java 查看文件

@@ -31,18 +31,18 @@ import com.dmdirc.ServerManager;
31 31
 import com.dmdirc.actions.ActionManager;
32 32
 import com.dmdirc.actions.interfaces.ActionType;
33 33
 import com.dmdirc.actions.CoreActionType;
34
+import com.dmdirc.addons.ui_swing.MainFrame;
34 35
 import com.dmdirc.interfaces.ActionListener;
35 36
 import com.dmdirc.interfaces.InviteListener;
36 37
 import com.dmdirc.ui.interfaces.StatusBarComponent;
37 38
 import com.dmdirc.util.MapList;
38 39
 
39
-import java.awt.Window;
40 40
 import java.awt.event.ActionEvent;
41 41
 import java.awt.event.MouseEvent;
42
-
43 42
 import java.util.ArrayList;
44 43
 import java.util.Arrays;
45 44
 import java.util.List;
45
+
46 46
 import javax.swing.AbstractAction;
47 47
 import javax.swing.BorderFactory;
48 48
 import javax.swing.JLabel;
@@ -74,17 +74,19 @@ public class InviteLabel extends StatusbarPopupPanel implements StatusBarCompone
74 74
     /** Accept invites menu item. */
75 75
     private final JMenuItem accept;
76 76
     /** Parent window. */
77
-    private Window parentWindow;
77
+    private MainFrame mainFrame;
78
+    /** Active frame. */
79
+    private FrameContainer activeFrame;
78 80
 
79 81
     /**
80 82
      * Instantiates a new invite label.
81 83
      * 
82
-     * @param parentWindow Parent window
84
+     * @param mainFrame Parent window
83 85
      */
84
-    public InviteLabel(final Window parentWindow) {
86
+    public InviteLabel(final MainFrame mainFrame) {
85 87
         super(new JLabel());
86 88
         
87
-        this.parentWindow = parentWindow;
89
+        this.mainFrame = mainFrame;
88 90
 
89 91
         setBorder(BorderFactory.createEtchedBorder());
90 92
         label.setIcon(IconManager.getIconManager().getIcon("invite"));
@@ -134,7 +136,7 @@ public class InviteLabel extends StatusbarPopupPanel implements StatusBarCompone
134 136
     /** {@inheritDoc} */
135 137
     @Override
136 138
     protected StatusbarPopupWindow getWindow() {
137
-        return new InvitePopup(this, activeServer, parentWindow);
139
+        return new InvitePopup(this, activeServer, mainFrame);
138 140
     }
139 141
 
140 142
     /**
@@ -156,19 +158,14 @@ public class InviteLabel extends StatusbarPopupPanel implements StatusBarCompone
156 158
      * Updates the invite label for the currently active server.
157 159
      */
158 160
     private void update() {
159
-        update(Main.getUI().getActiveServer());
160
-    }
161
-
162
-    /**
163
-     * Updates the invite label for the server.
164
-     *
165
-     * @param server Server to update
166
-     */
167
-    private void update(final Server server) {
168
-        activeServer = server;
169
-        if (server != null && !inviteList.containsKey(server)) {
170
-            inviteList.add(server, server.getInvites());
171
-            server.addInviteListener(this);
161
+        if (activeFrame == null) {
162
+            activeServer = null;
163
+        } else {
164
+            activeServer = activeFrame.getServer();
165
+        }
166
+        if (activeServer != null && !inviteList.containsKey(activeServer)) {
167
+            inviteList.add(activeServer, activeServer.getInvites());
168
+            activeServer.addInviteListener(this);
172 169
         }
173 170
 
174 171
         if (activeServer == null || inviteList.get(activeServer).isEmpty()) {
@@ -206,11 +203,7 @@ public class InviteLabel extends StatusbarPopupPanel implements StatusBarCompone
206 203
     @Override
207 204
     public void processEvent(final ActionType type, final StringBuffer format,
208 205
             final Object... arguments) {
209
-        if (arguments[0] == null) {
210
-            update((Server) null);
211
-        } else {
212
-            update(((FrameContainer) arguments[0]).getServer());
213
-        }
206
+        update();
214 207
     }
215 208
 
216 209
     /**

+ 1
- 1
src/com/dmdirc/addons/ui_swing/dialogs/serversetting/IgnoreListPanel.java 查看文件

@@ -117,7 +117,7 @@ public final class IgnoreListPanel extends JPanel implements ActionListener,
117 117
         viewToggle.setEnabled(cachedIgnoreList.canConvert());
118 118
 
119 119
         setLayout(new MigLayout("fill, wrap 1"));
120
-        add(scrollPane, "growx, growy");
120
+        add(scrollPane, "grow, push");
121 121
         add(sizeLabel, "split 2, pushx, growx");
122 122
         add(viewToggle, "alignx center");
123 123
         add(addButton, "split 2, width 50%");

+ 1
- 1
src/com/dmdirc/addons/ui_swing/dialogs/serversetting/PerformPanel.java 查看文件

@@ -108,7 +108,7 @@ public final class PerformPanel extends JPanel implements ActionListener {
108 108
         textarea = new JTextArea();
109 109
         textarea.setColumns(40);
110 110
         
111
-        add(new JScrollPane(textarea), "grow");
111
+        add(new JScrollPane(textarea), "grow, push");
112 112
     }
113 113
     
114 114
     /** Adds listeners to the components. */

+ 9
- 7
src/com/dmdirc/addons/ui_swing/framemanager/windowmenu/WindowMenuFrameManager.java 查看文件

@@ -69,6 +69,8 @@ public final class WindowMenuFrameManager extends JMenu implements FrameManager,
69 69
     private final JMenuItem toggleStateMenuItem,  closeMenuItem,  minimiseMenuItem;
70 70
     /** Seperator. */
71 71
     private final JSeparator separator;
72
+    /** Active window. */
73
+    private Window activeWindow;
72 74
 
73 75
     /** 
74 76
      * Creates a new instance of WindowMenuFrameManager.
@@ -239,20 +241,20 @@ public final class WindowMenuFrameManager extends JMenu implements FrameManager,
239 241
     @Override
240 242
     public void actionPerformed(final ActionEvent e) {
241 243
         if ("ToggleState".equals(e.getActionCommand())) {
242
-            final Window window = Main.getUI().getActiveWindow();
243
-            if (window != null) {
244
-                window.toggleMaximise();
244
+            if (activeWindow != null) {
245
+                activeWindow.toggleMaximise();
245 246
             }
246 247
         } else if (e.getActionCommand().equals("Minimise")) {
247
-            ((TextFrame) Main.getUI().getActiveWindow()).minimise();
248
+            activeWindow.minimise();
248 249
         } else if (e.getActionCommand().equals("Close")) {
249
-            ((TextFrame) Main.getUI().getActiveWindow()).close();
250
+            activeWindow.close();
250 251
         }
251 252
     }
252 253
 
253 254
     /** {@inheritDoc} */
254 255
     @Override
255 256
     public void selectionChanged(final Window window) {
257
+        activeWindow = window;
256 258
         final Map<FrameContainer, FrameContainerMenuItem> newMap =
257 259
                 new TreeMap<FrameContainer, FrameContainerMenuItem>(
258 260
                 comparator);
@@ -269,7 +271,7 @@ public final class WindowMenuFrameManager extends JMenu implements FrameManager,
269 271
      * Checks and sets the state of the toggle menu item.
270 272
      */
271 273
     private void checkToggleState() {
272
-        if (Main.getUI().getActiveWindow() == null) {
274
+        if (activeWindow == null) {
273 275
             toggleStateMenuItem.setEnabled(false);
274 276
             closeMenuItem.setEnabled(false);
275 277
             minimiseMenuItem.setEnabled(false);
@@ -278,7 +280,7 @@ public final class WindowMenuFrameManager extends JMenu implements FrameManager,
278 280
             closeMenuItem.setEnabled(true);
279 281
             minimiseMenuItem.setEnabled(true);
280 282
 
281
-            if (Main.getUI().getActiveWindow().isMaximum()) {
283
+            if (activeWindow.isMaximum()) {
282 284
                 toggleStateMenuItem.setText("Restore");
283 285
                 toggleStateMenuItem.setIcon(IconManager.getIconManager().getIcon(
284 286
                         "restore"));

Loading…
取消
儲存