Sfoglia il codice sorgente

Move more ui init code to swing ui initialiser.

Depends-On: I9e67f7f9fbb479c13ff04fc237f2cb82c08a506c
Change-Id: Ia552a47b40002a346eaeabab3f757ecc32b12b68
Reviewed-on: http://gerrit.dmdirc.com/3317
Automatic-Compile: DMDirc Build Manager
Reviewed-by: Chris Smith <chris@dmdirc.com>
changes/17/3317/5
Greg Holmes 10 anni fa
parent
commit
75c1f2d3b0

+ 1
- 62
src/com/dmdirc/addons/ui_swing/SwingController.java Vedi File

@@ -30,20 +30,12 @@ import com.dmdirc.addons.ui_swing.commands.ServerSettings;
30 30
 import com.dmdirc.addons.ui_swing.framemanager.FrameManagerProvider;
31 31
 import com.dmdirc.addons.ui_swing.injection.SwingModule;
32 32
 import com.dmdirc.config.prefs.PreferencesDialogModel;
33
-import com.dmdirc.events.FeedbackNagEvent;
34
-import com.dmdirc.events.FirstRunEvent;
35
-import com.dmdirc.events.UnknownURLEvent;
36
-import com.dmdirc.interfaces.config.ConfigProvider;
37
-import com.dmdirc.interfaces.config.IdentityController;
38 33
 import com.dmdirc.interfaces.ui.UIController;
39 34
 import com.dmdirc.plugins.Exported;
40 35
 import com.dmdirc.plugins.PluginInfo;
41 36
 import com.dmdirc.plugins.implementations.BaseCommandPlugin;
42 37
 import com.dmdirc.updater.Version;
43 38
 
44
-import com.google.common.eventbus.EventBus;
45
-import com.google.common.eventbus.Subscribe;
46
-
47 39
 import java.awt.GraphicsEnvironment;
48 40
 
49 41
 import javax.swing.UIManager;
@@ -57,31 +49,19 @@ public class SwingController extends BaseCommandPlugin implements UIController {
57 49
 
58 50
     /** This plugin's plugin info object. */
59 51
     private final PluginInfo pluginInfo;
60
-    /** Addon config identity. */
61
-    private final ConfigProvider addonIdentity;
62 52
     /** The manager we're using for dependencies. */
63 53
     private SwingManager swingManager;
64 54
     /** This plugin's settings domain. */
65 55
     private final String domain;
66
-    /** Event bus to subscribe to events with. */
67
-    private final EventBus eventBus;
68 56
 
69 57
     /**
70 58
      * Instantiates a new SwingController.
71 59
      *
72 60
      * @param pluginInfo      Plugin info
73
-     * @param identityManager Identity Manager
74
-     * @param eventBus        The bus to publish and subscribe to events on.
75 61
      */
76
-    public SwingController(
77
-            final PluginInfo pluginInfo,
78
-            final IdentityController identityManager,
79
-            final EventBus eventBus) {
62
+    public SwingController(final PluginInfo pluginInfo) {
80 63
         this.pluginInfo = pluginInfo;
81 64
         this.domain = pluginInfo.getDomain();
82
-        this.eventBus = eventBus;
83
-
84
-        addonIdentity = identityManager.getAddonSettings();
85 65
     }
86 66
 
87 67
     @Override
@@ -116,20 +96,12 @@ public class SwingController extends BaseCommandPlugin implements UIController {
116 96
             }
117 97
         });
118 98
 
119
-        addonIdentity.setOption("ui", "textPaneFontName",
120
-                UIManager.getFont("TextPane.font").getFamily());
121
-        addonIdentity.setOption("ui", "textPaneFontSize",
122
-                UIManager.getFont("TextPane.font").getSize());
123
-
124
-        eventBus.register(this);
125
-
126 99
         super.onLoad();
127 100
     }
128 101
 
129 102
     @Override
130 103
     public void onUnload() {
131 104
         swingManager.unload();
132
-        eventBus.unregister(this);
133 105
 
134 106
         super.onUnload();
135 107
     }
