Browse Source

Make MainFrame dependencies more explicit.

Change-Id: Id947cffed7ff7a879610769f8ab34bd6310d4c2c
Reviewed-on: http://gerrit.dmdirc.com/2919
Automatic-Compile: DMDirc Build Manager
Reviewed-by: Greg Holmes <greg@dmdirc.com>
tags/0.8
Chris Smith 10 years ago
parent
commit
03c127ee34

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

@@ -25,7 +25,6 @@ package com.dmdirc.addons.ui_swing;
25 25
 import com.dmdirc.FrameContainer;
26 26
 import com.dmdirc.actions.ActionManager;
27 27
 import com.dmdirc.actions.CoreActionType;
28
-import com.dmdirc.addons.ui_swing.components.LoggingSwingWorker;
29 28
 import com.dmdirc.addons.ui_swing.components.SplitPane;
30 29
 import com.dmdirc.addons.ui_swing.components.frames.TextFrame;
31 30
 import com.dmdirc.addons.ui_swing.components.menubar.MenuBar;
@@ -39,11 +38,13 @@ import com.dmdirc.addons.ui_swing.framemanager.tree.TreeFrameManager;
39 38
 import com.dmdirc.interfaces.FrameInfoListener;
40 39
 import com.dmdirc.interfaces.LifecycleController;
41 40
 import com.dmdirc.interfaces.NotificationListener;
41
+import com.dmdirc.interfaces.config.AggregateConfigProvider;
42 42
 import com.dmdirc.interfaces.config.ConfigChangeListener;
43 43
 import com.dmdirc.logger.ErrorLevel;
44 44
 import com.dmdirc.logger.Logger;
45 45
 import com.dmdirc.ui.Colour;
46 46
 import com.dmdirc.ui.CoreUIUtils;
47
+import com.dmdirc.ui.IconManager;
47 48
 import com.dmdirc.ui.WindowManager;
48 49
 import com.dmdirc.util.collections.ListenerList;
49 50
 import com.dmdirc.util.collections.QueuedLinkedHashSet;
@@ -54,6 +55,7 @@ import java.awt.event.WindowEvent;
54 55
 import java.awt.event.WindowFocusListener;
55 56
 import java.awt.event.WindowListener;
56 57
 
58
+import javax.inject.Provider;
57 59
 import javax.swing.ImageIcon;
58 60
 import javax.swing.JFrame;
59 61
 import javax.swing.JPanel;
@@ -88,6 +90,12 @@ public class MainFrame extends JFrame implements WindowListener,
88 90
     private final LifecycleController lifecycleController;
89 91
     /** The window factory to use to create and listen for windows. */
90 92
     private final SwingWindowFactory windowFactory;
93
+    /** The global config to read settings from. */
94
+    private final AggregateConfigProvider globalConfig;
95
+    /** The icon manager to use to get icons. */
96
+    private final IconManager iconManager;
97
+    /** The quit worker to use when quitting the app. */
98
+    private final Provider<QuitWorker> quitWorker;
91 99
     /** Client Version. */
92 100
     private final String version;
93 101
     /** Frame manager used for ctrl tab frame switching. */
@@ -126,47 +134,47 @@ public class MainFrame extends JFrame implements WindowListener,
126 134
      * @param controller Swing controller
127 135
      * @param windowFactory The window factory to use to create and listen for windows.
128 136
      * @param lifecycleController Controller to use to end the application.
137
+     * @param globalConfig The config to read settings from.
138
+     * @param quitWorker The quit worker to use when quitting the app.
139
+     * @param iconManager The icon manager to use to get icons.
129 140
      * @param windowManager Window management
130 141
      */
