Browse Source

Tidy font + plaf handling

Change-Id: I892219602e96f57e5cba6b5da8f166442354d598
Reviewed-on: http://gerrit.dmdirc.com/3307
Automatic-Compile: DMDirc Build Manager
Reviewed-by: Chris Smith <chris@dmdirc.com>
changes/07/3307/3
Greg Holmes 10 years ago
parent
commit
da5a0b3037

+ 0
- 23
src/com/dmdirc/addons/ui_swing/MainFrame.java View File

@@ -44,14 +44,12 @@ import com.dmdirc.interfaces.config.ConfigChangeListener;
44 44
 import com.dmdirc.ui.Colour;
45 45
 import com.dmdirc.ui.CoreUIUtils;
46 46
 import com.dmdirc.ui.IconManager;
47
-import com.dmdirc.ui.WindowManager;
48 47
 import com.dmdirc.util.collections.ListenerList;
49 48
 import com.dmdirc.util.collections.QueuedLinkedHashSet;
50 49
 
51 50
 import com.google.common.eventbus.EventBus;
52 51
 
53 52
 import java.awt.Dimension;
54
-import java.awt.Font;
55 53
 import java.awt.event.WindowEvent;
56 54
 import java.awt.event.WindowFocusListener;
57 55
 import java.awt.event.WindowListener;
@@ -88,8 +86,6 @@ public class MainFrame extends JFrame implements WindowListener,
88 86
     private final QueuedLinkedHashSet<TextFrame> focusOrder;
89 87
     /** Apple instance. */
90 88
     private final Apple apple;
91
-    /** Swing Controller. */
92
-    private final SwingController controller;
93 89
     /** Controller to use to end the program. */
94 90
     private final LifecycleController lifecycleController;
95 91
     /** The window factory to use to create and listen for windows. */
@@ -106,8 +102,6 @@ public class MainFrame extends JFrame implements WindowListener,
106 102
     private CtrlTabWindowManager frameManager;
107 103
     /** The listeners registered with this class. */
108 104
     private final ListenerList listeners = new ListenerList();
109
-    /** Window management. */
110
-    private final WindowManager windowManager;
111 105
     /** Provider of frame managers. */
112 106
     private final Provider<FrameManager> frameManagerProvider;
113 107
     /** The bus to despatch events on. */
@@ -138,37 +132,31 @@ public class MainFrame extends JFrame implements WindowListener,
138 132
     /**
139 133
      * Creates new form MainFrame.
140 134
      *
141
-     * @param controller           Swing controller
142 135
      * @param apple                Apple instance
143 136
      * @param windowFactory        The window factory to use to create and listen for windows.
144 137
      * @param lifecycleController  Controller to use to end the application.
145 138
      * @param globalConfig         The config to read settings from.
146 139
      * @param quitWorker           The quit worker to use when quitting the app.
147 140
      * @param iconManager          The icon manager to use to get icons.
148
-     * @param windowManager        Window management
149 141
      * @param frameManagerProvider Provider to use to retrieve frame managers.
150 142
      * @param eventBus             The event bus to post events to.
151 143
      */