@@ -141,39 +113,6 @@ public class SwingController extends BaseCommandPlugin implements UIController {
141 113
                         manager.getIdentity()).getSwingUICategory());
142 114
     }
143 115
 
144
-    @Subscribe
145
-    public void showFirstRunWizard(final FirstRunEvent event) {
146
-        if (!event.isHandled()) {
147
-            swingManager.getFirstRunExecutor().showWizardAndWait();
148
-            event.setHandled(true);
149
-        }
150
-    }
151
-
152
-    @Subscribe
153
-    public void showURLDialog(final UnknownURLEvent event) {
154
-        if (!event.isHandled()) {
155
-            event.setHandled(true);
156
-            UIUtilities.invokeLater(new Runnable() {
157
-
158
-                @Override
159
-                public void run() {
160
-                    swingManager.getUrlDialogFactory().getURLDialog(event.getURI()).display();
161
-                }
162
-            });
163
-        }
164
-    }
165
-
166
-    @Subscribe
167
-    public void showFeedbackNag(final FeedbackNagEvent event) {
168
-        UIUtilities.invokeLater(new Runnable() {
169
-
170
-            @Override
171
-            public void run() {
172
-                swingManager.getFeedbackNagProvider().get();
173
-            }
174
-        });
175
-    }
176
-
177 116
     /**
178 117
      * Returns the version of this swing UI.
179 118
      *

+ 28
- 79
src/com/dmdirc/addons/ui_swing/SwingManager.java Vedi File

@@ -25,7 +25,6 @@ package com.dmdirc.addons.ui_swing;
25 25
 import com.dmdirc.addons.ui_swing.components.menubar.MenuBar;
26 26
 import com.dmdirc.addons.ui_swing.components.statusbar.FeedbackNag;
27 27
 import com.dmdirc.addons.ui_swing.components.statusbar.SwingStatusBar;
28
-import com.dmdirc.addons.ui_swing.dialogs.DialogKeyListener;
29 28
 import com.dmdirc.addons.ui_swing.dialogs.error.ErrorListDialog;
30 29
 import com.dmdirc.addons.ui_swing.dialogs.url.URLDialogFactory;
31 30
 import com.dmdirc.addons.ui_swing.framemanager.buttonbar.ButtonBarProvider;
@@ -34,14 +33,16 @@ import com.dmdirc.addons.ui_swing.framemanager.tree.TreeFrameManagerProvider;
34 33
 import com.dmdirc.addons.ui_swing.injection.DialogProvider;
35 34
 import com.dmdirc.addons.ui_swing.wizard.SwingWindowManager;
36 35
 import com.dmdirc.addons.ui_swing.wizard.firstrun.FirstRunWizardExecutor;
36
+import com.dmdirc.events.FeedbackNagEvent;
37
+import com.dmdirc.events.FirstRunEvent;
38
+import com.dmdirc.events.UnknownURLEvent;
37 39
 import com.dmdirc.logger.ErrorManager;
38 40
 import com.dmdirc.ui.WindowManager;
39 41
 import com.dmdirc.ui.core.components.StatusBarManager;
40 42
 
41 43
 import com.google.common.eventbus.EventBus;
44
+import com.google.common.eventbus.Subscribe;
42 45
 
43
-import java.awt.KeyboardFocusManager;
44
-import java.awt.Toolkit;
45 46
 import java.awt.Window;
46 47
 
47 48
 import javax.inject.Inject;
@@ -55,8 +56,6 @@ import javax.swing.SwingUtilities;
55 56
 @Singleton
56 57
 public class SwingManager {
57 58
 
58
-    /** The event queue to use. */
59
-    private final DMDircEventQueue eventQueue;
60 59
     /** The window factory in use. */
61 60
     private final Provider<SwingWindowFactory> windowFactory;
62 61
     /** The status bar manager to register our status bar with. */