131 142
     public MainFrame(
132 143
             final SwingController controller,
133 144
             final SwingWindowFactory windowFactory,
134 145
             final LifecycleController lifecycleController,
146
+            final AggregateConfigProvider globalConfig,
147
+            final Provider<QuitWorker> quitWorker,
148
+            final IconManager iconManager,
135 149
             final WindowManager windowManager) {
136 150
         super();
137 151
 
138 152
         this.controller = controller;
139 153
         this.windowFactory = windowFactory;
140 154
         this.lifecycleController = lifecycleController;
155
+        this.globalConfig = globalConfig;
156
+        this.quitWorker = quitWorker;
157
+        this.iconManager = iconManager;
141 158
         this.windowManager = windowManager;
142 159
 
143 160
         focusOrder = new QueuedLinkedHashSet<>();
144 161
         initComponents();
145 162
 
146
-        imageIcon = new ImageIcon(controller.getIconManager().getImage("icon"));
163
+        imageIcon = new ImageIcon(iconManager.getImage("icon"));
147 164
         setIconImage(imageIcon.getImage());
148 165
 
149 166
         CoreUIUtils.centreWindow(this);
150 167
 
151 168
         addWindowListener(this);
152 169
 
153
-        showVersion = controller.getGlobalConfig().getOptionBool("ui",
154
-                "showversion");
155
-        version = controller.getGlobalConfig().getOption("version",
156
-                "version");
157
-        controller.getGlobalConfig().addChangeListener("ui", "lookandfeel",
158
-                this);
159
-        controller.getGlobalConfig().addChangeListener("ui", "showversion",
160
-                this);
161
-        controller.getGlobalConfig().addChangeListener("ui",
162
-                "framemanager", this);
163
-        controller.getGlobalConfig().addChangeListener("ui",
164
-                "framemanagerPosition", this);
165
-        controller.getGlobalConfig().addChangeListener("ui",
166
-                "textPaneFontName", this);
167
-        controller.getGlobalConfig().addChangeListener("icon", "icon",
168
-                this);
169
-
170
+        showVersion = globalConfig.getOptionBool("ui", "showversion");
171
+        version = globalConfig.getOption("version", "version");
172
+        globalConfig.addChangeListener("ui", "lookandfeel", this);
173
+        globalConfig.addChangeListener("ui", "showversion", this);
174
+        globalConfig.addChangeListener("ui", "framemanager", this);
175
+        globalConfig.addChangeListener("ui", "framemanagerPosition", this);
176
+        globalConfig.addChangeListener("ui", "textPaneFontName", this);
177
+        globalConfig.addChangeListener("icon", "icon", this);
170 178
 
171 179
         addWindowFocusListener(new WindowFocusListener() {
172 180
 
@@ -220,7 +228,7 @@ public class MainFrame extends JFrame implements WindowListener,
220 228
         return (MenuBar) super.getJMenuBar();
221 229
     }
222 230
 
223
-    /** {@inheritDoc}. */
231
+    /** {@inheritDoc} */
224 232
     @Override
225 233
     public void setTitle(final String title) {
226 234
         UIUtilities.invokeLater(new Runnable() {
@@ -247,7 +255,7 @@ public class MainFrame extends JFrame implements WindowListener,
247 255
     }
248 256
 
249 257
     /**
250
-     * {@inheritDoc}.
258
+     * {@inheritDoc}
251 259
      *
252 260
      * @param windowEvent Window event
253 261
      */
@@ -257,7 +265,7 @@ public class MainFrame extends JFrame implements WindowListener,
257 265
     }
258 266
 
259 267
     /**
260
-     * {@inheritDoc}.
268
+     * {@inheritDoc}
261 269
      *
262 270
      * @param windowEvent Window event
263 271
      */
@@ -267,7 +275,7 @@ public class MainFrame extends JFrame implements WindowListener,
267 275
     }
268 276
 
269 277
     /**
270
-     * {@inheritDoc}.
278
+     * {@inheritDoc}
271 279
      *
272 280
      * @param windowEvent Window event
273 281
      */
@@ -284,7 +292,7 @@ public class MainFrame extends JFrame implements WindowListener,
284 292
     }
285 293
 
286 294
     /**
287
-     * {@inheritDoc}.
295
+     * {@inheritDoc}
288 296
      *
289 297
      * @param windowEvent Window event
290 298
      */
@@ -336,8 +344,7 @@ public class MainFrame extends JFrame implements WindowListener,
336 344
                 if (mainFrameManager != null) {
337 345
                     windowFactory.removeWindowListener(mainFrameManager);
338 346
                 }
339
-                final String manager = controller.getGlobalConfig()
340
-                        .getOption("ui", "framemanager");
347
+                final String manager = globalConfig.getOption("ui", "framemanager");
341 348
                 try {
342 349
                     mainFrameManager = (FrameManager) Class.forName(manager)
343 350
                             .getConstructor(WindowManager.class).newInstance(windowManager);
@@ -398,10 +405,9 @@ public class MainFrame extends JFrame implements WindowListener,
398 405
      * @return Returns the initialised split pane
399 406
      */
400 407
     private SplitPane initSplitPane() {
401
-        final SplitPane splitPane = new SplitPane(controller.getGlobalConfig(),
402
-                SplitPane.Orientation.HORIZONTAL);
403
-        position = FramemanagerPosition.getPosition(controller
404
-                .getGlobalConfig().getOption("ui", "framemanagerPosition"));
408
+        final SplitPane splitPane = new SplitPane(globalConfig, SplitPane.Orientation.HORIZONTAL);
409
+        position = FramemanagerPosition.getPosition(
410
+                globalConfig.getOption("ui", "framemanagerPosition"));
405 411
 
406 412
         if (position == FramemanagerPosition.UNKNOWN) {
407 413
             position = FramemanagerPosition.LEFT;
@@ -425,8 +431,7 @@ public class MainFrame extends JFrame implements WindowListener,
425 431
                 splitPane.setResizeWeight(0.0);
426 432
                 splitPane.setOrientation(JSplitPane.VERTICAL_SPLIT);
427 433
                 frameManagerPanel.setPreferredSize(new Dimension(
428
-                        Integer.MAX_VALUE, controller.getGlobalConfig().
429
-                        getOptionInt("ui", "frameManagerSize")));
434
+                        Integer.MAX_VALUE, globalConfig.getOptionInt("ui", "frameManagerSize")));
430 435
                 break;
431 436
             case LEFT:
432 437
                 splitPane.setLeftComponent(frameManagerPanel);
@@ -434,8 +439,7 @@ public class MainFrame extends JFrame implements WindowListener,
434 439
                 splitPane.setResizeWeight(0.0);
435 440
                 splitPane.setOrientation(JSplitPane.HORIZONTAL_SPLIT);
436 441
                 frameManagerPanel.setPreferredSize(new Dimension(
437
-                        controller.getGlobalConfig().getOptionInt("ui",
438
-                        "frameManagerSize"), Integer.MAX_VALUE));
442
+                        globalConfig.getOptionInt("ui", "frameManagerSize"), Integer.MAX_VALUE));
439 443
                 break;
