Browse Source

pass more objects directly

tags/0.6.3m1rc1
Gregory Holmes 15 years ago
parent
commit
8dbf247506

+ 1
- 1
src/com/dmdirc/addons/ui_swing/MainFrame.java View File

@@ -361,7 +361,7 @@ public final class MainFrame extends JFrame implements WindowListener,
361 361
      * Initialises the components for this frame.
362 362
      */
363 363
     private void initComponents() {
364
-        statusBar = new SwingStatusBar(controller);
364
+        statusBar = new SwingStatusBar(controller, this);
365 365
         frameManagerPanel = new JPanel();
366 366
         desktopPane = new DMDircDesktopPane(this);
367 367
 

+ 21
- 41
src/com/dmdirc/addons/ui_swing/SwingController.java View File

@@ -88,11 +88,9 @@ public final class SwingController extends Plugin implements UIController {
88 88
     private MainFrame me;
89 89
     /** Status bar. */
90 90
     private SwingStatusBar statusBar;
91
-    /** Semaphore used for controlling access to statusBar. */
92
-    private static final Semaphore STATUSBAR_SEMAPHORE = new Semaphore(1);
93 91
     /** Top level window list. */
94 92
     private final List<java.awt.Window> windows;
95
-    
93
+
96 94
     /** Instantiates a new SwingController. */
97 95
     public SwingController() {
98 96
         windows = new ArrayList<java.awt.Window>();
@@ -119,29 +117,7 @@ public final class SwingController extends Plugin implements UIController {
119 117
      * @return This UI's main window
120 118
      */
121 119
     public MainFrame getMainFrame() {
122
-        synchronized (SwingController.this) {
123
-            if (me == null) {
124
-                UIUtilities.invokeAndWait(new Runnable() {
125
-
126
-                    /** {@inheritDoc} */
127
-                    @Override
128
-                    public void run() {
129
-                        me = new MainFrame(SwingController.this);
130
-                        statusBar = me.getStatusBar();
131
-                    }
132
-                });
133
-                UIUtilities.invokeLater(new Runnable() {
134
-
135
-                    /** {@inheritDoc} */
136
-                    @Override
137
-                    public void run() {
138
-                        ErrorListDialog.getErrorListDialog(SwingController.this);
139
-                    }
140
-                });
141
-            }
142
-
143
-            return me;
144
-        }
120
+        return me;
145 121
     }
146 122
 
147 123
     /** {@inheritDoc} */
@@ -156,11 +132,6 @@ public final class SwingController extends Plugin implements UIController {
156 132
      * @return This UI's status bar
157 133
      */
158 134
     public SwingStatusBar getSwingStatusBar() {
159
-        STATUSBAR_SEMAPHORE.acquireUninterruptibly();
160
-        if (statusBar == null) {
161
-            getMainFrame();
162
-        }
163
-        STATUSBAR_SEMAPHORE.release();
164 135
         return statusBar;
165 136
     }
166 137
 
@@ -238,8 +209,7 @@ public final class SwingController extends Plugin implements UIController {
238 209
             /** {@inheritDoc} */
239 210
             @Override
240 211
             public void run() {
241
-                setObject(SwingUpdaterDialog.getSwingUpdaterDialog(updates,
242
-                        SwingController.this));
212
+                setObject(SwingUpdaterDialog.getSwingUpdaterDialog(updates, me));
243 213
             }
244 214
         });
245 215
     }
@@ -299,7 +269,7 @@ public final class SwingController extends Plugin implements UIController {
299 269
             /** {@inheritDoc} */
300 270
             @Override
301 271
             public void run() {
302
-                ChannelSettingsDialog.showChannelSettingsDialog(channel, getMainFrame());
272
+                ChannelSettingsDialog.showChannelSettingsDialog(channel, me);
303 273
             }
304 274
         });
305 275
     }
@@ -312,7 +282,7 @@ public final class SwingController extends Plugin implements UIController {
312 282
             /** {@inheritDoc} */
313 283
             @Override
314 284
             public void run() {
315
-                ServerSettingsDialog.showServerSettingsDialog(server, getMainFrame());
285
+                ServerSettingsDialog.showServerSettingsDialog(server, me);
316 286
             }
317 287
         });
