Browse Source

DI more things.

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

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

@@ -99,7 +99,7 @@ public class MainFrame extends JFrame implements WindowListener,
99 99
     /** Client Version. */
100 100
     private final String version;
101 101
     /** Frame manager used for ctrl tab frame switching. */
102
-    private final CtrlTabWindowManager frameManager;
102
+    private CtrlTabWindowManager frameManager;
103 103
     /** The listeners registered with this class. */
104 104
     private final ListenerList listeners = new ListenerList();
105 105
     /** Window management. */
@@ -158,8 +158,6 @@ public class MainFrame extends JFrame implements WindowListener,
158 158
         this.windowManager = windowManager;
159 159
 
160 160
         focusOrder = new QueuedLinkedHashSet<>();
161
-        initComponents();
162
-
163 161
         imageIcon = new ImageIcon(iconManager.getImage("icon"));
164 162
         setIconImage(imageIcon.getImage());
165 163
 
@@ -196,7 +194,6 @@ public class MainFrame extends JFrame implements WindowListener,
196 194
         windowFactory.addWindowListener(this);
197 195
 
198 196
         setTitle(getTitlePrefix());
199
-        frameManager = new CtrlTabWindowManager(controller, windowFactory, this, rootPane);
200 197
     }
201 198
 
202 199
     /**
@@ -367,28 +364,36 @@ public class MainFrame extends JFrame implements WindowListener,
367 364
     /**
368 365
      * Initialises the components for this frame.
369 366
      */
370
-    private void initComponents() {
371
-        statusBar = new SwingStatusBar(controller, this);
372
-        frameManagerPanel = new JPanel();
373
-        activeFrame = null;
374
-        framePanel = new JPanel(new MigLayout("fill, ins 0"));
375
-        initFrameManagers();
376
-        mainSplitPane = initSplitPane();
367
+    public void initComponents() {
368
+        UIUtilities.invokeAndWait(new Runnable() {
369
+
370
+            /** {@inheritDoc} */
371
+            @Override
372
+            public void run() {
373
+                frameManagerPanel = new JPanel();
374
+                activeFrame = null;
375
+                framePanel = new JPanel(new MigLayout("fill, ins 0"));
376
+                initFrameManagers();
377
+                mainSplitPane = initSplitPane();
377 378
 
378
-        setPreferredSize(new Dimension(800, 600));
379
+                setPreferredSize(new Dimension(800, 600));
379 380
 
380
-        getContentPane().setLayout(new MigLayout(
381
-                "fill, ins rel, wrap 1, hidemode 2"));
382
-        layoutComponents();
381
+                getContentPane().setLayout(new MigLayout(
382
+                        "fill, ins rel, wrap 1, hidemode 2"));
383
+                layoutComponents();
383 384
 
384
-        setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
385
+                setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
385 386
 
386
-        pack();
387
+                pack();
388
+            }
389
+        });
387 390
     }
388 391
 
389 392
     /**
390 393
      * Sets the menu bar that this frame will use.
391 394
      *
395
+     * <p>Must be called prior to {@link #initComponents()}.
396
+     *
392 397
      * @param menuBar The menu bar to use.
393 398
      */
394 399
     public void setMenuBar(final MenuBar menuBar) {
@@ -402,6 +407,28 @@ public class MainFrame extends JFrame implements WindowListener,
402 407
         });
403 408
     }
404 409
 
410
+    /**
411
+     * Sets the window manager that this frame will use.
412
+     *
413
+     * <p>Must be called prior to {@link #initComponents()}.
414
+     *
415
+     * @param windowManager The window manager to use.
416
+     */
417
+    public void setWindowManager(final CtrlTabWindowManager windowManager) {
418
+        this.frameManager = windowManager;
419
+    }
420
+
421
+    /**
422
+     * Sets the status bar that will be used.
423
+     *
424
+     * <p>Must be called prior to {@link #initComponents()}.
425
+     *
426
+     * @param statusBar The status bar to be used.
427
+     */
428
+    public void setStatusBar(final SwingStatusBar statusBar) {
429
+        this.statusBar = statusBar;
430
+    }
431
+
405 432
     /**
406 433
      * Lays out the this component.
407 434
      */

+ 25
- 80
src/com/dmdirc/addons/ui_swing/SwingController.java View File

@@ -23,7 +23,6 @@
23 23
 package com.dmdirc.addons.ui_swing;
24 24
 
25 25
 import com.dmdirc.Channel;
26
-import com.dmdirc.CorePluginExtractor;
27 26
 import com.dmdirc.Server;
