1414public class PreferencesUIFactory {
1515
1616 private static PreferencesUIFactory instance ;
17-
17+
1818 public static PreferencesUIFactory getInstance () {
1919 if (instance == null ) {
2020 instance = new PreferencesUIFactory ();
2121 }
2222 return instance ;
2323 }
24-
24+
2525 private PreferencesPanel panel ;
2626 private Dialog dialog ;
27-
27+
2828 /*package*/ PreferencesUIFactory () {
2929 }
30-
30+
3131 /**
3232 * Returns the currently visible preferences UI, if any.
3333 */
3434 public PreferencesUI getCurrentUI () {
3535 return panel ;
3636 }
37-
37+
3838 /**
3939 * Creates a new current preferences UI but does not show it yet.
4040 */
4141 public PreferencesUI createCurrentPreferencesUI () {
4242 this .panel = new PreferencesPanel ();
4343 return this .panel ;
4444 }
45-
45+
4646 public boolean isPreferencesUiVisible () {
4747 return dialog != null ;
4848 }
49-
49+
5050 public void activateVisiblePreferencesUi () {
5151 if (dialog == null ) {
5252 throw new IllegalStateException ("Preferences UI not visible" );
5353 }
54- dialog .requestFocus ();
54+ SwingUtilities .invokeLater (new Runnable () {
55+ @ Override
56+ public void run () {
57+ dialog .requestFocus ();
58+ }
59+ });
5560 }
56-
61+
5762 /**
5863 * Shows the preferences dialog.
59- *
64+ *
6065 * <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+ *
6569 * <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.
7174 */
7275 public void showPreferencesDialog (final ActionListener dialogListener ) {
7376 if (panel == null ) {
@@ -76,7 +79,7 @@ public void showPreferencesDialog(final ActionListener dialogListener) {
7679 if (dialog != null ) {
7780 throw new IllegalStateException ("Preferences UI already visible" );
7881 }
79-
82+
8083 ActionListener closeListener = new ActionListener () {
8184 @ Override
8285 public void actionPerformed (ActionEvent e ) {
@@ -85,7 +88,7 @@ public void actionPerformed(ActionEvent e) {
8588 dialogListener .actionPerformed (e );
8689 }
8790 };
88-
91+
8992 DialogDescriptor descriptor = new DialogDescriptor (
9093 panel ,
9194 "TMC Settings" ,
0 commit comments