440 444
             case BOTTOM:
441 445
                 splitPane.setTopComponent(framePanel);
@@ -443,8 +447,7 @@ public class MainFrame extends JFrame implements WindowListener,
443 447
                 splitPane.setResizeWeight(1.0);
444 448
                 splitPane.setOrientation(JSplitPane.VERTICAL_SPLIT);
445 449
                 frameManagerPanel.setPreferredSize(new Dimension(
446
-                        Integer.MAX_VALUE, controller.getGlobalConfig().
447
-                        getOptionInt("ui", "frameManagerSize")));
450
+                        Integer.MAX_VALUE, globalConfig.getOptionInt("ui", "frameManagerSize")));
448 451
                 break;
449 452
             case RIGHT:
450 453
                 splitPane.setLeftComponent(framePanel);
@@ -452,8 +455,7 @@ public class MainFrame extends JFrame implements WindowListener,
452 455
                 splitPane.setResizeWeight(1.0);
453 456
                 splitPane.setOrientation(JSplitPane.HORIZONTAL_SPLIT);
454 457
                 frameManagerPanel.setPreferredSize(new Dimension(
455
-                        controller.getGlobalConfig().getOptionInt("ui",
456
-                        "frameManagerSize"), Integer.MAX_VALUE));
458
+                        globalConfig.getOptionInt("ui", "frameManagerSize"), Integer.MAX_VALUE));
457 459
                 break;
458 460
             default:
459 461
                 break;
@@ -475,8 +477,7 @@ public class MainFrame extends JFrame implements WindowListener,
475 477
      * @param exitCode Exit code
476 478
      */
477 479
     public void quit(final int exitCode) {
478
-        if (exitCode == 0 && controller.getGlobalConfig().getOptionBool(
479
-                "ui", "confirmQuit")) {
480
+        if (exitCode == 0 && globalConfig.getOptionBool("ui", "confirmQuit")) {
480 481
             final StandardQuestionDialog dialog = new ConfirmQuitDialog(controller) {
481 482
 
482 483
                 /** Serial version UID. */
@@ -503,28 +504,7 @@ public class MainFrame extends JFrame implements WindowListener,
503 504
         this.exitCode = exitCode;
504 505
         quitting = true;
505 506
 
506
-        new LoggingSwingWorker<Void, Void>() {
507
-
508
-            /** {@inheritDoc} */
509
-            @Override
510
-            protected Void doInBackground() {
511
-                ActionManager.getActionManager().triggerEvent(
512
-                        CoreActionType.CLIENT_CLOSING, null);
513
-                controller.getServerManager().closeAll(controller
514
-                        .getGlobalConfig().getOption("general", "closemessage"));
515
-                controller.getGlobalIdentity().setOption("ui",
516
-                        "frameManagerSize",
517
-                        String.valueOf(getFrameManagerSize()));
518
-                return null;
519
-            }
520
-
521
-            /** {@inheritDoc} */
522
-            @Override
523
-            protected void done() {
524
-                super.done();
525
-                dispose();
526
-            }
527
-        }.executeInExecutor();
507
+        quitWorker.get().executeInExecutor();
528 508
     }
529 509
 
530 510
     /** {@inheritDoc} */
@@ -552,19 +532,17 @@ public class MainFrame extends JFrame implements WindowListener,
552 532
                     });
553 533
                     break;
554 534
                 case "textPaneFontName":
555
-                    final String font = controller.getGlobalConfig()
556
-                            .getOptionString("ui", "textPaneFontName");
535
+                    final String font = globalConfig.getOptionString("ui", "textPaneFontName");
557 536
                     log.debug("Changing textpane font: {}", font);
558 537
                     UIUtilities.setUIFont(new Font(font, Font.PLAIN, 12));
559 538
                     controller.updateComponentTrees();
560 539
                     break;
561 540
                 default:
562
-                    showVersion = controller.getGlobalConfig().getOptionBool(
563
-                            "ui", "showversion");
541
+                    showVersion = globalConfig.getOptionBool("ui", "showversion");
564 542
                     break;
565 543
             }
