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 17 years ago
parent
commit
a7eb16e57e

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

46
 import java.util.HashMap;
46
 import java.util.HashMap;
47
 import java.util.List;
47
 import java.util.List;
48
 import java.util.Map;
48
 import java.util.Map;
49
+import java.util.Map.Entry;
49
 import java.util.Properties;
50
 import java.util.Properties;
50
 
51
 
51
 import javax.swing.BorderFactory;
52
 import javax.swing.BorderFactory;
52
 import javax.swing.Box;
53
 import javax.swing.Box;
54
+import javax.swing.DefaultComboBoxModel;
53
 import javax.swing.JButton;
55
 import javax.swing.JButton;
54
 import javax.swing.JCheckBox;
56
 import javax.swing.JCheckBox;
55
 import javax.swing.JComboBox;
57
 import javax.swing.JComboBox;
59
 import javax.swing.JSpinner;
61
 import javax.swing.JSpinner;
60
 import javax.swing.JTextField;
62
 import javax.swing.JTextField;
61
 import javax.swing.JTree;
63
 import javax.swing.JTree;
64
+import javax.swing.ListCellRenderer;
62
 import javax.swing.SpinnerNumberModel;
65
 import javax.swing.SpinnerNumberModel;
63
 import javax.swing.SpringLayout;
66
 import javax.swing.SpringLayout;
64
 import javax.swing.WindowConstants;
67
 import javax.swing.WindowConstants;
299
                 checkBoxes.put(optionName, (JCheckBox) option);
302
                 checkBoxes.put(optionName, (JCheckBox) option);
300
                 break;
303
                 break;
301
             case COMBOBOX:
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
                 comboBoxes.put(optionName, (JComboBox) option);
322
                 comboBoxes.put(optionName, (JComboBox) option);
305
                 ((JComboBox) option).setEditable((Boolean) args[2]);
323
                 ((JComboBox) option).setEditable((Boolean) args[2]);
306
                 break;
324
                 break;
413
                 OptionType.COMBOBOX, options, defaultValue, editable);
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
     /** {@inheritDoc} */
454
     /** {@inheritDoc} */
417
     public void addSpinnerOption(final String category, final String name,
455
     public void addSpinnerOption(final String category, final String name,
418
             final String displayName, final String helpText,
456
             final String displayName, final String helpText,
501
         }
539
         }