28 27
 import com.dmdirc.ServerManager;
29 28
 import com.dmdirc.actions.ActionFactory;
@@ -39,7 +38,6 @@ import com.dmdirc.addons.ui_swing.commands.ServerSettings;
39 38
 import com.dmdirc.addons.ui_swing.components.frames.TextFrame;
40 39
 import com.dmdirc.addons.ui_swing.components.statusbar.FeedbackNag;
41 40
 import com.dmdirc.addons.ui_swing.components.statusbar.SwingStatusBar;
42
-import com.dmdirc.addons.ui_swing.dialogs.DialogKeyListener;
43 41
 import com.dmdirc.addons.ui_swing.dialogs.DialogManager;
44 42
 import com.dmdirc.addons.ui_swing.dialogs.StandardDialog;
45 43
 import com.dmdirc.addons.ui_swing.dialogs.channelsetting.ChannelSettingsDialog;
@@ -47,15 +45,12 @@ import com.dmdirc.addons.ui_swing.dialogs.error.ErrorListDialog;
47 45
 import com.dmdirc.addons.ui_swing.dialogs.prefs.SwingPreferencesDialog;
48 46
 import com.dmdirc.addons.ui_swing.dialogs.serversetting.ServerSettingsDialog;
49 47
 import com.dmdirc.addons.ui_swing.dialogs.url.URLDialog;
50
-import com.dmdirc.addons.ui_swing.wizard.WizardListener;
51
-import com.dmdirc.addons.ui_swing.wizard.firstrun.SwingFirstRunWizard;
52 48
 import com.dmdirc.config.prefs.PluginPreferencesCategory;
53 49
 import com.dmdirc.config.prefs.PreferencesCategory;
54 50
 import com.dmdirc.config.prefs.PreferencesDialogModel;
55 51
 import com.dmdirc.config.prefs.PreferencesSetting;
56 52
 import com.dmdirc.config.prefs.PreferencesType;
57 53
 import com.dmdirc.interfaces.CommandController;
58
-import com.dmdirc.interfaces.LifecycleController;
59 54
 import com.dmdirc.interfaces.config.AggregateConfigProvider;
60 55
 import com.dmdirc.interfaces.config.ConfigProvider;
61 56
 import com.dmdirc.interfaces.config.IdentityController;
@@ -69,8 +64,6 @@ import com.dmdirc.plugins.PluginInfo;
69 64
 import com.dmdirc.plugins.PluginManager;
70 65
 import com.dmdirc.plugins.implementations.BaseCommandPlugin;
71 66
 import com.dmdirc.ui.IconManager;
72
-import com.dmdirc.ui.WindowManager;
73
-import com.dmdirc.ui.core.components.StatusBarManager;
74 67
 import com.dmdirc.ui.core.util.URLHandler;
75 68
 import com.dmdirc.ui.messages.ColourManager;
76 69
 import com.dmdirc.ui.themes.ThemeManager;
@@ -81,15 +74,12 @@ import com.dmdirc.util.validators.OptionalValidator;
81 74
 
82 75
 import java.awt.Font;
83 76
 import java.awt.GraphicsEnvironment;
84
-import java.awt.KeyboardFocusManager;
85 77
 import java.net.URI;
86 78
 import java.util.ArrayList;
87 79
 import java.util.HashMap;
88 80
 import java.util.List;
89 81
 import java.util.Map;
90 82
 import java.util.concurrent.Callable;
91
-import java.util.concurrent.Semaphore;
92
-import java.util.concurrent.atomic.AtomicBoolean;
93 83
 
94 84
 import javax.swing.JMenuItem;
95 85
 import javax.swing.SwingUtilities;
@@ -109,18 +99,10 @@ import dagger.ObjectGraph;
109 99
 @SuppressWarnings("PMD.UnusedPrivateField")
