Преглед на файлове

Fix showConfig for Nick Colour plugin.

This isn't hugely pretty and we should probably investigate a
better way of doing this.

Change-Id: I4644706347084eee101eaeaa494626147b3eae6e
Fixes-Issue: CLIENT-429
Reviewed-on: http://gerrit.dmdirc.com/3154
Automatic-Compile: DMDirc Build Manager
Reviewed-by: Chris Smith <chris@dmdirc.com>
tags/0.8
Greg Holmes преди 10 години
родител
ревизия
f2c96e4760

+ 15
- 87
src/com/dmdirc/addons/nickcolours/NickColourManager.java Целия файл

@@ -28,13 +28,6 @@ import com.dmdirc.ClientModule.GlobalConfig;
28 28
 import com.dmdirc.ClientModule.UserConfig;
29 29
 import com.dmdirc.actions.ActionManager;
30 30
 import com.dmdirc.actions.CoreActionType;
31
-import com.dmdirc.addons.ui_swing.MainFrame;
32
-import com.dmdirc.addons.ui_swing.UIUtilities;
33
-import com.dmdirc.config.prefs.PluginPreferencesCategory;
34
-import com.dmdirc.config.prefs.PreferencesCategory;
35
-import com.dmdirc.config.prefs.PreferencesDialogModel;
36
-import com.dmdirc.config.prefs.PreferencesSetting;
37
-import com.dmdirc.config.prefs.PreferencesType;
38 31
 import com.dmdirc.interfaces.ActionListener;
39 32
 import com.dmdirc.interfaces.actions.ActionType;
40 33
 import com.dmdirc.interfaces.config.AggregateConfigProvider;
@@ -43,15 +36,12 @@ import com.dmdirc.interfaces.config.ConfigProvider;
43 36
 import com.dmdirc.parser.interfaces.ChannelClientInfo;
44 37
 import com.dmdirc.parser.interfaces.ChannelInfo;
45 38
 import com.dmdirc.parser.interfaces.ClientInfo;
46
-import com.dmdirc.plugins.PluginInfo;
47 39
 import com.dmdirc.ui.Colour;
48
-import com.dmdirc.ui.IconManager;
49 40
 import com.dmdirc.ui.messages.ColourManager;
50 41
 
51 42
 import java.util.ArrayList;
52 43
 import java.util.List;
53 44
 import java.util.Map;
54
-import java.util.concurrent.Callable;
55 45
 
56 46
 import javax.inject.Inject;
57 47
 import javax.inject.Singleton;
