Browse Source

Inject the AMD.

Change-Id: I6bf2a097c7dbb54e631cd1a1a13f411df374428f
Reviewed-on: http://gerrit.dmdirc.com/3041
Automatic-Compile: DMDirc Build Manager
Reviewed-by: Greg Holmes <greg@dmdirc.com>
tags/0.8
Chris Smith 10 years ago
parent
commit
0f7aebad7e

+ 5
- 2
src/com/dmdirc/addons/ui_swing/PrefsComponentFactory.java View File

@@ -44,6 +44,8 @@ import java.awt.event.KeyAdapter;
44 44
 import java.awt.event.KeyEvent;
45 45
 import java.util.Map;
46 46
 
47
+import javax.inject.Inject;
48
+import javax.inject.Singleton;
47 49
 import javax.swing.BorderFactory;
48 50
 import javax.swing.JCheckBox;
49 51
 import javax.swing.JComboBox;
@@ -63,6 +65,7 @@ import org.jdesktop.jxlayer.JXLayer;
63 65
 /**
64 66
  * Provides methods for constructing a JComponent from a PreferencesSetting.
65 67
  */
68
+@Singleton
66 69
 public final class PrefsComponentFactory {
67 70
 
68 71
     /** Swing Controller. */
@@ -73,9 +76,9 @@ public final class PrefsComponentFactory {
73 76
      *
74 77
      * @param controller Swing Controller
75 78
      */
76
-    protected PrefsComponentFactory(final SwingController controller) {
79
+    @Inject
80
+    public PrefsComponentFactory(final SwingController controller) {
77 81
         this.controller = controller;
78
-
79 82
     }
80 83
 
81 84
     /**

+ 1
- 4
src/com/dmdirc/addons/ui_swing/SwingController.java View File

@@ -121,8 +121,6 @@ public class SwingController extends BaseCommandPlugin implements UIController {
121 121
     private final ConfigProvider addonIdentity;
122 122
     /** Global Swing UI Icon manager. */
123 123
     private final IconManager iconManager;
124
-    /** Prefs component factory instance. */
125
-    private final PrefsComponentFactory prefsComponentFactory;
126 124
     /** Action manager. */
127 125
     private final ActionManager actionManager;
128 126
     /** Action factory. */
@@ -204,7 +202,6 @@ public class SwingController extends BaseCommandPlugin implements UIController {
204 202
         addonIdentity = identityManager.getAddonSettings();
205 203
         apple = new Apple(globalConfig, serverManager, eventBus);
206 204
         iconManager = new IconManager(globalConfig, urlBuilder);
207
-        prefsComponentFactory = new PrefsComponentFactory(this);
208 205
         setAntiAlias();
209 206
         windows = new ArrayList<>();
210 207
     }
@@ -241,7 +238,7 @@ public class SwingController extends BaseCommandPlugin implements UIController {
241 238
 
242 239
     @Deprecated
243 240
     public PrefsComponentFactory getPrefsComponentFactory() {
244
-        return prefsComponentFactory;
241
+        return swingManager.getPrefsComponentFactory();
245 242
     }
246 243
 
247 244
     @Deprecated

+ 12
- 1
src/com/dmdirc/addons/ui_swing/SwingManager.java View File

@@ -83,6 +83,9 @@ public class SwingManager {
83 83
     /** Provider of first run executors. */
84 84
     private final Provider<FirstRunWizardExecutor> firstRunExecutor;
85 85
 
86
+    /** The factory to use to create prefs components. */
87
+    private final PrefsComponentFactory prefsComponentFactory;
88
+
86 89
     /**
87 90
      * Creates a new instance of {@link SwingManager}.
88 91
      *
@@ -100,6 +103,7 @@ public class SwingManager {
100 103
      * @param dataLoaderWorkerFactory Factory used to create data loader workers.
101 104
      * @param cachingUpdateManager Update manager to use.
102 105
      * @param firstRunExecutor A provider of first run executors.
106
+     * @param prefsComponentFactory The factory to use to create prefs components.
103 107
      */
104 108
     @Inject
105 109
     public SwingManager(
@@ -116,7 +120,8 @@ public class SwingManager {
116 120
             final DialogKeyListener dialogKeyListener,
117 121
             final DataLoaderWorkerFactory dataLoaderWorkerFactory,
118 122
             final CachingUpdateManager cachingUpdateManager,
119
-            final Provider<FirstRunWizardExecutor> firstRunExecutor) {
123
+            final Provider<FirstRunWizardExecutor> firstRunExecutor,
124
+            final PrefsComponentFactory prefsComponentFactory) {
120 125
         this.dialogManager = dialogManager;
121 126
         this.eventQueue = eventQueue;
122 127
         this.windowFactory = windowFactory;
@@ -128,6 +133,7 @@ public class SwingManager {
128 133
         this.dataLoaderWorkerFactory = dataLoaderWorkerFactory;
129 134
         this.cachingUpdateManager = cachingUpdateManager;
130 135
         this.firstRunExecutor = firstRunExecutor;
136
+        this.prefsComponentFactory = prefsComponentFactory;
131 137
 
132 138
         this.mainFrame = mainFrame;
133 139
         this.mainFrame.setMenuBar(menuBar);
@@ -191,6 +197,11 @@ public class SwingManager {
191 197
         return cachingUpdateManager;
192 198
     }
193 199
 
200
+    @Deprecated
201
+    public PrefsComponentFactory getPrefsComponentFactory() {
202
+        return prefsComponentFactory;
203
+    }
204
+
194 205
     /**
195 206
      * Retrieves the window factory to use.
196 207
      *

+ 6
- 2
src/com/dmdirc/addons/ui_swing/components/menubar/SettingsMenu.java View File

@@ -50,14 +50,18 @@ public class SettingsMenu extends JMenu implements ActionListener {
50 50
     private final SwingController controller;
51 51
     /** Provider of profile manager dialogs. */
52 52
     private final Provider<ProfileManagerDialog> profileDialogProvider;
53
+    /** Provider of action manager dialogs. */
54
+    private final Provider<ActionsManagerDialog> actionsDialogProvider;
53 55
 
54 56
     @Inject
55 57
     public SettingsMenu(
56 58
             final SwingController controller,
57
-            final Provider<ProfileManagerDialog> profileDialogProvider) {
59
+            final Provider<ProfileManagerDialog> profileDialogProvider,
60
+            final Provider<ActionsManagerDialog> actionsDialogProvider) {
58 61
         super("Settings");
59 62
         this.controller = controller;
60 63
         this.profileDialogProvider = profileDialogProvider;
64
+        this.actionsDialogProvider = actionsDialogProvider;
61 65
 
62 66
         setMnemonic('e');
63 67
         initSettingsMenu();
@@ -111,7 +115,7 @@ public class SettingsMenu extends JMenu implements ActionListener {
111 115
                 profileDialogProvider.get().displayOrRequestFocus();
112 116
                 break;
113 117
             case "Actions":
114
-                controller.showDialog(ActionsManagerDialog.class);
118
+                actionsDialogProvider.get().displayOrRequestFocus();
115 119
                 break;
116 120
             case "Aliases":
117 121
                 controller.showDialog(AliasManagerDialog.class);

+ 10
- 6
src/com/dmdirc/addons/ui_swing/dialogs/actionsmanager/ActionsManagerDialog.java View File

@@ -22,6 +22,7 @@
22 22
 
23 23
 package com.dmdirc.addons.ui_swing.dialogs.actionsmanager;
24 24
 
25
+import com.dmdirc.ClientModule.UserConfig;
25 26
 import com.dmdirc.actions.Action;
26 27
 import com.dmdirc.actions.ActionGroup;
27 28
 import com.dmdirc.actions.ActionManager;
@@ -51,6 +52,8 @@ import java.util.HashMap;
51 52
 import java.util.Map;
52 53
 import java.util.concurrent.atomic.AtomicBoolean;
53 54
 
55
+import javax.inject.Inject;
56
+import javax.inject.Singleton;
54 57
 import javax.swing.BorderFactory;
55 58
 import javax.swing.DefaultListModel;
56 59
 import javax.swing.JButton;
@@ -67,6 +70,7 @@ import net.miginfocom.swing.MigLayout;
67 70
 /**
68 71
  * Allows the user to manage actions.
69 72
  */
73
+@Singleton
70 74
 public class ActionsManagerDialog extends StandardDialog implements
71 75
         ActionListener, com.dmdirc.interfaces.ActionListener,
72 76
         ListSelectionListener {
@@ -119,14 +123,15 @@ public class ActionsManagerDialog extends StandardDialog implements
119 123
      * @param config Config to save dialog state to
120 124
      * @param compFactory Prefs setting component factory
121 125
      */
122
-    @SuppressWarnings("unchecked")
123
-    public ActionsManagerDialog(final Window parentWindow,
126
+    @Inject
127
+    public ActionsManagerDialog(
128
+            final MainFrame parentWindow,
124 129
             final SwingController controller,
125 130
             final DialogManager dialogManager,
126
-            final ConfigProvider config,
131
+            @UserConfig final ConfigProvider config,
127 132
             final PrefsComponentFactory compFactory) {
128 133
         super(dialogManager, Apple.isAppleUI()
129
-                ? new AppleJFrame((MainFrame) parentWindow, controller)
134
+                ? new AppleJFrame(parentWindow, controller)
130 135
                 : parentWindow, ModalityType.MODELESS);
131 136
         this.controller = controller;
132 137
         this.dialogManager = dialogManager;
@@ -159,8 +164,7 @@ public class ActionsManagerDialog extends StandardDialog implements
159 164
         actions = new ActionsGroupPanel(dialogManager, this, null);
160 165
         info = new ActionGroupInformationPanel(null);
161 166
         settings = new HashMap<>();
162
-        activeSettings = new ActionGroupSettingsPanel(controller
163
-                .getPrefsComponentFactory(), null, this);
167
+        activeSettings = new ActionGroupSettingsPanel(compFactory, null, this);
164 168
         settings.put(null, activeSettings);
165 169
         add = new JButton("Add");
166 170
         edit = new JButton("Edit");

Loading…
Cancel
Save