502
         for (String option : comboBoxes.keySet()) {
540
         for (String option : comboBoxes.keySet()) {
503
             if (comboBoxes.get(option).getSelectedItem() != null) {
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
         for (String option : spinners.keySet()) {
551
         for (String option : spinners.keySet()) {

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

34
 import com.dmdirc.ui.interfaces.PreferencesInterface;
34
 import com.dmdirc.ui.interfaces.PreferencesInterface;
35
 import com.dmdirc.ui.swing.MainFrame;
35
 import com.dmdirc.ui.swing.MainFrame;
36
 import com.dmdirc.ui.swing.components.SwingPreferencesPanel;
36
 import com.dmdirc.ui.swing.components.SwingPreferencesPanel;
37
+import java.awt.Component;
38
+import java.util.AbstractMap.SimpleImmutableEntry;
37
 
39
 
38
 import java.util.HashMap;
40
 import java.util.HashMap;
39
 import java.util.Map;
41
 import java.util.Map;
40
 import java.util.Map.Entry;
42
 import java.util.Map.Entry;
41
 import java.util.Properties;
43
 import java.util.Properties;
44
+import javax.swing.DefaultComboBoxModel;
45
+import javax.swing.DefaultListCellRenderer;
46
+import javax.swing.JList;
42
 import javax.swing.JOptionPane;
47
 import javax.swing.JOptionPane;
43
 
48
 
44
 import javax.swing.UIManager;
49
 import javax.swing.UIManager;
222
     private void initNotificationsTab() {
227
     private void initNotificationsTab() {
223
         final String tabName = "Notifications";
228
         final String tabName = "Notifications";
224
         preferencesPanel.addCategory("Messages", tabName, "");
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
         preferencesPanel.addComboboxOption(tabName, "notifications.socketClosed",
245
         preferencesPanel.addComboboxOption(tabName, "notifications.socketClosed",
229
                 "Socket closed: ", "Where to display socket closed notifications",
246
                 "Socket closed: ", "Where to display socket closed notifications",
230
-                windowOptions,
247
+                windowOptions, new MapEntryRenderer(),
231
                 config.getOption("notifications", "socketClosed"), false);
248
                 config.getOption("notifications", "socketClosed"), false);
232
         preferencesPanel.addComboboxOption(tabName, "notifications.privateNotice",
249
         preferencesPanel.addComboboxOption(tabName, "notifications.privateNotice",
233
                 "Private notice: ", "Where to display private notice notifications",
250
                 "Private notice: ", "Where to display private notice notifications",
234
-                windowOptions,
251
+                windowOptions, new MapEntryRenderer(),
235
                 config.getOption("notifications", "privateNotice"), false);
252
                 config.getOption("notifications", "privateNotice"), false);
236
         preferencesPanel.addComboboxOption(tabName, "notifications.privateCTCP",
253
         preferencesPanel.addComboboxOption(tabName, "notifications.privateCTCP",
237
                 "CTCP request: ", "Where to display CTCP request notifications",
254
                 "CTCP request: ", "Where to display CTCP request notifications",
238
-                windowOptions,
255
+                windowOptions, new MapEntryRenderer(),
239
                 config.getOption("notifications", "privateCTCP"), false);
256
                 config.getOption("notifications", "privateCTCP"), false);
240
         preferencesPanel.addComboboxOption(tabName, "notifications.privateCTCPreply",
257
         preferencesPanel.addComboboxOption(tabName, "notifications.privateCTCPreply",
241
                 "CTCP reply: ", "Where to display CTCP reply notifications",
258
                 "CTCP reply: ", "Where to display CTCP reply notifications",
242
-                windowOptions,
259
+                windowOptions, new MapEntryRenderer(),
243
                 config.getOption("notifications", "privateCTCPreply"), false);
260
                 config.getOption("notifications", "privateCTCPreply"), false);
244
         preferencesPanel.addComboboxOption(tabName, "notifications.connectError",
261
         preferencesPanel.addComboboxOption(tabName, "notifications.connectError",
245
                 "Connect error: ", "Where to display connect error notifications",
262
                 "Connect error: ", "Where to display connect error notifications",
246
-                windowOptions,
263
+                windowOptions, new MapEntryRenderer(),
247
                 config.getOption("notifications", "connectError"), false);
264
                 config.getOption("notifications", "connectError"), false);
248
         preferencesPanel.addComboboxOption(tabName, "notifications.connectRetry",
265
         preferencesPanel.addComboboxOption(tabName, "notifications.connectRetry",
249
                 "Connect retry: ", "Where to display connect retry notifications",
266
                 "Connect retry: ", "Where to display connect retry notifications",
250
-                windowOptions,
267
+                windowOptions, new MapEntryRenderer(),
251
                 config.getOption("notifications", "connectRetry"), false);
268
                 config.getOption("notifications", "connectRetry"), false);
252
         preferencesPanel.addComboboxOption(tabName, "notifications.stonedServer",
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
                 config.getOption("notifications", "stonedServer"), false);
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
     }
480
     }
460
     
481
     
461
     /** {@inheritDoc}. */
482
     /** {@inheritDoc}. */
483
+    @Override
462
     public void configClosed(final Properties properties) {
484
     public void configClosed(final Properties properties) {
463
         final Identity identity = IdentityManager.getConfigIdentity();
485
         final Identity identity = IdentityManager.getConfigIdentity();
464
         for (Map.Entry<Object, Object> entry : properties.entrySet()) {
486
         for (Map.Entry<Object, Object> entry : properties.entrySet()) {
495
     
517
     
496
     
518
     
497
     /** {@inheritDoc} */
519
     /** {@inheritDoc} */
520
+    @Override
498
     public void configCancelled() {
521
     public void configCancelled() {
499
         dispose();
522
         dispose();
500
     }
523
     }
501
     
524
     
502
     /** {@inheritDoc} */
525
     /** {@inheritDoc} */
526
+    @Override
503
     public void configChanged(final String domain, final String key) {
527
     public void configChanged(final String domain, final String key) {
504
         if ("ui".equals(domain) && ("lookandfeel".equals(key)
528
         if ("ui".equals(domain) && ("lookandfeel".equals(key)
505
         || "framemanager".equals(key) || "framemanagerPosition".equals(key))
529
         || "framemanager".equals(key) || "framemanagerPosition".equals(key))
521
             me = null;
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