Browse Source

Initial foray into Swing UI DI.

Add a SwingManager to manage the injected content - eventually
this will become the SwingController.

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

+ 4
- 0
src/com/dmdirc/addons/ui_swing/DMDircEventQueue.java View File

@@ -37,6 +37,8 @@ import java.awt.event.KeyEvent;
37 37
 import java.awt.event.MouseEvent;
38 38
 import java.awt.event.WindowEvent;
39 39
 
40
+import javax.inject.Inject;
41
+import javax.inject.Singleton;
40 42
 import javax.swing.JPopupMenu;
41 43
 import javax.swing.KeyStroke;
42 44
 import javax.swing.MenuSelectionManager;
@@ -46,6 +48,7 @@ import javax.swing.text.JTextComponent;
46 48
 /**
47 49
  * Custom event queue to add common functionality to certain components.
48 50
  */
51
+@Singleton
49 52
 public class DMDircEventQueue extends EventQueue {
50 53
 
51 54
     /** Swing Controller. */
@@ -56,6 +59,7 @@ public class DMDircEventQueue extends EventQueue {
56 59
      *
57 60
      * @param controller Swing controller
58 61
      */
62
+    @Inject
59 63
     public DMDircEventQueue(final SwingController controller) {
60 64
         super();
61 65
 

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

@@ -86,6 +86,8 @@ public class MainFrame extends JFrame implements WindowListener,
86 86
     private final SwingController controller;
87 87
     /** Controller to use to end the program. */
88 88
     private final LifecycleController lifecycleController;
89
+    /** The window factory to use to create and listen for windows. */
90
+    private final SwingWindowFactory windowFactory;
89 91
     /** Client Version. */
90 92
     private final String version;
91 93
     /** Frame manager used for ctrl tab frame switching. */
@@ -122,16 +124,19 @@ public class MainFrame extends JFrame implements WindowListener,
122 124
      * Creates new form MainFrame.
123 125
      *
124 126
      * @param controller Swing controller
127
+     * @param windowFactory The window factory to use to create and listen for windows.
125 128
      * @param lifecycleController Controller to use to end the application.
126 129
      * @param windowManager Window management
127 130
      */
128 131
     public MainFrame(
129 132
             final SwingController controller,
133
+            final SwingWindowFactory windowFactory,
130 134
             final LifecycleController lifecycleController,
131 135
             final WindowManager windowManager) {
132 136
         super();
133 137
 
134 138
         this.controller = controller;
139
+        this.windowFactory = windowFactory;
135 140
         this.lifecycleController = lifecycleController;
136 141
         this.windowManager = windowManager;
137 142
 
@@ -180,10 +185,10 @@ public class MainFrame extends JFrame implements WindowListener,
180 185
             }
181 186
         });
182 187
 
183
-        controller.getWindowFactory().addWindowListener(this);
188
+        windowFactory.addWindowListener(this);
184 189
 
185 190
         setTitle(getTitlePrefix());
186
-        frameManager = new CtrlTabWindowManager(controller, this, rootPane);
191
+        frameManager = new CtrlTabWindowManager(controller, windowFactory, this, rootPane);
187 192
     }
188 193
 
189 194
     /**
@@ -329,8 +334,7 @@ public class MainFrame extends JFrame implements WindowListener,
329 334
             public void run() {
330 335
                 frameManagerPanel.removeAll();
331 336
                 if (mainFrameManager != null) {
332
-                    controller.getWindowFactory().removeWindowListener(
333
-                            mainFrameManager);
337
+                    windowFactory.removeWindowListener(mainFrameManager);
334 338
                 }
335 339
                 final String manager = controller.getGlobalConfig()
336 340
                         .getOption("ui", "framemanager");
@@ -348,8 +352,7 @@ public class MainFrame extends JFrame implements WindowListener,
348 352
                 mainFrameManager.setController(controller);
349 353
                 mainFrameManager.setParent(frameManagerPanel);
350 354
                 addSelectionListener(mainFrameManager);
351
-                controller.getWindowFactory().addWindowListener(
352
-                        mainFrameManager);
355
+                windowFactory.addWindowListener(mainFrameManager);
353 356
             }
354 357
         });
355 358
     }
@@ -365,7 +368,7 @@ public class MainFrame extends JFrame implements WindowListener,
365 368
         initFrameManagers();
366 369
         mainSplitPane = initSplitPane();
367 370
 
368
-        final MenuBar menu = new MenuBar(controller, this);
371
+        final MenuBar menu = new MenuBar(controller, windowFactory, this);
369 372
         controller.getApple().setMenuBar(menu);
370 373
         setJMenuBar(menu);
371 374
 

+ 74
- 70
src/com/dmdirc/addons/ui_swing/SwingController.java View File

@@ -82,7 +82,6 @@ import com.dmdirc.util.validators.OptionalValidator;
82 82
 import java.awt.Font;
83 83
 import java.awt.GraphicsEnvironment;
84 84
 import java.awt.KeyboardFocusManager;
85
-import java.awt.Toolkit;
86 85
 import java.net.URI;
87 86
 import java.util.ArrayList;
88 87
 import java.util.HashMap;
@@ -109,18 +108,10 @@ import dagger.ObjectGraph;
109 108
  */
