|
@@ -23,39 +23,80 @@
|
23
|
23
|
package com.dmdirc.addons.osd;
|
24
|
24
|
|
25
|
25
|
import com.dmdirc.addons.ui_swing.UIUtilities;
|
|
26
|
+import com.dmdirc.addons.ui_swing.injection.MainWindow;
|
|
27
|
+import com.dmdirc.config.prefs.CategoryChangeListener;
|
|
28
|
+import com.dmdirc.config.prefs.PluginPreferencesCategory;
|
|
29
|
+import com.dmdirc.config.prefs.PreferencesCategory;
|
|
30
|
+import com.dmdirc.config.prefs.PreferencesDialogModel;
|
|
31
|
+import com.dmdirc.config.prefs.PreferencesInterface;
|
|
32
|
+import com.dmdirc.config.prefs.PreferencesSetting;
|
|
33
|
+import com.dmdirc.config.prefs.PreferencesType;
|
|
34
|
+import com.dmdirc.config.prefs.SettingChangeListener;
|
|
35
|
+import com.dmdirc.events.ClientPrefsOpenedEvent;
|
26
|
36
|
import com.dmdirc.interfaces.config.IdentityController;
|
|
37
|
+import com.dmdirc.plugins.PluginDomain;
|
27
|
38
|
import com.dmdirc.plugins.PluginInfo;
|
28
|
39
|
import com.dmdirc.ui.messages.ColourManager;
|
|
40
|
+import com.dmdirc.ui.messages.ColourManagerFactory;
|
|
41
|
+import com.dmdirc.util.validators.NumericalValidator;
|
|
42
|
+import com.dmdirc.util.validators.OptionalValidator;
|
29
|
43
|
|
30
|
44
|
import java.awt.Window;
|
31
|
45
|
import java.util.ArrayList;
|
|
46
|
+import java.util.HashMap;
|
32
|
47
|
import java.util.LinkedList;
|
33
|
48
|
import java.util.List;
|
|
49
|
+import java.util.Map;
|
34
|
50
|
import java.util.Queue;
|
35
|
51
|
|
|
52
|
+import javax.inject.Inject;
|
|
53
|
+
|
|
54
|
+import net.engio.mbassy.listener.Handler;
|
|
55
|
+
|
36
|
56
|
/**
|
37
|
57
|
* Class to manage OSD Windows.
|
38
|
58
|
*/
|
39
|
|
-public class OsdManager {
|
|
59
|
+public class OsdManager implements CategoryChangeListener, PreferencesInterface,
|
|
60
|
+ SettingChangeListener {
|
40
|
61
|
|
41
|
62
|
/** The frame the OSD will be associated with. */
|
42
|
63
|
private final Window mainFrame;
|
43
|
|
- /** The controller to read/write settings with. */
|
44
|
|
- private final IdentityController identityController;
|
45
|
|
- /** The colour manager to use to parse colours. */
|
46
|
|
- private final ColourManager colourManager;
|
47
|
64
|
/** List of OSD Windows. */
|
48
|
65
|
private final List<OsdWindow> windowList = new ArrayList<>();
|
49
|
66
|
/** List of messages to be queued. */
|
50
|
67
|
private final Queue<QueuedMessage> windowQueue = new LinkedList<>();
|
51
|
68
|
/** This plugin's settings domain. */
|
52
|
69
|
private final String domain;
|
|
70
|
+ /** Config OSD Window. */
|
|
71
|
+ private OsdWindow osdWindow;
|
|
72
|
+ /** X-axis position of OSD. */
|
|
73
|
+ private int x;
|
|
74
|
+ /** Y-axis potion of OSD. */
|
|
75
|
+ private int y;
|
|
76
|
+ /** Setting objects with registered change listeners. */
|
|
77
|
+ private PreferencesSetting fontSizeSetting;
|
|
78
|
+ private PreferencesSetting backgroundSetting;
|
|
79
|
+ private PreferencesSetting foregroundSetting;
|
|
80
|
+ private PreferencesSetting widthSetting;
|
|
81
|
+ private PreferencesSetting timeoutSetting;
|
|
82
|
+ private PreferencesSetting maxWindowsSetting;
|
|
83
|
+ /** This plugin's plugin info. */
|
|
84
|
+ private final PluginInfo pluginInfo;
|
|
85
|
+ /** The controller to read/write settings with. */
|
|
86
|
+ private final IdentityController identityController;
|
|
87
|
+ /** The manager to use to parse colours. */
|
|
88
|
+ private final ColourManager colourManager;
|
53
|
89
|
|
54
|
|
- public OsdManager(final Window mainFrame, final IdentityController identityController,
|
55
|
|
- final ColourManager colourManager, final PluginInfo pluginInfo) {
|
|
90
|
+ @Inject
|
|
91
|
+ public OsdManager(
|
|
92
|
+ @MainWindow final Window mainFrame,
|
|
93
|
+ final IdentityController identityController,
|
|
94
|
+ final ColourManagerFactory colourManagerFactory,
|
|
95
|
+ @PluginDomain(OsdPlugin.class) final PluginInfo pluginInfo) {
|
56
|
96
|
this.mainFrame = mainFrame;
|
57
|
97
|
this.identityController = identityController;
|
58
|
|
- this.colourManager = colourManager;
|
|
98
|
+ this.colourManager = colourManagerFactory.getColourManager(identityController.getGlobalConfiguration());
|
|
99
|
+ this.pluginInfo = pluginInfo;
|
59
|
100
|
this.domain = pluginInfo.getDomain();
|
60
|
101
|
}
|
61
|
102
|
|
|
@@ -97,8 +138,9 @@ public class OsdManager {
|
97
|
138
|
* @param message Text to display in the OSD window.
|
98
|
139
|
*/
|
99
|
140
|
private synchronized void displayWindow(final int timeout, final String message) {
|
100
|
|
- final OsdPolicy policy = OsdPolicy.valueOf(identityController.getGlobalConfiguration()
|
101
|
|
- .getOption(domain, "newbehaviour").toUpperCase());
|
|
141
|
+ final OsdPolicy policy = OsdPolicy.valueOf(
|
|
142
|
+ identityController.getGlobalConfiguration().getOption(domain, "newbehaviour")
|
|
143
|
+ .toUpperCase());
|
102
|
144
|
final int startY = identityController.getGlobalConfiguration()
|
103
|
145
|
.getOptionInt(domain, "locationY");
|
104
|
146
|
|
|
@@ -167,4 +209,116 @@ public class OsdManager {
|
167
|
209
|
return windowList.size();
|
168
|
210
|
}
|
169
|
211
|
|
|
212
|
+ @Handler
|
|
213
|
+ public void showConfig(final ClientPrefsOpenedEvent event) {
|
|
214
|
+ final PreferencesDialogModel manager = event.getModel();
|
|
215
|
+ x = identityController.getGlobalConfiguration()
|
|
216
|
+ .getOptionInt(domain, "locationX");
|
|
217
|
+ y = identityController.getGlobalConfiguration()
|
|
218
|
+ .getOptionInt(domain, "locationY");
|
|
219
|
+
|
|
220
|
+ final PreferencesCategory category = new PluginPreferencesCategory(
|
|
221
|
+ pluginInfo, "OSD",
|
|
222
|
+ "General configuration for OSD plugin.", "category-osd");
|
|
223
|
+
|
|
224
|
+ fontSizeSetting = new PreferencesSetting(PreferencesType.INTEGER,
|
|
225
|
+ domain, "fontSize", "Font size", "Changes the font " + "size of the OSD",
|
|
226
|
+ manager.getConfigManager(),
|
|
227
|
+ manager.getIdentity()).registerChangeListener(this);
|
|
228
|
+ backgroundSetting = new PreferencesSetting(PreferencesType.COLOUR,
|
|
229
|
+ domain, "bgcolour", "Background colour",
|
|
230
|
+ "Background colour for the OSD", manager.getConfigManager(),
|
|
231
|
+ manager.getIdentity()).registerChangeListener(this);
|
|
232
|
+ foregroundSetting = new PreferencesSetting(PreferencesType.COLOUR,
|
|
233
|
+ domain, "fgcolour", "Foreground colour",
|
|
234
|
+ "Foreground colour for the OSD", manager.getConfigManager(),
|
|
235
|
+ manager.getIdentity()).registerChangeListener(this);
|
|
236
|
+ widthSetting = new PreferencesSetting(PreferencesType.INTEGER,
|
|
237
|
+ domain, "width", "OSD Width", "Width of the OSD Window",
|
|
238
|
+ manager.getConfigManager(), manager.getIdentity())
|
|
239
|
+ .registerChangeListener(this);
|
|
240
|
+ timeoutSetting = new PreferencesSetting(PreferencesType.OPTIONALINTEGER,
|
|
241
|
+ new OptionalValidator(new NumericalValidator(1, Integer.MAX_VALUE)),
|
|
242
|
+ domain, "timeout", "Timeout", "Length of time in "
|
|
243
|
+ + "seconds before the OSD window closes", manager.getConfigManager(),
|
|
244
|
+ manager.getIdentity());
|
|
245
|
+ maxWindowsSetting = new PreferencesSetting(PreferencesType.OPTIONALINTEGER,
|
|
246
|
+ new OptionalValidator(new NumericalValidator(1, Integer.MAX_VALUE)),
|
|
247
|
+ domain, "maxWindows", "Maximum open windows",
|
|
248
|
+ "Maximum number of OSD windows that will be displayed at any given time",
|
|
249
|
+ manager.getConfigManager(), manager.getIdentity());
|
|
250
|
+
|
|
251
|
+ category.addSetting(fontSizeSetting);
|
|
252
|
+ category.addSetting(backgroundSetting);
|
|
253
|
+ category.addSetting(foregroundSetting);
|
|
254
|
+ category.addSetting(widthSetting);
|
|
255
|
+ category.addSetting(timeoutSetting);
|
|
256
|
+ category.addSetting(maxWindowsSetting);
|
|
257
|
+
|
|
258
|
+ final Map<String, String> posOptions = new HashMap<>();
|
|
259
|
+
|
|
260
|
+ //Populate policy MULTICHOICE
|
|
261
|
+ for (OsdPolicy policy : OsdPolicy.values()) {
|
|
262
|
+ posOptions.put(policy.name(), policy.getDescription());
|
|
263
|
+ }
|
|
264
|
+
|
|
265
|
+ category.addSetting(new PreferencesSetting(domain, "newbehaviour",
|
|
266
|
+ "New window policy", "What to do when an OSD Window "
|
|
267
|
+ + "is opened when there are other, existing windows open",
|
|
268
|
+ posOptions, manager.getConfigManager(), manager.getIdentity()));
|
|
269
|
+
|
|
270
|
+ category.addChangeListener(this);
|
|
271
|
+ manager.getCategory("Plugins").addSubCategory(category);
|
|
272
|
+ manager.registerSaveListener(this);
|
|
273
|
+ }
|
|
274
|
+
|
|
275
|
+ @Override
|
|
276
|
+ public void categorySelected(final PreferencesCategory category) {
|
|
277
|
+ osdWindow = new OsdWindow(mainFrame, identityController, this, colourManager,
|
|
278
|
+ -1, "Please drag this OSD to position", true, x, y, domain);
|
|
279
|
+ osdWindow.setBackgroundColour(backgroundSetting.getValue());
|
|
280
|
+ osdWindow.setForegroundColour(foregroundSetting.getValue());
|
|
281
|
+ osdWindow.setFontSize(Integer.parseInt(fontSizeSetting.getValue()));
|
|
282
|
+ }
|
|
283
|
+
|
|
284
|
+ @Override
|
|
285
|
+ public void categoryDeselected(final PreferencesCategory category) {
|
|
286
|
+ x = osdWindow.getLocationOnScreen().x;
|
|
287
|
+ y = osdWindow.getLocationOnScreen().y;
|
|
288
|
+
|
|
289
|
+ osdWindow.dispose();
|
|
290
|
+ osdWindow = null;
|
|
291
|
+ }
|
|
292
|
+
|
|
293
|
+ @Override
|
|
294
|
+ public void save() {
|
|
295
|
+ identityController.getUserSettings().setOption(domain, "locationX", x);
|
|
296
|
+ identityController.getUserSettings().setOption(domain, "locationY", y);
|
|
297
|
+ }
|
|
298
|
+
|
|
299
|
+ @Override
|
|
300
|
+ public void settingChanged(final PreferencesSetting setting) {
|
|
301
|
+ if (osdWindow == null) {
|
|
302
|
+ // They've changed categories but are somehow poking settings.
|
|
303
|
+ // Ignore the request.
|
|
304
|
+ return;
|
|
305
|
+ }
|
|
306
|
+
|
|
307
|
+ if (setting.equals(fontSizeSetting)) {
|
|
308
|
+ osdWindow.setFontSize(Integer.parseInt(setting.getValue()));
|
|
309
|
+ } else if (setting.equals(backgroundSetting)) {
|
|
310
|
+ osdWindow.setBackgroundColour(setting.getValue());
|
|
311
|
+ } else if (setting.equals(foregroundSetting)) {
|
|
312
|
+ osdWindow.setForegroundColour(setting.getValue());
|
|
313
|
+ } else if (setting.equals(widthSetting)) {
|
|
314
|
+ int width = 500;
|
|
315
|
+ try {
|
|
316
|
+ width = Integer.parseInt(setting.getValue());
|
|
317
|
+ } catch (NumberFormatException e) {
|
|
318
|
+ //Ignore
|
|
319
|
+ }
|
|
320
|
+ osdWindow.setSize(width, osdWindow.getHeight());
|
|
321
|
+ }
|
|
322
|
+ }
|
|
323
|
+
|
170
|
324
|
}
|