@@ -70,34 +60,20 @@ public class NickColourManager implements ActionListener, ConfigChangeListener {
70 60
     private boolean userandomcolour;
71 61
     private boolean settext;
72 62
     private boolean setnicklist;
73
-    /** This plugin's plugin info. */
74
-    private final PluginInfo pluginInfo;
75 63
     /** Manager to parse colours with. */
76 64
     private final ColourManager colourManager;
77
-    /** Main frame to parent dialogs on. */
78
-    private final MainFrame mainFrame;
79
-    /** Icon manager to retrieve icons from. */
80
-    private final IconManager iconManager;
81 65
     /** Config to read settings from. */
82 66
     private final AggregateConfigProvider globalConfig;
83
-    /** Config to write settings to. */
84
-    private final ConfigProvider userConfig;
85 67
     /** Plugin's setting domain. */
86 68
     private final String domain;
87 69
 
88 70
     @Inject
89
-    public NickColourManager(final PluginInfo pluginInfo,
71
+    public NickColourManager(final ColourManager colourManager,
90 72
             @NickColourModule.NickColourSettingsDomain final String domain,
91
-            final ColourManager colourManager, final MainFrame mainFrame,
92
-            @GlobalConfig final IconManager iconManager,
93 73
             @GlobalConfig final AggregateConfigProvider globalConfig,
94 74
             @UserConfig final ConfigProvider userConfig) {
95
-        this.mainFrame = mainFrame;
96 75
         this.domain = domain;
97
-        this.iconManager = iconManager;
98
-        this.pluginInfo = pluginInfo;
99 76
         this.globalConfig = globalConfig;
100
-        this.userConfig = userConfig;
101 77
         this.colourManager = colourManager;
102 78
     }
103 79
 
@@ -147,9 +123,9 @@ public class NickColourManager implements ActionListener, ConfigChangeListener {
147 123
         String[] parts = null;
148 124
 
149 125
         if (globalConfig.hasOptionString(domain, nickOption1)) {
150
-            parts = getParts(nickOption1);
126
+            parts = getParts(globalConfig, domain, nickOption1);
151 127
         } else if (globalConfig.hasOptionString(domain, nickOption2)) {
152
-            parts = getParts(nickOption2);
128
+            parts = getParts(globalConfig, domain, nickOption2);
153 129
         }
154 130
 
155 131
         if (parts != null) {
@@ -207,16 +183,19 @@ public class NickColourManager implements ActionListener, ConfigChangeListener {
207 183
     /**
208 184
      * Reads the nick colour data from the config.
209 185
      *
186
+     * @param config Config to read settings from
187
+     * @param domain Config domain
188
+     *
210 189
      * @return A multi-dimensional array of nick colour info.
211 190
      */
212
-    public Object[][] getData() {
191
+    public static Object[][] getData(final AggregateConfigProvider config, final String domain) {
213 192
         final List<Object[]> data = new ArrayList<>();
214 193
 
215
-        for (String key : globalConfig.getOptions(domain).keySet()) {
194
+        for (String key : config.getOptions(domain).keySet()) {
216 195
             if (key.startsWith("color:")) {
217 196
                 final String network = key.substring(6, key.indexOf(':', 6));
218 197
                 final String user = key.substring(1 + key.indexOf(':', 6));
219
-                final String[] parts = getParts(key);
198
+                final String[] parts = getParts(config, domain, key);
220 199
 
221 200
                 data.add(new Object[]{network, user, parts[0], parts[1]});
222 201
             }
@@ -238,12 +217,15 @@ public class NickColourManager implements ActionListener, ConfigChangeListener {
238 217
      * Retrieves the config option with the specified key, and returns an array of the colours that
239 218
      * should be used for it.
240 219
      *
241
-     * @param key The config key to look up
220
+     * @param config Config to read settings from
221
+     * @param domain Config domain
222
+     * @param key    The config key to look up
242 223
      *
243 224
      * @return The colours specified by the given key
244 225
      */
245
-    private String[] getParts(final String key) {
246
-        String[] parts = globalConfig.getOption(domain, key).split(":");
226
+    private static String[] getParts(final AggregateConfigProvider config, final String domain,
227
+            final String key) {
228
+        String[] parts = config.getOption(domain, key).split(":");
247 229
 
248 230
         if (parts.length == 0) {
249 231
             parts = new String[]{null, null};
@@ -270,60 +252,6 @@ public class NickColourManager implements ActionListener, ConfigChangeListener {
270 252
         ActionManager.getActionManager().unregisterListener(this);
271 253
     }
272 254
 
273
-    /**
274
-     * Shows the prefs configuration page for this plugin.
275
-     *
276
-     * @param manager Prefs manager to add settings to
277
-     */
278
-    public void showConfig(final PreferencesDialogModel manager) {
279
-        final PreferencesCategory general = new PluginPreferencesCategory(
280
-                pluginInfo, "Nick Colours",
281
-                "General configuration for NickColour plugin.");
282
-        final PreferencesCategory colours = new PluginPreferencesCategory(
283
-                pluginInfo, "Colours",
284
-                "Set colours for specific nicknames.", UIUtilities.invokeAndWait(
285
-                new Callable<NickColourPanel>() {
286
-            /** {@inheritDoc} */
287
-            @Override
288
-            public NickColourPanel call() {
289
-                return new NickColourPanel(mainFrame, iconManager,
290
-                        NickColourManager.this, colourManager, userConfig);
291
-            }
292
-        }));
293
-
294
-        general.addSetting(new PreferencesSetting(PreferencesType.BOOLEAN,
295
-                "ui", "shownickcoloursintext", "Show colours in text area",
296
-                "Colour nicknames in main text area?",
297
-                manager.getConfigManager(), manager.getIdentity()));
298
-        general.addSetting(new PreferencesSetting(PreferencesType.BOOLEAN,
299
-                "ui", "shownickcoloursinnicklist", "Show colours in"
300
-                + " nick list", "Colour nicknames in channel nick lists?",
301
-                manager.getConfigManager(), manager.getIdentity()));
302
-        general.addSetting(new PreferencesSetting(PreferencesType.BOOLEAN,
303
-                domain, "settext", "Set colours in textarea",
304
-                "Should the plugin set the textarea colour of nicks?",
305
-                manager.getConfigManager(), manager.getIdentity()));
306
-        general.addSetting(new PreferencesSetting(PreferencesType.BOOLEAN,
307
-                domain, "setnicklist", "Set colours in nick list",
308
-                "Should the plugin set the nick list colour of nicks?",
309
-                manager.getConfigManager(), manager.getIdentity()));
310
-        general.addSetting(new PreferencesSetting(PreferencesType.BOOLEAN,
311
-                domain, "userandomcolour", "Use random colour",
312
-                "Use a pseudo-random colour for each person?",
313
-                manager.getConfigManager(), manager.getIdentity()));
314
-        general.addSetting(new PreferencesSetting(PreferencesType.BOOLEAN,
315
-                domain, "useowncolour", "Use colour for own nick",
316
-                "Always use the same colour for our own nickname?",
317
-                manager.getConfigManager(), manager.getIdentity()));
318
-        general.addSetting(new PreferencesSetting(PreferencesType.COLOUR, domain,
319
-                "owncolour", "Colour to use for own nick",
320
-                "Colour used for our own nickname, if above setting is "
321
-                + "enabled.", manager.getConfigManager(), manager.getIdentity()));
322
-
323
-        general.addSubCategory(colours);
324
-        manager.getCategory("Plugins").addSubCategory(general);
325
-    }
326
-
327 255
     /**
328 256
      * Updates cached settings.
329 257
      */

+ 1
- 10
src/com/dmdirc/addons/nickcolours/NickColourModule.java Целия файл

@@ -23,7 +23,6 @@
23 23
 package com.dmdirc.addons.nickcolours;
24 24
 
25 25
 import com.dmdirc.addons.ui_swing.injection.SwingModule;
26
-import com.dmdirc.plugins.PluginInfo;
27 26
 
28 27
 import javax.inject.Qualifier;
29 28
 
@@ -38,15 +37,12 @@ public class NickColourModule {
38 37
 
39 38
     /** The domain for plugin settings. */
40 39
     private final String domain;
41
-    /** The plugin's plugin info. */
42
-    private final PluginInfo pluginInfo;
43 40
 
44 41
     @Qualifier
45 42
     public static @interface NickColourSettingsDomain {
46 43
     }
47 44
 
48
-    public NickColourModule(final PluginInfo pluginInfo, final String domain) {
49
-        this.pluginInfo = pluginInfo;
45
+    public NickColourModule(final String domain) {
50 46
         this.domain = domain;
51 47
     }
52 48
 
@@ -61,9 +57,4 @@ public class NickColourModule {
61 57
         return domain;
62 58
     }
63 59
 
64
-    @Provides
65
-    public PluginInfo getPluginInfo() {
66
-        return pluginInfo;
67
-    }
68
-
69 60
 }

+ 21
- 24
src/com/dmdirc/addons/nickcolours/NickColourPanel.java Целия файл

@@ -24,6 +24,7 @@ package com.dmdirc.addons.nickcolours;
24 24
 
25 25
 import com.dmdirc.addons.ui_swing.MainFrame;
26 26
 import com.dmdirc.config.prefs.PreferencesInterface;
27
+import com.dmdirc.interfaces.config.AggregateConfigProvider;
27 28
 import com.dmdirc.interfaces.config.ConfigProvider;
28 29
 import com.dmdirc.ui.IconManager;
29 30
 import com.dmdirc.ui.messages.ColourManager;
@@ -54,11 +55,10 @@ public class NickColourPanel extends JPanel implements ActionListener,
54 55
     /** A version number for this class. */
55 56
     private static final long serialVersionUID = 1;
56 57
     /** The table headings. */
57
-    private static final String[] HEADERS = {"Network", "Nickname", "Text colour", "Nicklist colour"};
58
+    private static final String[] HEADERS
59
+            = {"Network", "Nickname", "Text colour", "Nicklist colour"};
58 60
     /** The table used for displaying the options. */
59 61
     private final JTable table;
60
-    /** The plugin we're associated with. */
61
-    private final transient NickColourManager plugin;
62 62
     /** The identity to write settings to. */
63 63
     private final ConfigProvider configIdentity;
64 64
     /** Edit button. */
@@ -71,26 +71,33 @@ public class NickColourPanel extends JPanel implements ActionListener,
71 71
     private final IconManager iconManager;
72 72
     /** Colour manage to use to parse colours. */
73 73
     private final ColourManager colourManager;
74
+    /** Config provider to read settings from. */
75
+    private final AggregateConfigProvider config;
76
+    /** The plugin's config domain. */
77
+    private final String domain;
74 78
 
75 79
     /**
76 80
      * Creates a new instance of NickColourPanel.
77 81
      *
78 82
      * @param mainFrame     Main frame to parent dialogs on
79 83
      * @param iconManager   Icon manager to load icons from
80
-     * @param plugin        The plugin that owns this panel
81 84
      * @param colourManager The colour manager to use to parse colours.
82 85
      * @param userSettings  The provider to write user settings to.
86
+     * @param config        The config provider to read settings from.
87
+     * @param domain        The plugin's config domain
83 88
      */
84 89
     public NickColourPanel(
85
-            final MainFrame mainFrame, final IconManager iconManager, final NickColourManager plugin,
86
-            final ColourManager colourManager, final ConfigProvider userSettings) {
90
+            final MainFrame mainFrame, final IconManager iconManager,
91
+            final ColourManager colourManager, final ConfigProvider userSettings,
92
+            final AggregateConfigProvider config, final String domain) {
87 93
         this.mainFrame = mainFrame;
88 94
         this.iconManager = iconManager;
89 95
         this.colourManager = colourManager;
90
-        this.plugin = plugin;
91 96
         this.configIdentity = userSettings;
97
+        this.config = config;
98
+        this.domain = domain;
92 99
 
93
-        final Object[][] data = plugin.getData();
100
+        final Object[][] data = NickColourManager.getData(config, domain);
94 101
 
95 102
         table = new JTable(new DefaultTableModel(data, HEADERS)) {
96 103
             /** A version number for this class. */
@@ -141,15 +148,6 @@ public class NickColourPanel extends JPanel implements ActionListener,
141 148
         deleteButton.setEnabled(false);
142 149
     }
143 150
 
144
-    /**
145
-     * Get an instance of the plugin that owns us.
146
-     *
147
-     * @return Our plugin.
148
-     */
149
-    public NickColourManager getPlugin() {
150
-        return plugin;
151
-    }
152
-
153 151
     /**
154 152
      * {@inheritDoc}
155 153
      *
@@ -217,10 +215,10 @@ public class NickColourPanel extends JPanel implements ActionListener,
217 215
         final List<Object[]> res = new ArrayList<>();
218 216
         final DefaultTableModel model = ((DefaultTableModel) table.getModel());
219 217
 
218
+        @SuppressWarnings("unchecked")
220 219
         final List<List<?>> rows = (List<List<?>>) model.getDataVector();
221 220
         for (List<?> row : rows) {
222
-            res.add(new Object[]{row.get(0), row.get(1), row.get(2),
223
-                row.get(3)});
221
+            res.add(new Object[]{row.get(0), row.get(1), row.get(2), row.get(3)});
224 222
         }
225 223
 
226 224
         return res;
@@ -230,15 +228,14 @@ public class NickColourPanel extends JPanel implements ActionListener,
230 228
     @Override
231 229
     public void save() {
232 230
         // Remove all old config entries
233
-        for (Object[] parts : plugin.getData()) {
234
-            configIdentity.unsetOption(plugin.getDomain(),
235
-                    "color:" + parts[0] + ":" + parts[1]);
231
+        for (Object[] parts : NickColourManager.getData(config, domain)) {
232
+            configIdentity.unsetOption(domain, "color:" + parts[0] + ":" + parts[1]);
236 233
         }
237 234
 
238 235
         // And write the new ones
239 236
         for (Object[] row : getData()) {
240
-            configIdentity.setOption(plugin.getDomain(),
241
-                    "color:" + row[0] + ":" + row[1], row[2] + ":" + row[3]);
237
+            configIdentity.
238
+                    setOption(domain, "color:" + row[0] + ":" + row[1], row[2] + ":" + row[3]);
242 239
         }
243 240
     }
244 241
 

+ 73
- 3
src/com/dmdirc/addons/nickcolours/NickColourPlugin.java Целия файл

@@ -22,9 +22,20 @@
22 22
 
23 23
 package com.dmdirc.addons.nickcolours;
24 24
 
25
+import com.dmdirc.addons.ui_swing.MainFrame;
26
+import com.dmdirc.addons.ui_swing.SwingController;
27
+import com.dmdirc.addons.ui_swing.UIUtilities;
28
+import com.dmdirc.config.prefs.PluginPreferencesCategory;
29
+import com.dmdirc.config.prefs.PreferencesCategory;
25 30
 import com.dmdirc.config.prefs.PreferencesDialogModel;
31
+import com.dmdirc.config.prefs.PreferencesSetting;
32
+import com.dmdirc.config.prefs.PreferencesType;
26 33
 import com.dmdirc.plugins.PluginInfo;
27 34
 import com.dmdirc.plugins.implementations.BasePlugin;
35
+import com.dmdirc.ui.IconManager;
36
+import com.dmdirc.ui.messages.ColourManager;
37
+
38
+import java.util.concurrent.Callable;
28 39
 
29 40
 import dagger.ObjectGraph;
30 41
 
@@ -33,17 +44,30 @@ import dagger.ObjectGraph;
33 44
  */
34 45
 public class NickColourPlugin extends BasePlugin {
35 46
 
47
+    /** Plugin info. */
48
+    private final PluginInfo pluginInfo;
49
+    /** Main frame. */
50
+    private final MainFrame mainFrame;
51
+    /** Icon manager. */
52
+    private final IconManager iconManager;
53
+    /** Colour manager. */
54
+    private final ColourManager colourManager;
36 55
     /** Nick colour manager. */
37 56
     private NickColourManager nickColourManager;
38 57
 
39
-    public NickColourPlugin() {
58
+    public NickColourPlugin(final PluginInfo pluginInfo, final SwingController controller,
59
+            final IconManager iconManager, final ColourManager colourManager) {
60
+        this.pluginInfo = pluginInfo;
61
+        this.mainFrame = controller.getMainFrame();
62
+        this.iconManager = iconManager;
63
+        this.colourManager = colourManager;
40 64
     }
41 65
 
42 66
     @Override
43 67
     public void load(final PluginInfo pluginInfo, final ObjectGraph graph) {
44 68
         super.load(pluginInfo, graph);
45 69
 
46
-        setObjectGraph(graph.plus(new NickColourModule(pluginInfo, getDomain())));
70
+        setObjectGraph(graph.plus(new NickColourModule(pluginInfo.getDomain())));
47 71
         nickColourManager = getObjectGraph().get(NickColourManager.class);
48 72
     }
49 73
 
@@ -61,7 +85,53 @@ public class NickColourPlugin extends BasePlugin {
61 85
 
62 86
     @Override
63 87
     public void showConfig(final PreferencesDialogModel manager) {
64
-        nickColourManager.showConfig(manager);
88
+        final PreferencesCategory general = new PluginPreferencesCategory(
89
+                pluginInfo, "Nick Colours",
90
+                "General configuration for NickColour plugin.");
91
+        final PreferencesCategory colours = new PluginPreferencesCategory(
92
+                pluginInfo, "Colours",
93
+                "Set colours for specific nicknames.", UIUtilities.invokeAndWait(
94
+                        new Callable<NickColourPanel>() {
95
+                            /** {@inheritDoc} */
96
+                            @Override
97
+                            public NickColourPanel call() {
98
+                                return new NickColourPanel(mainFrame, iconManager, colourManager,
99
+                                        manager.getIdentity(), manager.getConfigManager(),
100
+                                        pluginInfo.getDomain());
101
+                            }
102
+                        }));
103
+
104
+        general.addSetting(new PreferencesSetting(PreferencesType.BOOLEAN,
105
+                "ui", "shownickcoloursintext", "Show colours in text area",
106
+                "Colour nicknames in main text area?",
107
+                manager.getConfigManager(), manager.getIdentity()));
108
+        general.addSetting(new PreferencesSetting(PreferencesType.BOOLEAN,
109
+                "ui", "shownickcoloursinnicklist", "Show colours in"
110
+                + " nick list", "Colour nicknames in channel nick lists?",
111
+                manager.getConfigManager(), manager.getIdentity()));
112
+        general.addSetting(new PreferencesSetting(PreferencesType.BOOLEAN, pluginInfo.getDomain(),
113
+                "settext", "Set colours in textarea",
114
+                "Should the plugin set the textarea colour of nicks?",
115
+                manager.getConfigManager(), manager.getIdentity()));
116
+        general.addSetting(new PreferencesSetting(PreferencesType.BOOLEAN, pluginInfo.getDomain(),
117
+                "setnicklist", "Set colours in nick list",
118
+                "Should the plugin set the nick list colour of nicks?",
119
+                manager.getConfigManager(), manager.getIdentity()));
120
+        general.addSetting(new PreferencesSetting(PreferencesType.BOOLEAN,
121
+                pluginInfo.getDomain(), "userandomcolour", "Use random colour",
122
+                "Use a pseudo-random colour for each person?",
123
+                manager.getConfigManager(), manager.getIdentity()));
124
+        general.addSetting(new PreferencesSetting(PreferencesType.BOOLEAN,
125
+                pluginInfo.getDomain(), "useowncolour", "Use colour for own nick",
126
+                "Always use the same colour for our own nickname?",
127
+                manager.getConfigManager(), manager.getIdentity()));
128
+        general.addSetting(new PreferencesSetting(PreferencesType.COLOUR, pluginInfo.getDomain(),
129
+                "owncolour", "Colour to use for own nick",
130
+                "Colour used for our own nickname, if above setting is "
131
+                + "enabled.", manager.getConfigManager(), manager.getIdentity()));
132
+
133
+        general.addSubCategory(colours);
134
+        manager.getCategory("Plugins").addSubCategory(general);
65 135
     }
66 136
 
67 137
 }

Loading…
Отказ
Запис