Переглянути джерело

slightly prettier url dialog (now with ok/cancel buttons!)

git-svn-id: http://svn.dmdirc.com/trunk@2772 00569f92-eb28-0410-84fd-f71c24880f
tags/0.5.5
Gregory Holmes 16 роки тому
джерело
коміт
5c303b88c0
1 змінених файлів з 57 додано та 41 видалено
  1. 57
    41
      src/com/dmdirc/ui/swing/dialogs/URLDialog.java

+ 57
- 41
src/com/dmdirc/ui/swing/dialogs/URLDialog.java Переглянути файл

@@ -33,11 +33,11 @@ import java.awt.event.ActionEvent;
33 33
 import java.awt.event.ActionListener;
34 34
 import java.net.URI;
35 35
 
36
-import javax.swing.DefaultComboBoxModel;
36
+import javax.swing.ButtonGroup;
37 37
 import javax.swing.JButton;
38
-import javax.swing.JComboBox;
39 38
 import javax.swing.JFileChooser;
40 39
 import javax.swing.JLabel;
40
+import javax.swing.JRadioButton;
41 41
 import javax.swing.JTextField;
42 42
 import javax.swing.event.DocumentEvent;
43 43
 import javax.swing.event.DocumentListener;
@@ -63,7 +63,15 @@ public class URLDialog extends StandardDialog implements ActionListener,
63 63
     /** Command text field. */
64 64
     private JTextField commandPath;
65 65
     /** Option selection. */
66
-    private JComboBox optionType;
66
+    private ButtonGroup optionType;
67
+    /** DMDirc choice. */
68
+    private JRadioButton dmdirc;
69
+    /** Browser choice. */
70
+    private JRadioButton browser;
71
+    /** Mail choice. */
72
+    private JRadioButton mail;
73
+    /** Custom command choice. */
74
+    private JRadioButton custom;
67 75
     /** Blurb label. */
68 76
     private JLabel blurbLabel;
69 77
     /** Substitutions label */
@@ -127,31 +135,31 @@ public class URLDialog extends StandardDialog implements ActionListener,
127 135
         showFileChooser = new JButton();
128 136
         blurbLabel = new JLabel();
129 137
         commandPath = new JTextField();
130
-        optionType = new JComboBox(new DefaultComboBoxModel(new String[]{
131
-            "Handle internally (irc links only)",
132
-            "Use browser (or registered handler)",
133
-            "Use mail client",
134
-            "Custom command"
135
-        
136
-           
137
-           
138
-        ,
139
-        }));
138
+        optionType = new ButtonGroup();
139
+        dmdirc = new JRadioButton("Handle internally (irc links only)");
140
+        browser = new JRadioButton("Use browser (or registered handler)");
141
+        mail = new JRadioButton("Use mail client");
142
+        custom = new JRadioButton("Custom command");
140 143
         subsLabel = new JLabel();
141 144
         exampleLabel = new JLabel();
142 145
 
143
-        commandPath.setVisible(false);
144
-        showFileChooser.setVisible(false);
145
-        subsLabel.setVisible(false);
146
-        exampleLabel.setVisible(false);
146
+        commandPath.setEnabled(false);
147
+        showFileChooser.setEnabled(false);
148
+        subsLabel.setEnabled(false);
149
+        exampleLabel.setEnabled(false);
150
+
151
+        optionType.add(dmdirc);
152
+        optionType.add(browser);
153
+        optionType.add(mail);
154
+        optionType.add(custom);
147 155
 
148 156
         fileChooser.addChoosableFileFilter(new ExecutableFileFilter());
149 157
         fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
150 158
         showFileChooser.setText("Browse");
151
-        blurbLabel.setText("<html><p>Use this dialog to add support for a " +
152
-                "new protocol.</p></html>");
153
-        subsLabel.setText("<html><p>$url, $fragment, $path, $port, $query, " +
154
-                "$protocol, $username and $password all substituted.</p></html>");
159
+        blurbLabel.setText("Use this dialog to add support for a " +
160
+                "new protocol.");
161
+        subsLabel.setText("$url, $fragment, $path, $port, $query, " +
162
+                "$protocol, $username and $password all substituted.");
155 163
         updateExample();
