|
@@ -39,6 +39,8 @@ import com.dmdirc.util.validators.NumericalValidator;
|
39
|
39
|
import com.dmdirc.util.validators.OptionalValidator;
|
40
|
40
|
import com.dmdirc.util.validators.Validator;
|
41
|
41
|
|
|
42
|
+import com.google.common.eventbus.EventBus;
|
|
43
|
+
|
42
|
44
|
import java.awt.Dimension;
|
43
|
45
|
import java.awt.Font;
|
44
|
46
|
import java.awt.event.ActionEvent;
|
|
@@ -75,19 +77,24 @@ public final class PrefsComponentFactory {
|
75
|
77
|
private final IconManager iconManager;
|
76
|
78
|
/** The colour manager to use for colour preferences. */
|
77
|
79
|
private final ColourManager colourManager;
|
|
80
|
+ /** The global event bus. */
|
|
81
|
+ private final EventBus eventBus;
|
78
|
82
|
|
79
|
83
|
/**
|
80
|
84
|
* Creates a new instance of PrefsComponentFactory.
|
81
|
85
|
*
|
|
86
|
+ * @param eventBus The global event bus.
|
82
|
87
|
* @param iconManager The icon manager to use for dialog and error icons.
|
83
|
88
|
* @param colourManager The colour manager to use for colour preferences.
|
84
|
89
|
*/
|
85
|
90
|
@Inject
|
86
|
91
|
public PrefsComponentFactory(
|
|
92
|
+ final EventBus eventBus,
|
87
|
93
|
@GlobalConfig final IconManager iconManager,
|
88
|
94
|
final ColourManager colourManager) {
|
89
|
95
|
this.iconManager = iconManager;
|
90
|
96
|
this.colourManager = colourManager;
|
|
97
|
+ this.eventBus = eventBus;
|
91
|
98
|
}
|
92
|
99
|
|
93
|
100
|
/**
|
|
@@ -100,7 +107,7 @@ public final class PrefsComponentFactory {
|
100
|
107
|
* @return An appropriate JComponent descendant
|
101
|
108
|
*/
|
102
|
109
|
public JComponent getComponent(final PreferencesSetting setting) {
|
103
|
|
- JComponent option;
|
|
110
|
+ final JComponent option;
|
104
|
111
|
|
105
|
112
|
switch (setting.getType()) {
|
106
|
113
|
case TEXT:
|
|
@@ -160,7 +167,7 @@ public final class PrefsComponentFactory {
|
160
|
167
|
*
|
161
|
168
|
* @param setting The setting to create the component for
|
162
|
169
|
*
|
163
|
|
- * @return A JComponent descendent for the specified setting
|
|
170
|
+ * @return A JComponent descendant for the specified setting
|
164
|
171
|
*/
|
165
|
172
|
private JComponent getTextOption(final PreferencesSetting setting) {
|
166
|
173
|
final ValidatingJTextField option = new ValidatingJTextField(
|
|
@@ -182,7 +189,7 @@ public final class PrefsComponentFactory {
|
182
|
189
|
*
|
183
|
190
|
* @param setting The setting to create the component for
|
184
|
191
|
*
|
185
|
|
- * @return A JComponent descendent for the specified setting
|
|
192
|
+ * @return A JComponent descendant for the specified setting
|
186
|
193
|
*/
|
187
|
194
|
private JComponent getBooleanOption(
|
188
|
195
|
final PreferencesSetting setting) {
|
|
@@ -206,7 +213,7 @@ public final class PrefsComponentFactory {
|
206
|
213
|
*
|
207
|
214
|
* @param setting The setting to create the component for
|
208
|
215
|
*
|
209
|
|
- * @return A JComponent descendent for the specified setting
|
|
216
|
+ * @return A JComponent descendant for the specified setting
|
210
|
217
|
*/
|
211
|
218
|
private JComponent getComboOption(final PreferencesSetting setting) {
|
212
|
219
|
final JComboBox<Object> option = new JComboBox<>(setting.getComboOptions().entrySet().
|
|
@@ -227,7 +234,7 @@ public final class PrefsComponentFactory {
|
227
|
234
|
@Override
|
228
|
235
|
@SuppressWarnings("unchecked")
|
229
|
236
|
public void actionPerformed(final ActionEvent e) {
|
230
|
|
- final Object selected = ((JComboBox) e.getSource())
|
|
237
|
+ final Object selected = ((JComboBox<?>) e.getSource())
|
231
|
238
|
.getSelectedItem();
|
232
|
239
|
if (selected != null) {
|
233
|
240
|
setting.setValue(((Map.Entry<String, String>) selected).getKey());
|
|
@@ -243,7 +250,7 @@ public final class PrefsComponentFactory {
|
243
|
250
|
*
|
244
|
251
|
* @param setting The setting to create the component for
|
245
|
252
|
*
|
246
|
|
- * @return A JComponent descendent for the specified setting
|
|
253
|
+ * @return A JComponent descendant for the specified setting
|
247
|
254
|
*/
|
248
|
255
|
private JComponent getIntegerOption(
|
249
|
256
|
final PreferencesSetting setting) {
|
|
@@ -289,7 +296,7 @@ public final class PrefsComponentFactory {
|
289
|
296
|
*
|
290
|
297
|
* @param setting The setting to create the component for
|
291
|
298
|
*
|
292
|
|
- * @return A JComponent descendent for the specified setting
|
|
299
|
+ * @return A JComponent descendant for the specified setting
|
293
|
300
|
*/
|
294
|
301
|
private JComponent getOptionalIntegerOption(
|
295
|
302
|
final PreferencesSetting setting) {
|
|
@@ -343,7 +350,7 @@ public final class PrefsComponentFactory {
|
343
|
350
|
*
|
344
|
351
|
* @param setting The setting to create the component for
|
345
|
352
|
*
|
346
|
|
- * @return A JComponent descendent for the specified setting
|
|
353
|
+ * @return A JComponent descendant for the specified setting
|
347
|
354
|
*/
|
348
|
355
|
private JComponent getDurationOption(
|
349
|
356
|
final PreferencesSetting setting) {
|
|
@@ -371,7 +378,7 @@ public final class PrefsComponentFactory {
|
371
|
378
|
*
|
372
|
379
|
* @param setting The setting to create the component for
|
373
|
380
|
*
|
374
|
|
- * @return A JComponent descendent for the specified setting
|
|
381
|
+ * @return A JComponent descendant for the specified setting
|
375
|
382
|
*/
|
376
|
383
|
private JComponent getColourOption(
|
377
|
384
|
final PreferencesSetting setting) {
|
|
@@ -382,9 +389,8 @@ public final class PrefsComponentFactory {
|
382
|
389
|
|
383
|
390
|
@Override
|
384
|
391
|
public void actionPerformed(final ActionEvent e) {
|
385
|
|
- final OptionalColourChooser chooser = ((OptionalColourChooser) e.getSource());
|
386
|
|
- setting.setValue(chooser.isEnabled() + ":"
|
387
|
|
- + chooser.getColour());
|
|
392
|
+ final OptionalColourChooser chooser = (OptionalColourChooser) e.getSource();
|
|
393
|
+ setting.setValue(chooser.isEnabled() + ":" + chooser.getColour());
|
388
|
394
|
}
|
389
|
395
|
});
|
390
|
396
|
|
|
@@ -396,7 +402,7 @@ public final class PrefsComponentFactory {
|
396
|
402
|
*
|
397
|
403
|
* @param setting The setting to create the component for
|
398
|
404
|
*
|
399
|
|
- * @return A JComponent descendent for the specified setting
|
|
405
|
+ * @return A JComponent descendant for the specified setting
|
400
|
406
|
*/
|
401
|
407
|
private JComponent getOptionalColourOption(
|
402
|
408
|
final PreferencesSetting setting) {
|
|
@@ -426,12 +432,12 @@ public final class PrefsComponentFactory {
|
426
|
432
|
*
|
427
|
433
|
* @param setting The setting to create the component for
|
428
|
434
|
*
|
429
|
|
- * @return A JComponent descendent for the specified setting
|
|
435
|
+ * @return A JComponent descendant for the specified setting
|
430
|
436
|
*/
|
431
|
437
|
private JComponent getFontOption(final PreferencesSetting setting) {
|
432
|
438
|
final String value = setting.getValue();
|
433
|
439
|
|
434
|
|
- final FontPicker option = new FontPicker(value);
|
|
440
|
+ final FontPicker option = new FontPicker(eventBus, value);
|
435
|
441
|
|
436
|
442
|
option.addActionListener(new ActionListener() {
|
437
|
443
|
|
|
@@ -454,9 +460,9 @@ public final class PrefsComponentFactory {
|
454
|
460
|
* Initialises and returns a FileBrowser for the specified setting.
|
455
|
461
|
*
|
456
|
462
|
* @param setting The setting to create the component for
|
457
|
|
- * @param type The type of filechooser we want (Files/Directories/Both)
|
|
463
|
+ * @param type The type of file chooser we want (Files/Directories/Both)
|
458
|
464
|
*
|
459
|
|
- * @return A JComponent descendent for the specified setting
|
|
465
|
+ * @return A JComponent descendant for the specified setting
|
460
|
466
|
*/
|
461
|
467
|
private JComponent getFileBrowseOption(
|
462
|
468
|
final PreferencesSetting setting, final int type) {
|
|
@@ -486,7 +492,7 @@ public final class PrefsComponentFactory {
|
486
|
492
|
*
|
487
|
493
|
* @param setting The setting to create the component for
|
488
|
494
|
*
|
489
|
|
- * @return A JComponent descendent for the specified setting
|
|
495
|
+ * @return A JComponent descendant for the specified setting
|
490
|
496
|
*/
|
491
|
497
|
private static JComponent getLabelOption(final PreferencesSetting setting) {
|
492
|
498
|
final JPanel panel = new JPanel(new MigLayout("fill"));
|