110 100
 public class SwingController extends BaseCommandPlugin implements UIController {
111 101
 
112
-    /** URL Handler to use. */
113
-    @Getter
114
-    private final URLHandler urlHandler;
115
-    /** Status bar. */
116
-    @Getter
117
-    private SwingStatusBar swingStatusBar;
118 102
     /** Top level window list. */
119 103
     private final List<java.awt.Window> windows;
120 104
     /** Error dialog. */
121 105
     private ErrorListDialog errorDialog;
122
-    /** Key listener to handle dialog key events. */
123
-    private DialogKeyListener keyListener;
124 106
     /** This plugin's plugin info object. */
125 107
     private final PluginInfo pluginInfo;
126 108
     /** Global config manager. */
@@ -165,18 +147,12 @@ public class SwingController extends BaseCommandPlugin implements UIController {
165 147
     /** Alias wrapper. */
166 148
     @Getter
167 149
     private final AliasWrapper aliasWrapper;
168
-    /** Controller to use to close the application. */
169
-    private final LifecycleController lifecycleController;
170
-    /** Extractor to use for core plugins. */
171
-    private final CorePluginExtractor corePluginExtractor;
172 150
     /** Theme manager to use. */
173 151
     @Getter
174 152
     private final ThemeManager themeManager;
175 153
     /** Apple handler, deals with Mac specific code. */
176 154
     @Getter
177 155
     private final Apple apple;
178
-    /** Window Management. */
179
-    private final WindowManager windowManager;
180 156
     /** The colour manager to use to parse colours. */
181 157
     @Getter
182 158
     private final ColourManager colourManager;
@@ -200,13 +176,10 @@ public class SwingController extends BaseCommandPlugin implements UIController {
200 176
      * @param actionManager Action manager
201 177
      * @param actionFactory The factory to use to create actions.
202 178
      * @param serverManager Server manager to use for server information.
203
-     * @param lifecycleController Controller to use to close the application.
204
-     * @param corePluginExtractor Extractor to use for core plugins.
205 179
      * @param performWrapper Perform wrapper to use for performs.
206 180
      * @param aliasWrapper Alias wrapper to use for aliases.
207 181
      * @param themeManager Theme manager to use.
208 182
      * @param urlBuilder URL builder to use to resolve icons etc.
209
-     * @param windowManager Window management
210 183
      * @param colourManager The colour manager to use to parse colours.
211 184
      * @param actionSubstitutorFactory Factory to use to create action substitutors.
212 185
      */
@@ -218,13 +191,10 @@ public class SwingController extends BaseCommandPlugin implements UIController {
218 191
             final ActionManager actionManager,
219 192
             final ActionFactory actionFactory,
220 193
             final ServerManager serverManager,
221
-            final LifecycleController lifecycleController,
222
-            final CorePluginExtractor corePluginExtractor,
223 194
             final PerformWrapper performWrapper,
224 195
             final AliasWrapper aliasWrapper,
225 196
             final ThemeManager themeManager,
226 197
             final URLBuilder urlBuilder,
227
-            final WindowManager windowManager,
228 198
             final ColourManager colourManager,
229 199
             final ActionSubstitutorFactory actionSubstitutorFactory) {
230 200
         this.pluginInfo = pluginInfo;
@@ -234,12 +204,9 @@ public class SwingController extends BaseCommandPlugin implements UIController {
234 204
         this.actionFactory = actionFactory;
235 205
         this.pluginManager = pluginManager;
236 206
         this.serverManager = serverManager;
237
-        this.lifecycleController = lifecycleController;
238
-        this.corePluginExtractor = corePluginExtractor;
239 207
         this.performWrapper = performWrapper;
240 208
         this.aliasWrapper = aliasWrapper;
241 209
         this.themeManager = themeManager;
242
-        this.windowManager = windowManager;
243 210
         this.colourManager = colourManager;
244 211
         this.urlBuilder = urlBuilder;
245 212
         this.actionSubstitutorFactory = actionSubstitutorFactory;
@@ -251,8 +218,6 @@ public class SwingController extends BaseCommandPlugin implements UIController {
251 218
         iconManager = new IconManager(globalConfig, urlBuilder);
252 219
         prefsComponentFactory = new PrefsComponentFactory(this);
253 220
         dialogManager = new DialogManager(this);
254
-        urlHandler = new URLHandler(this, globalConfig, serverManager,
255
-                StatusBarManager.getStatusBarManager());
256 221
         setAntiAlias();
257 222
         windows = new ArrayList<>();
258 223
     }
@@ -281,34 +246,7 @@ public class SwingController extends BaseCommandPlugin implements UIController {
281 246
     /** {@inheritDoc} */
282 247
     @Override
283 248
     public void showFirstRunWizard() {
284
-        final Semaphore semaphore = new Semaphore(0);
285
-        UIUtilities.invokeLater(new Runnable() {
286
-
287
-            /** {@inheritDoc} */
288
-            @Override
289
-            public void run() {
290
-                final WizardListener listener = new WizardListener() {
291
-
292
-                    /** {@inheritDoc} */
293
-                    @Override
294
-                    public void wizardFinished() {
295
-                        semaphore.release();
296
-                    }
297
-
298
-                    /** {@inheritDoc} */
299
-                    @Override
300
-                    public void wizardCancelled() {
301
-                        semaphore.release();
302
-                    }
303
-                };
304
-                final SwingFirstRunWizard wizard = new SwingFirstRunWizard(
305
-                        getMainFrame(), SwingController.this,
306
-                        corePluginExtractor, iconManager);
307
-                wizard.getWizardDialog().addWizardListener(listener);
308
-                wizard.display();
309
-            }
310
-        });
311
-        semaphore.acquireUninterruptibly();
249
+        swingManager.getFirstRunExecutor().showWizardAndWait();
312 250
     }
313 251
 
314 252
     /** {@inheritDoc} */
@@ -526,16 +464,6 @@ public class SwingController extends BaseCommandPlugin implements UIController {
526 464
         }
527 465
 
528 466
         swingManager.load();
529
-        keyListener = new DialogKeyListener();
530
-        UIUtilities.invokeAndWait(new Runnable() {
531
-
532
-            /** {@inheritDoc} */
533
-            @Override
534
-            public void run() {
535
-                KeyboardFocusManager.getCurrentKeyboardFocusManager()
536
-                        .addKeyEventDispatcher(keyListener);
537
-            }
538
-        });
539 467
 
540 468
         UIUtilities.invokeAndWait(new Runnable() {
541 469
 
@@ -543,10 +471,7 @@ public class SwingController extends BaseCommandPlugin implements UIController {
543 471
             @Override
544 472
             public void run() {
545 473
                 getMainFrame().setVisible(true);
546
-                swingStatusBar = getMainFrame().getStatusBar();
547 474
                 errorDialog = new ErrorListDialog(SwingController.this);
548
-                StatusBarManager.getStatusBarManager().registerStatusBar(
549
-                        getSwingStatusBar());
550 475
             }
551 476
         });
552 477
 
@@ -559,10 +484,7 @@ public class SwingController extends BaseCommandPlugin implements UIController {
559 484
         swingManager.unload();
560 485
 
561 486
         errorDialog.dispose();
562
-        StatusBarManager.getStatusBarManager()
563
-                .registerStatusBar(getSwingStatusBar());
564
-        KeyboardFocusManager.getCurrentKeyboardFocusManager().
565
-                removeKeyEventDispatcher(keyListener);
487
+
566 488
         for (final java.awt.Window window : getTopLevelWindows()) {
567 489
             window.dispose();
568 490
         }
@@ -913,4 +835,27 @@ public class SwingController extends BaseCommandPlugin implements UIController {
913 835
     public MainFrame getMainFrame() {
914 836
         return swingManager.getMainFrame();
915 837
     }
838
+
839
+    /**
840
+     * Retrieves the status bar that's in use.
841
+     *
842
+     * @return The status bar that's in use.
843
+     * @deprecated Should be injected where needed.
844
+     */
845
+    @Deprecated
846
+    public SwingStatusBar getSwingStatusBar() {
847
+        return swingManager.getMainFrame().getStatusBar();
848
+    }
849
+
850
+    /**
851
+     * Gets the URL handler to use.
852
+     *
853
+     * @return The URL handler to use.
854
+     * @deprecated Should be injected.
855
+     */
856
+    @Deprecated
857
+    public URLHandler getUrlHandler() {
858
+        return swingManager.getUrlHandler();
859
+    }
860
+
916 861
 }

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

@@ -23,11 +23,19 @@
23 23
 package com.dmdirc.addons.ui_swing;
24 24
 
25 25
 import com.dmdirc.addons.ui_swing.components.menubar.MenuBar;
26
+import com.dmdirc.addons.ui_swing.components.statusbar.SwingStatusBar;
27
+import com.dmdirc.addons.ui_swing.dialogs.DialogKeyListener;
28
+import com.dmdirc.addons.ui_swing.framemanager.ctrltab.CtrlTabWindowManager;
29
+import com.dmdirc.addons.ui_swing.wizard.firstrun.FirstRunWizardExecutor;
26 30
 import com.dmdirc.ui.WindowManager;
31
+import com.dmdirc.ui.core.components.StatusBarManager;
32
+import com.dmdirc.ui.core.util.URLHandler;
27 33
 
34
+import java.awt.KeyboardFocusManager;
28 35
 import java.awt.Toolkit;
29 36
 
30 37
 import javax.inject.Inject;
38
+import javax.inject.Provider;
31 39
 import javax.inject.Singleton;
32 40
 
33 41
 /**
@@ -42,34 +50,69 @@ public class SwingManager {
42 50
     /** The window factory in use. */
43 51
     private final SwingWindowFactory windowFactory;
44 52
 
53
+    /** The status bar manager to register our status bar with. */
54
+    private final StatusBarManager statusBarManager;
55
+
56
+    /** The status bar in use. */
57
+    private final SwingStatusBar statusBar;
58
+
45 59
     /** The window manager to listen on for events. */
46 60
     private final WindowManager windowManager;
47 61
 
48 62
     /** The main frame of the Swing UI. */
49 63
     private final MainFrame mainFrame;
50 64
 
65
+    /** The URL handler to use. */
66
+    private final URLHandler urlHandler;
67
+
68
+    /** The key listener that supports dialogs. */
69
+    private final DialogKeyListener dialogKeyListener;
70
+
71
+    /** Provider of first run executors. */
72
+    private final Provider<FirstRunWizardExecutor> firstRunExecutor;
73
+
51 74
     /**
52 75
      * Creates a new instance of {@link SwingManager}.
53 76
      *
54 77
      * @param eventQueue The event queue to use.
55 78
      * @param windowFactory The window factory in use.
56 79
      * @param windowManager The window manager to listen on for events.
80
+     * @param statusBarManager The core status bar manager to register our status bar with.
57 81
      * @param mainFrame The main frame of the Swing UI.
58 82
      * @param menuBar The menu bar to use for the main frame.
83
+     * @param statusBar The status bar to use in the main frame.
84
+     * @param ctrlTabManager The window manager that handles ctrl+tab behaviour.
85
+     * @param urlHandler The URL handler to use.
86
+     * @param dialogKeyListener The key listener that supports dialogs.
87
+     * @param firstRunExecutor A provider of first run executors.
59 88
      */
60 89
     @Inject
61 90
     public SwingManager(
62 91
             final DMDircEventQueue eventQueue,
63 92
             final SwingWindowFactory windowFactory,
64 93
             final WindowManager windowManager,
94
+            final StatusBarManager statusBarManager,
65 95
             final MainFrame mainFrame,
66
-            final MenuBar menuBar) {
96
+            final MenuBar menuBar,
97
+            final SwingStatusBar statusBar,
98
+            final CtrlTabWindowManager ctrlTabManager,
99
+            final URLHandler urlHandler,
100
+            final DialogKeyListener dialogKeyListener,
101
+            final Provider<FirstRunWizardExecutor> firstRunExecutor) {
67 102
         this.eventQueue = eventQueue;
68 103
         this.windowFactory = windowFactory;
69 104
         this.windowManager = windowManager;
105
+        this.statusBar = statusBar;
106
+        this.statusBarManager = statusBarManager;
107
+        this.urlHandler = urlHandler;
108
+        this.dialogKeyListener = dialogKeyListener;
109
+        this.firstRunExecutor = firstRunExecutor;
70 110
 
71 111
         this.mainFrame = mainFrame;
72 112
         this.mainFrame.setMenuBar(menuBar);
113
+        this.mainFrame.setWindowManager(ctrlTabManager);
114
+        this.mainFrame.setStatusBar(statusBar);
115
+        this.mainFrame.initComponents();
73 116
     }
74 117
 
75 118
     /**
@@ -77,7 +120,10 @@ public class SwingManager {
77 120
      */
78 121
     public void load() {
79 122
         installEventQueue();
123
+        installKeyListener();
124
+
80 125
         windowManager.addListenerAndSync(windowFactory);
126
+        statusBarManager.registerStatusBar(statusBar);
81 127
     }
82 128
 
83 129
     /**
@@ -85,9 +131,21 @@ public class SwingManager {
85 131
      */
86 132
     public void unload() {
87 133
         uninstallEventQueue();
134
+        uninstallKeyListener();
135
+
88 136
         windowManager.removeListener(windowFactory);
89 137
         windowFactory.dispose();
90 138
         mainFrame.dispose();
139
+        statusBarManager.unregisterStatusBar(statusBar);
140
+    }
141
+
142
+    /**
143
+     * Gets a first run wizard executor to use.
144
+     *
145
+     * @return A first run wizard executor.
146
+     */
147
+    public FirstRunWizardExecutor getFirstRunExecutor() {
148
+        return firstRunExecutor.get();
91 149
     }
92 150
 
93 151
     /**
@@ -112,6 +170,17 @@ public class SwingManager {
112 170
         return mainFrame;
113 171
     }
114 172
 
173
+    /**
174
+     * Gets the URL handler to use.
175
+     *
176
+     * @return The URL handler to use.
177
+     * @deprecated Should be injected.
178
+     */
179
+    @Deprecated
180
+    public URLHandler getUrlHandler() {
181
+        return urlHandler;
182
+    }
183
+
115 184
     /**
116 185
      * Installs the DMDirc event queue.
117 186
      */
@@ -132,4 +201,26 @@ public class SwingManager {
132 201
         eventQueue.pop();
133 202
     }
134 203
 
204
+    /**
205
+     * Installs the dialog key listener.
206
+     */
207
+    private void installKeyListener() {
208
+        UIUtilities.invokeAndWait(new Runnable() {
209
+            /** {@inheritDoc} */
210
+            @Override
211
+            public void run() {
212
+                KeyboardFocusManager.getCurrentKeyboardFocusManager()
213
+                        .addKeyEventDispatcher(dialogKeyListener);
214
+            }
215
+        });
216
+    }
217
+
218
+    /**
219
+     * Removes the dialog key listener.
220
+     */
221
+    private void uninstallKeyListener() {
222
+        KeyboardFocusManager.getCurrentKeyboardFocusManager()
223
+                .removeKeyEventDispatcher(dialogKeyListener);
224
+    }
225
+
135 226
 }

+ 47
- 0
src/com/dmdirc/addons/ui_swing/SwingModule.java View File

@@ -24,15 +24,20 @@ package com.dmdirc.addons.ui_swing;
24 24
 
25 25
 import com.dmdirc.ClientModule;
26 26
 import com.dmdirc.ClientModule.GlobalConfig;
27
+import com.dmdirc.CorePluginExtractor;
28
+import com.dmdirc.ServerManager;
27 29
 import com.dmdirc.addons.ui_swing.commands.ChannelSettings;
28 30
 import com.dmdirc.addons.ui_swing.commands.Input;
29 31
 import com.dmdirc.addons.ui_swing.commands.PopInCommand;
30 32
 import com.dmdirc.addons.ui_swing.commands.PopOutCommand;
31 33
 import com.dmdirc.addons.ui_swing.commands.ServerSettings;
34
+import com.dmdirc.addons.ui_swing.wizard.firstrun.SwingFirstRunWizard;
32 35
 import com.dmdirc.interfaces.LifecycleController;
33 36
 import com.dmdirc.interfaces.config.AggregateConfigProvider;
34 37
 import com.dmdirc.ui.IconManager;
35 38
 import com.dmdirc.ui.WindowManager;
39
+import com.dmdirc.ui.core.components.StatusBarManager;
40
+import com.dmdirc.ui.core.util.URLHandler;
36 41
 import com.dmdirc.util.URLBuilder;
37 42
 
38 43
 import java.util.concurrent.Callable;
@@ -120,4 +125,46 @@ public class SwingModule {
120 125
         });
121 126
     }
122 127
 
128
+    /**
129
+     * Provides an URL handler for use in the swing UI.
130
+     *
131
+     * @param swingController The controller that will own the handler.
132
+     * @param globalConfig The global configuration to read settings from.
133
+     * @param serverManager The server manager to use to connect to servers.
134
+     * @param statusBarManager The status bar manager to add messages to.
135
+     * @return The URL handler to use.
136
+     */
137
+    @Provides
138
+    @Singleton
139
+    public URLHandler getURLHandler(
140
+            final SwingController swingController,
141
+            @GlobalConfig final AggregateConfigProvider globalConfig,
142
+            final ServerManager serverManager,
143
+            final StatusBarManager statusBarManager) {
144
+        return new URLHandler(swingController, globalConfig, serverManager, statusBarManager);
145
+    }
146
+
147
+    /**
148
+     * Gets a first run wizard to display.
149
+     *
150
+     * @param mainFrame The main frame, which will be the parent window.
151
+     * @param swingController The controller that owns the wizard.
152
+     * @param pluginExtractor The extractor to use to extract plugins.
153
+     * @param globalConfig The config to read settings from.
154
+     * @param urlBuilder The URL builder to use to build icons.
155
+     * @return
156
+     */
157
+    @Provides
158
+    public SwingFirstRunWizard getFirstRunWizard(
159
+            final MainFrame mainFrame,
160
+            final SwingController swingController,
161
+            final CorePluginExtractor pluginExtractor,
162
+            @GlobalConfig final AggregateConfigProvider globalConfig,
163
+            final URLBuilder urlBuilder) {
164
+        return new SwingFirstRunWizard(
165
+                mainFrame, swingController, pluginExtractor,
166
+                // TODO: Allow global icon manager to be injected.
167
+                new IconManager(globalConfig, urlBuilder));
168
+    }
169
+
123 170
 }

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

@@ -33,6 +33,8 @@ import com.dmdirc.ui.StatusMessage;
33 33
 import java.awt.Component;
34 34
 import java.util.Arrays;
35 35
 
36
+import javax.inject.Inject;
37
+import javax.inject.Singleton;
36 38
 import javax.swing.JPanel;
37 39
 import javax.swing.SwingUtilities;
38 40
 import javax.swing.UIManager;
@@ -41,7 +43,8 @@ import net.miginfocom.layout.PlatformDefaults;
41 43
 import net.miginfocom.swing.MigLayout;
42 44
 
43 45
 /** Status bar, shows message and info on the GUI. */
44
-public final class SwingStatusBar extends JPanel implements StatusBar {
46
+@Singleton
47
+public class SwingStatusBar extends JPanel implements StatusBar {
45 48
 
46 49
     /**
47 50
      * A version number for this class. It should be changed whenever the class
@@ -68,7 +71,9 @@ public final class SwingStatusBar extends JPanel implements StatusBar {
68 71
      * @param controller Swing controller
69 72
      * @param mainFrame Main frame
70 73
      */
71
-    public SwingStatusBar(final SwingController controller,
74
+    @Inject
75
+    public SwingStatusBar(
76
+            final SwingController controller,
72 77
             final MainFrame mainFrame) {
73 78
         super();
74 79
 

+ 10
- 0
src/com/dmdirc/addons/ui_swing/dialogs/DialogKeyListener.java View File

@@ -28,13 +28,23 @@ import java.awt.KeyEventDispatcher;
28 28
 import java.awt.KeyboardFocusManager;
29 29
 import java.awt.event.KeyEvent;
30 30
 
31
+import javax.inject.Inject;
32
+import javax.inject.Singleton;
31 33
 import javax.swing.JButton;
32 34
 
33 35
 /**
34 36
  * Dialog key listener.
35 37
  */
38
+@Singleton
36 39
 public class DialogKeyListener implements KeyEventDispatcher {
37 40
 
41
+    /**
42
+     * Creates a new instance of {@link DialogKeyListener}.
43
+     */
44
+    @Inject
45
+    public DialogKeyListener() {
46
+    }
47
+
38 48
     /** {@inheritDoc} */
39 49
     @Override
40 50
     public boolean dispatchKeyEvent(final KeyEvent e) {

+ 10
- 8
src/com/dmdirc/addons/ui_swing/framemanager/ctrltab/CtrlTabWindowManager.java View File

@@ -34,14 +34,16 @@ import com.dmdirc.addons.ui_swing.components.TreeScroller;
34 34
 import com.dmdirc.addons.ui_swing.components.frames.TextFrame;
35 35
 import com.dmdirc.addons.ui_swing.framemanager.tree.TreeViewModel;
36 36
 import com.dmdirc.addons.ui_swing.framemanager.tree.TreeViewNode;
37
+import com.dmdirc.interfaces.ui.Window;
37 38
 import com.dmdirc.logger.ErrorLevel;
38 39
 import com.dmdirc.logger.Logger;
39
-import com.dmdirc.interfaces.ui.Window;
40 40
 
41 41
 import java.awt.event.KeyEvent;
42 42
 import java.util.HashMap;
43 43
 import java.util.Map;
44 44
 
45
+import javax.inject.Inject;
46
+import javax.inject.Singleton;
45 47
 import javax.swing.JComponent;
46 48
 import javax.swing.KeyStroke;
47 49
 import javax.swing.tree.DefaultTreeSelectionModel;
@@ -52,6 +54,7 @@ import javax.swing.tree.TreeSelectionModel;
52 54
 /**
53 55
  * A Window manager to handle ctrl[+shift]+tab switching between windows.
54 56
  */
57
+@Singleton
55 58
 public class CtrlTabWindowManager implements SwingWindowListener,
56 59
         SelectionListener {
57 60
 
@@ -70,13 +73,12 @@ public class CtrlTabWindowManager implements SwingWindowListener,
70 73
      * @param controller Parent controller
71 74
      * @param windowFactory The window factory to use to create and listen for windows.
72 75
      * @param mainFrame The main frame that owns this window manager
73
-     * @param component Component to add listen to events on
74 76
      */
77
+    @Inject
75 78
     public CtrlTabWindowManager(
76 79
             final SwingController controller,
77 80
             final SwingWindowFactory windowFactory,
78
-            final MainFrame mainFrame,
79
-            final JComponent component) {
81
+            final MainFrame mainFrame) {
80 82
         nodes = new HashMap<>();
81 83
         model = new TreeViewModel(controller, new TreeViewNode(null, null));
82 84
         selectionModel = new DefaultTreeSelectionModel();
@@ -94,15 +96,15 @@ public class CtrlTabWindowManager implements SwingWindowListener,
94 96
         windowFactory.addWindowListener(this);
95 97
         mainFrame.addSelectionListener(this);
96 98
 
97
-        component.getActionMap().put("prevFrameAction",
99
+        mainFrame.getRootPane().getActionMap().put("prevFrameAction",
98 100
                 new PreviousFrameAction(treeScroller));
99
-        component.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT)
101
+        mainFrame.getRootPane().getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT)
100 102
                 .put(KeyStroke.getKeyStroke(KeyEvent.VK_TAB,
101 103
                 KeyEvent.CTRL_DOWN_MASK | KeyEvent.SHIFT_DOWN_MASK),
102 104
                 "prevFrameAction");
103
-        component.getActionMap().put(
105
+        mainFrame.getRootPane().getActionMap().put(
104 106
                 "nextFrameAction", new NextFrameAction(treeScroller));
105
-        component.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT)
107
+        mainFrame.getRootPane().getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT)
106 108
                 .put(KeyStroke.getKeyStroke(KeyEvent.VK_TAB,
107 109
                 KeyEvent.CTRL_DOWN_MASK), "nextFrameAction");
108 110
     }

+ 95
- 0
src/com/dmdirc/addons/ui_swing/wizard/firstrun/FirstRunWizardExecutor.java View File

@@ -0,0 +1,95 @@
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.wizard.firstrun;
24
+
25
+import com.dmdirc.addons.ui_swing.UIUtilities;
26
+import com.dmdirc.addons.ui_swing.wizard.WizardListener;
27
+
28
+import java.util.concurrent.Semaphore;
29
+
30
+import javax.inject.Inject;
31
+import javax.inject.Provider;
32
+
33
+/**
34
+ * Utility to create and run a first-run wizard.
35
+ */
36
+public class FirstRunWizardExecutor {
37
+
38
+    /** Semaphore used to signal when the dialog is complete. */
39
+    private final Semaphore semaphore = new Semaphore(0);
40
+
41
+    /** The provider of actual first-run wizards. */
42
+    private final Provider<SwingFirstRunWizard> wizardProvider;
43
+
44
+    /**
45
+     * Creates a new instance of {@link FirstRunWizardExecutor}.
46
+     *
47
+     * @param wizardProvider The provider of first-run wizards to use.
48
+     */
49
+    @Inject
50
+    public FirstRunWizardExecutor(final Provider<SwingFirstRunWizard> wizardProvider) {
51
+        this.wizardProvider = wizardProvider;
52
+    }
53
+
54
+    /**
55
+     * Shows the wizard and waits for it to finish.
56
+     */
57
+    public void showWizardAndWait() {
58
+        UIUtilities.invokeLater(new FirstRunWizardRunnable());
59
+        semaphore.acquireUninterruptibly();
60
+    }
61
+
62
+    /**
63
+     * Creates a new wizard, adds a listener, and displays the wizard.
64
+     */
65
+    private class FirstRunWizardRunnable implements Runnable {
66
+
67
+        /** {@inheritDoc} */
68
+        @Override
69
+        public void run() {
70
+            final SwingFirstRunWizard wizard = wizardProvider.get();
71
+            wizard.getWizardDialog().addWizardListener(new FirstRunWizardListener());
72
+            wizard.display();
73
+        }
74
+    }
75
+
76
+    /**
77
+     * Listens for wizard finished events and releases the semaphore.
78
+     */
79
+    private class FirstRunWizardListener implements WizardListener {
80
+
81
+        /** {@inheritDoc} */
82
+        @Override
83
+        public void wizardFinished() {
84
+            semaphore.release();
85
+        }
86
+
87
+        /** {@inheritDoc} */
88
+        @Override
89
+        public void wizardCancelled() {
90
+            semaphore.release();
91
+        }
92
+
93
+    }
94
+
95
+}

+ 1
- 2
src/com/dmdirc/addons/ui_swing/wizard/firstrun/SwingFirstRunWizard.java View File

@@ -49,8 +49,7 @@ import java.util.Map;
49 49
 import java.util.Map.Entry;
50 50
 
51 51
 /** First run wizard, used to initially setup the client for the user. */
52
-public final class SwingFirstRunWizard implements WizardListener,
53
-        FirstRunWizard {
52
+public class SwingFirstRunWizard implements WizardListener, FirstRunWizard {
54 53
 
55 54
     /** Wizard dialog. */
56 55
     private final WizardDialog wizardDialog;

Loading…
Cancel
Save