566 544
         } else {
567
-            imageIcon = new ImageIcon(controller.getIconManager().getImage("icon"));
545
+            imageIcon = new ImageIcon(iconManager.getImage("icon"));
568 546
             UIUtilities.invokeLater(new Runnable() {
569 547
 
570 548
                 /** {@inheritDoc} */
@@ -721,7 +699,8 @@ public class MainFrame extends JFrame implements WindowListener,
721 699
         if (!quitting) {
722 700
             removeWindowListener(this);
723 701
         }
724
-        controller.getGlobalConfig().removeListener(this);
702
+
703
+        globalConfig.removeListener(this);
725 704
         super.dispose();
726 705
     }
727 706
 }

+ 92
- 0
src/com/dmdirc/addons/ui_swing/QuitWorker.java View File

@@ -0,0 +1,92 @@
1
+/*
2
+ * Copyright (c) 2006-2013 DMDirc Developers
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.addons.ui_swing;
24
+
25
+import com.dmdirc.ServerManager;
26
+import com.dmdirc.actions.ActionManager;
27
+import com.dmdirc.actions.CoreActionType;
28
+import com.dmdirc.interfaces.config.AggregateConfigProvider;
29
+import com.dmdirc.interfaces.config.ConfigProvider;
30
+import com.dmdirc.interfaces.config.IdentityController;
31
+
32
+import javax.inject.Inject;
33
+import javax.swing.SwingWorker;
34
+
35
+/**
36
+ * Worker which handles quitting the application on behalf of a {@link MainFrame}.
37
+ */
38
+public class QuitWorker extends SwingWorker<Void, Void> {
39
+
40
+    /** The identity to write settings to. */
41
+    private final ConfigProvider globalIdentity;
42
+    /** The config to read settings from. */
43
+    private final AggregateConfigProvider globalConfig;
44
+    /** The server manager to use to disconnect all servers. */
45
+    private final ServerManager serverManager;
46
+    /** The main frame to interact with. */
47
+    private final MainFrame mainFrame;
48
+
49
+    /**
50
+     * Creates a new {@link QuitWorker}.
51
+     *
52
+     * @param identityController The identity controller to use to read/write settings.
53
+     * @param serverManager The server manager to use to disconnect all servers.
54
+     * @param mainFrame The main frame to interact with.
55
+     */
56
+    @Inject
57
+    public QuitWorker(
58
+            final IdentityController identityController,
59
+            final ServerManager serverManager,
60
+            final MainFrame mainFrame) {
61
+        this.globalIdentity = identityController.getUserSettings();
62
+        this.globalConfig = identityController.getGlobalConfiguration();
63
+        this.serverManager = serverManager;
64
+        this.mainFrame = mainFrame;
65
+    }
66
+
67
+    /** {@inheritDoc} */
68
+    @Override
69
+    protected Void doInBackground() {
70
+        ActionManager.getActionManager().triggerEvent(
71
+                CoreActionType.CLIENT_CLOSING, null);
72
+        serverManager.closeAll(globalConfig.getOption("general", "closemessage"));
73
+        globalIdentity.setOption("ui", "frameManagerSize",
74
+                String.valueOf(mainFrame.getFrameManagerSize()));
75
+        return null;
76
+    }
77
+
78
+    /** {@inheritDoc} */
79
+    @Override
80
+    protected void done() {
81
+        super.done();
82
+        mainFrame.dispose();
83
+    }
84
+
85
+    /**
86
+     * Execute this swing worker in the swing worker executor.
87
+     */
88
+    public void executeInExecutor() {
89
+        SwingWorkerExecutor.queue(this);
90
+    }
91
+
92
+}

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

@@ -507,6 +507,7 @@ public class SwingController extends BaseCommandPlugin implements UIController {
507 507
         initUISettings();
508 508
 
509 509
         setObjectGraph(graph.plus(new SwingModule(this)));
510
+        getObjectGraph().validate();
510 511
         swingManager = getObjectGraph().get(SwingManager.class);
511 512
 
512 513
         registerCommand(ServerSettings.class, ServerSettings.INFO);

+ 15
- 2
src/com/dmdirc/addons/ui_swing/SwingModule.java View File

@@ -23,16 +23,21 @@
23 23
 package com.dmdirc.addons.ui_swing;
24 24
 
25 25
 import com.dmdirc.ClientModule;
26
+import com.dmdirc.ClientModule.GlobalConfig;
26 27
 import com.dmdirc.addons.ui_swing.commands.ChannelSettings;
27 28
 import com.dmdirc.addons.ui_swing.commands.Input;
28 29
 import com.dmdirc.addons.ui_swing.commands.PopInCommand;
29 30
 import com.dmdirc.addons.ui_swing.commands.PopOutCommand;
30 31
 import com.dmdirc.addons.ui_swing.commands.ServerSettings;
31 32
 import com.dmdirc.interfaces.LifecycleController;
33
+import com.dmdirc.interfaces.config.AggregateConfigProvider;
34
+import com.dmdirc.ui.IconManager;
32 35
 import com.dmdirc.ui.WindowManager;
36
+import com.dmdirc.util.URLBuilder;
33 37
 
34 38
 import java.util.concurrent.Callable;
35 39
 
40
+import javax.inject.Provider;
36 41
 import javax.inject.Singleton;
37 42
 
38 43
 import dagger.Module;
@@ -50,8 +55,7 @@ import dagger.Provides;
50 55
             Input.class,
51 56
             ServerSettings.class,
52 57
             ChannelSettings.class,
53
-        },
54
-        library = true
58
+        }
55 59
 )
