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