318 288
     }
@@ -328,7 +298,7 @@ public final class SwingController extends Plugin implements UIController {
328 298
                 /** {@inheritDoc} */
329 299
                 @Override
330 300
                 public void run() {
331
-                    setObject(getMainFrame().getExtendedState());
301
+                    setObject(me.getExtendedState());
332 302
                 }
333 303
             });
334 304
             for (final java.awt.Window window : getTopLevelWindows()) {
@@ -338,7 +308,7 @@ public final class SwingController extends Plugin implements UIController {
338 308
                     @Override
339 309
                     public void run() {
340 310
                         SwingUtilities.updateComponentTreeUI(window);
341
-                        if (window != getMainFrame()) {
311
+                        if (window != me) {
342 312
                             window.pack();
343 313
                         }
344 314
                     }
@@ -349,7 +319,7 @@ public final class SwingController extends Plugin implements UIController {
349 319
                 /** {@inheritDoc} */
350 320
                 @Override
351 321
                 public void run() {
352
-                    getMainFrame().setExtendedState(state);
322
+                    me.setExtendedState(state);
353 323
                 }
354 324
             });
355 325
         } catch (ClassNotFoundException ex) {
@@ -460,7 +430,7 @@ public final class SwingController extends Plugin implements UIController {
460 430
             /** {@inheritDoc} */
461 431
             @Override
462 432
             public void run() {
463
-                URLDialog.showURLDialog(url, getMainFrame());
433
+                URLDialog.showURLDialog(url, me);
464 434
 
465 435
             }
466 436
         });
@@ -474,7 +444,7 @@ public final class SwingController extends Plugin implements UIController {
474 444
             /** {@inheritDoc} */
475 445
             @Override
476 446
             public void run() {
477
-                new SSLCertificateDialog(getMainFrame(), model).setVisible(true);
447
+                new SSLCertificateDialog(me, model).setVisible(true);
478 448
             }
479 449
         });
480 450
     }