156 164
     }
157 165
 
@@ -160,11 +168,16 @@ public class URLDialog extends StandardDialog implements ActionListener,
160 168
         setLayout(new MigLayout("fill, wrap 1, hidemode 3"));
161 169
 
162 170
         add(blurbLabel, "grow");
163
-        add(optionType, "growx");
171
+        add(dmdirc, "growx");
172
+        add(browser, "growx");
173
+        add(mail, "growx");
174
+        add(custom, "growx");
164 175
         add(commandPath, "split 2, growx, pushx");
165 176
         add(showFileChooser, "");
166 177
         add(subsLabel, "growx");
167 178
         add(exampleLabel, "growx");
179
+        add(getLeftButton(), "split 2, right");
180
+        add(getRightButton(), "right");
168 181
     }
169 182
 
170 183
     /** Adds listeners to the components. */
@@ -172,20 +185,23 @@ public class URLDialog extends StandardDialog implements ActionListener,
172 185
         getOkButton().addActionListener(this);
173 186
         getCancelButton().addActionListener(this);
174 187
         showFileChooser.addActionListener(this);
175
-        optionType.addActionListener(this);
188
+        dmdirc.addActionListener(this);
189
+        browser.addActionListener(this);
190
+        mail.addActionListener(this);
191
+        custom.addActionListener(this);
176 192
         commandPath.getDocument().addDocumentListener(this);
177 193
     }
178 194
 
179 195
     /** Saves the settings. */
180 196
     private void save() {
181 197
         final String value;
182
-        if (optionType.getSelectedIndex() == 0) {
198
+        if (optionType.getSelection() == dmdirc) {
183 199
             value = "DMDIRC";
184
-        } else if (optionType.getSelectedIndex() == 1) {
200
+        } else if (optionType.getSelection() == browser) {
185 201
             value = "BROWSER";
186
-        } else if (optionType.getSelectedIndex() == 2) {
202
+        } else if (optionType.getSelection() == mail) {
187 203
             value = "MAIL";
188
-        } else if (optionType.getSelectedIndex() == 3) {
204
+        } else if (optionType.getSelection() == custom) {
189 205
             value = commandPath.getText();
190 206
         } else {
191 207
             value = "";
@@ -212,20 +228,7 @@ public class URLDialog extends StandardDialog implements ActionListener,
212 228
      */
213 229
     @Override
214 230
     public void actionPerformed(final ActionEvent e) {
215
-        if (e.getSource() == optionType) {
216
-            if (optionType.getSelectedIndex() == 3) {
217
-                commandPath.setVisible(true);
218
-                showFileChooser.setVisible(true);
219
-                subsLabel.setVisible(true);
220
-                exampleLabel.setVisible(true);
221
-            } else {
222
-                commandPath.setVisible(false);
223
-                showFileChooser.setVisible(false);
224
-                subsLabel.setVisible(false);
225
-                exampleLabel.setVisible(false);
226
-            }
227
-            pack();
228
-        } else if (e.getSource() == getOkButton()) {
231
+        if (e.getSource() == getOkButton()) {
229 232
             save();
230 233
         } else if (e.getSource() == getCancelButton()) {
231 234
             dispose();
@@ -234,6 +237,19 @@ public class URLDialog extends StandardDialog implements ActionListener,
234 237
                     JFileChooser.APPROVE_OPTION) {
235 238
                 commandPath.setText(fileChooser.getSelectedFile().toString());
236 239
             }
240
+        } else {
241
+            if (optionType.getSelection() == custom.getModel()) {
242
+                commandPath.setEnabled(true);
243
+                showFileChooser.setEnabled(true);
244
+                subsLabel.setEnabled(true);
245
+                exampleLabel.setEnabled(true);
246
+            } else {
247
+                commandPath.setEnabled(false);
248
+                showFileChooser.setEnabled(false);
249
+                subsLabel.setEnabled(false);
250
+                exampleLabel.setEnabled(false);
251
+            }
252
+            pack();
237 253
         }
238 254
     }
239 255
 

Завантаження…
Відмінити
Зберегти