14
14
public class PreferencesUIFactory {
15
15
16
16
private static PreferencesUIFactory instance ;
17
-
17
+
18
18
public static PreferencesUIFactory getInstance () {
19
19
if (instance == null ) {
20
20
instance = new PreferencesUIFactory ();
21
21
}
22
22
return instance ;
23
23
}
24
-
24
+
25
25
private PreferencesPanel panel ;
26
26
private Dialog dialog ;
27
-
27
+
28
28
/*package*/ PreferencesUIFactory () {
29
29
}
30
-
30
+
31
31
/**
32
32
* Returns the currently visible preferences UI, if any.
33
33
*/
34
34
public PreferencesUI getCurrentUI () {
35
35
return panel ;
36
36
}
37
-
37
+
38
38
/**
39
39
* Creates a new current preferences UI but does not show it yet.
40
40
*/
41
41
public PreferencesUI createCurrentPreferencesUI () {
42
42
this .panel = new PreferencesPanel ();
43
43
return this .panel ;
44
44
}
45
-
45
+
46
46
public boolean isPreferencesUiVisible () {
47
47
return dialog != null ;
48
48
}
49
-
49
+
50
50
public void activateVisiblePreferencesUi () {
51
51
if (dialog == null ) {
52
52
throw new IllegalStateException ("Preferences UI not visible" );
53
53
}
54
- dialog .requestFocus ();
54
+ SwingUtilities .invokeLater (new Runnable () {
55
+ @ Override
56
+ public void run () {
57
+ dialog .requestFocus ();
58
+ }
59
+ });
55
60
}
56
-
61
+
57
62
/**
58
63
* Shows the preferences dialog.
59
- *
64
+ *
60
65
* <p>
61
- * This must be called after
62
- * {@link #createCurrentPreferencesUI()} but not twice without
63
- * creating a new preferences UI in between.
64
- *
66
+ * This must be called after {@link #createCurrentPreferencesUI()} but not
67
+ * twice without creating a new preferences UI in between.
68
+ *
65
69
* <p>
66
- * The <code>dialogListener</code> shall receive an event with either
67
- * the OK or cancel button constant in <code>DialogDescriptor</code>
68
- * as the event source. After the event is processed, the current
69
- * panel is forgotten and {@link #getCurrentPanel()} shall return null
70
- * again.
70
+ * The <code>dialogListener</code> shall receive an event with either the OK
71
+ * or cancel button constant in <code>DialogDescriptor</code> as the event
72
+ * source. After the event is processed, the current panel is forgotten and
73
+ * {@link #getCurrentPanel()} shall return null again.
71
74
*/
72
75
public void showPreferencesDialog (final ActionListener dialogListener ) {
73
76
if (panel == null ) {
@@ -76,7 +79,7 @@ public void showPreferencesDialog(final ActionListener dialogListener) {
76
79
if (dialog != null ) {
77
80
throw new IllegalStateException ("Preferences UI already visible" );
78
81
}
79
-
82
+
80
83
ActionListener closeListener = new ActionListener () {
81
84
@ Override
82
85
public void actionPerformed (ActionEvent e ) {
@@ -85,7 +88,7 @@ public void actionPerformed(ActionEvent e) {
85
88
dialogListener .actionPerformed (e );
86
89
}
87
90
};
88
-
91
+
89
92
DialogDescriptor descriptor = new DialogDescriptor (
90
93
panel ,
91
94
"TMC Settings" ,
0 commit comments