|
@@ -24,13 +24,15 @@ package com.dmdirc.addons.nickcolours;
|
24
|
24
|
|
25
|
25
|
import com.dmdirc.ClientModule.GlobalConfig;
|
26
|
26
|
import com.dmdirc.DMDircMBassador;
|
|
27
|
+import com.dmdirc.addons.ui_swing.EDTInvocation;
|
|
28
|
+import com.dmdirc.config.ConfigBinder;
|
|
29
|
+import com.dmdirc.config.ConfigBinding;
|
27
|
30
|
import com.dmdirc.events.ChannelGotnamesEvent;
|
28
|
31
|
import com.dmdirc.events.ChannelJoinEvent;
|
29
|
32
|
import com.dmdirc.events.DisplayProperty;
|
30
|
33
|
import com.dmdirc.interfaces.GroupChatUser;
|
31
|
34
|
import com.dmdirc.interfaces.User;
|
32
|
35
|
import com.dmdirc.interfaces.config.AggregateConfigProvider;
|
33
|
|
-import com.dmdirc.interfaces.config.ConfigChangeListener;
|
34
|
36
|
import com.dmdirc.interfaces.config.ReadOnlyConfigProvider;
|
35
|
37
|
import com.dmdirc.parser.interfaces.StringConverter;
|
36
|
38
|
import com.dmdirc.plugins.PluginDomain;
|
|
@@ -50,12 +52,14 @@ import net.engio.mbassy.listener.Handler;
|
50
|
52
|
* Provides various features related to nickname colouring.
|
51
|
53
|
*/
|
52
|
54
|
@Singleton
|
53
|
|
-public class NickColourManager implements ConfigChangeListener {
|
|
55
|
+public class NickColourManager {
|
54
|
56
|
|
55
|
57
|
/** Manager to parse colours with. */
|
56
|
58
|
private final ColourManager colourManager;
|
57
|
59
|
/** Config to read settings from. */
|
58
|
60
|
private final AggregateConfigProvider globalConfig;
|
|
61
|
+ /** Config binder. */
|
|
62
|
+ private final ConfigBinder configBinder;
|
59
|
63
|
/** Plugin's setting domain. */
|
60
|
64
|
private final String domain;
|
61
|
65
|
/** Event bus to subscribe to events on . */
|
|
@@ -70,11 +74,13 @@ public class NickColourManager implements ConfigChangeListener {
|
70
|
74
|
@Inject
|
71
|
75
|
public NickColourManager(@GlobalConfig final ColourManager colourManager,
|
72
|
76
|
@PluginDomain(NickColourPlugin.class) final String domain,
|
73
|
|
- @GlobalConfig final AggregateConfigProvider globalConfig, final DMDircMBassador eventBus) {
|
|
77
|
+ @GlobalConfig final AggregateConfigProvider globalConfig,
|
|
78
|
+ final DMDircMBassador eventBus) {
|
74
|
79
|
this.domain = domain;
|
75
|
80
|
this.globalConfig = globalConfig;
|
76
|
81
|
this.colourManager = colourManager;
|
77
|
82
|
this.eventBus = eventBus;
|
|
83
|
+ configBinder = globalConfig.getBinder().withDefaultDomain(domain);
|
78
|
84
|
}
|
79
|
85
|
|
80
|
86
|
@Handler
|
|
@@ -218,8 +224,8 @@ public class NickColourManager implements ConfigChangeListener {
|
218
|
224
|
* Loads this plugin.
|
219
|
225
|
*/
|
220
|
226
|
public void onLoad() {
|
221
|
|
- setCachedSettings();
|
222
|
227
|
eventBus.subscribe(this);
|
|
228
|
+ configBinder.bind(this, NickColourManager.class);
|
223
|
229
|
}
|
224
|
230
|
|
225
|
231
|
/**
|
|
@@ -227,24 +233,26 @@ public class NickColourManager implements ConfigChangeListener {
|
227
|
233
|
*/
|
228
|
234
|
public void onUnload() {
|
229
|
235
|
eventBus.unsubscribe(this);
|
|
236
|
+ configBinder.unbind(this);
|
230
|
237
|
}
|
231
|
238
|
|
232
|
|
- /**
|
233
|
|
- * Updates cached settings.
|
234
|
|
- */
|
235
|
|
- private void setCachedSettings() {
|
236
|
|
- useowncolour = globalConfig.getOptionBool(domain, "useowncolour");
|
237
|
|
- owncolour = globalConfig.getOption(domain, "owncolour");
|
238
|
|
- userandomcolour = globalConfig.getOptionBool(domain, "userandomcolour");
|
239
|
|
- if (globalConfig.hasOptionString(domain, "randomcolours")) {
|
240
|
|
- final List<String> list = globalConfig.getOptionList(domain, "randomcolours");
|
241
|
|
- randColours = list.toArray(new String[list.size()]);
|
242
|
|
- }
|
|
239
|
+ @ConfigBinding(key = "useowncolour", invocation = EDTInvocation.class)
|
|
240
|
+ public void handleUseOwnColour(final boolean value) {
|
|
241
|
+ useowncolour = value;
|
243
|
242
|
}
|
244
|
243
|
|
245
|
|
- @Override
|
246
|
|
- public void configChanged(final String domain, final String key) {
|
247
|
|
- setCachedSettings();
|
|
244
|
+ @ConfigBinding(key = "userandomcolour", invocation = EDTInvocation.class)
|
|
245
|
+ public void handleUseRandomColour(final boolean value) {
|
|
246
|
+ userandomcolour = value;
|
248
|
247
|
}
|
249
|
248
|
|
|
249
|
+ @ConfigBinding(key = "owncolour", invocation = EDTInvocation.class)
|
|
250
|
+ public void handleOwnColour(final String value) {
|
|
251
|
+ owncolour = value;
|
|
252
|
+ }
|
|
253
|
+
|
|
254
|
+ @ConfigBinding(key = "randomcolours", invocation = EDTInvocation.class)
|
|
255
|
+ public void handleRandomColours(final List<String> value) {
|
|
256
|
+ randColours = value.toArray(new String[value.size()]);
|
|
257
|
+ }
|
250
|
258
|
}
|