110 109
 @SuppressWarnings("PMD.UnusedPrivateField")
111 110
 public class SwingController extends BaseCommandPlugin implements UIController {
112
-    /** Window factory. */
113
-    @Getter
114
-    private final SwingWindowFactory windowFactory =
115
-            new SwingWindowFactory(this);
116
-    /** Waiting on mainframe creation. */
117
-    private final AtomicBoolean mainFrameCreated = new AtomicBoolean(false);
111
+
118 112
     /** URL Handler to use. */
119 113
     @Getter
120 114
     private final URLHandler urlHandler;
121
-    /** Singleton instance of MainFrame. */
122
-    @Getter
123
-    private MainFrame mainFrame;
124 115
     /** Status bar. */
125 116
     @Getter
126 117
     private SwingStatusBar swingStatusBar;
@@ -128,8 +119,6 @@ public class SwingController extends BaseCommandPlugin implements UIController {
128 119
     private final List<java.awt.Window> windows;
129 120
     /** Error dialog. */
130 121
     private ErrorListDialog errorDialog;
131
-    /** DMDirc event queue. */
132
-    private DMDircEventQueue eventQueue;
133 122
     /** Key listener to handle dialog key events. */
134 123
     private DialogKeyListener keyListener;
135 124
     /** This plugin's plugin info object. */
@@ -198,6 +187,9 @@ public class SwingController extends BaseCommandPlugin implements UIController {
198 187
     @Getter
199 188
     private final ActionSubstitutorFactory actionSubstitutorFactory;
200 189
 
190
+    /** The manager we're using for dependencies. */
191
+    private SwingManager swingManager;
192
+
201 193
     /**
202 194
      * Instantiates a new SwingController.
203 195
      *
@@ -207,7 +199,6 @@ public class SwingController extends BaseCommandPlugin implements UIController {
207 199
      * @param pluginManager Plugin manager
208 200
      * @param actionManager Action manager
209 201
      * @param actionFactory The factory to use to create actions.
210
-     * @param commandController Command controller to register commands
211 202
      * @param serverManager Server manager to use for server information.
212 203
      * @param lifecycleController Controller to use to close the application.
213 204
      * @param corePluginExtractor Extractor to use for core plugins.
@@ -226,7 +217,6 @@ public class SwingController extends BaseCommandPlugin implements UIController {
226 217
             final PluginManager pluginManager,
227 218
             final ActionManager actionManager,
228 219
             final ActionFactory actionFactory,
229
-            final CommandController commandController,
230 220
             final ServerManager serverManager,
231 221
             final LifecycleController lifecycleController,
232 222
             final CorePluginExtractor corePluginExtractor,
@@ -237,7 +227,6 @@ public class SwingController extends BaseCommandPlugin implements UIController {
237 227
             final WindowManager windowManager,
238 228
             final ColourManager colourManager,
239 229
             final ActionSubstitutorFactory actionSubstitutorFactory) {
240
-        super(commandController);
241 230
         this.pluginInfo = pluginInfo;
242 231
         this.identityManager = identityManager;
243 232
         this.identityFactory = identityFactory;
@@ -266,11 +255,6 @@ public class SwingController extends BaseCommandPlugin implements UIController {
266 255
                 StatusBarManager.getStatusBarManager());
267 256
         setAntiAlias();
268 257
         windows = new ArrayList<>();
269
-        registerCommand(new ServerSettings(this), ServerSettings.INFO);
270
-        registerCommand(new ChannelSettings(this), ChannelSettings.INFO);
271
-        registerCommand(new Input(windowFactory, commandController), Input.INFO);
272
-        registerCommand(new PopOutCommand(this), PopOutCommand.INFO);
273
-        registerCommand(new PopInCommand(this), PopInCommand.INFO);
274 258
     }
275 259
 
276 260
     /**
@@ -291,7 +275,7 @@ public class SwingController extends BaseCommandPlugin implements UIController {
291 275
      * @return true iif mainframe exists
292 276
      */
293 277
     protected boolean hasMainFrame() {
294
-        return mainFrameCreated.get();
278
+        return swingManager != null;
295 279
     }
296 280
 
297 281
     /** {@inheritDoc} */
@@ -434,35 +418,42 @@ public class SwingController extends BaseCommandPlugin implements UIController {
434 418
      * Initialises the global UI settings for the Swing UI.
435 419
      */
436 420
     private void initUISettings() {
437
-        // This will do nothing on non OS X Systems
438
-        if (Apple.isApple()) {
439
-            apple.setUISettings();
440
-            apple.setListener();
441
-        }
421
+        UIUtilities.invokeAndWait(new Runnable() {
442 422
 
443
-        final Font defaultFont = new Font(Font.DIALOG, Font.TRUETYPE_FONT, 12);
444
-        if (UIManager.getFont("TextField.font") == null) {
445
-            UIManager.put("TextField.font", defaultFont);
446
-        }
447
-        if (UIManager.getFont("TextPane.font") == null) {
448
-            UIManager.put("TextPane.font", defaultFont);
449
-        }
423
+            /** {@inheritDoc} */
424
+            @Override
425
+            public void run() {
426
+                // This will do nothing on non OS X Systems
427
+                if (Apple.isApple()) {
428
+                    apple.setUISettings();
429
+                    apple.setListener();
430
+                }
450 431
 
451
-        try {
452
-            UIUtilities.initUISettings();
453
-            UIManager.setLookAndFeel(UIUtilities.getLookAndFeel(
454
-                    getGlobalConfig().getOption("ui", "lookandfeel")));
455
-            UIUtilities.setUIFont(new Font(getGlobalConfig()
456
-                    .getOption("ui", "textPaneFontName"), Font.PLAIN, 12));
457
-        } catch (UnsupportedOperationException | UnsupportedLookAndFeelException |
458
-                IllegalAccessException | InstantiationException | ClassNotFoundException ex) {
459
-            Logger.userError(ErrorLevel.LOW, "Unable to set UI Settings");
460
-        }
432
+                final Font defaultFont = new Font(Font.DIALOG, Font.TRUETYPE_FONT, 12);
433
+                if (UIManager.getFont("TextField.font") == null) {
434
+                    UIManager.put("TextField.font", defaultFont);
435
+                }
436
+                if (UIManager.getFont("TextPane.font") == null) {
437
+                    UIManager.put("TextPane.font", defaultFont);
438
+                }
461 439
 
462
-        if ("Metal".equals(UIManager.getLookAndFeel().getName())
463
-                || Apple.isAppleUI()) {
464
-            PlatformDefaults.setPlatform(PlatformDefaults.WINDOWS_XP);
465
-        }
440
+                try {
441
+                    UIUtilities.initUISettings();
442
+                    UIManager.setLookAndFeel(UIUtilities.getLookAndFeel(
443
+                            getGlobalConfig().getOption("ui", "lookandfeel")));
444
+                    UIUtilities.setUIFont(new Font(getGlobalConfig()
445
+                            .getOption("ui", "textPaneFontName"), Font.PLAIN, 12));
446
+                } catch (UnsupportedOperationException | UnsupportedLookAndFeelException |
447
+                        IllegalAccessException | InstantiationException | ClassNotFoundException ex) {
448
+                    Logger.userError(ErrorLevel.LOW, "Unable to set UI Settings");
449
+                }
450
+
451
+                if ("Metal".equals(UIManager.getLookAndFeel().getName())
452
+                        || Apple.isAppleUI()) {
453
+                    PlatformDefaults.setPlatform(PlatformDefaults.WINDOWS_XP);
454
+                }
455
+            }
456
+        });
466 457
     }
467 458
 
468 459
     /** {@inheritDoc} */
@@ -512,7 +503,17 @@ public class SwingController extends BaseCommandPlugin implements UIController {
512 503
     public void load(final PluginInfo pluginInfo, final ObjectGraph graph) {
513 504
         super.load(pluginInfo, graph);
514 505
 
506
+        // Init the UI settings before we start any DI, as we might create frames etc.
507
+        initUISettings();
508
+
515 509
         setObjectGraph(graph.plus(new SwingModule(this)));
510
+        swingManager = getObjectGraph().get(SwingManager.class);
511
+
512
+        registerCommand(ServerSettings.class, ServerSettings.INFO);
513
+        registerCommand(ChannelSettings.class, ChannelSettings.INFO);
514
+        registerCommand(Input.class, Input.INFO);
515
+        registerCommand(PopOutCommand.class, PopOutCommand.INFO);
516
+        registerCommand(PopInCommand.class, PopInCommand.INFO);
516 517
     }
517 518
 
518 519
     /** {@inheritDoc} */
@@ -522,17 +523,9 @@ public class SwingController extends BaseCommandPlugin implements UIController {
522 523
             throw new IllegalStateException(
523 524
                     "Swing UI can't be run in a headless environment");
524 525
         }
525
-        eventQueue = new DMDircEventQueue(this);
526
-        keyListener = new DialogKeyListener();
527
-        UIUtilities.invokeAndWait(new Runnable() {
528 526
 
529
-            /** {@inheritDoc} */
530
-            @Override
531
-            public void run() {
532
-                Toolkit.getDefaultToolkit().getSystemEventQueue()
533
-                        .push(eventQueue);
534
-            }
535
-        });
527
+        swingManager.load();
528
+        keyListener = new DialogKeyListener();
536 529
         UIUtilities.invokeAndWait(new Runnable() {
537 530
 
538 531
             /** {@inheritDoc} */
@@ -548,10 +541,7 @@ public class SwingController extends BaseCommandPlugin implements UIController {
548 541
             /** {@inheritDoc} */
549 542
             @Override
550 543
             public void run() {
551
-                initUISettings();
552
-                mainFrame = new MainFrame(SwingController.this, lifecycleController, windowManager);
553 544
                 getMainFrame().setVisible(true);
554
-                mainFrameCreated.set(true);
555 545
                 swingStatusBar = getMainFrame().getStatusBar();
556 546
                 errorDialog = new ErrorListDialog(SwingController.this);
557 547
                 StatusBarManager.getStatusBarManager().registerStatusBar(
@@ -559,25 +549,17 @@ public class SwingController extends BaseCommandPlugin implements UIController {
559 549
             }
560 550
         });
561 551
 
562
-        if (!mainFrameCreated.get()) {
563
-            throw new IllegalStateException(
564
-                    "Main frame not created. Unable to continue.");
565
-        }
566
-        windowManager.addListenerAndSync(windowFactory);
567 552
         super.onLoad();
568 553
     }
569 554
 
570 555
     /** {@inheritDoc} */
571 556
     @Override
572 557
     public void onUnload() {
558
+        swingManager.unload();
559
+
573 560
         errorDialog.dispose();
574
-        windowManager.removeListener(windowFactory);
575
-        mainFrameCreated.set(false);
576
-        getMainFrame().dispose();
577
-        windowFactory.dispose();
578 561
         StatusBarManager.getStatusBarManager()
579 562
                 .registerStatusBar(getSwingStatusBar());
580
-        eventQueue.pop();
581 563
         KeyboardFocusManager.getCurrentKeyboardFocusManager().
582 564
                 removeKeyEventDispatcher(keyListener);
583 565
         for (final java.awt.Window window : getTopLevelWindows()) {
@@ -908,4 +890,26 @@ public class SwingController extends BaseCommandPlugin implements UIController {
908 890
     public CommandController getCommandController() {
909 891
         return super.getCommandController();
910 892
     }
893
+
894
+    /**
895
+     * Retrieves the window factory to use.
896
+     *
897
+     * @return The window factory to use.
898
+     * @deprecated Should be injected where needed.
899
+     */
900
+    @Deprecated
901
+    public SwingWindowFactory getWindowFactory() {
902
+        return swingManager.getWindowFactory();
903
+    }
904
+
905
+    /**
906
+     * Retrieves the main frame to use.
907
+     *
908
+     * @return The main frame to use.
909
+     * @deprecated Should be injected where needed.
910
+     */
911
+    @Deprecated
912
+    public MainFrame getMainFrame() {
913
+        return swingManager.getMainFrame();
914
+    }
911 915
 }

+ 130
- 0
src/com/dmdirc/addons/ui_swing/SwingManager.java View File

@@ -0,0 +1,130 @@
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.ui.WindowManager;
26
+
27
+import java.awt.Toolkit;
28
+
29
+import javax.inject.Inject;
30
+import javax.inject.Singleton;
31
+
32
+/**
33
+ * Manages swing components and dependencies.
34
+ */
35
+@Singleton
36
+public class SwingManager {
37
+
38
+    /** The event queue to use. */
39
+    private final DMDircEventQueue eventQueue;
40
+
41
+    /** The window factory in use. */
42
+    private final SwingWindowFactory windowFactory;
43
+
44
+    /** The window manager to listen on for events. */
45
+    private final WindowManager windowManager;
46
+
47
+    /** The main frame of the Swing UI. */
48
+    private final MainFrame mainFrame;
49
+
50
+    /**
51
+     * Creates a new instance of {@link SwingManager}.
52
+     *
53
+     * @param eventQueue The event queue to use.
54
+     * @param windowFactory The window factory in use.
55
+     * @param windowManager The window manager to listen on for events.
56
+     * @param mainFrame The main frame of the Swing UI.
57
+     */
58
+    @Inject
59
+    public SwingManager(
60
+            final DMDircEventQueue eventQueue,
61
+            final SwingWindowFactory windowFactory,
62
+            final WindowManager windowManager,
63
+            final MainFrame mainFrame) {
64
+        this.eventQueue = eventQueue;
65
+        this.windowFactory = windowFactory;
66
+        this.windowManager = windowManager;
67
+        this.mainFrame = mainFrame;
68
+    }
69
+
70
+    /**
71
+     * Handles loading of the UI.
72
+     */
73
+    public void load() {
74
+        installEventQueue();
75
+        windowManager.addListenerAndSync(windowFactory);
76
+    }
77
+
78
+    /**
79
+     * Handles unloading of the UI.
80
+     */
81
+    public void unload() {
82
+        uninstallEventQueue();
83
+        windowManager.removeListener(windowFactory);
84
+        windowFactory.dispose();
85
+        mainFrame.dispose();
86
+    }
87
+
88
+    /**
89
+     * Retrieves the window factory to use.
90
+     *
91
+     * @return A swing window factory instance.
92
+     * @deprecated Should be injected.
93
+     */
94
+    @Deprecated
95
+    public SwingWindowFactory getWindowFactory() {
96
+        return windowFactory;
97
+    }
98
+
99
+    /**
100
+     * Retrieves the main frame.
101
+     *
102
+     * @return A main frame instance.
103
+     * @deprecated Should be injected.
104
+     */
105
+    @Deprecated
106
+    public MainFrame getMainFrame() {
107
+        return mainFrame;
108
+    }
109
+
110
+    /**
111
+     * Installs the DMDirc event queue.
112
+     */
113
+    private void installEventQueue() {
114
+        UIUtilities.invokeAndWait(new Runnable() {
115
+            /** {@inheritDoc} */
116
+            @Override
117
+            public void run() {
118
+                Toolkit.getDefaultToolkit().getSystemEventQueue().push(eventQueue);
119
+            }
120
+        });
121
+    }
122
+
123
+    /**
124
+     * Removes the DMDirc event queue.
125
+     */
126
+    private void uninstallEventQueue() {
127
+        eventQueue.pop();
128
+    }
129
+
130
+}

+ 44
- 3
src/com/dmdirc/addons/ui_swing/SwingModule.java View File

@@ -23,6 +23,17 @@
23 23
 package com.dmdirc.addons.ui_swing;
24 24
 
25 25
 import com.dmdirc.ClientModule;
26
+import com.dmdirc.addons.ui_swing.commands.ChannelSettings;
27
+import com.dmdirc.addons.ui_swing.commands.Input;
28
+import com.dmdirc.addons.ui_swing.commands.PopInCommand;
29
+import com.dmdirc.addons.ui_swing.commands.PopOutCommand;
30
+import com.dmdirc.addons.ui_swing.commands.ServerSettings;
31
+import com.dmdirc.interfaces.LifecycleController;
32
+import com.dmdirc.ui.WindowManager;
33
+
34
+import java.util.concurrent.Callable;
35
+
36
+import javax.inject.Singleton;
26 37
 
27 38
 import dagger.Module;
28 39
 import dagger.Provides;
@@ -30,7 +41,18 @@ import dagger.Provides;
30 41
 /**
31 42
  * Dagger module that provides Swing-specific dependencies.
32 43
  */
33
-@Module(addsTo = ClientModule.class, library = true)
44
+@Module(
45
+        addsTo = ClientModule.class,
46
+        injects = {
47
+            SwingManager.class,
48
+            PopInCommand.class,
49
+            PopOutCommand.class,
50
+            Input.class,
51
+            ServerSettings.class,
52
+            ChannelSettings.class,
53
+        },
54
+        library = true
55
+)
34 56
 public class SwingModule {
35 57
 
36 58
     /** The controller to return to clients. */
@@ -59,11 +81,30 @@ public class SwingModule {
59 81
     /**
60 82
      * Gets the main DMDirc window.
61 83
      *
84
+     * @param swingController The controller that will own the frame.
85
+     * @param windowFactory The window factory to use to create and listen for windows.
86
+     * @param lifecycleController The controller to use to quit the application.
87
+     * @param windowManager The core window manager to use to find windows.
62 88
      * @return The main window.
63 89
      */
64 90
     @Provides
65
-    public MainFrame getMainFrame() {
66
-        return controller.getMainFrame();
91
+    @Singleton
92
+    public MainFrame getMainFrame(
93
+            final SwingController swingController,
94
+            final SwingWindowFactory windowFactory,
95
+            final LifecycleController lifecycleController,
96
+            final WindowManager windowManager) {
97
+        return UIUtilities.invokeAndWait(new Callable<MainFrame>() {
98
+            /** {@inheritDoc} */
99
+            @Override
100
+            public MainFrame call() {
101
+                return new MainFrame(
102
+                        swingController,
103
+                        windowFactory,
104
+                        lifecycleController,
105
+                        windowManager);
106
+            }
107
+        });
67 108
     }
68 109
 
69 110
 }

+ 6
- 2
src/com/dmdirc/addons/ui_swing/SwingWindowFactory.java View File

@@ -42,11 +42,15 @@ import java.util.HashSet;
42 42
 import java.util.Map;
43 43
 import java.util.Set;
44 44
 
45
+import javax.inject.Inject;
46
+import javax.inject.Singleton;
47
+
45 48
 /**
46 49
  * Handles creation of windows in the Swing UI.
47 50
  *
48 51
  * @since 0.6.4
49 52
  */
53
+@Singleton
50 54
 public class SwingWindowFactory implements FrameListener {
51 55
 
52 56
     /** A map of known implementations of window interfaces. */
@@ -63,6 +67,7 @@ public class SwingWindowFactory implements FrameListener {
63 67
      *
64 68
      * @param controller The controller this factory is for
65 69
      */
70
+    @Inject
66 71
     public SwingWindowFactory(final SwingController controller) {
67 72
         this.controller = controller;
68 73
 
@@ -215,8 +220,7 @@ public class SwingWindowFactory implements FrameListener {
215 220
 
216 221
     /** Disposes of this window factory, removing all listeners. */
217 222
     public void dispose() {
218
-        for (SwingWindowListener listener : listeners.get(
219
-                SwingWindowListener.class)) {
223
+        for (SwingWindowListener listener : listeners.get(SwingWindowListener.class)) {
220 224
             listeners.remove(SwingWindowListener.class, listener);
221 225
         }
222 226
         for (TextFrame frame : windows.values()) {

+ 9
- 2
src/com/dmdirc/addons/ui_swing/commands/ChannelSettings.java View File

@@ -33,8 +33,11 @@ import com.dmdirc.commandparser.commands.CommandOptions;
33 33
 import com.dmdirc.commandparser.commands.IntelligentCommand;
34 34
 import com.dmdirc.commandparser.commands.context.ChannelCommandContext;
35 35
 import com.dmdirc.commandparser.commands.context.CommandContext;
36
+import com.dmdirc.interfaces.CommandController;
36 37
 import com.dmdirc.ui.input.AdditionalTabTargets;
37 38
 
39
+import javax.inject.Inject;
40
+
38 41
 /**
39 42
  * Opens the channel settings window for the channel.
40 43
  */
@@ -53,9 +56,13 @@ public class ChannelSettings extends Command implements IntelligentCommand {
53 56
      * Creates a new instance of the {@link ChannelSettings} command.
54 57
      *
55 58
      * @param controller The controller to use to show the settings window.
59
+     * @param commandController The command controller to use for command info.
56 60
      */
57
-    public ChannelSettings(final SwingController controller) {
58
-        super(controller.getCommandController());
61
+    @Inject
62
+    public ChannelSettings(
63
+            final SwingController controller,
64
+            final CommandController commandController) {
65
+        super(commandController);
59 66
         this.controller = controller;
60 67
     }
61 68
 

+ 3
- 0
src/com/dmdirc/addons/ui_swing/commands/Input.java View File

@@ -35,6 +35,8 @@ import com.dmdirc.interfaces.CommandController;
35 35
 import com.dmdirc.interfaces.ui.InputWindow;
36 36
 import com.dmdirc.ui.input.AdditionalTabTargets;
37 37
 
38
+import javax.inject.Inject;
39
+
38 40
 /**
39 41
  * The input command allows you to manipulate text in a windows inputField.
40 42
  *
@@ -56,6 +58,7 @@ public class Input extends Command implements IntelligentCommand {
56 58
      * @param windowFactory Window factory to get windows from
57 59
      * @param commandController The controller to use for command information.
58 60
      */
61
+    @Inject
59 62
     public Input(final SwingWindowFactory windowFactory, final CommandController commandController) {
60 63
         super(commandController);
61 64
         this.windowFactory = windowFactory;

+ 9
- 2
src/com/dmdirc/addons/ui_swing/commands/PopInCommand.java View File

@@ -32,6 +32,9 @@ import com.dmdirc.commandparser.CommandInfo;
32 32
 import com.dmdirc.commandparser.CommandType;
33 33
 import com.dmdirc.commandparser.commands.Command;
34 34
 import com.dmdirc.commandparser.commands.context.CommandContext;
35
+import com.dmdirc.interfaces.CommandController;
36
+
37
+import javax.inject.Inject;
35 38
 
36 39
 /**
37 40
  * Command to pop in windows.
@@ -50,9 +53,13 @@ public class PopInCommand extends Command {
50 53
      * Create a new instance of PopInCommand.
51 54
      *
52 55
      * @param controller SwingWindowController associated with this command
56
+     * @param commandController The command controller to use for command info.
53 57
      */
54
-    public PopInCommand(final SwingController controller) {
55
-        super(controller.getCommandController());
58
+    @Inject
59
+    public PopInCommand(
60
+            final SwingController controller,
61
+            final CommandController commandController) {
62
+        super(commandController);
56 63
         this.controller = controller;
57 64
     }
58 65
 

+ 9
- 2
src/com/dmdirc/addons/ui_swing/commands/PopOutCommand.java View File

@@ -32,6 +32,9 @@ import com.dmdirc.commandparser.CommandInfo;
32 32
 import com.dmdirc.commandparser.CommandType;
33 33
 import com.dmdirc.commandparser.commands.Command;
34 34
 import com.dmdirc.commandparser.commands.context.CommandContext;
35
+import com.dmdirc.interfaces.CommandController;
36
+
37
+import javax.inject.Inject;
35 38
 
36 39
 /**
37 40
  * Command to pop out windows.
@@ -50,9 +53,13 @@ public class PopOutCommand extends Command {
50 53
      * Create a new instance of PopOutCommand.
51 54
      *
52 55
      * @param controller SwingWindowController associated with this command
56
+     * @param commandController The command controller to use for command info.
53 57
      */
54
-    public PopOutCommand(final SwingController controller) {
55
-        super(controller.getCommandController());
58
+    @Inject
59
+    public PopOutCommand(
60
+            final SwingController controller,
61
+            final CommandController commandController) {
62
+        super(commandController);
56 63
         this.controller = controller;
57 64
     }
58 65
 

+ 9
- 2
src/com/dmdirc/addons/ui_swing/commands/ServerSettings.java View File

@@ -32,8 +32,11 @@ import com.dmdirc.commandparser.commands.Command;
32 32
 import com.dmdirc.commandparser.commands.CommandOptions;
33 33
 import com.dmdirc.commandparser.commands.IntelligentCommand;
34 34
 import com.dmdirc.commandparser.commands.context.CommandContext;
35
+import com.dmdirc.interfaces.CommandController;
35 36
 import com.dmdirc.ui.input.AdditionalTabTargets;
36 37
 
38
+import javax.inject.Inject;
39
+
37 40
 /**
38 41
  * Opens the server settings window for the server.
39 42
  *
@@ -54,9 +57,13 @@ public class ServerSettings extends Command implements IntelligentCommand {
54 57
      * Creates a new instance of the {@link ServerSettings} command.
55 58
      *
56 59
      * @param controller The controller to use to show the settings window.
60
+     * @param commandController The command controller to use for command info.
57 61
      */
58
-    public ServerSettings(final SwingController controller) {
59
-        super(controller.getCommandController());
62
+    @Inject
63
+    public ServerSettings(
64
+            final SwingController controller,
65
+            final CommandController commandController) {
66
+        super(commandController);
60 67
         this.controller = controller;
61 68
     }
62 69
 

+ 7
- 2
src/com/dmdirc/addons/ui_swing/components/MDIBar.java View File

@@ -25,6 +25,7 @@ package com.dmdirc.addons.ui_swing.components;
25 25
 import com.dmdirc.addons.ui_swing.MainFrame;
26 26
 import com.dmdirc.addons.ui_swing.SelectionListener;
27 27
 import com.dmdirc.addons.ui_swing.SwingController;
28
+import com.dmdirc.addons.ui_swing.SwingWindowFactory;
28 29
 import com.dmdirc.addons.ui_swing.SwingWindowListener;
29 30
 import com.dmdirc.addons.ui_swing.components.frames.TextFrame;
30 31
 import com.dmdirc.interfaces.config.AggregateConfigProvider;
@@ -67,9 +68,13 @@ public class MDIBar extends JPanel implements SwingWindowListener,
67 68
      * Instantiates a new MDI bar.
68 69
      *
69 70
      * @param controller The controller that owns this MDI bar
71
+     * @param windowFactory The window factory to use to create and listen for windows.
70 72
      * @param mainFrame Main frame instance
71 73
      */
72
-    public MDIBar(final SwingController controller, final MainFrame mainFrame) {
74
+    public MDIBar(
75
+            final SwingController controller,
76
+            final SwingWindowFactory windowFactory,
77
+            final MainFrame mainFrame) {
73 78
         super();
74 79
 
75 80
         this.mainFrame = mainFrame;
@@ -84,7 +89,7 @@ public class MDIBar extends JPanel implements SwingWindowListener,
84 89
         setLayout(new MigLayout("hmax 17, ins 1 0 0 0, fill"));
85 90
         add(closeButton, "w 17!, h 17!, right");
86 91
 
87
-        controller.getWindowFactory().addWindowListener(this);
92
+        windowFactory.addWindowListener(this);
88 93
 
89 94
         mainFrame.addSelectionListener(this);
90 95
         closeButton.addActionListener(this);

+ 6
- 2
src/com/dmdirc/addons/ui_swing/components/frames/AppleJFrame.java View File

@@ -24,6 +24,7 @@ package com.dmdirc.addons.ui_swing.components.frames;
24 24
 
25 25
 import com.dmdirc.addons.ui_swing.MainFrame;
26 26
 import com.dmdirc.addons.ui_swing.SwingController;
27
+import com.dmdirc.addons.ui_swing.SwingWindowFactory;
27 28
 import com.dmdirc.addons.ui_swing.components.menubar.MenuBar;
28 29
 
29 30
 import javax.swing.JFrame;
@@ -41,12 +42,15 @@ public class AppleJFrame extends JFrame {
41 42
      * Create a new Apple JFrame
42 43
      *
43 44
      * @param parentWindow Main Window
45
+     * @param windowFactory The window factory to use to create and listen for windows.
44 46
      * @param controller Parent swing controller
45 47
      */
46
-    public AppleJFrame(final MainFrame parentWindow,
48
+    public AppleJFrame(
49
+            final MainFrame parentWindow,
50
+            final SwingWindowFactory windowFactory,
47 51
             final SwingController controller) {
48 52
         super();
49
-        final MenuBar menu = new MenuBar(controller, parentWindow);
53
+        final MenuBar menu = new MenuBar(controller, windowFactory, parentWindow);
50 54
         controller.getApple().setMenuBar(menu);
51 55
         setJMenuBar(menu);
52 56
     }

+ 7
- 3
src/com/dmdirc/addons/ui_swing/components/menubar/MenuBar.java View File

@@ -24,6 +24,7 @@ package com.dmdirc.addons.ui_swing.components.menubar;
24 24
 
25 25
 import com.dmdirc.addons.ui_swing.MainFrame;
26 26
 import com.dmdirc.addons.ui_swing.SwingController;
27
+import com.dmdirc.addons.ui_swing.SwingWindowFactory;
27 28
 import com.dmdirc.addons.ui_swing.components.MDIBar;
28 29
 import com.dmdirc.addons.ui_swing.framemanager.windowmenu.WindowMenuFrameManager;
29 30
 
@@ -55,9 +56,12 @@ public class MenuBar extends JMenuBar {
55 56
      * Instantiates a new menu bar.
56 57
      *
57 58
      * @param controller Swing controller
59
+     * @param windowFactory The window factory to use to create and listen for windows.
58 60
      * @param mainFrame Main frame
59 61
      */
60
-    public MenuBar(final SwingController controller,
62
+    public MenuBar(
63
+            final SwingController controller,
64
+            final SwingWindowFactory windowFactory,
61 65
             final MainFrame mainFrame) {
62 66
         super();
63 67
 
@@ -66,11 +70,11 @@ public class MenuBar extends JMenuBar {
66 70
         add(new ServerMenu(controller, mainFrame));
67 71
         add(new ChannelMenu(controller, mainFrame));
68 72
         add(new SettingsMenu(controller));
69
-        add(new WindowMenuFrameManager(controller, mainFrame));
73
+        add(new WindowMenuFrameManager(controller, windowFactory, mainFrame));
70 74
         add(new HelpMenu(controller));
71 75
         final int tempCount = getComponentCount();
72 76
         add(Box.createHorizontalGlue(), "growx, pushx");
73
-        add(new MDIBar(controller, mainFrame));
77
+        add(new MDIBar(controller, windowFactory, mainFrame));
74 78
         add(Box.createHorizontalStrut(PlatformDefaults.getPanelInsets(1)
75 79
                 .getUnit()));
76 80
         menuItemCount = getComponentCount() - tempCount;

+ 1
- 1
src/com/dmdirc/addons/ui_swing/dialogs/actionsmanager/ActionsManagerDialog.java View File

@@ -110,7 +110,7 @@ public final class ActionsManagerDialog extends StandardDialog implements
110 110
             final SwingController controller) {
111 111
         super(controller, Apple.isAppleUI() ?
112 112
                 new AppleJFrame((MainFrame) parentWindow,
113
-                controller) : null, ModalityType.MODELESS);
113
+                controller.getWindowFactory(), controller) : null, ModalityType.MODELESS);
114 114
 
115 115
         initComponents();
116 116
         validator = new ValidatorChain<>(

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

@@ -70,10 +70,13 @@ public class CtrlTabWindowManager implements SwingWindowListener,
70 70
      * Creates a new ctrl tab window manager.
71 71
      *
72 72
      * @param controller Parent controller
73
+     * @param windowFactory The window factory to use to create and listen for windows.
73 74
      * @param mainFrame The main frame that owns this window manager
74 75
      * @param component Component to add listen to events on
75 76
      */
76
-    public CtrlTabWindowManager(final SwingController controller,
77
+    public CtrlTabWindowManager(
78
+            final SwingController controller,
79
+            final SwingWindowFactory windowFactory,
77 80
             final MainFrame mainFrame,
78 81
             final JComponent component) {
79 82
         nodes = new HashMap<>();
@@ -85,13 +88,12 @@ public class CtrlTabWindowManager implements SwingWindowListener,
85 88
             @Override
86 89
             protected void setPath(final TreePath path) {
87 90
                 super.setPath(path);
88
-                controller.getMainFrame().setActiveFrame(
89
-                        controller.getWindowFactory().getSwingWindow(
91
+                mainFrame.setActiveFrame(windowFactory.getSwingWindow(
90 92
                         ((TreeViewNode) path.getLastPathComponent()).getWindow()));
91 93
             }
92 94
         };
93 95
 
94
-        windowFactory = controller.getWindowFactory();
96
+        this.windowFactory = windowFactory;
95 97
         windowFactory.addWindowListener(this);
96 98
 
97 99
         mainFrame.addSelectionListener(this);

+ 6
- 2
src/com/dmdirc/addons/ui_swing/framemanager/windowmenu/WindowMenuFrameManager.java View File

@@ -27,6 +27,7 @@ import com.dmdirc.FrameContainerComparator;
27 27
 import com.dmdirc.addons.ui_swing.MainFrame;
28 28
 import com.dmdirc.addons.ui_swing.SelectionListener;
29 29
 import com.dmdirc.addons.ui_swing.SwingController;
30
+import com.dmdirc.addons.ui_swing.SwingWindowFactory;
30 31
 import com.dmdirc.addons.ui_swing.SwingWindowListener;
31 32
 import com.dmdirc.addons.ui_swing.UIUtilities;
32 33
 import com.dmdirc.addons.ui_swing.components.frames.TextFrame;
@@ -82,9 +83,12 @@ public final class WindowMenuFrameManager extends JMenu implements
82 83
      * Creates a new instance of WindowMenuFrameManager.
83 84
      *
84 85
      * @param controller Swing controller
86
+     * @param windowFactory The window factory to use to create and listen for windows.
85 87
      * @param mainFrame The frame that owns this manager
86 88
      */
87
-    public WindowMenuFrameManager(final SwingController controller,
89
+    public WindowMenuFrameManager(
90
+            final SwingController controller,
91
+            final SwingWindowFactory windowFactory,
88 92
             final MainFrame mainFrame) {
89 93
         super();
90 94
         this.controller = controller;
@@ -98,7 +102,7 @@ public final class WindowMenuFrameManager extends JMenu implements
98 102
 
99 103
         setText("Window");
100 104
         setMnemonic('w');
101
-        controller.getWindowFactory().addWindowListener(this);
105
+        windowFactory.addWindowListener(this);
102 106
 
103 107
         closeMenuItem = new JMenuItem(controller
104 108
                 .getIconManager().getIcon("close"));

Loading…
Cancel
Save