Browse Source

Issue 487: Prefs: Notification group for whois replies

git-svn-id: http://svn.dmdirc.com/trunk@2488 00569f92-eb28-0410-84fd-f71c24880f
tags/0.5.5
Gregory Holmes 16 years ago
parent
commit
a7eb16e57e

+ 47
- 4
src/com/dmdirc/ui/swing/components/SwingPreferencesPanel.java View File

@@ -46,10 +46,12 @@ import java.util.ArrayList;
46 46
 import java.util.HashMap;
47 47
 import java.util.List;
48 48
 import java.util.Map;
49
+import java.util.Map.Entry;
49 50
 import java.util.Properties;
50 51
 
51 52
 import javax.swing.BorderFactory;
52 53
 import javax.swing.Box;
54
+import javax.swing.DefaultComboBoxModel;
53 55
 import javax.swing.JButton;
54 56
 import javax.swing.JCheckBox;
55 57
 import javax.swing.JComboBox;
@@ -59,6 +61,7 @@ import javax.swing.JPanel;
59 61
 import javax.swing.JSpinner;
60 62
 import javax.swing.JTextField;
61 63
 import javax.swing.JTree;
64
+import javax.swing.ListCellRenderer;
62 65
 import javax.swing.SpinnerNumberModel;
63 66
 import javax.swing.SpringLayout;
64 67
 import javax.swing.WindowConstants;
@@ -299,8 +302,23 @@ public final class SwingPreferencesPanel extends StandardDialog implements
299 302
                 checkBoxes.put(optionName, (JCheckBox) option);
300 303
                 break;
301 304
             case COMBOBOX:
302
-                option = new JComboBox((String[]) args[0]);
303
-                ((JComboBox) option).setSelectedItem(args[1]);
305
+                if (args[0] instanceof String[]) {
306
+                    option = new JComboBox((String[]) args[0]);
307
+                    ((JComboBox) option).setSelectedItem(args[1]);
308
+                } else {
309
+                    System.out.println(args[1]);
310
+                    final DefaultComboBoxModel model = (DefaultComboBoxModel) args[0];
311
+                    option = new JComboBox(model);
312
+                    ((JComboBox) option).setRenderer((ListCellRenderer) args[3]);
313
+                    for (int i = 0; i < model.getSize(); i++) {
314
+                        final Object entry = model.getElementAt(i);
315
+                        if (((Entry) entry).getValue().equals(args[1])) {
316
+                            System.out.println("match");
317
+                            ((JComboBox) option).setSelectedItem(entry);
318
+                            break;
319
+                        }
320
+                    }
321
+                }
304 322
                 comboBoxes.put(optionName, (JComboBox) option);
305 323
                 ((JComboBox) option).setEditable((Boolean) args[2]);
306 324
                 break;
@@ -413,6 +431,26 @@ public final class SwingPreferencesPanel extends StandardDialog implements
413 431
                 OptionType.COMBOBOX, options, defaultValue, editable);
414 432
     }
415 433
     
434
+    /**
435
+     * Adds an option to the specified category.
436
+     *
437
+     * @param category category option is to be added to
438
+     * @param name config name for the option
439
+     * @param displayName displayable name for the option
440
+     * @param helpText Help text to be displayed for the option
441
+     * @param options Combo box model
442
+     * @param renderer Combo box renderer
443
+     * @param defaultValue default value
444
+     * @param editable editable combo box
445
+     */
446
+    public void addComboboxOption(final String category, final String name,
447
+            final String displayName, final String helpText,
448
+            final DefaultComboBoxModel options, final ListCellRenderer renderer,
449
+            final String defaultValue, final boolean editable) {
450
+        addComponent(categories.get(category), name, displayName, helpText,
451
+                OptionType.COMBOBOX, options, defaultValue, editable, renderer);
452
+    }
453
+    
416 454
     /** {@inheritDoc} */
417 455
     public void addSpinnerOption(final String category, final String name,
418 456
             final String displayName, final String helpText,
@@ -501,8 +539,13 @@ public final class SwingPreferencesPanel extends StandardDialog implements
501 539
         }
