Browse Source

Merge pull request #92 from greboid/tidying

Tidying
pull/93/head
Chris Smith 9 years ago
parent
commit
052bbb10b8
1 changed files with 60 additions and 124 deletions
  1. 60
    124
      ui_swing/src/com/dmdirc/addons/ui_swing/MainFrame.java

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

@@ -48,7 +48,6 @@ import com.dmdirc.interfaces.config.ConfigChangeListener;
48 48
 import com.dmdirc.interfaces.ui.Window;
49 49
 import com.dmdirc.ui.CoreUIUtils;
50 50
 import com.dmdirc.ui.IconManager;
51
-import com.dmdirc.util.collections.ListenerList;
52 51
 import com.dmdirc.util.collections.QueuedLinkedHashSet;
53 52
 
54 53
 import java.awt.Dimension;
@@ -95,8 +94,6 @@ public class MainFrame extends JFrame implements WindowListener, ConfigChangeLis
95 94
     private final String version;
96 95
     /** Frame manager used for ctrl tab frame switching. */
97 96
     private CtrlTabWindowManager frameManager;
98
-    /** The listeners registered with this class. */
99
-    private final ListenerList listeners = new ListenerList();
100 97
     /** Provider of frame managers. */
101 98
     private final Provider<FrameManager> frameManagerProvider;
102 99
     /** The bus to despatch events on. */
@@ -118,7 +115,7 @@ public class MainFrame extends JFrame implements WindowListener, ConfigChangeLis
118 115
     /** Show version? */
119 116
     private boolean showVersion;
120 117
     /** Exit code. */
121
-    private int exitCode = 0;
118
+    private int exitCode;
122 119
     /** Status bar. */
123 120
     private SwingStatusBar statusBar;
124 121
     /** Main split pane. */
@@ -197,10 +194,6 @@ public class MainFrame extends JFrame implements WindowListener, ConfigChangeLis
197 194
         super.setVisible(visible);
198 195
     }
199 196
 
200
-    public SwingStatusBar getStatusBar() {
201
-        return statusBar;
202
-    }
203
-
204 197
     /**
205 198
      * Returns the size of the frame manager.
206 199
      *
@@ -221,15 +214,11 @@ public class MainFrame extends JFrame implements WindowListener, ConfigChangeLis
221 214
 
222 215
     @Override
223 216
     public void setTitle(final String title) {
224
-        UIUtilities.invokeLater(new Runnable() {
225
-
226
-            @Override
227
-            public void run() {
228
-                if (title == null || activeFrame == null) {
229
-                    MainFrame.super.setTitle(getTitlePrefix());
230
-                } else {
231
-                    MainFrame.super.setTitle(getTitlePrefix() + " - " + title);
232
-                }
217
+        UIUtilities.invokeLater(() -> {
218
+            if (title == null || activeFrame == null) {
219
+                MainFrame.super.setTitle(getTitlePrefix());
220
+            } else {
221
+                MainFrame.super.setTitle(getTitlePrefix() + " - " + title);
233 222
             }
234 223
         });
235 224
     }
@@ -240,7 +229,7 @@ public class MainFrame extends JFrame implements WindowListener, ConfigChangeLis
240 229
      * @return This frame's title prefix
241 230
      */
242 231
     private String getTitlePrefix() {
243
-        return "DMDirc" + (showVersion ? " " + version : "");
232
+        return "DMDirc" + (showVersion ? ' ' + version : "");
244 233
     }
245 234
 
246 235
     @Override
@@ -255,13 +244,7 @@ public class MainFrame extends JFrame implements WindowListener, ConfigChangeLis
255 244
 
256 245
     @Override
257 246
     public void windowClosed(final WindowEvent windowEvent) {
258
-        new Thread(new Runnable() {
259
-
260
-            @Override
261
-            public void run() {
262
-                lifecycleController.quit(exitCode);
263
-            }
264
-        }, "Quit thread").start();
247
+        new Thread(() -> lifecycleController.quit(exitCode), "Quit thread").start();
265 248
     }
266 249
 
267 250
     @Override
@@ -269,31 +252,16 @@ public class MainFrame extends JFrame implements WindowListener, ConfigChangeLis
269 252
         eventBus.publishAsync(new ClientMinimisedEvent());
270 253
     }
271 254
 
272
-    /**
273
-     * {@inheritDoc}.
274
-     *
275
-     * @param windowEvent Window event
276
-     */
277 255
     @Override
