浏览代码

Use services for frame managers.

To add a frame manager, a plugin must export a FrameManagerProvider instance.
This will drop users back to using a treeview as their previous config setting
will be wrong (it needs to point to the Provider class now), and I don't think
it's worth adding migration code given we know of 0 users of the buttonbar.

This also enables us to dependency inject the frame managers.

Change-Id: Ic66997625587e1adc0ee6ed1c7e38fba31ec47e7
Reviewed-on: http://gerrit.dmdirc.com/3283
Automatic-Compile: DMDirc Build Manager
Reviewed-by: Greg Holmes <greg@dmdirc.com>
changes/83/3283/2
Chris Smith 10 年前
父节点
当前提交
31dc4b5c37

+ 17
- 27
src/com/dmdirc/addons/ui_swing/MainFrame.java 查看文件

@@ -32,7 +32,6 @@ import com.dmdirc.addons.ui_swing.dialogs.StandardQuestionDialog;
32 32
 import com.dmdirc.addons.ui_swing.framemanager.FrameManager;
33 33
 import com.dmdirc.addons.ui_swing.framemanager.FramemanagerPosition;
34 34
 import com.dmdirc.addons.ui_swing.framemanager.ctrltab.CtrlTabWindowManager;
35
-import com.dmdirc.addons.ui_swing.framemanager.tree.TreeFrameManager;
36 35
 import com.dmdirc.events.ClientFocusGainedEvent;
37 36
 import com.dmdirc.events.ClientFocusLostEvent;
38 37
 import com.dmdirc.events.ClientMinimisedEvent;
@@ -42,8 +41,6 @@ import com.dmdirc.interfaces.LifecycleController;
42 41
 import com.dmdirc.interfaces.NotificationListener;
43 42
 import com.dmdirc.interfaces.config.AggregateConfigProvider;
44 43
 import com.dmdirc.interfaces.config.ConfigChangeListener;
45
-import com.dmdirc.logger.ErrorLevel;
46
-import com.dmdirc.logger.Logger;
47 44
 import com.dmdirc.ui.Colour;
48 45
 import com.dmdirc.ui.CoreUIUtils;
49 46
 import com.dmdirc.ui.IconManager;
@@ -111,6 +108,8 @@ public class MainFrame extends JFrame implements WindowListener,
111 108
     private final ListenerList listeners = new ListenerList();
112 109
     /** Window management. */
113 110
     private final WindowManager windowManager;
111
+    /** Provider of frame managers. */
112
+    private final Provider<FrameManager> frameManagerProvider;
114 113
     /** The bus to despatch events on. */
115 114
     private final EventBus eventBus;
116 115
     /** The main application icon. */
@@ -139,15 +138,16 @@ public class MainFrame extends JFrame implements WindowListener,
139 138
     /**
140 139
      * Creates new form MainFrame.
141 140
      *
142
-     * @param controller          Swing controller
143
-     * @param apple               Apple instance
144
-     * @param windowFactory       The window factory to use to create and listen for windows.
145
-     * @param lifecycleController Controller to use to end the application.
146
-     * @param globalConfig        The config to read settings from.
147
-     * @param quitWorker          The quit worker to use when quitting the app.
148
-     * @param iconManager         The icon manager to use to get icons.
149
-     * @param windowManager       Window management
150
-     * @param eventBus            The event bus to post events to.
141
+     * @param controller           Swing controller
142
+     * @param apple                Apple instance
143
+     * @param windowFactory        The window factory to use to create and listen for windows.
144
+     * @param lifecycleController  Controller to use to end the application.
145
+     * @param globalConfig         The config to read settings from.
146
+     * @param quitWorker           The quit worker to use when quitting the app.
147
+     * @param iconManager          The icon manager to use to get icons.
148
+     * @param windowManager        Window management
149
+     * @param frameManagerProvider Provider to use to retrieve frame managers.
150
+     * @param eventBus             The event bus to post events to.
151 151
      */