56 60
 public class SwingModule {
57 61
 
@@ -84,6 +88,9 @@ public class SwingModule {
84 88
      * @param swingController The controller that will own the frame.
85 89
      * @param windowFactory The window factory to use to create and listen for windows.
86 90
      * @param lifecycleController The controller to use to quit the application.
91
+     * @param globalConfig The config to read settings from.
92
+     * @param quitWorker The worker to use when quitting the application.
93
+     * @param urlBuilder The URL builder to use to find icons.
87 94
      * @param windowManager The core window manager to use to find windows.
88 95
      * @return The main window.
89 96
      */
@@ -93,6 +100,9 @@ public class SwingModule {
93 100
             final SwingController swingController,
94 101
             final SwingWindowFactory windowFactory,
95 102
             final LifecycleController lifecycleController,
103
+            @GlobalConfig final AggregateConfigProvider globalConfig,
104
+            final Provider<QuitWorker> quitWorker,
105
+            final URLBuilder urlBuilder,
96 106
             final WindowManager windowManager) {
97 107
         return UIUtilities.invokeAndWait(new Callable<MainFrame>() {
98 108
             /** {@inheritDoc} */
@@ -102,6 +112,9 @@ public class SwingModule {
102 112
                         swingController,
103 113
                         windowFactory,
104 114
                         lifecycleController,
115
+                        globalConfig,
116
+                        quitWorker,
117
+                        new IconManager(globalConfig, urlBuilder),
105 118
                         windowManager);
106 119
             }
107 120
         });

+ 0
- 4
src/com/dmdirc/addons/ui_swing/framemanager/ctrltab/CtrlTabWindowManager.java View File

@@ -61,8 +61,6 @@ public class CtrlTabWindowManager implements SwingWindowListener,
61 61
     private final TreeViewModel model;
62 62
     /** Tree Scroller. */
63 63
     private final TreeScroller treeScroller;
64
-    /** Window factory. */
65
-    private final SwingWindowFactory windowFactory;
66 64
     /** Selection model for the tree scroller. */
67 65
     private final TreeSelectionModel selectionModel;
68 66
 
@@ -93,9 +91,7 @@ public class CtrlTabWindowManager implements SwingWindowListener,
93 91
             }
94 92
         };
95 93
 
96
-        this.windowFactory = windowFactory;
97 94
         windowFactory.addWindowListener(this);
98
-
99 95
         mainFrame.addSelectionListener(this);
100 96
 
101 97
         component.getActionMap().put("prevFrameAction",

Loading…
Cancel
Save