278 256
     public void windowDeiconified(final WindowEvent windowEvent) {
279 257
         eventBus.publishAsync(new ClientUnminimisedEvent());
280 258
     }
281 259
 
282
-    /**
283
-     * {@inheritDoc}.
284
-     *
285
-     * @param windowEvent Window event
286
-     */
287 260
     @Override
288 261
     public void windowActivated(final WindowEvent windowEvent) {
289 262
         //ignore
290 263
     }
291 264
 
292
-    /**
293
-     * {@inheritDoc}.
294
-     *
295
-     * @param windowEvent Window event
296
-     */
297 265
     @Override
298 266
     public void windowDeactivated(final WindowEvent windowEvent) {
299 267
         //ignore
@@ -301,18 +269,14 @@ public class MainFrame extends JFrame implements WindowListener, ConfigChangeLis
301 269
 
302 270
     /** Initialiases the frame managers. */
303 271
     private void initFrameManagers() {
304
-        UIUtilities.invokeAndWait(new Runnable() {
305
-
306
-            @Override
307
-            public void run() {
308
-                frameManagerPanel.removeAll();
309
-                if (mainFrameManager != null) {
310
-                    swingEventBus.unsubscribe(mainFrameManager);
311
-                }
312
-                mainFrameManager = frameManagerProvider.get();
313
-                mainFrameManager.setParent(frameManagerPanel);
314
-                swingEventBus.subscribe(mainFrameManager);
272
+        UIUtilities.invokeAndWait(() -> {
273
+            frameManagerPanel.removeAll();
274
+            if (mainFrameManager != null) {
275
+                swingEventBus.unsubscribe(mainFrameManager);
315 276
             }
277
+            mainFrameManager = frameManagerProvider.get();
278
+            mainFrameManager.setParent(frameManagerPanel);
279
+            swingEventBus.subscribe(mainFrameManager);
316 280
         });
317 281
     }
318 282
 
@@ -320,26 +284,22 @@ public class MainFrame extends JFrame implements WindowListener, ConfigChangeLis
320 284
      * Initialises the components for this frame.
321 285
      */
322 286
     public void initComponents() {
323
-        UIUtilities.invokeAndWait(new Runnable() {
324
-
325
-            @Override
326
-            public void run() {
327
-                frameManagerPanel = new JPanel();
328
-                activeFrame = null;
329
-                framePanel = new JPanel(new MigLayout("fill, ins 0"));
330
-                initFrameManagers();
331
-                mainSplitPane = initSplitPane();
287
+        UIUtilities.invokeAndWait(() -> {
288
+            frameManagerPanel = new JPanel();
289
+            activeFrame = null;
290
+            framePanel = new JPanel(new MigLayout("fill, ins 0"));
291
+            initFrameManagers();
292
+            mainSplitPane = initSplitPane();
332 293
 
333
-                setPreferredSize(new Dimension(800, 600));
294
+            setPreferredSize(new Dimension(800, 600));
334 295
 
335
-                getContentPane().setLayout(new MigLayout(
336
-                        "fill, ins rel, wrap 1, hidemode 2"));
337
-                layoutComponents();
296
+            getContentPane().setLayout(new MigLayout(
297
+                    "fill, ins rel, wrap 1, hidemode 2"));
298
+            layoutComponents();
338 299
 
339
-                setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
300
+            setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
340 301
 
341
-                pack();
342
-            }
302
+            pack();
343 303
         });
344 304
     }
345 305
 
@@ -352,13 +312,9 @@ public class MainFrame extends JFrame implements WindowListener, ConfigChangeLis
352 312
      * @param menuBar The menu bar to use.
353 313
      */
354 314
     public void setMenuBar(final MenuBar menuBar) {
355
-        UIUtilities.invokeAndWait(new Runnable() {
356
-
357
-            @Override
358
-            public void run() {
359
-                apple.setMenuBar(menuBar);
360
-                setJMenuBar(menuBar);
361
-            }
315
+        UIUtilities.invokeAndWait(() -> {
316
+            apple.setMenuBar(menuBar);
317
+            setJMenuBar(menuBar);
362 318
         });
363 319
     }
364 320
 
@@ -507,17 +463,13 @@ public class MainFrame extends JFrame implements WindowListener, ConfigChangeLis
507 463
             switch (key) {
508 464
                 case "framemanager":
509 465
                 case "framemanagerPosition":
510
-                    UIUtilities.invokeAndWait(new Runnable() {
511
-
512
-                        @Override
513
-                        public void run() {
514
-                            setVisible(false);
515
-                            getContentPane().remove(mainSplitPane);
516
-                            initFrameManagers();
517
-                            getContentPane().removeAll();
518
-                            layoutComponents();
519
-                            setVisible(true);
520
-                        }
466
+                    UIUtilities.invokeAndWait(() -> {
467
+                        setVisible(false);
468
+                        getContentPane().remove(mainSplitPane);
469
+                        initFrameManagers();
470
+                        getContentPane().removeAll();
471
+                        layoutComponents();
472
+                        setVisible(true);
521 473
                     });
522 474
                     break;
523 475
                 default:
@@ -526,13 +478,7 @@ public class MainFrame extends JFrame implements WindowListener, ConfigChangeLis
526 478
             }
527 479
         } else {
528 480
             imageIcon = new ImageIcon(iconManager.getImage("icon"));
529
-            UIUtilities.invokeLater(new Runnable() {
530
-
531
-                @Override
532
-                public void run() {
533
-                    setIconImage(imageIcon.getImage());
534
-                }
535
-            });
481
+            UIUtilities.invokeLater(() -> setIconImage(imageIcon.getImage()));
536 482
         }
537 483
     }
538 484
 
@@ -543,35 +489,31 @@ public class MainFrame extends JFrame implements WindowListener, ConfigChangeLis
543 489
 
544 490
     @Override
545 491
     public void setActiveFrame(final TextFrame activeFrame) {
546
-        UIUtilities.invokeLater(new Runnable() {
547
-
548
-            @Override
549
-            public void run() {
550
-                focusOrder.offerAndMove(activeFrame);
551
-                framePanel.setVisible(false);
552
-                framePanel.removeAll();
553
-
554
-                MainFrame.this.activeFrame = activeFrame;
555
-
556
-                if (activeFrame == null) {
557
-                    framePanel.add(new JPanel(), "grow");
558
-                    setTitle(null);
559
-                } else {
560
-                    framePanel.add(activeFrame.getDisplayFrame(), "grow");
561
-                    setTitle(activeFrame.getContainer().getTitle());
562
-                }
492
+        UIUtilities.invokeLater(() -> {
493
+            focusOrder.offerAndMove(activeFrame);
494
+            framePanel.setVisible(false);
495
+            framePanel.removeAll();
563 496
 
564
-                framePanel.setVisible(true);
497
+            this.activeFrame = activeFrame;
565 498
 
566
-                if (activeFrame != null) {
567
-                    activeFrame.requestFocus();
568
-                    activeFrame.requestFocusInWindow();
569
-                    activeFrame.activateFrame();
570
-                }
499
+            if (activeFrame == null) {
500
+                framePanel.add(new JPanel(), "grow");
501
+                setTitle(null);
502
+            } else {
503
+                framePanel.add(activeFrame.getDisplayFrame(), "grow");
504
+                setTitle(activeFrame.getContainer().getTitle());
505
+            }
571 506
 
572
-                swingEventBus.publish(
573
-                        new SwingWindowSelectedEvent(Optional.ofNullable((Window) activeFrame)));
507
+            framePanel.setVisible(true);
508
+
509
+            if (activeFrame != null) {
510
+                activeFrame.requestFocus();
511
+                activeFrame.requestFocusInWindow();
512
+                activeFrame.activateFrame();
574 513
             }
514
+
515
+            swingEventBus.publish(
516
+                    new SwingWindowSelectedEvent(Optional.ofNullable((Window) activeFrame)));
575 517
         });
576 518
     }
577 519
 
@@ -596,13 +538,7 @@ public class MainFrame extends JFrame implements WindowListener, ConfigChangeLis
596 538
             framePanel.removeAll();
597 539
             framePanel.setVisible(true);
598 540
             if (focusOrder.peek() == null) {
599
-                SwingUtilities.invokeLater(new Runnable() {
600
-
601
-                    @Override
602
-                    public void run() {
603
-                        frameManager.scrollUp();
604
-                    }
605
-                });
541
+                SwingUtilities.invokeLater(frameManager::scrollUp);
606 542
             } else {
607 543
                 setActiveFrame(focusOrder.peek());
608 544
             }

Loading…
Cancel
Save