@@ -527,7 +497,7 @@ public final class SwingController extends Plugin implements UIController {
527 497
     /** {@inheritDoc} */
528 498
     @Override
529 499
     public PreferencesInterface getUrlHandlersPrefsPanel() {
530
-        return new URLConfigPanel(getMainFrame());
500
+        return new URLConfigPanel(me);
531 501
     }
532 502
 
533 503
     /** {@inheritDoc} */
@@ -551,6 +521,16 @@ public final class SwingController extends Plugin implements UIController {
551 521
         if (GraphicsEnvironment.isHeadless()) {
552 522
             throw new IllegalStateException("Swing UI can't be run in a headless environment");
553 523
         }
524
+        UIUtilities.invokeAndWait(new Runnable() {
525
+
526
+            /** {@inheritDoc} */
527
+            @Override
528
+            public void run() {
529
+                me = new MainFrame(SwingController.this);
530
+                statusBar = me.getStatusBar();
531
+                ErrorListDialog.getErrorListDialog(me, me.getStatusBar());
532
+            }
533
+        });
554 534
 
555 535
         Main.setUI(this);
556 536
     }

+ 14
- 9
src/com/dmdirc/addons/ui_swing/components/statusbar/ErrorPanel.java View File

@@ -22,7 +22,7 @@
22 22
 
23 23
 package com.dmdirc.addons.ui_swing.components.statusbar;
24 24
 
25
-import com.dmdirc.addons.ui_swing.SwingController;
25
+import com.dmdirc.addons.ui_swing.MainFrame;
26 26
 import com.dmdirc.addons.ui_swing.dialogs.error.ErrorListDialog;
27 27
 import com.dmdirc.logger.ErrorLevel;
28 28
 import com.dmdirc.logger.ErrorListener;
@@ -63,7 +63,9 @@ public class ErrorPanel extends StatusbarPopupPanel implements ErrorListener, Ac
63 63
     /** Currently showing error level. */
64 64
     private ErrorLevel errorLevel;
65 65
     /** Status controller. */
66
-    private final SwingController controller;
66
+    private final MainFrame mainFrame;
67
+    /** Swing status bar. */
68
+    private SwingStatusBar statusBar;
67 69
     /** Error manager. */
68 70
     private final ErrorManager errorManager = ErrorManager.getErrorManager();
69 71
     /** Dismiss menu. */
@@ -76,12 +78,15 @@ public class ErrorPanel extends StatusbarPopupPanel implements ErrorListener, Ac
76 78
     /**
77 79
      * Creates a new ErrorPanel for the speicified status bar.
78 80
      *
79
-     * @param controller Swing controller
81
+     * @param mainFrame Main frame
82
+     * @param statusBar Status bar  
80 83
      */
81
-    public ErrorPanel(final SwingController controller) {
84
+    public ErrorPanel(final MainFrame mainFrame, final SwingStatusBar statusBar) {
82 85
         super(new JLabel());
83 86
 
84
-        this.controller = controller;
87
+        this.mainFrame = mainFrame;
88
+        this.statusBar = statusBar;
89
+        
85 90
         menu = new JPopupMenu();
86 91
         dismiss = new JMenuItem("Clear All");
87 92
         show = new JMenuItem("Open");
@@ -98,7 +103,7 @@ public class ErrorPanel extends StatusbarPopupPanel implements ErrorListener, Ac
98 103
     /** {@inheritDoc} */
99 104
     @Override
100 105
     protected StatusbarPopupWindow getWindow() {
101
-        return new ErrorPopup(this, controller.getMainFrame());
106
+        return new ErrorPopup(this, mainFrame);
102 107
     }
103 108
 
104 109
     /** Clears the error. */
@@ -154,7 +159,7 @@ public class ErrorPanel extends StatusbarPopupPanel implements ErrorListener, Ac
154 159
     /** {@inheritDoc} */
155 160
     @Override
156 161
     public boolean isReady() {
157
-        return controller.getMainFrame().getStatusBar().isValid();
162
+        return statusBar.isValid();
158 163
     }
159 164
 
160 165
     /**
@@ -210,7 +215,7 @@ public class ErrorPanel extends StatusbarPopupPanel implements ErrorListener, Ac
210 215
     public void mouseClicked(final MouseEvent mouseEvent) {
211 216
         super.mouseClicked(mouseEvent);
212 217
         if (mouseEvent.getButton() == MouseEvent.BUTTON1) {
213
-            ErrorListDialog.showErrorListDialog(controller);
218
+            ErrorListDialog.showErrorListDialog(mainFrame, statusBar);
214 219
         }
215 220
         checkMouseEvent(mouseEvent);
216 221
     }
@@ -234,7 +239,7 @@ public class ErrorPanel extends StatusbarPopupPanel implements ErrorListener, Ac
234 239
     @Override
235 240
     public void actionPerformed(final ActionEvent e) {
236 241
         if (e.getSource() == show) {
237
-            ErrorListDialog.showErrorListDialog(controller);
242
+            ErrorListDialog.showErrorListDialog(mainFrame, statusBar);
238 243
         } else {
239 244
             final Collection<ProgramError> errors =
240 245
                     ErrorManager.getErrorManager().getErrors();

+ 9
- 4
src/com/dmdirc/addons/ui_swing/components/statusbar/SwingStatusBar.java View File

@@ -22,6 +22,7 @@
22 22
 
23 23
 package com.dmdirc.addons.ui_swing.components.statusbar;
24 24
 
25
+import com.dmdirc.addons.ui_swing.MainFrame;
25 26
 import com.dmdirc.addons.ui_swing.SwingController;
26 27
 import com.dmdirc.logger.ErrorLevel;
27 28
 import com.dmdirc.logger.Logger;
@@ -56,21 +57,25 @@ public final class SwingStatusBar extends JPanel implements StatusBar {
56 57
     private final InviteLabel inviteLabel;
57 58
     /** Swing controller. */
58 59
     private SwingController controller;
60
+    /** Main frame. */
61
+    private MainFrame mainFrame;
59 62
 
60 63
     /**
61 64
      * Creates a new instance of SwingStatusBar.
62 65
      * 
63 66
      * @param controller Swing controller
67
+     * @param mainFrame Main frame
64 68
      */
65
-    public SwingStatusBar(final SwingController controller) {
69
+    public SwingStatusBar(final SwingController controller, final MainFrame mainFrame) {
66 70
         super();
67 71
         
68 72
         this.controller = controller;
73
+        this.mainFrame = mainFrame;
69 74
 
70 75
         messageLabel = new MessageLabel();
71
-        errorPanel = new ErrorPanel(controller);
72
-        updateLabel = new UpdaterLabel(controller);
73
-        inviteLabel = new InviteLabel(controller.getMainFrame());
76
+        errorPanel = new ErrorPanel(mainFrame, this);
77
+        updateLabel = new UpdaterLabel(mainFrame);
78
+        inviteLabel = new InviteLabel(mainFrame);
74 79
 
75 80
         setLayout(new MigLayout("fill, ins 0, hidemode 3"));
76 81
 

+ 6
- 6
src/com/dmdirc/addons/ui_swing/components/statusbar/UpdaterLabel.java View File

@@ -22,7 +22,7 @@
22 22
 
23 23
 package com.dmdirc.addons.ui_swing.components.statusbar;
24 24
 
25
-import com.dmdirc.addons.ui_swing.SwingController;
25
+import com.dmdirc.addons.ui_swing.MainFrame;
26 26
 import com.dmdirc.addons.ui_swing.dialogs.updater.SwingRestartDialog;
27 27
 import com.dmdirc.addons.ui_swing.dialogs.updater.SwingUpdaterDialog;
28 28
 import com.dmdirc.interfaces.UpdateCheckerListener;
@@ -52,17 +52,17 @@ public class UpdaterLabel extends JLabel implements StatusBarComponent,
52 52
      */
53 53
     private static final long serialVersionUID = 1;
54 54
     /** Swing controller. */
55
-    private SwingController controller;
55
+    private MainFrame mainFrame;
56 56
 
57 57
     /**
58 58
      * Instantiates a new updater label, handles showing updates on the status bar.
59 59
      * 
60
-     * @param controller Swing controller
60
+     * @param mainFrame Main frame
61 61
      */
62
-    public UpdaterLabel(final SwingController controller) {
62
+    public UpdaterLabel(final MainFrame mainFrame) {
63 63
         super();
64 64
         
65
-        this.controller = controller;
65
+        this.mainFrame = mainFrame;
66 66
         setBorder(BorderFactory.createEtchedBorder());
67 67
         addMouseListener(this);
68 68
         UpdateChecker.addListener(this);
@@ -123,7 +123,7 @@ public class UpdaterLabel extends JLabel implements StatusBarComponent,
123 123
                 restartDialog.setVisible(true);
124 124
             } else if (!UpdateChecker.getStatus().equals(UpdateChecker.STATE.CHECKING)) {
125 125
                 SwingUpdaterDialog.showSwingUpdaterDialog(
126
-                        UpdateChecker.getAvailableUpdates(), controller);
126
+                        UpdateChecker.getAvailableUpdates(), mainFrame);
127 127
             }
128 128
         }
129 129
     }

+ 23
- 15
src/com/dmdirc/addons/ui_swing/dialogs/error/ErrorListDialog.java View File

@@ -22,11 +22,12 @@
22 22
 
23 23
 package com.dmdirc.addons.ui_swing.dialogs.error;
24 24
 
25
-import com.dmdirc.addons.ui_swing.SwingController;
25
+import com.dmdirc.addons.ui_swing.MainFrame;
26 26
 import com.dmdirc.addons.ui_swing.components.PackingTable;
27 27
 import com.dmdirc.addons.ui_swing.components.StandardDialog;
28 28
 import com.dmdirc.addons.ui_swing.components.renderers.ErrorLevelIconCellRenderer;
29 29
 import com.dmdirc.addons.ui_swing.components.renderers.DateCellRenderer;
30
+import com.dmdirc.addons.ui_swing.components.statusbar.SwingStatusBar;
30 31
 import com.dmdirc.logger.ErrorListener;
31 32
 import com.dmdirc.logger.ErrorManager;
32 33
 import com.dmdirc.logger.ErrorReportStatus;
@@ -82,16 +83,22 @@ public final class ErrorListDialog extends StandardDialog implements
82 83
     /** Delete all button. */
83 84
     private JButton deleteAllButton;
84 85
     /** Swing Controller. */
85
-    private SwingController controller;
86
+    private MainFrame mainFrame;
87
+    /** Status bar. */
88
+    private SwingStatusBar statusBar;
86 89
 
87 90
     /** 
88 91
      * Creates a new instance of ErrorListDialog. 
89 92
      * 
90 93
      * @param controller Swing controller
91 94
      */
92
-    private ErrorListDialog(final SwingController controller) {
93
-        super(controller.getMainFrame(), ModalityType.MODELESS);
94
-        this.controller = controller;
95
+    private ErrorListDialog(final MainFrame mainFrame, final SwingStatusBar statusBar) {
96
+        super(mainFrame, ModalityType.MODELESS);
97
+        if (statusBar == null) {
98
+            new Exception().printStackTrace();
99
+        }
100
+        this.mainFrame = mainFrame;
101
+        this.statusBar = statusBar;
95 102
 
96 103
         setTitle("DMDirc: Error list");
97 104
 
@@ -107,10 +114,12 @@ public final class ErrorListDialog extends StandardDialog implements
107 114
     /** 
108 115
      * Returns the instance of ErrorListDialog.
109 116
      * 
110
-     * @param controller Swing controller
117
+     * @param mainFrame Main frame
118
+     * @param statusBar Status bar
111 119
      */
112
-    public static void showErrorListDialog(final SwingController controller) {
113
-        me = getErrorListDialog(controller);
120
+    public static void showErrorListDialog(final MainFrame mainFrame, 
121
+            final SwingStatusBar statusBar) {
122
+        me = getErrorListDialog(mainFrame, statusBar);
114 123
 
115 124
         me.setLocationRelativeTo(me.getParent());
116 125
         me.setVisible(true);
@@ -120,14 +129,16 @@ public final class ErrorListDialog extends StandardDialog implements
120 129
     /**
121 130
      * Returns the current instance of the ErrorListDialog.
122 131
      * 
123
-     * @param controller Swing controller
132
+     * @param mainFrame Main frame
133
+     * @param statusBar Status bar
124 134
      *
125 135
      * @return The current PluginDErrorListDialogialog instance
126 136
      */
127
-    public static ErrorListDialog getErrorListDialog(final SwingController controller) {
137
+    public static ErrorListDialog getErrorListDialog(final MainFrame mainFrame, 
138
+            final SwingStatusBar statusBar) {
128 139
         synchronized (ErrorListDialog.class) {
129 140
             if (me == null) {
130
-                me = new ErrorListDialog(controller);
141
+                me = new ErrorListDialog(mainFrame, statusBar);
131 142
             } else if (me.tableModel.getRowCount() !=
132 143
                     me.errorManager.getErrorCount()) {
133 144
                 me.tableModel = new ErrorTableModel(me.errorManager.getErrors());
@@ -382,10 +393,7 @@ public final class ErrorListDialog extends StandardDialog implements
382 393
     /** {@inheritDoc} */
383 394
     @Override
384 395
     public boolean isReady() {
385
-        if (controller == null) {
386
-            return false;
387
-        }
388
-        return controller.getSwingStatusBar().isVisible();
396
+        return statusBar.isVisible();
389 397
     }
390 398
     
391 399
     /** {@inheritDoc} */

+ 13
- 14
src/com/dmdirc/addons/ui_swing/dialogs/updater/SwingUpdaterDialog.java View File

@@ -22,10 +22,10 @@
22 22
 
23 23
 package com.dmdirc.addons.ui_swing.dialogs.updater;
24 24
 
25
+import com.dmdirc.addons.ui_swing.MainFrame;
25 26
 import com.dmdirc.interfaces.UpdateCheckerListener;
26 27
 import com.dmdirc.ui.interfaces.UpdaterDialog;
27 28
 import com.dmdirc.addons.ui_swing.components.TextLabel;
28
-import com.dmdirc.addons.ui_swing.SwingController;
29 29
 import com.dmdirc.addons.ui_swing.components.PackingTable;
30 30
 import com.dmdirc.addons.ui_swing.components.StandardDialog;
31 31
 import com.dmdirc.addons.ui_swing.components.renderers.UpdateComponentTableCellRenderer;
@@ -74,18 +74,18 @@ public final class SwingUpdaterDialog extends StandardDialog implements
74 74
     /** Update.Status renderer. */
75 75
     private UpdateStatusTableCellRenderer updateStatusRenderer;
76 76
     /** Swing controller. */
77
-    private SwingController controller;
77
+    private MainFrame mainFrame;
78 78
 
79 79
     /**
80 80
      * Creates a new instance of the updater dialog.
81 81
      * 
82 82
      * @param updates A list of updates that are available.
83
-     * @param controller Swing controller
83
+     * @param mainFrame Main frame
84 84
      */
85
-    private SwingUpdaterDialog(final List<Update> updates, final SwingController controller) {
86
-        super(controller.getMainFrame(), false);
85
+    private SwingUpdaterDialog(final List<Update> updates, final MainFrame mainFrame) {
86
+        super(mainFrame, ModalityType.MODELESS);
87 87
         
88
-        this.controller = controller;
88
+        this.mainFrame = mainFrame;
89 89
 
90 90
         initComponents(updates);
91 91
         layoutComponents();
@@ -103,11 +103,11 @@ public final class SwingUpdaterDialog extends StandardDialog implements
103 103
      * Creates the dialog if one doesn't exist, and displays it.
104 104
      * 
105 105
      * @param updates The updates that are available
106
-     * @param controller Swing controller
106
+     * @param mainFrame Main frame
107 107
      */
108 108
     public static void showSwingUpdaterDialog(
109
-            final List<Update> updates, final SwingController controller) {
110
-        me = getSwingUpdaterDialog(updates, controller);
109
+            final List<Update> updates, final MainFrame mainFrame) {
110
+        me = getSwingUpdaterDialog(updates, mainFrame);
111 111
         me.display();
112 112
     }
113 113
 
@@ -115,15 +115,14 @@ public final class SwingUpdaterDialog extends StandardDialog implements
115 115
      * Gets the dialog if one doesn't exist.
116 116
      * 
117 117
      * @param updates The updates that are available
118
-     * @param controller Swing controller
119
-     * 
118
+     * @param mainFrame Main frame
120 119
      * @return SwingUpdaterDialog instance
121 120
      */
122 121
     public static SwingUpdaterDialog getSwingUpdaterDialog(
123
-            final List<Update> updates, final SwingController controller) {
122
+            final List<Update> updates, final MainFrame mainFrame) {
124 123
         synchronized (SwingUpdaterDialog.class) {
125 124
             if (me == null) {
126
-                me = new SwingUpdaterDialog(updates, controller);
125
+                me = new SwingUpdaterDialog(updates, mainFrame);
127 126
             } else {
128 127
                 ((UpdateTableModel) me.table.getModel()).setUpdates(updates);
129 128
             }
@@ -194,7 +193,7 @@ public final class SwingUpdaterDialog extends StandardDialog implements
194 193
     /** {@inheritDoc} */
195 194
     @Override
196 195
     public void display() {
197
-        setLocationRelativeTo(controller.getMainFrame());
196
+        setLocationRelativeTo(mainFrame);
198 197
         setVisible(true);
199 198
         requestFocusInWindow();
200 199
     }

Loading…
Cancel
Save