Browse Source

Add ability pass owner to display and focus method.

This should enable propery hierachies to be build in with/in
dialogs.

Change-Id: I5889941371ab2d83da79e809fd1493589a5fd91d
Fixes-Issue: CLIENT-431
Reviewed-on: http://gerrit.dmdirc.com/3146
Automatic-Compile: DMDirc Build Manager
Reviewed-by: Chris Smith <chris@dmdirc.com>
tags/0.8
Greg Holmes 10 years ago
parent
commit
240e0bfe96

+ 1
- 1
src/com/dmdirc/addons/ui_swing/components/durationeditor/DurationDisplay.java View File

@@ -151,7 +151,7 @@ public class DurationDisplay extends JPanel implements ActionListener,
151 151
     @Override
152 152
     public void actionPerformed(final ActionEvent e) {
153 153
         final DurationEditor editor = new DurationEditor(window, duration);
154
-        editor.display(this);
154
+        editor.display(window);
155 155
         editor.addDurationListener(this);
156 156
     }
157 157
 

+ 1
- 1
src/com/dmdirc/addons/ui_swing/dialogs/NewServerDialog.java View File

@@ -316,7 +316,7 @@ public class NewServerDialog extends StandardDialog implements
316 316
         if (e.getSource() == getOkButton()) {
317 317
             save();
318 318
         } else if (e.getSource() == editProfileButton) {
319
-            profileDialogProvider.displayOrRequestFocus();
319
+            profileDialogProvider.displayOrRequestFocus(this);
320 320
         } else if (e.getSource() == getCancelButton()) {
321 321
             dispose();
322 322
         }

+ 21
- 10
src/com/dmdirc/addons/ui_swing/dialogs/StandardDialog.java View File

@@ -44,7 +44,7 @@ public class StandardDialog extends JDialog {
44 44
     /** Serial version UID. */
45 45
     private static final long serialVersionUID = 1;
46 46
     /** Parent window. */
47
-    private final Window owner;
47
+    private Window owner;
48 48
     /** The OK button for this frame. */
49 49
     private JButton okButton;
50 50
     /** The cancel button for this frame. */
@@ -84,20 +84,23 @@ public class StandardDialog extends JDialog {
84 84
     }
85 85
 
86 86
     /**
87
-     * Displays the dialog centering on the parent window.
87
+     * Displays the dialog if it is not visible, otherwise requests focus.
88 88
      */
89
-    public void display() {
90
-        display(owner);
89
+    public void displayOrRequestFocus() {
90
+        displayOrRequestFocus(owner);
91 91
     }
92 92
 
93 93
     /**
94
-     * Displays the dialog if it is not visible, otherwise requests focus.
94
+     * Displays the dialog if it is not visible, otherwise requests focus.  The parent window will
95
+     * only be changed if the dialog has not been displayed.
96
+     *
97
+     * @param parent Parent window
95 98
      */
96
-    public void displayOrRequestFocus() {
99
+    public void displayOrRequestFocus(final Window parent) {
97 100
         if (isVisible()) {
98 101
             requestFocus();
99 102
         } else {
100
-            display();
103
+            display(parent);
101 104
         }
102 105
     }
103 106
 
@@ -106,7 +109,15 @@ public class StandardDialog extends JDialog {
106 109
      *
107 110
      * @param owner Window to center on
108 111
      */
109
-    public void display(final Component owner) {
112
+    public void display(final Window owner) {
113
+        this.owner = owner;
114
+        display();
115
+    }
116
+
117
+    /**
118
+     * Displays the dialog centering on the parent window.
119
+     */
120
+    public void display() {
110 121
         if (isVisible()) {
111 122
             return;
112 123
         }
@@ -146,7 +157,7 @@ public class StandardDialog extends JDialog {
146 157
             /** {@inheritDoc} */
147 158
             @Override
148 159
             public void run() {
149
-                display(owner);
160
+                display();
150 161
                 addWindowListener(new WindowAdapter() {
151 162
                     @Override
152 163
                     public void windowClosed(final WindowEvent e) {
@@ -174,7 +185,7 @@ public class StandardDialog extends JDialog {
174 185
      *
175 186
      * @return Parent window or null
176 187
      */
177
-    public Window getParentWindow() {
188
+    public Component getParentWindow() {
178 189
         return owner;
179 190
     }
180 191
 

+ 1
- 1
src/com/dmdirc/addons/ui_swing/dialogs/serversetting/ServerSettingsDialog.java View File

@@ -183,7 +183,7 @@ public class ServerSettingsDialog extends StandardDialog implements ActionListen
183 183
                         public void cancelled() {
184 184
                             //Ignore
185 185
                         }
186
-                    }.display(getOwner());
186
+                    }.display();
187 187
         } else {
188 188
             closeAndSave();
189 189
         }

+ 19
- 0
src/com/dmdirc/addons/ui_swing/injection/DialogProvider.java View File

@@ -24,6 +24,7 @@ package com.dmdirc.addons.ui_swing.injection;
24 24
 
25 25
 import com.dmdirc.addons.ui_swing.dialogs.StandardDialog;
26 26
 
27
+import java.awt.Window;
27 28
 import java.awt.event.WindowAdapter;
28 29
 import java.awt.event.WindowEvent;
29 30
 
@@ -90,6 +91,24 @@ public class DialogProvider<T extends StandardDialog> {
90 91
         get().displayOrRequestFocus();
91 92
     }
92 93
 
94
+    /**
95
+     * Ensures the dialog is visible to the user.
96
+     *
97
+     * <p>The parent will only change if the dialog has not been made visible to the user.
98
+     *
99
+     * <p>If no dialog currently exists, a new one will be created and displayed to the user. If a
100
+     * dialog existed prior to this method being invoked, it will request focus to bring it to the
101
+     * user's attention.
102
+     *
103
+     * <p>This method <em>must</em> be called on the Event Despatch Thread.
104
+     *
105
+     * @param parent Parent window for the dialog
106
+     */
107
+    public void displayOrRequestFocus(final Window parent) {
108
+        checkOnEDT();
109
+        get().displayOrRequestFocus(parent);
110
+    }
111
+
93 112
     /**
94 113
      * Listens to window closing events to remove the cached instance of the dialog.
95 114
      */

Loading…
Cancel
Save