@@ -67,8 +66,6 @@ public class SwingManager {
67 66
     /** The window manager to listen on for events. */
68 67
     private final WindowManager windowManager;
69 68
     private final CtrlTabWindowManager ctrlTabManager;
70
-    /** The key listener that supports dialogs. */
71
-    private final DialogKeyListener dialogKeyListener;
72 69
     /** Provider of first run executors. */
73 70
     private final Provider<FirstRunWizardExecutor> firstRunExecutor;
74 71
     /** Provider of feedback nags. */
@@ -97,7 +94,6 @@ public class SwingManager {
97 94
     /**
98 95
      * Creates a new instance of {@link SwingManager}.
99 96
      *
100
-     * @param eventQueue              The event queue to use.
101 97
      * @param windowFactory           The window factory in use.
102 98
      * @param windowManager           The window manager to listen on for events.
103 99
      * @param statusBarManager        The status bar manager to register our status bar with.
@@ -105,7 +101,6 @@ public class SwingManager {
105 101
      * @param menuBar                 The menu bar to use for the main frame.
106 102
      * @param statusBar               The status bar to use in the main frame.
107 103
      * @param ctrlTabManager          The window manager that handles ctrl+tab behaviour.
108
-     * @param dialogKeyListener       The key listener that supports dialogs.
109 104
      * @param firstRunExecutor        A provider of first run executors.
110 105
      * @param feedbackNagProvider     Provider of feedback nags.
111 106
      * @param urlDialogFactory        Factory to use to create URL dialogs.
@@ -119,7 +114,6 @@ public class SwingManager {
119 114
      */
120 115
     @Inject
121 116
     public SwingManager(
122
-            final DMDircEventQueue eventQueue,
123 117
             final Provider<SwingWindowFactory> windowFactory,
124 118
             final WindowManager windowManager,
125 119
             final StatusBarManager statusBarManager,
@@ -127,7 +121,6 @@ public class SwingManager {
127 121
             final Provider<MenuBar> menuBar,
128 122
             final Provider<SwingStatusBar> statusBar,
129 123
             final CtrlTabWindowManager ctrlTabManager,
130
-            final DialogKeyListener dialogKeyListener,
131 124
             final Provider<FirstRunWizardExecutor> firstRunExecutor,
132 125
             final Provider<FeedbackNag> feedbackNagProvider,
133 126
             final URLDialogFactory urlDialogFactory,
@@ -138,7 +131,6 @@ public class SwingManager {
138 131
             final Provider<SwingWindowManager> swingWindowManager,
139 132
             final DialogProvider<ErrorListDialog> errorListDialogProvider,
140 133
             final SwingUIInitialiser uiInitialiser) {
141
-        this.eventQueue = eventQueue;
142 134
         this.windowFactory = windowFactory;
143 135
         this.windowManager = windowManager;
144 136
         this.menuBar = menuBar;
@@ -146,7 +138,6 @@ public class SwingManager {
146 138
         this.statusBarManager = statusBarManager;
147 139
         this.mainFrameProvider = mainFrameProvider;
148 140
         this.ctrlTabManager = ctrlTabManager;
149
-        this.dialogKeyListener = dialogKeyListener;
150 141
         this.firstRunExecutor = firstRunExecutor;
151 142
         this.feedbackNagProvider = feedbackNagProvider;
152 143
         this.urlDialogFactory = urlDialogFactory;
@@ -170,11 +161,9 @@ public class SwingManager {
170 161
         this.mainFrame.setStatusBar(statusBar.get());
171 162
         this.mainFrame.initComponents();
172 163
 
173
-        installEventQueue();
174
-        installKeyListener();
175
-
176 164
         windowManager.addListenerAndSync(windowFactory.get());
177 165
         statusBarManager.registerStatusBar(statusBar.get());
166
+        eventBus.register(this);
178 167
         eventBus.register(linkHandler);
179 168
         SwingUtilities.invokeLater(new Runnable() {
180 169
 
@@ -189,9 +178,6 @@ public class SwingManager {
189 178
      * Handles unloading of the UI.
190 179
      */
191 180
     public void unload() {
192
-        uninstallEventQueue();
193
-        uninstallKeyListener();
194
-
195 181
         for (final Window window : swingWindowManager.get().getTopLevelWindows()) {
196 182
             window.dispose();
197 183
         }
@@ -207,35 +193,7 @@ public class SwingManager {
207 193
         mainFrame.dispose();
208 194
         statusBarManager.unregisterStatusBar(statusBar.get());
209 195
         eventBus.unregister(linkHandler);
210
-    }
211
-
212
-    /**
213
-     * Gets a first run wizard executor to use.
214
-     *
215
-     * @return A first run wizard executor.
216
-     */
217
-    public FirstRunWizardExecutor getFirstRunExecutor() {
218
-        return firstRunExecutor.get();
219
-    }
220
-
221
-    /**
222
-     * @return Feedback nag provider.
223
-     *
224
-     * @deprecated Should be injected.
225
-     */
226
-    @Deprecated
227
-    public Provider<FeedbackNag> getFeedbackNagProvider() {
228
-        return feedbackNagProvider;
229
-    }
230
-
231
-    /**
232
-     * @return URL dialog factory.
233
-     *
234
-     * @deprecated Should be injected.
235
-     */
236
-    @Deprecated
237
-    public URLDialogFactory getUrlDialogFactory() {
238
-        return urlDialogFactory;
196
+        uiInitialiser.unload();
239 197
     }
240 198
 
241 199
     /**
@@ -258,46 +216,37 @@ public class SwingManager {
258 216
         return buttonProvider;
259 217
     }
260 218
 
261
-    /**
262
-     * Installs the DMDirc event queue.
263
-     */
264
-    private void installEventQueue() {
265
-        UIUtilities.invokeAndWait(new Runnable() {
266
-
267
-            @Override
268
-            public void run() {
269
-                Toolkit.getDefaultToolkit().getSystemEventQueue().push(eventQueue);
270
-            }
271
-        });
219
+    @Subscribe
220
+    public void showFirstRunWizard(final FirstRunEvent event) {
221
+        if (!event.isHandled()) {
222
+            firstRunExecutor.get().showWizardAndWait();
223
+            event.setHandled(true);
224
+        }
272 225
     }
273 226
 
274
-    /**
275
-     * Removes the DMDirc event queue.
276
-     */
277
-    private void uninstallEventQueue() {
278
-        eventQueue.pop();
227
+    @Subscribe
228
+    public void showURLDialog(final UnknownURLEvent event) {
229
+        if (!event.isHandled()) {
230
+            event.setHandled(true);
231
+            UIUtilities.invokeLater(new Runnable() {
232
+
233
+                @Override
234
+                public void run() {
235
+                    urlDialogFactory.getURLDialog(event.getURI()).display();
236
+                }
237
+            });
238
+        }
279 239
     }
280 240
 
281
-    /**
282
-     * Installs the dialog key listener.
283
-     */
284
-    private void installKeyListener() {
285
-        UIUtilities.invokeAndWait(new Runnable() {
241
+    @Subscribe
242
+    public void showFeedbackNag(final FeedbackNagEvent event) {
243
+        UIUtilities.invokeLater(new Runnable() {
286 244
 
287 245
             @Override
288 246
             public void run() {
289
-                KeyboardFocusManager.getCurrentKeyboardFocusManager()
290
-                        .addKeyEventDispatcher(dialogKeyListener);
247
+                feedbackNagProvider.get();
291 248
             }
292 249
         });
293 250
     }
294 251
 
295
-    /**
296
-     * Removes the dialog key listener.
297
-     */
298
-    private void uninstallKeyListener() {
299
-        KeyboardFocusManager.getCurrentKeyboardFocusManager()
300
-                .removeKeyEventDispatcher(dialogKeyListener);
301
-    }
302
-
303 252
 }

+ 68
- 1
src/com/dmdirc/addons/ui_swing/SwingUIInitialiser.java Vedi File

@@ -22,12 +22,17 @@
22 22
 
23 23
 package com.dmdirc.addons.ui_swing;
24 24
 
25
+import com.dmdirc.ClientModule.AddonConfig;
25 26
 import com.dmdirc.ClientModule.GlobalConfig;
27
+import com.dmdirc.addons.ui_swing.dialogs.DialogKeyListener;
26 28
 import com.dmdirc.interfaces.config.AggregateConfigProvider;
29
+import com.dmdirc.interfaces.config.ConfigProvider;
27 30
 import com.dmdirc.logger.ErrorLevel;
28 31
 import com.dmdirc.logger.Logger;
29 32
 
30 33
 import java.awt.Font;
34
+import java.awt.KeyboardFocusManager;
35
+import java.awt.Toolkit;
31 36
 
32 37
 import javax.inject.Inject;
33 38
 import javax.swing.UIManager;
@@ -42,18 +47,34 @@ public class SwingUIInitialiser {
42 47
 
43 48
     private final Apple apple;
44 49
     private final AggregateConfigProvider globalConfig;
50
+    private final ConfigProvider addonConfig;
51
+    private final DialogKeyListener dialogKeyListener;
52
+    private final DMDircEventQueue eventQueue;
45 53
 
46 54
     @Inject
47 55
     public SwingUIInitialiser(final Apple apple,
48
-            @GlobalConfig final AggregateConfigProvider globalConfig) {
56
+            @GlobalConfig final AggregateConfigProvider globalConfig,
57
+            @AddonConfig final ConfigProvider addonConfig,
58
+            final DialogKeyListener dialogKeyListener,
59
+            final DMDircEventQueue eventQueue) {
49 60
         this.apple = apple;
50 61
         this.globalConfig = globalConfig;
62
+        this.addonConfig = addonConfig;
63
+        this.dialogKeyListener = dialogKeyListener;
64
+        this.eventQueue = eventQueue;
51 65
     }
52 66
 
53 67
     public void load() {
54 68
         apple.load();
55 69
         setAntiAlias();
56 70
         initUISettings();
71
+        installEventQueue();
72
+        installKeyListener();
73
+    }
74
+
75
+    public void unload() {
76
+        uninstallEventQueue();
77
+        uninstallKeyListener();
57 78
     }
58 79
 
59 80
     /**
@@ -88,6 +109,10 @@ public class SwingUIInitialiser {
88 109
                 if (UIManager.getFont("TextPane.font") == null) {
89 110
                     UIManager.put("TextPane.font", defaultFont);
90 111
                 }
112
+                addonConfig.setOption("ui", "textPaneFontName",
113
+                        UIManager.getFont("TextPane.font").getFamily());
114
+                addonConfig.setOption("ui", "textPaneFontSize",
115
+                        UIManager.getFont("TextPane.font").getSize());
91 116
 
92 117
                 try {
93 118
                     UIUtilities.initUISettings();
@@ -108,4 +133,46 @@ public class SwingUIInitialiser {
108 133
         });
109 134
     }
110 135
 
136
+    /**
137
+     * Installs the dialog key listener.
138
+     */
139
+    private void installKeyListener() {
140
+        UIUtilities.invokeAndWait(new Runnable() {
141
+
142
+            @Override
143
+            public void run() {
144
+                KeyboardFocusManager.getCurrentKeyboardFocusManager()
145
+                        .addKeyEventDispatcher(dialogKeyListener);
146
+            }
147
+        });
148
+    }
149
+
150
+    /**
151
+     * Removes the dialog key listener.
152
+     */
153
+    private void uninstallKeyListener() {
154
+        KeyboardFocusManager.getCurrentKeyboardFocusManager()
155
+                .removeKeyEventDispatcher(dialogKeyListener);
156
+    }
157
+
158
+    /**
159
+     * Installs the DMDirc event queue.
160
+     */
161
+    private void installEventQueue() {
162
+        UIUtilities.invokeAndWait(new Runnable() {
163
+
164
+            @Override
165
+            public void run() {
166
+                Toolkit.getDefaultToolkit().getSystemEventQueue().push(eventQueue);
167
+            }
168
+        });
169
+    }
170
+
171
+    /**
172
+     * Removes the DMDirc event queue.
173
+     */
174
+    private void uninstallEventQueue() {
175
+        eventQueue.pop();
176
+    }
177
+
111 178
 }

Loading…
Annulla
Salva