152 152
     public MainFrame(
153 153
             final Apple apple,
@@ -158,6 +158,7 @@ public class MainFrame extends JFrame implements WindowListener,
158 158
             final Provider<QuitWorker> quitWorker,
159 159
             final IconManager iconManager,
160 160
             final WindowManager windowManager,
161
+            final Provider<FrameManager> frameManagerProvider,
161 162
             final EventBus eventBus) {
162 163
         checkOnEDT();
163 164
         this.apple = apple;
@@ -168,6 +169,7 @@ public class MainFrame extends JFrame implements WindowListener,
168 169
         this.quitWorker = quitWorker;
169 170
         this.iconManager = iconManager;
170 171
         this.windowManager = windowManager;
172
+        this.frameManagerProvider = frameManagerProvider;
171 173
         this.eventBus = eventBus;
172 174
 
173 175
         focusOrder = new QueuedLinkedHashSet<>();
@@ -215,8 +217,7 @@ public class MainFrame extends JFrame implements WindowListener,
215 217
      * @return Frame manager size.
216 218
      */
217 219
     public int getFrameManagerSize() {
218
-        if (position == FramemanagerPosition.LEFT
219
-                || position == FramemanagerPosition.RIGHT) {
220
+        if (position == FramemanagerPosition.LEFT || position == FramemanagerPosition.RIGHT) {
220 221
             return frameManagerPanel.getWidth();
221 222
         } else {
222 223
             return frameManagerPanel.getHeight();
@@ -346,20 +347,9 @@ public class MainFrame extends JFrame implements WindowListener,
346 347
                 frameManagerPanel.removeAll();
347 348
                 if (mainFrameManager != null) {
348 349
                     windowFactory.removeWindowListener(mainFrameManager);
350
+                    removeSelectionListener(mainFrameManager);
349 351
                 }
350
-                final String manager = globalConfig.getOption("ui", "framemanager");
351
-                try {
352
-                    mainFrameManager = (FrameManager) Class.forName(manager)
353
-                            .getConstructor(WindowManager.class).newInstance(windowManager);
354
-                } catch (final ReflectiveOperationException | SecurityException | LinkageError ex) {
355
-                    Logger.appError(ErrorLevel.MEDIUM, "Unable to load frame "
356
-                            + "manager, falling back to default.", ex);
357
-                } finally {
358
-                    if (mainFrameManager == null) {
359
-                        mainFrameManager = new TreeFrameManager(windowManager);
360
-                    }
361
-                }
362
-                mainFrameManager.setController(controller);
352
+                mainFrameManager = frameManagerProvider.get();
363 353
                 mainFrameManager.setParent(frameManagerPanel);
364 354
                 addSelectionListener(mainFrameManager);
365 355
                 windowFactory.addWindowListener(mainFrameManager);

+ 14
- 2
src/com/dmdirc/addons/ui_swing/SwingController.java 查看文件

@@ -32,6 +32,7 @@ import com.dmdirc.addons.ui_swing.commands.PopOutCommand;
32 32
 import com.dmdirc.addons.ui_swing.commands.ServerSettings;
33 33
 import com.dmdirc.addons.ui_swing.components.frames.TextFrame;
34 34
 import com.dmdirc.addons.ui_swing.dialogs.error.ErrorListDialog;
35
+import com.dmdirc.addons.ui_swing.framemanager.FrameManagerProvider;
35 36
 import com.dmdirc.addons.ui_swing.injection.SwingModule;
36 37
 import com.dmdirc.config.prefs.PluginPreferencesCategory;
37 38
 import com.dmdirc.config.prefs.PreferencesCategory;
@@ -423,11 +424,12 @@ public class SwingController extends BaseCommandPlugin implements UIController {
423 424
         final Map<String, String> framemanagers = new HashMap<>();
424 425
         final Map<String, String> fmpositions = new HashMap<>();
425 426
 
427
+        // TODO: When we can inject nicely, use a service locator to find all implementations.
426 428
         framemanagers.put(
427
-                "com.dmdirc.addons.ui_swing.framemanager.tree.TreeFrameManager",
429
+                "com.dmdirc.addons.ui_swing.framemanager.tree.TreeFrameManagerProvider",
428 430
                 "Treeview");
429 431
         framemanagers.put(
430
-                "com.dmdirc.addons.ui_swing.framemanager.buttonbar.ButtonBar",
432
+                "com.dmdirc.addons.ui_swing.framemanager.buttonbar.ButtonBarProvider",
431 433
                 "Button bar");
432 434
 
433 435
         fmpositions.put("top", "Top");
@@ -717,4 +719,14 @@ public class SwingController extends BaseCommandPlugin implements UIController {
717 719
         return swingManager.getMainFrame();
718 720
     }
719 721
 
722
+    @Exported
723
+    public FrameManagerProvider getTreeManager() {
724
+        return swingManager.getTreeProvider();
725
+    }
726
+
727
+    @Exported
728
+    public FrameManagerProvider getButtonManager() {
729
+        return swingManager.getButtonProvider();
730
+    }
731
+
720 732
 }

+ 38
- 11
src/com/dmdirc/addons/ui_swing/SwingManager.java 查看文件

@@ -31,7 +31,9 @@ import com.dmdirc.addons.ui_swing.dialogs.DialogKeyListener;
31 31
 import com.dmdirc.addons.ui_swing.dialogs.channelsetting.ChannelSettingsDialog;
32 32
 import com.dmdirc.addons.ui_swing.dialogs.serversetting.ServerSettingsDialog;
33 33
 import com.dmdirc.addons.ui_swing.dialogs.url.URLDialogFactory;
34
+import com.dmdirc.addons.ui_swing.framemanager.buttonbar.ButtonBarProvider;
34 35
 import com.dmdirc.addons.ui_swing.framemanager.ctrltab.CtrlTabWindowManager;
36
+import com.dmdirc.addons.ui_swing.framemanager.tree.TreeFrameManagerProvider;
35 37
 import com.dmdirc.addons.ui_swing.injection.KeyedDialogProvider;
36 38
 import com.dmdirc.addons.ui_swing.wizard.firstrun.FirstRunWizardExecutor;
37 39
 import com.dmdirc.ui.WindowManager;
@@ -58,12 +60,12 @@ public class SwingManager {
58 60
     private final SwingWindowFactory windowFactory;
59 61
     /** The status bar manager to register our status bar with. */
60 62
     private final StatusBarManager statusBarManager;
63
+    private final MenuBar menuBar;
61 64
     /** The status bar in use. */
62 65
     private final SwingStatusBar statusBar;
63 66
     /** The window manager to listen on for events. */
64 67
     private final WindowManager windowManager;
65
-    /** The main frame of the Swing UI. */
66
-    private final MainFrame mainFrame;
68
+    private final CtrlTabWindowManager ctrlTabManager;
67 69
     /** The key listener that supports dialogs. */
68 70
     private final DialogKeyListener dialogKeyListener;
69 71
     /** Provider of first run executors. */
@@ -80,6 +82,14 @@ public class SwingManager {
80 82
     private final SwingLinkHandler linkHandler;
81 83
     /** Bus to listen on for events. */
82 84
     private final EventBus eventBus;
85
+    /** The provider to use to create tree-based frame managers. */
86
+    private final TreeFrameManagerProvider treeProvider;
87
+    /** The provider to use to create button-based frame managers. */
88
+    private final ButtonBarProvider buttonProvider;
89
+    /** The provider to use to create new main frames. */
90
+    private final Provider<MainFrame> mainFrameProvider;
91
+    /** The main frame of the Swing UI. */
92
+    private MainFrame mainFrame;
83 93
 
84 94
     /**
85 95
      * Creates a new instance of {@link SwingManager}.
@@ -88,7 +98,7 @@ public class SwingManager {
88 98
      * @param windowFactory                 The window factory in use.
89 99
      * @param windowManager                 The window manager to listen on for events.
90 100
      * @param statusBarManager              The status bar manager to register our status bar with.
91
-     * @param mainFrame                     The main frame of the Swing UI.
101
+     * @param mainFrameProvider             The provider to use for the main frame.
92 102
      * @param menuBar                       The menu bar to use for the main frame.
93 103
      * @param statusBar                     The status bar to use in the main frame.
94 104
      * @param ctrlTabManager                The window manager that handles ctrl+tab behaviour.
@@ -100,6 +110,8 @@ public class SwingManager {
100 110
      * @param urlDialogFactory              Factory to use to create URL dialogs.
101 111
      * @param linkHandler                   The handler to use when users click links.
102 112
      * @param eventBus                      The bus to listen on for events.
113
+     * @param treeProvider                  Provider to use for tree-based frame managers.
114
+     * @param buttonProvider                Provider to use for button-based frame managers.
103 115
      */
104 116
     @Inject
105 117
     public SwingManager(
@@ -107,7 +119,7 @@ public class SwingManager {
107 119
             final SwingWindowFactory windowFactory,
108 120
             final WindowManager windowManager,
109 121
             final StatusBarManager statusBarManager,
110
-            final MainFrame mainFrame,
122
+            final Provider<MainFrame> mainFrameProvider,
111 123
             final MenuBar menuBar,
112 124
             final SwingStatusBar statusBar,
113 125
             final CtrlTabWindowManager ctrlTabManager,
@@ -118,12 +130,17 @@ public class SwingManager {
118 130
             final Provider<FeedbackNag> feedbackNagProvider,
119 131
             final URLDialogFactory urlDialogFactory,
120 132
             final SwingLinkHandler linkHandler,
121
-            final EventBus eventBus) {
133
+            final EventBus eventBus,
134
+            final TreeFrameManagerProvider treeProvider,
135
+            final ButtonBarProvider buttonProvider) {
122 136
         this.eventQueue = eventQueue;
123 137
         this.windowFactory = windowFactory;
124 138
         this.windowManager = windowManager;
139
+        this.menuBar = menuBar;
125 140
         this.statusBar = statusBar;
126 141
         this.statusBarManager = statusBarManager;
142
+        this.mainFrameProvider = mainFrameProvider;
143
+        this.ctrlTabManager = ctrlTabManager;
127 144
         this.dialogKeyListener = dialogKeyListener;
128 145
         this.firstRunExecutor = firstRunExecutor;
129 146
         this.serverSettingsDialogProvider = serverSettingsDialogProvider;
@@ -132,18 +149,20 @@ public class SwingManager {
132 149
         this.urlDialogFactory = urlDialogFactory;
133 150
         this.linkHandler = linkHandler;
134 151
         this.eventBus = eventBus;
135
-
136
-        this.mainFrame = mainFrame;
137
-        this.mainFrame.setMenuBar(menuBar);
138
-        this.mainFrame.setWindowManager(ctrlTabManager);
139
-        this.mainFrame.setStatusBar(statusBar);
140
-        this.mainFrame.initComponents();
152
+        this.treeProvider = treeProvider;
153
+        this.buttonProvider = buttonProvider;
141 154
     }
142 155
 
143 156
     /**
144 157
      * Handles loading of the UI.
145 158
      */
146 159
     public void load() {
160
+        this.mainFrame = mainFrameProvider.get();
161
+        this.mainFrame.setMenuBar(menuBar);
162
+        this.mainFrame.setWindowManager(ctrlTabManager);
163
+        this.mainFrame.setStatusBar(statusBar);
164
+        this.mainFrame.initComponents();
165
+
147 166
         installEventQueue();
148 167
         installKeyListener();
149 168
 
@@ -219,6 +238,14 @@ public class SwingManager {
219 238
         return mainFrame;
220 239
     }
221 240
 
241
+    public TreeFrameManagerProvider getTreeProvider() {
242
+        return treeProvider;
243
+    }
244
+
245
+    public ButtonBarProvider getButtonProvider() {
246
+        return buttonProvider;
247
+    }
248
+
222 249
     /**
223 250
      * Installs the DMDirc event queue.
224 251
      */

+ 0
- 9
src/com/dmdirc/addons/ui_swing/framemanager/FrameManager.java 查看文件

@@ -23,7 +23,6 @@
23 23
 package com.dmdirc.addons.ui_swing.framemanager;
24 24
 
25 25
 import com.dmdirc.addons.ui_swing.SelectionListener;
26
-import com.dmdirc.addons.ui_swing.SwingController;
27 26
 import com.dmdirc.addons.ui_swing.SwingWindowListener;
28 27
 
29 28
 import javax.swing.JComponent;
@@ -42,14 +41,6 @@ public interface FrameManager extends SwingWindowListener, SelectionListener {
42 41
      */
43 42
     void setParent(JComponent parent);
44 43
 
45
-    /**
46
-     * Sets the UIController for the frame manager. This method will be called immediately after
47
-     * construction of the frame manager.
48
-     *
49
-     * @param controller UIController
50
-     */
51
-    void setController(SwingController controller);
52
-
53 44
     /**
54 45
      * Indicates whether this frame manager can be positioned vertically (i.e., at the side of the
55 46
      * screen).

+ 32
- 0
src/com/dmdirc/addons/ui_swing/framemanager/FrameManagerProvider.java 查看文件

@@ -0,0 +1,32 @@
1
+/*
2
+ * Copyright (c) 2006-2014 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.framemanager;
24
+
25
+/**
26
+ * Service interface for plugins that provide frame managers.
27
+ */
28
+public interface FrameManagerProvider {
29
+
30
+    FrameManager getFrameManager();
31
+
32
+}

+ 57
- 48
src/com/dmdirc/addons/ui_swing/framemanager/buttonbar/ButtonBar.java 查看文件

@@ -22,8 +22,10 @@
22 22
 
23 23
 package com.dmdirc.addons.ui_swing.framemanager.buttonbar;
24 24
 
25
+import com.dmdirc.ClientModule.GlobalConfig;
25 26
 import com.dmdirc.FrameContainer;
26 27
 import com.dmdirc.FrameContainerComparator;
28
+import com.dmdirc.addons.ui_swing.MainFrame;
27 29
 import com.dmdirc.addons.ui_swing.SwingController;
28 30
 import com.dmdirc.addons.ui_swing.SwingWindowFactory;
29 31
 import com.dmdirc.addons.ui_swing.UIUtilities;
@@ -33,6 +35,7 @@ import com.dmdirc.addons.ui_swing.framemanager.FrameManager;
33 35
 import com.dmdirc.addons.ui_swing.framemanager.FramemanagerPosition;
34 36
 import com.dmdirc.interfaces.FrameInfoListener;
35 37
 import com.dmdirc.interfaces.NotificationListener;
38
+import com.dmdirc.interfaces.config.AggregateConfigProvider;
36 39
 import com.dmdirc.interfaces.config.ConfigChangeListener;
37 40
 import com.dmdirc.interfaces.ui.Window;
38 41
 import com.dmdirc.ui.Colour;
@@ -53,6 +56,8 @@ import java.util.Collections;
53 56
 import java.util.HashMap;
54 57
 import java.util.Map;
55 58
 
59
+import javax.inject.Inject;
60
+import javax.inject.Provider;
56 61
 import javax.swing.JComponent;
57 62
 import javax.swing.JMenuItem;
58 63
 import javax.swing.JPopupMenu;
@@ -78,13 +83,13 @@ public final class ButtonBar implements FrameManager, ActionListener,
78 83
     /** The default height of buttons. */
79 84
     private static final int BUTTON_HEIGHT = 25;
80 85
     /** A map of windows to the buttons we're using for them. */
81
-    private Map<Window, FrameToggleButton> buttons;
86
+    private final Map<Window, FrameToggleButton> buttons;
82 87
     /** The scrolling panel for our ButtonBar. */
83 88
     private final JScrollPane scrollPane;
84 89
     /** The panel used for our buttons. */
85
-    private ButtonPanel buttonPanel;
90
+    private final ButtonPanel buttonPanel;
86 91
     /** The position of this frame manager. */
87
-    private FramemanagerPosition position;
92
+    private final FramemanagerPosition position;
88 93
     /** The default width of buttons. */
89 94
     private int buttonWidth = 0;
90 95
     /** The parent for the manager. */
@@ -98,19 +103,35 @@ public final class ButtonBar implements FrameManager, ActionListener,
98 103
     /** Sort child windows prefs setting. */
99 104
     private boolean sortChildWindows;
100 105
     /** UI Window Factory. */
101
-    private SwingWindowFactory windowFactory;
102
-    /** UI Controller. */
103
-    private SwingController controller;
106
+    private final SwingWindowFactory windowFactory;
104 107
     /** Window management. */
105 108
     private final WindowManager windowManager;
109
+    /** Global configuration to read settings from. */
110
+    private final AggregateConfigProvider globalConfig;
111
+    /** Provider to use to retrieve the current main frame. */
112
+    private final Provider<MainFrame> mainFrameProvider;
106 113
 
107 114
     /**
108 115
      * Creates a new instance of ButtonBar.
109 116
      *
110
-     * @param windowManager Window management
117
+     * @param controller        The controller to use to change window focus.
118
+     * @param windowFactory     The factory to use to retrieve window information.
119
+     * @param windowManager     The window manager to use to read window state.
120
+     * @param globalConfig      Global configuration to read settings from.
121
+     * @param mainFrameProvider The provider to use to retrieve the current main frame.
111 122
      */
112
-    public ButtonBar(final WindowManager windowManager) {
123
+    @Inject
124
+    public ButtonBar(
125
+            final SwingController controller,
126
+            final SwingWindowFactory windowFactory,
127
+            @GlobalConfig final AggregateConfigProvider globalConfig,
128
+            final WindowManager windowManager,
129
+            final Provider<MainFrame> mainFrameProvider) {
130
+        this.windowFactory = windowFactory;
131
+        this.globalConfig = globalConfig;
113 132
         this.windowManager = windowManager;
133
+        this.mainFrameProvider = mainFrameProvider;
134
+
114 135
         scrollPane = new JScrollPane();
115 136
         scrollPane.setBorder(null);
116 137
         scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
@@ -118,6 +139,26 @@ public final class ButtonBar implements FrameManager, ActionListener,
118 139
         scrollPane.setMinimumSize(new Dimension(0, BUTTON_HEIGHT
119 140
                 + ((int) PlatformDefaults.getUnitValueX("related")
120 141
                 .getValue()) * 2));
142
+
143
+        position = FramemanagerPosition.getPosition(
144
+                globalConfig.getOption("ui", "framemanagerPosition"));
145
+
146
+        if (position.isHorizontal()) {
147
+            buttonPanel = new ButtonPanel(controller,
148
+                    new MigLayout("ins rel, fill, flowx"), this);
149
+        } else {
150
+            buttonPanel = new ButtonPanel(controller,
151
+                    new MigLayout("ins rel, fill, flowy"), this);
152
+        }
153
+        scrollPane.getViewport().addMouseWheelListener(buttonPanel);
154
+        scrollPane.getViewport().add(buttonPanel);
155
+
156
+        buttons = Collections.synchronizedMap(new HashMap<Window, FrameToggleButton>());
157
+        sortChildWindows = globalConfig.getOptionBool("ui", "sortchildwindows");
158
+        sortRootWindows = globalConfig.getOptionBool("ui", "sortrootwindows");
159
+
160
+        globalConfig.addChangeListener("ui", "sortrootwindows", this);
161
+        globalConfig.addChangeListener("ui", "sortchildwindows", this);
121 162
     }
122 163
 
123 164
     /**
@@ -156,9 +197,10 @@ public final class ButtonBar implements FrameManager, ActionListener,
156 197
                 ButtonBar.this.buttonWidth = position.isHorizontal()
157 198
                         ? 150 : (parent.getWidth() / NUM_CELLS);
158 199
                 initButtons(windowManager.getRootWindows());
159
-                if (controller.getMainFrame().getActiveFrame() != null) {
160
-                    selectionChanged(controller.getMainFrame()
161
-                            .getActiveFrame());
200
+
201
+                final TextFrame activeFrame = mainFrameProvider.get().getActiveFrame();
202
+                if (activeFrame != null) {
203
+                    selectionChanged(activeFrame);
162 204
                 }
163 205
                 parent.setVisible(true);
164 206
             }
@@ -209,38 +251,6 @@ public final class ButtonBar implements FrameManager, ActionListener,
209 251
         return null;
210 252
     }
211 253
 
212
-    @Override
213
-    public void setController(final SwingController controller) {
214
-        this.windowFactory = controller.getWindowFactory();
215
-        this.controller = controller;
216
-
217
-        position = FramemanagerPosition.getPosition(
218
-                controller.getGlobalConfig().getOption("ui",
219
-                        "framemanagerPosition"));
220
-
221
-        if (position.isHorizontal()) {
222
-            buttonPanel = new ButtonPanel(controller,
223
-                    new MigLayout("ins rel, fill, flowx"), this);
224
-        } else {
225
-            buttonPanel = new ButtonPanel(controller,
226
-                    new MigLayout("ins rel, fill, flowy"), this);
227
-        }
228
-        scrollPane.getViewport().addMouseWheelListener(buttonPanel);
229
-        scrollPane.getViewport().add(buttonPanel);
230
-
231
-        buttons = Collections.synchronizedMap(
232
-                new HashMap<Window, FrameToggleButton>());
233
-        sortChildWindows = controller.getGlobalConfig()
234
-                .getOptionBool("ui", "sortchildwindows");
235
-        sortRootWindows = controller.getGlobalConfig()
236
-                .getOptionBool("ui", "sortrootwindows");
237
-
238
-        controller.getGlobalConfig().addChangeListener("ui",
239
-                "sortrootwindows", this);
240
-        controller.getGlobalConfig().addChangeListener("ui",
241
-                "sortchildwindows", this);
242
-    }
243
-
244 254
     /**
245 255
      * Adds buttons for the collection of windows that is passed to it. This method also iterates
246 256
      * through any children for each item in the collection.
@@ -363,7 +373,8 @@ public final class ButtonBar implements FrameManager, ActionListener,
363 373
         if (frame != null && frame.equals(activeWindow)) {
364 374
             button.setSelected(true);
365 375
         }
366
-        controller.getMainFrame().setActiveFrame(frame);
376
+
377
+        mainFrameProvider.get().setActiveFrame(frame);
367 378
     }
368 379
 
369 380
     /**
@@ -568,12 +579,10 @@ public final class ButtonBar implements FrameManager, ActionListener,
568 579
     public void configChanged(final String domain, final String key) {
569 580
         switch (key) {
570 581
             case "sortrootwindows":
571
-                sortRootWindows = controller.getGlobalConfig()
572
-                        .getOptionBool("ui", "sortrootwindows");
582
+                sortRootWindows = globalConfig.getOptionBool("ui", "sortrootwindows");
573 583
                 break;
574 584
             case "sortchildwindows":
575
-                sortChildWindows = controller.getGlobalConfig()
576
-                        .getOptionBool("ui", "sortrootwindows");
585
+                sortChildWindows = globalConfig.getOptionBool("ui", "sortrootwindows");
577 586
                 break;
578 587
         }
579 588
         relayout();

+ 48
- 0
src/com/dmdirc/addons/ui_swing/framemanager/buttonbar/ButtonBarProvider.java 查看文件

@@ -0,0 +1,48 @@
1
+/*
2
+ * Copyright (c) 2006-2014 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.framemanager.buttonbar;
24
+
25
+import com.dmdirc.addons.ui_swing.framemanager.FrameManager;
26
+import com.dmdirc.addons.ui_swing.framemanager.FrameManagerProvider;
27
+
28
+import javax.inject.Inject;
29
+import javax.inject.Provider;
30
+
31
+/**
32
+ * Provider for button bar frame managers.
33
+ */
34
+public class ButtonBarProvider implements FrameManagerProvider {
35
+
36
+    private final Provider<ButtonBar> provider;
37
+
38
+    @Inject
39
+    public ButtonBarProvider(final Provider<ButtonBar> provider) {
40
+        this.provider = provider;
41
+    }
42
+
43
+    @Override
44
+    public FrameManager getFrameManager() {
45
+        return provider.get();
46
+    }
47
+
48
+}

+ 48
- 33
src/com/dmdirc/addons/ui_swing/framemanager/tree/TreeFrameManager.java 查看文件

@@ -22,7 +22,9 @@
22 22
 
23 23
 package com.dmdirc.addons.ui_swing.framemanager.tree;
24 24
 
25
+import com.dmdirc.ClientModule.GlobalConfig;
25 26
 import com.dmdirc.FrameContainer;
27
+import com.dmdirc.addons.ui_swing.MainFrame;
26 28
 import com.dmdirc.addons.ui_swing.SwingController;
27 29
 import com.dmdirc.addons.ui_swing.UIUtilities;
28 30
 import com.dmdirc.addons.ui_swing.components.TreeScroller;
@@ -46,6 +48,8 @@ import java.util.Collection;
46 48
 import java.util.HashMap;
47 49
 import java.util.Map;
48 50
 
51
+import javax.inject.Inject;
52
+import javax.inject.Provider;
49 53
 import javax.swing.JComponent;
50 54
 import javax.swing.JScrollPane;
51 55
 import javax.swing.JTree;
@@ -73,24 +77,59 @@ public class TreeFrameManager implements FrameManager,
73 77
     /** node storage, used for adding and deleting nodes correctly. */
74 78
     private final Map<FrameContainer, TreeViewNode> nodes;
75 79
     /** UI Controller. */
76
-    private SwingController controller;
80
+    private final SwingController controller;
77 81
     /** Tree scroller. */
78 82
     private TreeScroller scroller;
79 83
     /** Configuration manager. */
80
-    private AggregateConfigProvider config;
84
+    private final AggregateConfigProvider config;
81 85
     /** Colour manager. */
82
-    private ColourManager colourManager;
86
+    private final ColourManager colourManager;
83 87
     /** Window manage. */
84 88
     private final WindowManager windowManager;
89
+    /** Provider to use to retrieve the current main frame. */
90
+    private final Provider<MainFrame> mainFrameProvider;
85 91
 
86 92
     /**
87 93
      * Creates a new instance of the TreeFrameManager.
88 94
      *
89
-     * @param windowManager Window Management
95
+     * @param controller        The controller to use to switch windows.
96
+     * @param windowManager     The window manager to use to read window state.
97
+     * @param globalConfig      The provider to read config settings from.
98
+     * @param colourManager     The colour manager to use to retrieve colours.
99
+     * @param mainFrameProvider The provider to use to retrieve the current main frame.
90 100
      */
91
-    public TreeFrameManager(final WindowManager windowManager) {
101
+    @Inject
102
+    public TreeFrameManager(
103
+            final SwingController controller,
104
+            final WindowManager windowManager,
105
+            @GlobalConfig final AggregateConfigProvider globalConfig,
106
+            final ColourManager colourManager,
107
+            final Provider<MainFrame> mainFrameProvider) {
92 108
         this.windowManager = windowManager;
93 109
         nodes = new HashMap<>();
110
+
111
+        this.controller = controller;
112
+        this.config = globalConfig;
113
+        this.colourManager = colourManager;
114
+
115
+        UIUtilities.invokeLater(new Runnable() {
116
+            @Override
117
+            public void run() {
118
+                model = new TreeViewModel(config, new TreeViewNode(null, null));
119
+                tree = new Tree(TreeFrameManager.this, model,
120
+                        TreeFrameManager.this.controller);
121
+                tree.setCellRenderer(new TreeViewTreeCellRenderer(config, colourManager,
122
+                        TreeFrameManager.this));
123
+                tree.setVisible(true);
124
+
125
+                config.addChangeListener("treeview", TreeFrameManager.this);
126
+                config.addChangeListener("ui", "sortrootwindows", TreeFrameManager.this);
127
+                config.addChangeListener("ui", "sortchildwindows", TreeFrameManager.this);
128
+                config.addChangeListener("ui", "backgroundcolour", TreeFrameManager.this);
129
+                config.addChangeListener("ui", "foregroundcolour", TreeFrameManager.this);
130
+            }
131
+        });
132
+        this.mainFrameProvider = mainFrameProvider;
94 133
     }
95 134
 
96 135
     @Override
@@ -127,31 +166,6 @@ public class TreeFrameManager implements FrameManager,
127 166
         });
128 167
     }
129 168
 
130
-    @Override
131
-    public void setController(final SwingController controller) {
132
-        this.controller = controller;
133
-        this.config = controller.getGlobalConfig();
134
-        this.colourManager = controller.getColourManager();
135
-
136
-        UIUtilities.invokeLater(new Runnable() {
137
-            @Override
138
-            public void run() {
139
-                model = new TreeViewModel(config, new TreeViewNode(null, null));
140
-                tree = new Tree(TreeFrameManager.this, model,
141
-                        TreeFrameManager.this.controller);
142
-                tree.setCellRenderer(new TreeViewTreeCellRenderer(config, colourManager,
143
-                        TreeFrameManager.this));
144
-                tree.setVisible(true);
145
-
146
-                config.addChangeListener("treeview", TreeFrameManager.this);
147
-                config.addChangeListener("ui", "sortrootwindows", TreeFrameManager.this);
148
-                config.addChangeListener("ui", "sortchildwindows", TreeFrameManager.this);
149
-                config.addChangeListener("ui", "backgroundcolour", TreeFrameManager.this);
150
-                config.addChangeListener("ui", "foregroundcolour", TreeFrameManager.this);
151
-            }
152
-        });
153
-    }
154
-
155 169
     @Override
156 170
     public void windowAdded(final TextFrame parent, final TextFrame window) {
157 171
         if (nodes.containsKey(window.getContainer())) {
@@ -310,9 +324,10 @@ public class TreeFrameManager implements FrameManager,
310 324
                         addWindow(nodes.get(window), childWindow);
311 325
                     }
312 326
                 }
313
-                if (controller.getMainFrame() != null
314
-                        && controller.getMainFrame().getActiveFrame() != null) {
315
-                    selectionChanged(controller.getMainFrame().getActiveFrame());
327
+
328
+                final MainFrame mainFrame = mainFrameProvider.get();
329
+                if (mainFrame != null && mainFrame.getActiveFrame() != null) {
330
+                    selectionChanged(mainFrame.getActiveFrame());
316 331
                 }
317 332
             }
318 333
         });

+ 48
- 0
src/com/dmdirc/addons/ui_swing/framemanager/tree/TreeFrameManagerProvider.java 查看文件

@@ -0,0 +1,48 @@
1
+/*
2
+ * Copyright (c) 2006-2014 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.framemanager.tree;
24
+
25
+import com.dmdirc.addons.ui_swing.framemanager.FrameManager;
26
+import com.dmdirc.addons.ui_swing.framemanager.FrameManagerProvider;
27
+
28
+import javax.inject.Inject;
29
+import javax.inject.Provider;
30
+
31
+/**
32
+ * Provider for tree frame managers.
33
+ */
34
+public class TreeFrameManagerProvider implements FrameManagerProvider {
35
+
36
+    private final Provider<TreeFrameManager> provider;
37
+
38
+    @Inject
39
+    public TreeFrameManagerProvider(final Provider<TreeFrameManager> provider) {
40
+        this.provider = provider;
41
+    }
42
+
43
+    @Override
44
+    public FrameManager getFrameManager() {
45
+        return provider.get();
46
+    }
47
+
48
+}

+ 22
- 0
src/com/dmdirc/addons/ui_swing/injection/SwingModule.java 查看文件

@@ -48,12 +48,16 @@ import com.dmdirc.addons.ui_swing.components.statusbar.SwingStatusBar;
48 48
 import com.dmdirc.addons.ui_swing.components.statusbar.UpdaterLabel;
49 49
 import com.dmdirc.addons.ui_swing.dialogs.prefs.URLConfigPanel;
50 50
 import com.dmdirc.addons.ui_swing.dialogs.prefs.UpdateConfigPanel;
51
+import com.dmdirc.addons.ui_swing.framemanager.FrameManager;
52
+import com.dmdirc.addons.ui_swing.framemanager.FrameManagerProvider;
53
+import com.dmdirc.addons.ui_swing.framemanager.tree.TreeFrameManagerProvider;
51 54
 import com.dmdirc.config.prefs.PreferencesDialogModel;
52 55
 import com.dmdirc.interfaces.LifecycleController;
53 56
 import com.dmdirc.interfaces.config.AggregateConfigProvider;
54 57
 import com.dmdirc.interfaces.config.ConfigProvider;
55 58
 import com.dmdirc.plugins.PluginDomain;
56 59
 import com.dmdirc.plugins.PluginManager;
60
+import com.dmdirc.plugins.ServiceLocator;
57 61
 import com.dmdirc.ui.IconManager;
58 62
 import com.dmdirc.ui.WindowManager;
59 63
 import com.dmdirc.ui.core.components.StatusBarManager;
@@ -118,6 +122,7 @@ public class SwingModule {
118 122
             final Provider<QuitWorker> quitWorker,
119 123
             final URLBuilder urlBuilder,
120 124
             final WindowManager windowManager,
125
+            final Provider<FrameManager> frameManagerProvider,
121 126
             final EventBus eventBus) {
122 127
         return UIUtilities.invokeAndWait(new Callable<MainFrame>() {
123 128
 
@@ -132,6 +137,7 @@ public class SwingModule {
132 137
                         quitWorker,
133 138
                         new IconManager(globalConfig, urlBuilder),
134 139
                         windowManager,
140
+                        frameManagerProvider,
135 141
                         eventBus);
136 142
             }
137 143
         });
@@ -176,4 +182,20 @@ public class SwingModule {
176 182
                 configManager, identity, actionManager, pluginManager);
177 183
     }
178 184
 
185
+    @Provides
186
+    public FrameManager getFrameManager(
187
+            @GlobalConfig final AggregateConfigProvider globalConfig,
188
+            final TreeFrameManagerProvider fallbackProvider,
189
+            final ServiceLocator locator) {
190
+        final String manager = globalConfig.getOption("ui", "framemanager");
191
+
192
+        FrameManagerProvider provider = locator.getService(FrameManagerProvider.class, manager);
193
+        if (provider == null) {
194
+            // Couldn't find the user's selected provider - let's just use the fallback.
195
+            provider = fallbackProvider;
196
+        }
197
+
198
+        return provider.getFrameManager();
199
+    }
200
+
179 201
 }

正在加载...
取消
保存