152 144
     public MainFrame(
153 145
             final Apple apple,
154
-            final SwingController controller,
155 146
             final SwingWindowFactory windowFactory,
156 147
             final LifecycleController lifecycleController,
157 148
             final AggregateConfigProvider globalConfig,
158 149
             final Provider<QuitWorker> quitWorker,
159 150
             final IconManager iconManager,
160
-            final WindowManager windowManager,
161 151
             final Provider<FrameManager> frameManagerProvider,
162 152
             final EventBus eventBus) {
163 153
         checkOnEDT();
164 154
         this.apple = apple;
165
-        this.controller = controller;
166 155
         this.windowFactory = windowFactory;
167 156
         this.lifecycleController = lifecycleController;
168 157
         this.globalConfig = globalConfig;
169 158
         this.quitWorker = quitWorker;
170 159
         this.iconManager = iconManager;
171
-        this.windowManager = windowManager;
172 160
         this.frameManagerProvider = frameManagerProvider;
173 161
         this.eventBus = eventBus;
174 162
 
@@ -182,11 +170,9 @@ public class MainFrame extends JFrame implements WindowListener,
182 170
 
183 171
         showVersion = globalConfig.getOptionBool("ui", "showversion");
184 172
         version = globalConfig.getOption("version", "version");
185
-        globalConfig.addChangeListener("ui", "lookandfeel", this);
186 173
         globalConfig.addChangeListener("ui", "showversion", this);
187 174
         globalConfig.addChangeListener("ui", "framemanager", this);
188 175
         globalConfig.addChangeListener("ui", "framemanagerPosition", this);
189
-        globalConfig.addChangeListener("ui", "textPaneFontName", this);
190 176
         globalConfig.addChangeListener("icon", "icon", this);
191 177
 
192 178
         addWindowFocusListener(new WindowFocusListener() {
@@ -546,9 +532,6 @@ public class MainFrame extends JFrame implements WindowListener,
546 532
     public void configChanged(final String domain, final String key) {
547 533
         if ("ui".equals(domain)) {
548 534
             switch (key) {
549
-                case "lookandfeel":
550
-                    controller.updateLookAndFeel();
551
-                    break;
552 535
                 case "framemanager":
553 536
                 case "framemanagerPosition":
554 537
                     UIUtilities.invokeAndWait(new Runnable() {
@@ -564,12 +547,6 @@ public class MainFrame extends JFrame implements WindowListener,
564 547
                         }
565 548
                     });
566 549
                     break;
567
-                case "textPaneFontName":
568
-                    final String font = globalConfig.getOptionString("ui", "textPaneFontName");
569
-                    log.debug("Changing textpane font: {}", font);
570
-                    UIUtilities.setUIFont(new Font(font, Font.PLAIN, 12));
571
-                    controller.updateComponentTrees();
572
-                    break;
573 550
                 default:
574 551
                     showVersion = globalConfig.getOptionBool("ui", "showversion");
575 552
                     break;

+ 45
- 16
src/com/dmdirc/addons/ui_swing/SwingController.java View File

@@ -40,6 +40,7 @@ import com.dmdirc.events.FeedbackNagEvent;
40 40
 import com.dmdirc.events.FirstRunEvent;
41 41
 import com.dmdirc.events.UnknownURLEvent;
42 42
 import com.dmdirc.interfaces.config.AggregateConfigProvider;
43
+import com.dmdirc.interfaces.config.ConfigChangeListener;
43 44
 import com.dmdirc.interfaces.config.ConfigProvider;
44 45
 import com.dmdirc.interfaces.config.IdentityController;
45 46
 import com.dmdirc.interfaces.ui.UIController;
@@ -72,13 +73,17 @@ import javax.swing.UnsupportedLookAndFeelException;
72 73
 
73 74
 import net.miginfocom.layout.PlatformDefaults;
74 75
 
76
+import org.slf4j.LoggerFactory;
77
+
75 78
 import dagger.ObjectGraph;
76 79
 
77 80
 /**
78 81
  * Controls the main swing UI.
79 82
  */
80
-public class SwingController extends BaseCommandPlugin implements UIController {
83
+public class SwingController extends BaseCommandPlugin implements UIController,
84
+        ConfigChangeListener {
81 85
 
86
+    private static final org.slf4j.Logger log = LoggerFactory.getLogger(MainFrame.class);
82 87
     /** Top level window list. */
83 88
     private final List<java.awt.Window> windows;
84 89
     /** Error dialog. */
@@ -99,6 +104,8 @@ public class SwingController extends BaseCommandPlugin implements UIController {
99 104
     private SwingManager swingManager;
100 105
     /** This plugin's settings domain. */
101 106
     private final String domain;
107
+    /** Event bus to subscribe to events with. */
108
+    private final EventBus eventBus;
102 109
 
103 110
     /**
104 111
      * Instantiates a new SwingController.
@@ -117,6 +124,7 @@ public class SwingController extends BaseCommandPlugin implements UIController {
117 124
             final EventBus eventBus) {
118 125
         this.pluginInfo = pluginInfo;
119 126
         this.domain = pluginInfo.getDomain();
127
+        this.eventBus = eventBus;
120 128
 
121 129
         globalConfig = identityManager.getGlobalConfiguration();
122 130
         globalIdentity = identityManager.getUserSettings();
@@ -125,7 +133,6 @@ public class SwingController extends BaseCommandPlugin implements UIController {
125 133
         iconManager = new IconManager(globalConfig, urlBuilder);
126 134
         setAntiAlias();
127 135
         windows = new ArrayList<>();
128
-        eventBus.register(this);
129 136
     }
130 137
 
131 138
     @Deprecated
@@ -266,13 +273,13 @@ public class SwingController extends BaseCommandPlugin implements UIController {
266 273
     public void showURLDialog(final UnknownURLEvent event) {
267 274
         if (!event.isHandled()) {
268 275
             event.setHandled(true);
269
-        UIUtilities.invokeLater(new Runnable() {
276
+            UIUtilities.invokeLater(new Runnable() {
270 277
 
271
-            @Override
272
-            public void run() {
273
-                swingManager.getUrlDialogFactory().getURLDialog(event.getURI()).display();
274
-            }
275
-        });
278
+                @Override
279
+                public void run() {
280
+                    swingManager.getUrlDialogFactory().getURLDialog(event.getURI()).display();
281
+                }
282
+            });
276 283
         }
277 284
     }
278 285
 
@@ -339,6 +346,16 @@ public class SwingController extends BaseCommandPlugin implements UIController {
339 346
             }
340 347
         });
341 348
 
349
+        addonIdentity.setOption("ui", "textPaneFontName",
350
+                UIManager.getFont("TextPane.font").getFamily());
351
+        addonIdentity.setOption("ui", "textPaneFontSize",
352
+                UIManager.getFont("TextPane.font").getSize());
353
+
354
+        eventBus.register(this);
355
+        globalConfig.addChangeListener("ui", "lookandfeel", this);
356
+        globalConfig.addChangeListener("ui", "textPaneFontName", this);
357
+        globalConfig.addChangeListener("ui", "textPaneFontSize", this);
358
+
342 359
         super.onLoad();
343 360
     }
344 361
 
@@ -347,6 +364,8 @@ public class SwingController extends BaseCommandPlugin implements UIController {
347 364
         swingManager.unload();
348 365
 
349 366
         errorDialog.dispose();
367
+        eventBus.unregister(this);
368
+        globalConfig.removeListener(this);
350 369
 
351 370
         for (final java.awt.Window window : getTopLevelWindows()) {
352 371
             window.dispose();
@@ -354,14 +373,6 @@ public class SwingController extends BaseCommandPlugin implements UIController {
354 373
         super.onUnload();
355 374
     }
356 375
 
357
-    @Override
358
-    public void domainUpdated() {
359
-        addonIdentity.setOption("ui", "textPaneFontName",
360
-                UIManager.getFont("TextPane.font").getFamily());
361
-        addonIdentity.setOption("ui", "textPaneFontSize",
362
-                UIManager.getFont("TextPane.font").getSize());
363
-    }
364
-
365 376
     @Override
366 377
     public void showConfig(final PreferencesDialogModel manager) {
367 378
         manager.getCategory("GUI").addSubCategory(createGeneralCategory());
@@ -657,4 +668,22 @@ public class SwingController extends BaseCommandPlugin implements UIController {
657 668
         return swingManager.getButtonProvider();
658 669
     }
659 670
 
671
+    @Override
672
+    public void configChanged(final String domain, final String key) {
673
+        switch (key) {
674
+            case "lookandfeel":
675
+                updateLookAndFeel();
676
+                break;
677
+            case "textPaneFontSize":
678
+            case "textPaneFontName":
679
+                final String font = globalConfig.getOptionString("ui", "textPaneFontName");
680
+                log.debug("Changing textpane font: {}", font);
681
+                UIUtilities.setUIFont(new Font(font, Font.PLAIN, 12));
682
+                updateComponentTrees();
683
+                break;
684
+            default:
685
+                break;
686
+        }
687
+    }
688
+
660 689
 }

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

@@ -59,7 +59,6 @@ import com.dmdirc.plugins.PluginDomain;
59 59
 import com.dmdirc.plugins.PluginManager;
60 60
 import com.dmdirc.plugins.ServiceLocator;
61 61
 import com.dmdirc.ui.IconManager;
62
-import com.dmdirc.ui.WindowManager;
63 62
 import com.dmdirc.ui.core.components.StatusBarManager;
64 63
 import com.dmdirc.ui.core.util.URLHandler;
65 64
 import com.dmdirc.util.URLBuilder;
@@ -115,13 +114,11 @@ public class SwingModule {
115 114
     @Singleton
116 115
     public MainFrame getMainFrame(
117 116
             final Apple apple,
118
-            final SwingController swingController,
119 117
             final SwingWindowFactory windowFactory,
120 118
             final LifecycleController lifecycleController,
121 119
             @GlobalConfig final AggregateConfigProvider globalConfig,
122 120
             final Provider<QuitWorker> quitWorker,
123 121
             final URLBuilder urlBuilder,
124
-            final WindowManager windowManager,
125 122
             final Provider<FrameManager> frameManagerProvider,
126 123
             final EventBus eventBus) {
127 124
         return UIUtilities.invokeAndWait(new Callable<MainFrame>() {
@@ -130,13 +127,11 @@ public class SwingModule {
130 127
             public MainFrame call() {
131 128
                 return new MainFrame(
132 129
                         apple,
133
-                        swingController,
134 130
                         windowFactory,
135 131
                         lifecycleController,
136 132
                         globalConfig,
137 133
                         quitWorker,
138 134
                         new IconManager(globalConfig, urlBuilder),
139
-                        windowManager,
140 135
                         frameManagerProvider,
141 136
                         eventBus);
142 137
             }

Loading…
Cancel
Save