|
@@ -38,6 +38,7 @@ import com.dmdirc.addons.ui_swing.dialogs.serversetting.ServerSettingsDialog;
|
38
|
38
|
import com.dmdirc.addons.ui_swing.dialogs.url.URLDialog;
|
39
|
39
|
import com.dmdirc.addons.ui_swing.wizard.WizardListener;
|
40
|
40
|
import com.dmdirc.addons.ui_swing.wizard.firstrun.SwingFirstRunWizard;
|
|
41
|
+import com.dmdirc.config.ConfigManager;
|
41
|
42
|
import com.dmdirc.config.Identity;
|
42
|
43
|
import com.dmdirc.config.IdentityManager;
|
43
|
44
|
import com.dmdirc.config.prefs.PluginPreferencesCategory;
|
|
@@ -78,11 +79,13 @@ import javax.swing.UIManager;
|
78
|
79
|
import javax.swing.UnsupportedLookAndFeelException;
|
79
|
80
|
import javax.swing.UIManager.LookAndFeelInfo;
|
80
|
81
|
|
|
82
|
+import lombok.Getter;
|
81
|
83
|
import net.miginfocom.layout.PlatformDefaults;
|
82
|
84
|
|
83
|
85
|
/**
|
84
|
86
|
* Controls the main swing UI.
|
85
|
87
|
*/
|
|
88
|
+@SuppressWarnings("PMD.UnusedPrivateField")
|
86
|
89
|
public class SwingController extends BasePlugin implements UIController {
|
87
|
90
|
|
88
|
91
|
/**
|
|
@@ -93,16 +96,20 @@ public class SwingController extends BasePlugin implements UIController {
|
93
|
96
|
private static final long serialVersionUID = 1;
|
94
|
97
|
|
95
|
98
|
/** Window factory. */
|
|
99
|
+ @Getter
|
96
|
100
|
private final SwingWindowFactory windowFactory =
|
97
|
101
|
new SwingWindowFactory(this);
|
98
|
102
|
/** Waiting on mainframe creation. */
|
99
|
103
|
private final AtomicBoolean mainFrameCreated = new AtomicBoolean(false);
|
100
|
104
|
/** URL Handler to use. */
|
101
|
|
- private final URLHandler urlHandler = new URLHandler(this);
|
|
105
|
+ @Getter
|
|
106
|
+ private final URLHandler URLHandler = new URLHandler(this);
|
102
|
107
|
/** Singleton instance of MainFrame. */
|
103
|
|
- private MainFrame me;
|
|
108
|
+ @Getter
|
|
109
|
+ private MainFrame mainFrame;
|
104
|
110
|
/** Status bar. */
|
105
|
|
- private SwingStatusBar statusBar;
|
|
111
|
+ @Getter
|
|
112
|
+ private SwingStatusBar swingStatusBar;
|
106
|
113
|
/** Top level window list. */
|
107
|
114
|
private final List<java.awt.Window> windows;
|
108
|
115
|
/** Error dialog. */
|
|
@@ -113,6 +120,15 @@ public class SwingController extends BasePlugin implements UIController {
|
113
|
120
|
private DialogKeyListener keyListener;
|
114
|
121
|
/** This plugin's plugin info object. */
|
115
|
122
|
private final PluginInfo pluginInfo;
|
|
123
|
+ /** Global config manager. */
|
|
124
|
+ @Getter
|
|
125
|
+ private final ConfigManager globalConfig;
|
|
126
|
+ /** Global config identity. */
|
|
127
|
+ @Getter
|
|
128
|
+ private final Identity globalIdentity;
|
|
129
|
+ /** Addon config identity. */
|
|
130
|
+ @Getter
|
|
131
|
+ private final Identity addonIdentity;
|
116
|
132
|
|
117
|
133
|
/**
|
118
|
134
|
* Instantiates a new SwingController.
|
|
@@ -122,6 +138,12 @@ public class SwingController extends BasePlugin implements UIController {
|
122
|
138
|
public SwingController(final PluginInfo pluginInfo) {
|
123
|
139
|
super();
|
124
|
140
|
this.pluginInfo = pluginInfo;
|
|
141
|
+ globalConfig = IdentityManager.getIdentityManager()
|
|
142
|
+ .getGlobalConfiguration();
|
|
143
|
+ globalIdentity = IdentityManager.getIdentityManager()
|
|
144
|
+ .getGlobalConfigIdentity();
|
|
145
|
+ addonIdentity = IdentityManager.getIdentityManager()
|
|
146
|
+ .getGlobalAddonIdentity();
|
125
|
147
|
setAntiAlias();
|
126
|
148
|
windows = new ArrayList<java.awt.Window>();
|
127
|
149
|
registerCommand(new ServerSettings(), ServerSettings.INFO);
|
|
@@ -136,8 +158,8 @@ public class SwingController extends BasePlugin implements UIController {
|
136
|
158
|
*/
|
137
|
159
|
public final void setAntiAlias() {
|
138
|
160
|
// For this to work it *HAS* to be before anything else UI related.
|
139
|
|
- final boolean aaSetting = IdentityManager.getGlobalConfig().
|
140
|
|
- getOptionBool("ui", "antialias");
|
|
161
|
+ final boolean aaSetting = getGlobalConfig()
|
|
162
|
+ .getOptionBool("ui", "antialias");
|
141
|
163
|
System.setProperty("awt.useSystemAAFontSettings",
|
142
|
164
|
Boolean.toString(aaSetting));
|
143
|
165
|
System.setProperty("swing.aatext", Boolean.toString(aaSetting));
|
|
@@ -152,44 +174,6 @@ public class SwingController extends BasePlugin implements UIController {
|
152
|
174
|
return mainFrameCreated.get();
|
153
|
175
|
}
|
154
|
176
|
|
155
|
|
- /**
|
156
|
|
- * Returns a URL Handler which may be used when working with the Swing UI.
|
157
|
|
- *
|
158
|
|
- * @return A URL handler for use with the swing UI
|
159
|
|
- * @since 0.6.5
|
160
|
|
- */
|
161
|
|
- public URLHandler getURLHandler() {
|
162
|
|
- return urlHandler;
|
163
|
|
- }
|
164
|
|
-
|
165
|
|
- /**
|
166
|
|
- * Returns the window factory used by this controller.
|
167
|
|
- *
|
168
|
|
- * @return This controller's window factory
|
169
|
|
- * @since 0.6.4
|
170
|
|
- */
|
171
|
|
- public SwingWindowFactory getWindowFactory() {
|
172
|
|
- return windowFactory;
|
173
|
|
- }
|
174
|
|
-
|
175
|
|
- /**
|
176
|
|
- * Retrieves the main window used by this UI.
|
177
|
|
- *
|
178
|
|
- * @return This UI's main window
|
179
|
|
- */
|
180
|
|
- public MainFrame getMainFrame() {
|
181
|
|
- return me;
|
182
|
|
- }
|
183
|
|
-
|
184
|
|
- /**
|
185
|
|
- * Retrieves the Swing Status Bar used by this UI.
|
186
|
|
- *
|
187
|
|
- * @return This UI's status bar
|
188
|
|
- */
|
189
|
|
- public SwingStatusBar getSwingStatusBar() {
|
190
|
|
- return statusBar;
|
191
|
|
- }
|
192
|
|
-
|
193
|
177
|
/** {@inheritDoc} */
|
194
|
178
|
@Override
|
195
|
179
|
public void showFirstRunWizard() {
|
|
@@ -213,8 +197,8 @@ public class SwingController extends BasePlugin implements UIController {
|
213
|
197
|
semaphore.release();
|
214
|
198
|
}
|
215
|
199
|
};
|
216
|
|
- final SwingFirstRunWizard wizard = new SwingFirstRunWizard(me,
|
217
|
|
- SwingController.this);
|
|
200
|
+ final SwingFirstRunWizard wizard = new SwingFirstRunWizard(
|
|
201
|
+ getMainFrame(), SwingController.this);
|
218
|
202
|
wizard.getWizardDialog().addWizardListener(listener);
|
219
|
203
|
wizard.display();
|
220
|
204
|
}
|
|
@@ -230,9 +214,9 @@ public class SwingController extends BasePlugin implements UIController {
|
230
|
214
|
/** {@inheritDoc} */
|
231
|
215
|
@Override
|
232
|
216
|
public void run() {
|
233
|
|
- ChannelSettingsDialog.showChannelSettingsDialog(channel, me,
|
234
|
|
- (InputWindow) getWindowFactory().getSwingWindow(
|
235
|
|
- channel));
|
|
217
|
+ ChannelSettingsDialog.showChannelSettingsDialog(channel,
|
|
218
|
+ getMainFrame(), (InputWindow) getWindowFactory()
|
|
219
|
+ .getSwingWindow(channel));
|
236
|
220
|
}
|
237
|
221
|
});
|
238
|
222
|
}
|
|
@@ -245,7 +229,8 @@ public class SwingController extends BasePlugin implements UIController {
|
245
|
229
|
/** {@inheritDoc} */
|
246
|
230
|
@Override
|
247
|
231
|
public void run() {
|
248
|
|
- ServerSettingsDialog.showServerSettingsDialog(server, me);
|
|
232
|
+ ServerSettingsDialog.showServerSettingsDialog(
|
|
233
|
+ server, getMainFrame());
|
249
|
234
|
}
|
250
|
235
|
});
|
251
|
236
|
}
|
|
@@ -255,7 +240,7 @@ public class SwingController extends BasePlugin implements UIController {
|
255
|
240
|
*/
|
256
|
241
|
public void updateLookAndFeel() {
|
257
|
242
|
try {
|
258
|
|
- UIManager.setLookAndFeel(UIUtilities.getLookAndFeel(IdentityManager.
|
|
243
|
+ UIManager.setLookAndFeel(UIUtilities.getLookAndFeel(
|
259
|
244
|
getGlobalConfig().getOption("ui", "lookandfeel")));
|
260
|
245
|
final int state = UIUtilities.invokeAndWait(
|
261
|
246
|
new ReturnableThread<Integer>() {
|
|
@@ -263,7 +248,7 @@ public class SwingController extends BasePlugin implements UIController {
|
263
|
248
|
/** {@inheritDoc} */
|
264
|
249
|
@Override
|
265
|
250
|
public void run() {
|
266
|
|
- setObject(me.getExtendedState());
|
|
251
|
+ setObject(getMainFrame().getExtendedState());
|
267
|
252
|
}
|
268
|
253
|
});
|
269
|
254
|
UIUtilities.invokeLater(new Runnable() {
|
|
@@ -281,7 +266,7 @@ public class SwingController extends BasePlugin implements UIController {
|
281
|
266
|
@Override
|
282
|
267
|
public void run() {
|
283
|
268
|
SwingUtilities.updateComponentTreeUI(window);
|
284
|
|
- if (window != me) {
|
|
269
|
+ if (window != getMainFrame()) {
|
285
|
270
|
window.pack();
|
286
|
271
|
}
|
287
|
272
|
}
|
|
@@ -292,7 +277,7 @@ public class SwingController extends BasePlugin implements UIController {
|
292
|
277
|
/** {@inheritDoc} */
|
293
|
278
|
@Override
|
294
|
279
|
public void run() {
|
295
|
|
- me.setExtendedState(state);
|
|
280
|
+ getMainFrame().setExtendedState(state);
|
296
|
281
|
}
|
297
|
282
|
});
|
298
|
283
|
} catch (ClassNotFoundException ex) {
|
|
@@ -332,7 +317,7 @@ public class SwingController extends BasePlugin implements UIController {
|
332
|
317
|
|
333
|
318
|
try {
|
334
|
319
|
UIUtilities.initUISettings();
|
335
|
|
- UIManager.setLookAndFeel(UIUtilities.getLookAndFeel(IdentityManager.
|
|
320
|
+ UIManager.setLookAndFeel(UIUtilities.getLookAndFeel(
|
336
|
321
|
getGlobalConfig().getOption("ui", "lookandfeel")));
|
337
|
322
|
} catch (UnsupportedOperationException ex) {
|
338
|
323
|
Logger.userError(ErrorLevel.LOW, "Unable to set UI Settings");
|
|
@@ -360,7 +345,7 @@ public class SwingController extends BasePlugin implements UIController {
|
360
|
345
|
/** {@inheritDoc} */
|
361
|
346
|
@Override
|
362
|
347
|
public void run() {
|
363
|
|
- URLDialog.showURLDialog(url, me, urlHandler);
|
|
348
|
+ URLDialog.showURLDialog(url, getMainFrame(), getURLHandler());
|
364
|
349
|
|
365
|
350
|
}
|
366
|
351
|
});
|
|
@@ -387,8 +372,8 @@ public class SwingController extends BasePlugin implements UIController {
|
387
|
372
|
/** {@inheritDoc} */
|
388
|
373
|
@Override
|
389
|
374
|
public void run() {
|
390
|
|
- new StandardMessageDialog(me, ModalityType.MODELESS, title,
|
391
|
|
- message).display();
|
|
375
|
+ new StandardMessageDialog(getMainFrame(), ModalityType.MODELESS,
|
|
376
|
+ title, message).display();
|
392
|
377
|
}
|
393
|
378
|
});
|
394
|
379
|
}
|
|
@@ -443,13 +428,13 @@ public class SwingController extends BasePlugin implements UIController {
|
443
|
428
|
@Override
|
444
|
429
|
public void run() {
|
445
|
430
|
initUISettings();
|
446
|
|
- me = new MainFrame(SwingController.this);
|
447
|
|
- me.setVisible(true);
|
|
431
|
+ mainFrame = new MainFrame(SwingController.this);
|
|
432
|
+ getMainFrame().setVisible(true);
|
448
|
433
|
mainFrameCreated.set(true);
|
449
|
|
- statusBar = me.getStatusBar();
|
450
|
|
- errorDialog = new ErrorListDialog(me);
|
|
434
|
+ swingStatusBar = getMainFrame().getStatusBar();
|
|
435
|
+ errorDialog = new ErrorListDialog(getMainFrame());
|
451
|
436
|
StatusBarManager.getStatusBarManager().registerStatusBar(
|
452
|
|
- statusBar);
|
|
437
|
+ getSwingStatusBar());
|
453
|
438
|
}
|
454
|
439
|
});
|
455
|
440
|
|
|
@@ -467,9 +452,10 @@ public class SwingController extends BasePlugin implements UIController {
|
467
|
452
|
errorDialog.dispose();
|
468
|
453
|
WindowManager.getWindowManager().removeListener(windowFactory);
|
469
|
454
|
mainFrameCreated.set(false);
|
470
|
|
- me.dispose();
|
|
455
|
+ getMainFrame().dispose();
|
471
|
456
|
windowFactory.dispose();
|
472
|
|
- StatusBarManager.getStatusBarManager().registerStatusBar(statusBar);
|
|
457
|
+ StatusBarManager.getStatusBarManager()
|
|
458
|
+ .registerStatusBar(getSwingStatusBar());
|
473
|
459
|
eventQueue.pop();
|
474
|
460
|
KeyboardFocusManager.getCurrentKeyboardFocusManager().
|
475
|
461
|
removeKeyEventDispatcher(keyListener);
|
|
@@ -482,10 +468,9 @@ public class SwingController extends BasePlugin implements UIController {
|
482
|
468
|
/** {@inheritDoc} */
|
483
|
469
|
@Override
|
484
|
470
|
public void domainUpdated() {
|
485
|
|
- final Identity defaults = IdentityManager.getAddonIdentity();
|
486
|
|
- defaults.setOption("ui", "textPaneFontName",
|
|
471
|
+ getAddonIdentity().setOption("ui", "textPaneFontName",
|
487
|
472
|
UIManager.getFont("TextPane.font").getFamily());
|
488
|
|
- defaults.setOption("ui", "textPaneFontSize",
|
|
473
|
+ getAddonIdentity().setOption("ui", "textPaneFontSize",
|
489
|
474
|
UIManager.getFont("TextPane.font").getSize());
|
490
|
475
|
}
|
491
|
476
|
|
|
@@ -741,7 +726,7 @@ public class SwingController extends BasePlugin implements UIController {
|
741
|
726
|
* @param menuItem Menu item to add
|
742
|
727
|
*/
|
743
|
728
|
public void addMenuItem(final String parentMenu, final JMenuItem menuItem) {
|
744
|
|
- me.getJMenuBar().addMenuItem(parentMenu, menuItem);
|
|
729
|
+ getMainFrame().getJMenuBar().addMenuItem(parentMenu, menuItem);
|
745
|
730
|
}
|
746
|
731
|
|
747
|
732
|
/** {@inheritDoc} */
|