Browse Source

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 years ago
parent
commit
5c303b88c0
1 changed files with 57 additions and 41 deletions
  1. 57
    41
      src/com/dmdirc/ui/swing/dialogs/URLDialog.java

+ 57
- 41
src/com/dmdirc/ui/swing/dialogs/URLDialog.java View File

33
 import java.awt.event.ActionListener;
33
 import java.awt.event.ActionListener;
34
 import java.net.URI;
34
 import java.net.URI;
35
 
35
 
36
-import javax.swing.DefaultComboBoxModel;
36
+import javax.swing.ButtonGroup;
37
 import javax.swing.JButton;
37
 import javax.swing.JButton;
38
-import javax.swing.JComboBox;
39
 import javax.swing.JFileChooser;
38
 import javax.swing.JFileChooser;
40
 import javax.swing.JLabel;
39
 import javax.swing.JLabel;
40
+import javax.swing.JRadioButton;
41
 import javax.swing.JTextField;
41
 import javax.swing.JTextField;
42
 import javax.swing.event.DocumentEvent;
42
 import javax.swing.event.DocumentEvent;
43
 import javax.swing.event.DocumentListener;
43
 import javax.swing.event.DocumentListener;
63
     /** Command text field. */
63
     /** Command text field. */
64
     private JTextField commandPath;
64
     private JTextField commandPath;
65
     /** Option selection. */
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
     /** Blurb label. */
75
     /** Blurb label. */
68
     private JLabel blurbLabel;
76
     private JLabel blurbLabel;
69
     /** Substitutions label */
77
     /** Substitutions label */
127
         showFileChooser = new JButton();
135
         showFileChooser = new JButton();
128
         blurbLabel = new JLabel();
136
         blurbLabel = new JLabel();
129
         commandPath = new JTextField();
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
         subsLabel = new JLabel();
143
         subsLabel = new JLabel();
141
         exampleLabel = new JLabel();
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
         fileChooser.addChoosableFileFilter(new ExecutableFileFilter());
156
         fileChooser.addChoosableFileFilter(new ExecutableFileFilter());
149
         fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
157
         fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
150
         showFileChooser.setText("Browse");
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
         updateExample();
163
         updateExample();
156
     }
164
     }
157
 
165
 
160
         setLayout(new MigLayout("fill, wrap 1, hidemode 3"));
168
         setLayout(new MigLayout("fill, wrap 1, hidemode 3"));
161
 
169
 
162
         add(blurbLabel, "grow");
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
         add(commandPath, "split 2, growx, pushx");
175
         add(commandPath, "split 2, growx, pushx");
165
         add(showFileChooser, "");
176
         add(showFileChooser, "");
166
         add(subsLabel, "growx");
177
         add(subsLabel, "growx");
167
         add(exampleLabel, "growx");
178
         add(exampleLabel, "growx");
179
+        add(getLeftButton(), "split 2, right");
180
+        add(getRightButton(), "right");
168
     }
181
     }
169
 
182
 
170
     /** Adds listeners to the components. */
183
     /** Adds listeners to the components. */
172
         getOkButton().addActionListener(this);
185
         getOkButton().addActionListener(this);
173
         getCancelButton().addActionListener(this);
186
         getCancelButton().addActionListener(this);
174
         showFileChooser.addActionListener(this);
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
         commandPath.getDocument().addDocumentListener(this);
192
         commandPath.getDocument().addDocumentListener(this);
177
     }
193
     }
178
 
194
 
179
     /** Saves the settings. */
195
     /** Saves the settings. */
180
     private void save() {
196
     private void save() {
181
         final String value;
197
         final String value;
182
-        if (optionType.getSelectedIndex() == 0) {
198
+        if (optionType.getSelection() == dmdirc) {
183
             value = "DMDIRC";
199
             value = "DMDIRC";
184
-        } else if (optionType.getSelectedIndex() == 1) {
200
+        } else if (optionType.getSelection() == browser) {
185
             value = "BROWSER";
201
             value = "BROWSER";
186
-        } else if (optionType.getSelectedIndex() == 2) {
202
+        } else if (optionType.getSelection() == mail) {
187
             value = "MAIL";
203
             value = "MAIL";
188
-        } else if (optionType.getSelectedIndex() == 3) {
204
+        } else if (optionType.getSelection() == custom) {
189
             value = commandPath.getText();
205
             value = commandPath.getText();
190
         } else {
206
         } else {
191
             value = "";
207
             value = "";
212
      */
228
      */
213
     @Override
229
     @Override
214
     public void actionPerformed(final ActionEvent e) {
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
             save();
232
             save();
230
         } else if (e.getSource() == getCancelButton()) {
233
         } else if (e.getSource() == getCancelButton()) {
231
             dispose();
234
             dispose();
234
                     JFileChooser.APPROVE_OPTION) {
237
                     JFileChooser.APPROVE_OPTION) {
235
                 commandPath.setText(fileChooser.getSelectedFile().toString());
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
 

Loading…
Cancel
Save