502 540
         for (String option : comboBoxes.keySet()) {
503 541
             if (comboBoxes.get(option).getSelectedItem() != null) {
504
-                properties.setProperty(option, (String) comboBoxes.get(option)
505
-                .getSelectedItem());
542
+                if (comboBoxes.get(option).getSelectedItem() instanceof String) {
543
+                    properties.setProperty(option, (String) comboBoxes.get(option)
544
+                    .getSelectedItem());
545
+                } else {
546
+                    properties.setProperty(option, (String) ((Entry) comboBoxes.get(option)
547
+                    .getSelectedItem()).getValue());
548
+                }
506 549
             }
507 550
         }
508 551
         for (String option : spinners.keySet()) {

+ 64
- 10
src/com/dmdirc/ui/swing/dialogs/PreferencesDialog.java View File

@@ -34,11 +34,16 @@ import com.dmdirc.themes.ThemeManager;
34 34
 import com.dmdirc.ui.interfaces.PreferencesInterface;
35 35
 import com.dmdirc.ui.swing.MainFrame;
36 36
 import com.dmdirc.ui.swing.components.SwingPreferencesPanel;
37
+import java.awt.Component;
38
+import java.util.AbstractMap.SimpleImmutableEntry;
37 39
 
38 40
 import java.util.HashMap;
39 41
 import java.util.Map;
40 42
 import java.util.Map.Entry;
41 43
 import java.util.Properties;
44
+import javax.swing.DefaultComboBoxModel;
45
+import javax.swing.DefaultListCellRenderer;
46
+import javax.swing.JList;
42 47
 import javax.swing.JOptionPane;
43 48
 
44 49
 import javax.swing.UIManager;
@@ -222,37 +227,53 @@ public final class PreferencesDialog implements PreferencesInterface, ConfigChan
222 227
     private void initNotificationsTab() {
223 228
         final String tabName = "Notifications";
224 229
         preferencesPanel.addCategory("Messages", tabName, "");
225
-        final String[] windowOptions
226
-                = new String[] {"all", "active", "server", };
230
+        final DefaultComboBoxModel windowOptions = new DefaultComboBoxModel(
231
+                new Entry[] {
232
+                    new SimpleImmutableEntry<String, String>("All", "all"),
233
+                    new SimpleImmutableEntry<String, String>("Active", "active"), 
234
+                    new SimpleImmutableEntry<String, String>("Server", "server"), 
235
+                    new SimpleImmutableEntry<String, String>("None", "none  "), });
236
+        final DefaultComboBoxModel windowOptions2 = new DefaultComboBoxModel(
237
+                new Entry[] {
238
+                    new SimpleImmutableEntry<String, String>("All", "all"),
239
+                    new SimpleImmutableEntry<String, String>("Active", "active"), 
240
+                    new SimpleImmutableEntry<String, String>("Server", "server"), 
241
+                    new SimpleImmutableEntry<String, String>("Source of command", 
242
+                            "lastcommand:whois %4$s( %4$s)"),
243
+                    new SimpleImmutableEntry<String, String>("None", "none  "), });
227 244
         
228 245
         preferencesPanel.addComboboxOption(tabName, "notifications.socketClosed",
229 246
                 "Socket closed: ", "Where to display socket closed notifications",
230
-                windowOptions,
247
+                windowOptions, new MapEntryRenderer(),
231 248
                 config.getOption("notifications", "socketClosed"), false);
232 249
         preferencesPanel.addComboboxOption(tabName, "notifications.privateNotice",
233 250
                 "Private notice: ", "Where to display private notice notifications",
234
-                windowOptions,
251
+                windowOptions, new MapEntryRenderer(),
235 252
                 config.getOption("notifications", "privateNotice"), false);
236 253
         preferencesPanel.addComboboxOption(tabName, "notifications.privateCTCP",
237 254
                 "CTCP request: ", "Where to display CTCP request notifications",
238
-                windowOptions,
255
+                windowOptions, new MapEntryRenderer(),
239 256
                 config.getOption("notifications", "privateCTCP"), false);
240 257
         preferencesPanel.addComboboxOption(tabName, "notifications.privateCTCPreply",
241 258
                 "CTCP reply: ", "Where to display CTCP reply notifications",
242
-                windowOptions,
259
+                windowOptions, new MapEntryRenderer(),
243 260
                 config.getOption("notifications", "privateCTCPreply"), false);
244 261
         preferencesPanel.addComboboxOption(tabName, "notifications.connectError",
245 262
                 "Connect error: ", "Where to display connect error notifications",
246
-                windowOptions,
263
+                windowOptions, new MapEntryRenderer(),
247 264
                 config.getOption("notifications", "connectError"), false);
248 265
         preferencesPanel.addComboboxOption(tabName, "notifications.connectRetry",
249 266
                 "Connect retry: ", "Where to display connect retry notifications",
250
-                windowOptions,
267
+                windowOptions, new MapEntryRenderer(),
251 268
                 config.getOption("notifications", "connectRetry"), false);
252 269
         preferencesPanel.addComboboxOption(tabName, "notifications.stonedServer",
253
-                "Stoned server: ", "Where to display stone server notifications",
254
-                windowOptions,
270
+                "Stoned server: ", "Where to display stoned server notifications",
271
+                windowOptions, new MapEntryRenderer(),
255 272
                 config.getOption("notifications", "stonedServer"), false);
273
+        preferencesPanel.addComboboxOption(tabName, "notifications.whois",
274
+                "Whois output: ", "Where to display whois command output",
275
+                windowOptions2, new MapEntryRenderer(),
276
+                config.getOption("notifications", "whois"), false);
256 277
     }
257 278
     
258 279
     /**
@@ -459,6 +480,7 @@ public final class PreferencesDialog implements PreferencesInterface, ConfigChan
459 480
     }
460 481
     
461 482
     /** {@inheritDoc}. */
483
+    @Override
462 484
     public void configClosed(final Properties properties) {
463 485
         final Identity identity = IdentityManager.getConfigIdentity();
464 486
         for (Map.Entry<Object, Object> entry : properties.entrySet()) {
@@ -495,11 +517,13 @@ public final class PreferencesDialog implements PreferencesInterface, ConfigChan
495 517
     
496 518
     
497 519
     /** {@inheritDoc} */
520
+    @Override
498 521
     public void configCancelled() {
499 522
         dispose();
500 523
     }
501 524
     
502 525
     /** {@inheritDoc} */
526
+    @Override
503 527
     public void configChanged(final String domain, final String key) {
504 528
         if ("ui".equals(domain) && ("lookandfeel".equals(key)
505 529
         || "framemanager".equals(key) || "framemanagerPosition".equals(key))
@@ -521,4 +545,34 @@ public final class PreferencesDialog implements PreferencesInterface, ConfigChan
521 545
             me = null;
522 546
         }
523 547
     }
548
+    
549
+    private class MapEntryRenderer extends DefaultListCellRenderer {
550
+        
551
+        /**
552
+        * A version number for this class. It should be changed whenever the class
553
+        * structure is changed (or anything else that would prevent serialized
554
+        * objects being unserialized with the new class).
555
+        */
556
+        private static final long serialVersionUID = 1;
557
+        
558
+        /** {@inheritDoc} */
559
+        @Override
560
+        public Component getListCellRendererComponent(final JList list,
561
+                final Object value, final int index, final boolean isSelected,
562
+                final boolean hasFocus) {
563
+        
564
+            super.getListCellRendererComponent(list, value, index, isSelected, hasFocus);
565
+        
566
+            if (value == null) {
567
+                setText("Any");
568
+            } else if (value instanceof Entry) {
569
+                setText((String) ((Entry) value).getKey());
570
+            } else {
571
+                setText(value.toString());
572
+            }
573
+        
574
+            return this;
575
+        }
576
+        
577
+    }
524 578
 }

Loading…
Cancel
Save