Browse Source

Replace lots of instances of JOptionPane with StandardDialog equivilents, more to follow

Fixes issue 3489

Change-Id: I4fa515a001ccbe1390cb8ca67b717ad16a376218
Reviewed-on: http://gerrit.dmdirc.com/698
Automatic-Compile: DMDirc Local Commits <dmdirc@googlemail.com>
Reviewed-by: Shane Mc Cormack <shane@dmdirc.com>
tags/0.6.3
Gregory Holmes 14 years ago
parent
commit
911c77041e

+ 0
- 1
src/com/dmdirc/addons/ui_swing/DMDircEventQueue.java View File

@@ -39,7 +39,6 @@ import java.awt.event.KeyEvent;
39 39
 import java.awt.event.MouseEvent;
40 40
 
41 41
 import java.awt.event.WindowEvent;
42
-import java.util.concurrent.atomic.AtomicReference;
43 42
 import javax.swing.JPopupMenu;
44 43
 import javax.swing.KeyStroke;
45 44
 import javax.swing.MenuSelectionManager;

+ 47
- 17
src/com/dmdirc/addons/ui_swing/MainFrame.java View File

@@ -33,6 +33,7 @@ import com.dmdirc.Main;
33 33
 import com.dmdirc.ServerManager;
34 34
 import com.dmdirc.actions.ActionManager;
35 35
 import com.dmdirc.actions.CoreActionType;
36
+import com.dmdirc.addons.ui_swing.dialogs.StandardQuestionDialog;
36 37
 import com.dmdirc.config.IdentityManager;
37 38
 import com.dmdirc.interfaces.ConfigChangeListener;
38 39
 import com.dmdirc.ui.IconManager;
@@ -44,6 +45,7 @@ import com.dmdirc.ui.interfaces.Window;
44 45
 import com.dmdirc.ui.CoreUIUtils;
45 46
 import com.dmdirc.ui.interfaces.FrameListener;
46 47
 import com.dmdirc.util.ReturnableThread;
48
+import java.awt.Dialog.ModalityType;
47 49
 
48 50
 import java.awt.Dimension;
49 51
 import java.awt.event.WindowEvent;
@@ -54,7 +56,6 @@ import javax.swing.ImageIcon;
54 56
 import javax.swing.JDesktopPane;
55 57
 import javax.swing.JFrame;
56 58
 import javax.swing.JInternalFrame;
57
-import javax.swing.JOptionPane;
58 59
 import javax.swing.JPanel;
59 60
 import javax.swing.JSplitPane;
60 61
 import javax.swing.MenuSelectionManager;
@@ -125,7 +126,7 @@ public final class MainFrame extends JFrame implements WindowListener,
125 126
         showVersion = IdentityManager.getGlobalConfig().getOptionBool("ui",
126 127
                 "showversion");
127 128
         version = IdentityManager.getGlobalConfig().getOption("version",
128
-                    "version");
129
+                "version");
129 130
         IdentityManager.getGlobalConfig().addChangeListener("ui", "lookandfeel",
130 131
                 this);
131 132
         IdentityManager.getGlobalConfig().addChangeListener("ui", "showversion",
@@ -175,8 +176,8 @@ public final class MainFrame extends JFrame implements WindowListener,
175 176
             /** {@inheritDoc} */
176 177
             @Override
177 178
             public void run() {
178
-                if (position == FramemanagerPosition.LEFT ||
179
-                        position == FramemanagerPosition.RIGHT) {
179
+                if (position == FramemanagerPosition.LEFT || position
180
+                        == FramemanagerPosition.RIGHT) {
180 181
                     setObject(frameManagerPanel.getWidth());
181 182
                 } else {
182 183
                     setObject(frameManagerPanel.getHeight());
@@ -223,7 +224,8 @@ public final class MainFrame extends JFrame implements WindowListener,
223 224
     /** {@inheritDoc}. */
224 225
     @Override
225 226
     public void setTitle(final String title) {
226
-        if (title != null && getActiveFrame() != null && getActiveFrame().isMaximum()) {
227
+        if (title != null && getActiveFrame() != null && getActiveFrame().
228
+                isMaximum()) {
227 229
             super.setTitle(getTitlePrefix() + " - " + title);
228 230
         } else {
229 231
             super.setTitle(getTitlePrefix());
@@ -311,7 +313,7 @@ public final class MainFrame extends JFrame implements WindowListener,
311 313
      */
312 314
     @Override
313 315
     public void windowIconified(final WindowEvent windowEvent) {
314
-            ActionManager.processEvent(CoreActionType.CLIENT_MINIMISED, null);
316
+        ActionManager.processEvent(CoreActionType.CLIENT_MINIMISED, null);
315 317
     }
316 318
 
317 319
     /** 
@@ -416,14 +418,14 @@ public final class MainFrame extends JFrame implements WindowListener,
416 418
             position = FramemanagerPosition.LEFT;
417 419
         }
418 420
 
419
-        if (!mainFrameManager.canPositionVertically() &&
420
-                (position == FramemanagerPosition.LEFT ||
421
-                position == FramemanagerPosition.RIGHT)) {
421
+        if (!mainFrameManager.canPositionVertically() && (position
422
+                == FramemanagerPosition.LEFT || position
423
+                == FramemanagerPosition.RIGHT)) {
422 424
             position = FramemanagerPosition.BOTTOM;
423 425
         }
424
-        if (!mainFrameManager.canPositionHorizontally() &&
425
-                (position == FramemanagerPosition.TOP ||
426
-                position == FramemanagerPosition.BOTTOM)) {
426
+        if (!mainFrameManager.canPositionHorizontally() && (position
427
+                == FramemanagerPosition.TOP || position
428
+                == FramemanagerPosition.BOTTOM)) {
427 429
             position = FramemanagerPosition.LEFT;
428 430
         }
429 431
 
@@ -486,14 +488,42 @@ public final class MainFrame extends JFrame implements WindowListener,
486 488
      */
487 489
     public void quit(final int exitCode) {
488 490
         if (exitCode == 0 && IdentityManager.getGlobalConfig().getOptionBool(
489
-                "ui", "confirmQuit") && JOptionPane.showConfirmDialog(this,
490
-                "You are about to quit DMDirc, are you sure?", "Quit confirm",
491
-                JOptionPane.YES_NO_OPTION,
492
-                JOptionPane.WARNING_MESSAGE) !=
493
-                JOptionPane.YES_OPTION) {
491
+                "ui", "confirmQuit")) {
492
+            new StandardQuestionDialog(this, ModalityType.APPLICATION_MODAL,
493
+                    "Quit confirm",
494
+                    "You are about to quit DMDirc, are you sure?") {
495
+
496
+                /**
497
+                 * A version number for this class. It should be changed whenever the class
498
+                 * structure is changed (or anything else that would prevent serialized
499
+                 * objects being unserialized with the new class).
500
+                 */
501
+                private static final long serialVersionUID = 1;
502
+
503
+                /** {@inheritDoc} */
504
+                @Override
505
+                public boolean save() {
506
+                    doQuit(exitCode);
507
+                    return true;
508
+                }
509
+
510
+                /** {@inheritDoc} */
511
+                @Override
512
+                public void cancelled() {
513
+                    return;
514
+                }
515
+            }.display();
494 516
             return;
495 517
         }
518
+        doQuit(exitCode);
519
+    }
496 520
 
521
+    /**
522
+     * Exit code call to quit.
523
+     *
524
+     * @param exitCode Exit code
525
+     */
526
+    private void doQuit(final int exitCode) {
497 527
         this.exitCode = exitCode;
498 528
 
499 529
         new LoggingSwingWorker() {

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

@@ -131,7 +131,7 @@ public abstract class StandardQuestionDialog extends StandardDialog {
131 131
      * Lays out the components.
132 132
      */
133 133
     private final void layoutComponents() {
134
-        setLayout(new MigLayout("fill, wrap 1"));
134
+        setLayout(new MigLayout("fill, wrap 1, hidemode 3"));
135 135
 
136 136
         add(blurb, "growx");
137 137
         add(getLeftButton(), "split 2, right");

+ 0
- 1
src/com/dmdirc/addons/ui_swing/dialogs/actioneditor/ActionEditorDialog.java View File

@@ -24,7 +24,6 @@ package com.dmdirc.addons.ui_swing.dialogs.actioneditor;
24 24
 
25 25
 import com.dmdirc.actions.Action;
26 26
 import com.dmdirc.addons.ui_swing.dialogs.StandardDialog;
27
-import com.dmdirc.ui.CoreUIUtils;
28 27
 
29 28
 import java.awt.Dimension;
30 29
 import java.awt.Window;

+ 33
- 11
src/com/dmdirc/addons/ui_swing/dialogs/actionsmanager/ActionsGroupPanel.java View File

@@ -28,7 +28,9 @@ import com.dmdirc.actions.ActionManager;
28 28
 import com.dmdirc.addons.ui_swing.components.PackingTable;
29 29
 import com.dmdirc.addons.ui_swing.components.renderers.ActionTypeTableCellRenderer;
30 30
 import com.dmdirc.addons.ui_swing.components.renderers.ArrayCellRenderer;
31
+import com.dmdirc.addons.ui_swing.dialogs.StandardQuestionDialog;
31 32
 import com.dmdirc.addons.ui_swing.dialogs.actioneditor.ActionEditorDialog;
33
+import java.awt.Dialog.ModalityType;
32 34
 
33 35
 import java.awt.Window;
34 36
 import java.awt.event.ActionEvent;
@@ -38,7 +40,6 @@ import java.awt.event.MouseEvent;
38 40
 import java.util.ArrayList;
39 41
 
40 42
 import javax.swing.JButton;
41
-import javax.swing.JOptionPane;
42 43
 import javax.swing.JPanel;
43 44
 import javax.swing.JScrollPane;
44 45
 import javax.swing.ListSelectionModel;
@@ -129,7 +130,8 @@ public final class ActionsGroupPanel extends JPanel implements ActionListener,
129 130
      */
130 131
     private void initComponents() {
131 132
         scrollPane = new JScrollPane();
132
-        model = new ActionTableModel(group == null ? new ArrayList<Action>() : group.getActions());
133
+        model = new ActionTableModel(group == null ? new ArrayList<Action>() : group.
134
+                getActions());
133 135
         table = new PackingTable(model, false, scrollPane, false) {
134 136
 
135 137
             /**
@@ -234,18 +236,38 @@ public final class ActionsGroupPanel extends JPanel implements ActionListener,
234 236
         } else if (e.getSource() == edit) {
235 237
             ActionEditorDialog.showActionEditorDialog(parent, group.getName(),
236 238
                     model.getAction(
237
-                    table.getRowSorter().convertRowIndexToModel(table.getSelectedRow())));
239
+                    table.getRowSorter().convertRowIndexToModel(table.
240
+                    getSelectedRow())));
238 241
         } else if (e.getSource() == delete) {
239 242
             final Action action =
240 243
                     model.getAction(
241
-                    table.getRowSorter().convertRowIndexToModel(table.getSelectedRow()));
242
-            final int response = JOptionPane.showConfirmDialog(this,
243
-                    "Are you sure you wish to delete the action '" +
244
-                    action.getName() + "'?",
245
-                    "Confirm deletion", JOptionPane.YES_NO_OPTION);
246
-            if (response == JOptionPane.YES_OPTION) {
247
-                ActionManager.deleteAction(action);
248
-            }
244
+                    table.getRowSorter().convertRowIndexToModel(table.
245
+                    getSelectedRow()));
246
+            new StandardQuestionDialog(parent, ModalityType.APPLICATION_MODAL,
247
+                    "Confirm deletion",
248
+                    "Are you sure you wish to delete the action '" + action.
249
+                    getName() + "'?") {
250
+
251
+                /**
252
+                 * A version number for this class. It should be changed whenever the class
253
+                 * structure is changed (or anything else that would prevent serialized
254
+                 * objects being unserialized with the new class).
255
+                 */
256
+                private static final long serialVersionUID = 1;
257
+
258
+                /** {@inheritDoc} */
259
+                @Override
260
+                public boolean save() {
261
+                    ActionManager.deleteAction(action);
262
+                    return true;
263
+                }
264
+
265
+                /** {@inheritDoc} */
266
+                @Override
267
+                public void cancelled() {
268
+                    return;
269
+                }
270
+            }.display();
249 271
         }
250 272
     }
251 273
 

+ 37
- 31
src/com/dmdirc/addons/ui_swing/dialogs/actionsmanager/ActionsManagerDialog.java View File

@@ -41,7 +41,7 @@ import com.dmdirc.addons.ui_swing.components.SortedListModel;
41 41
 import com.dmdirc.addons.ui_swing.dialogs.StandardDialog;
42 42
 import com.dmdirc.addons.ui_swing.dialogs.StandardInputDialog;
43 43
 import com.dmdirc.addons.ui_swing.components.renderers.ActionGroupListCellRenderer;
44
-import com.dmdirc.addons.ui_swing.dialogs.actioneditor.ActionEditorDialog;
44
+import com.dmdirc.addons.ui_swing.dialogs.StandardQuestionDialog;
45 45
 
46 46
 import java.awt.Window;
47 47
 import java.awt.event.ActionEvent;
@@ -54,7 +54,6 @@ import javax.swing.BorderFactory;
54 54
 import javax.swing.DefaultListModel;
55 55
 import javax.swing.JButton;
56 56
 import javax.swing.JList;
57
-import javax.swing.JOptionPane;
58 57
 import javax.swing.JPanel;
59 58
 import javax.swing.JScrollPane;
60 59
 import javax.swing.ListSelectionModel;
@@ -323,18 +322,6 @@ public final class ActionsManagerDialog extends StandardDialog implements
323 322
         } else if (e.getSource() == getOkButton() || e.getSource()
324 323
                 == getCancelButton()) {
325 324
             if (!saving.getAndSet(true)) {
326
-                if (ActionEditorDialog.isOpen()) {
327
-                    if (JOptionPane.showConfirmDialog(this,
328
-                            "The action editor is currently open, do you want to cotinue and lose any unsaved changes?",
329
-                            "Confirm close?", JOptionPane.YES_NO_OPTION,
330
-                            JOptionPane.QUESTION_MESSAGE)
331
-                            == JOptionPane.YES_OPTION) {
332
-                        ActionEditorDialog.getActionEditorDialog(this, "").
333
-                                dispose();
334
-                    } else {
335
-                        return;
336
-                    }
337
-                }
338 325
                 for (ActionGroupSettingsPanel loopSettings : settings.values()) {
339 326
                     loopSettings.save();
340 327
                 }
@@ -442,25 +429,44 @@ public final class ActionsManagerDialog extends StandardDialog implements
442 429
     private void delGroup() {
443 430
         final String group =
444 431
                 ((ActionGroup) groups.getSelectedValue()).getName();
445
-        final int response = JOptionPane.showConfirmDialog(this,
432
+        new StandardQuestionDialog(this,
433
+                ModalityType.APPLICATION_MODAL,
434
+                "Confirm deletion",
446 435
                 "Are you sure you wish to delete the '" + group
447
-                + "' group and all actions within it?",
448
-                "Confirm deletion", JOptionPane.YES_NO_OPTION);
449
-        if (response == JOptionPane.YES_OPTION) {
450
-            int location =
451
-                    ((DefaultListModel) groups.getModel()).indexOf(
452
-                    ActionManager.getGroup(group));
453
-            ActionManager.removeGroup(group);
454
-            reloadGroups();
455
-            if (groups.getModel().getSize() == 0) {
456
-                location = -1;
457
-            } else if (location >= groups.getModel().getSize()) {
458
-                location = groups.getModel().getSize();
459
-            } else if (location <= 0) {
460
-                location = 0;
436
+                + "' group and all actions within it?") {
437
+
438
+            /**
439
+             * A version number for this class. It should be changed whenever the class
440
+             * structure is changed (or anything else that would prevent serialized
441
+             * objects being unserialized with the new class).
442
+             */
443
+            private static final long serialVersionUID = 1;
444
+
445
+            /** {@inheritDoc} */
446
+            @Override
447
+            public boolean save() {
448
+                int location =
449
+                        ((DefaultListModel) groups.getModel()).indexOf(
450
+                        ActionManager.getGroup(group));
451
+                ActionManager.removeGroup(group);
452
+                reloadGroups();
453
+                if (groups.getModel().getSize() == 0) {
454
+                    location = -1;
455
+                } else if (location >= groups.getModel().getSize()) {
456
+                    location = groups.getModel().getSize();
457
+                } else if (location <= 0) {
458
+                    location = 0;
459
+                }
460
+                groups.setSelectedIndex(location);
461
+                return true;
461 462
             }
462
-            groups.setSelectedIndex(location);
463
-        }
463
+
464
+            /** {@inheritDoc} */
465
+            @Override
466
+            public void cancelled() {
467
+                return;
468
+            }
469
+        }.display();
464 470
     }
465 471
 
466 472
     /** {@inheritDoc} */

+ 40
- 12
src/com/dmdirc/addons/ui_swing/dialogs/aliases/AliasManagerDialog.java View File

@@ -32,6 +32,7 @@ import com.dmdirc.actions.CoreActionComparison;
32 32
 import com.dmdirc.actions.wrappers.AliasWrapper;
33 33
 import com.dmdirc.addons.ui_swing.components.PackingTable;
34 34
 import com.dmdirc.addons.ui_swing.dialogs.StandardDialog;
35
+import com.dmdirc.addons.ui_swing.dialogs.StandardQuestionDialog;
35 36
 
36 37
 import java.awt.Dimension;
37 38
 import java.awt.Window;
@@ -42,7 +43,6 @@ import java.util.Arrays;
42 43
 import java.util.List;
43 44
 
44 45
 import javax.swing.JButton;
45
-import javax.swing.JOptionPane;
46 46
 import javax.swing.JScrollPane;
47 47
 import javax.swing.JSplitPane;
48 48
 import javax.swing.JTable;
@@ -123,7 +123,8 @@ public final class AliasManagerDialog extends StandardDialog implements
123 123
      *
124 124
      * @return Instance of AliasManagerDialog
125 125
      */
126
-    public static AliasManagerDialog getAliasManagerDialog(final Window parentWindow) {
126
+    public static AliasManagerDialog getAliasManagerDialog(
127
+            final Window parentWindow) {
127 128
         synchronized (AliasManagerDialog.class) {
128 129
             if (me == null) {
129 130
                 me = new AliasManagerDialog(parentWindow);
@@ -254,7 +255,8 @@ public final class AliasManagerDialog extends StandardDialog implements
254 255
     public void valueChanged(final ListSelectionEvent e) {
255 256
         if (!e.getValueIsAdjusting()) {
256 257
 
257
-            if (selectedRow > -1 && selectedRow < tableModel.getRowCount() && aliasDetails.getAlias() == tableModel.getAlias(
258
+            if (selectedRow > -1 && selectedRow < tableModel.getRowCount() && aliasDetails.
259
+                    getAlias() == tableModel.getAlias(
258 260
                     table.getRowSorter().convertRowIndexToModel(selectedRow))) {
259 261
                 updateAlias();
260 262
             }
@@ -301,10 +303,34 @@ public final class AliasManagerDialog extends StandardDialog implements
301 303
                 updateAlias();
302 304
             }
303 305
             if (checkForDuplicates()) {
304
-                JOptionPane.showMessageDialog(this,
305
-                        "There are duplicate aliases in the table, these need " +
306
-                        "to be removed before saving", "Duplicates",
307
-                        JOptionPane.WARNING_MESSAGE);
306
+                final StandardQuestionDialog dialog = new StandardQuestionDialog(
307
+                        this, ModalityType.APPLICATION_MODAL,
308
+                        "Duplicate Aliases",
309
+                        "There are duplicate aliases in the table, these need "
310
+                        + "to be removed before saving") {
311
+
312
+                    /**
313
+                     * A version number for this class. It should be changed whenever the class
314
+                     * structure is changed (or anything else that would prevent serialized
315
+                     * objects being unserialized with the new class).
316
+                     */
317
+                    private static final long serialVersionUID = 1;
318
+
319
+                    /** {@inheritDoc} */
320
+                    @Override
321
+                    public boolean save() {
322
+                        return true;
323
+                    }
324
+
325
+                    /** {@inheritDoc} */
326
+                    @Override
327
+                    public void cancelled() {
328
+                        return;
329
+                    }
330
+                };
331
+                dialog.getOkButton().setVisible(false);
332
+                dialog.getCancelButton().setText("OK");
333
+                dialog.display();
308 334
                 return;
309 335
             }
310 336
             save();
@@ -355,9 +381,10 @@ public final class AliasManagerDialog extends StandardDialog implements
355 381
             if (action == null) {
356 382
                 newAliases.add(alias);
357 383
             } else {
358
-                if (!action.getName().equals(alias.getName()) || !action.getConditions().
359
-                        equals(alias.getArguments()) ||
360
-                        !Arrays.equals(action.getResponse(), alias.getResponse())) {
384
+                if (!action.getName().equals(alias.getName()) || !action.
385
+                        getConditions().
386
+                        equals(alias.getArguments()) || !Arrays.equals(action.
387
+                        getResponse(), alias.getResponse())) {
361 388
                     modifiedAliases.add(alias);
362 389
                 }
363 390
                 actions.remove(action);
@@ -416,7 +443,8 @@ public final class AliasManagerDialog extends StandardDialog implements
416 443
         Action action = null;
417 444
 
418 445
         for (Action loopAction : actions) {
419
-            if (loopAction.getName().equals(alias.getName()) && loopAction.getConditions().
446
+            if (loopAction.getName().equals(alias.getName()) && loopAction.
447
+                    getConditions().
420 448
                     equals(alias.getArguments())) {
421 449
                 action = loopAction;
422 450
                 break;
@@ -450,7 +478,7 @@ public final class AliasManagerDialog extends StandardDialog implements
450 478
 
451 479
         return false;
452 480
     }
453
-    
481
+
454 482
     /** {@inheritDoc} */
455 483
     @Override
456 484
     public void dispose() {

+ 52
- 21
src/com/dmdirc/addons/ui_swing/dialogs/channelsetting/ChannelListModesPane.java View File

@@ -26,10 +26,14 @@ import com.dmdirc.addons.ui_swing.components.renderers.ListModeCellRenderer;
26 26
 import com.dmdirc.addons.ui_swing.components.renderers.ExtendedListModeCellRenderer;
27 27
 import com.dmdirc.addons.ui_swing.UIUtilities;
28 28
 import com.dmdirc.Channel;
29
+import com.dmdirc.addons.ui_swing.dialogs.StandardInputDialog;
29 30
 import com.dmdirc.config.IdentityManager;
31
+import com.dmdirc.config.prefs.validator.NotEmptyValidator;
30 32
 import com.dmdirc.interfaces.ConfigChangeListener;
31 33
 import com.dmdirc.parser.common.ChannelListModeItem;
32 34
 import com.dmdirc.util.MapList;
35
+import java.awt.Dialog.ModalityType;
36
+import java.awt.Window;
33 37
 
34 38
 import java.awt.event.ActionEvent;
35 39
 import java.awt.event.ActionListener;
@@ -48,7 +52,6 @@ import javax.swing.JCheckBox;
48 52
 import javax.swing.JComboBox;
49 53
 import javax.swing.JLabel;
50 54
 import javax.swing.JList;
51
-import javax.swing.JOptionPane;
52 55
 import javax.swing.JPanel;
53 56
 import javax.swing.JScrollPane;
54 57
 import javax.swing.ListCellRenderer;
@@ -89,17 +92,21 @@ public final class ChannelListModesPane extends JPanel implements ActionListener
89 92
     private ListCellRenderer renderer;
90 93
     /** Extended info toggle. */
91 94
     private final JCheckBox toggle;
95
+    /** Parent window. */
96
+    private Window parentWindow;
92 97
 
93 98
     /**
94 99
      * Creates a new instance of ChannelListModePane.
95 100
      *
96 101
      * @param channel Parent channel
102
+     * @param parentWindow Parent window
97 103
      */
98
-    public ChannelListModesPane(final Channel channel) {
104
+    public ChannelListModesPane(final Channel channel, final Window parentWindow) {
99 105
         super();
100 106
 
101 107
         this.setOpaque(UIUtilities.getTabbedPaneOpaque());
102 108
         this.channel = channel;
109
+        this.parentWindow = parentWindow;
103 110
 
104 111
         if (IdentityManager.getGlobalConfig().getOptionBool("general",
105 112
                 "extendedListModes")) {
@@ -110,7 +117,8 @@ public final class ChannelListModesPane extends JPanel implements ActionListener
110 117
         listModesPanel = new JScrollPane();
111 118
         listModesPanels = new ArrayList<JList>();
112 119
         listModesArray =
113
-                channel.getServer().getParser().getListChannelModes().toCharArray();
120
+                channel.getServer().getParser().getListChannelModes().
121
+                toCharArray();
114 122
         existingListItems =
115 123
                 new MapList<Character, ChannelListModeItem>();
116 124
         listModesMenu =
@@ -165,9 +173,10 @@ public final class ChannelListModesPane extends JPanel implements ActionListener
165 173
                 (DefaultComboBoxModel) listModesMenu.getModel();
166 174
         for (char mode : listModesArray) {
167 175
             String modeText = mode + " list";
168
-            if (channel.getConfigManager().hasOptionString("server", "mode" + mode)) {
176
+            if (channel.getConfigManager().hasOptionString("server", "mode"
177
+                    + mode)) {
169 178
                 modeText = channel.getConfigManager().getOption("server",
170
-                        "mode" + mode) + " list [+"+mode+"]";
179
+                        "mode" + mode) + " list [+" + mode + "]";
171 180
             }
172 181
             model.addElement(modeText);
173 182
 
@@ -227,7 +236,8 @@ public final class ChannelListModesPane extends JPanel implements ActionListener
227 236
                 i++) {
228 237
             final char mode = listModesArray[i];
229 238
             final Enumeration<?> values =
230
-                    ((DefaultListModel) listModesPanels.get(i).getModel()).elements();
239
+                    ((DefaultListModel) listModesPanels.get(i).getModel()).
240
+                    elements();
231 241
             final List<ChannelListModeItem> listItems =
232 242
                     existingListItems.get(mode);
233 243
 
@@ -252,7 +262,8 @@ public final class ChannelListModesPane extends JPanel implements ActionListener
252 262
             }
253 263
         }
254 264
 
255
-        for (Entry<ChannelListModeItem, Character> entry : currentModes.entrySet()) {
265
+        for (Entry<ChannelListModeItem, Character> entry :
266
+                currentModes.entrySet()) {
256 267
             channel.getChannelInfo().
257 268
                     alterMode(false, entry.getValue(), entry.getKey().getItem());
258 269
         }
@@ -267,22 +278,41 @@ public final class ChannelListModesPane extends JPanel implements ActionListener
267 278
     private void addListMode() {
268 279
         final int selectedIndex = listModesMenu.getSelectedIndex();
269 280
         String modeText = String.valueOf(listModesArray[selectedIndex]);
270
-        String modeMask;
271 281
         if (channel.getConfigManager().hasOptionString("server", "mode"
272 282
                 + listModesArray[selectedIndex])) {
273 283
             modeText = channel.getConfigManager().
274 284
                     getOption("server", "mode" + listModesArray[selectedIndex]);
275 285
         }
276
-        modeMask = JOptionPane.showInputDialog(listModesPanel,
277
-                "Please enter the hostmask for the new " + modeText);
278
-        if (modeMask != null && (!modeMask.isEmpty() || !modeMask.isEmpty())) {
279
-            final DefaultListModel model =
280
-                    (DefaultListModel) listModesPanels.get(selectedIndex).
281
-                    getModel();
282
-            model.addElement(new ChannelListModeItem(modeMask, "",
283
-                    System.currentTimeMillis() / 1000));
284
-        }
285
-        updateModeCount();
286
+        new StandardInputDialog(parentWindow, ModalityType.DOCUMENT_MODAL,
287
+                "Add new " + modeText,
288
+                "Please enter the hostmask for the new " + modeText,
289
+                new NotEmptyValidator()) {
290
+
291
+            /**
292
+             * A version number for this class. It should be changed whenever the class
293
+             * structure is changed (or anything else that would prevent serialized
294
+             * objects being unserialized with the new class).
295
+             */
296
+            private static final long serialVersionUID = 1;
297
+
298
+            /** {@inheritDoc} */
299
+            @Override
300
+            public boolean save() {
301
+                final DefaultListModel model =
302
+                        (DefaultListModel) listModesPanels.get(selectedIndex).
303
+                        getModel();
304
+                model.addElement(new ChannelListModeItem(getText(), "",
305
+                        System.currentTimeMillis() / 1000));
306
+                updateModeCount();
307
+                return true;
308
+            }
309
+
310
+            /** {@inheritDoc} */
311
+            @Override
312
+            public void cancelled() {
313
+                return;
314
+            }
315
+        }.display();
286 316
     }
287 317
 
288 318
     /** Removes a list mode. */
@@ -348,14 +378,15 @@ public final class ChannelListModesPane extends JPanel implements ActionListener
348 378
             modeCount.setText(null);
349 379
             return;
350 380
         }
351
-        
381
+
352 382
         final int selected = listModesMenu.getSelectedIndex();
353 383
         final int current = listModesPanels.get(selected).getModel().getSize();
354 384
         final int maxModes = channel.getServer().getParser().
355 385
                 getMaxListModes(listModesArray[selected]);
356
-        
386
+
357 387
         if (maxModes == -1) {
358
-            modeCount.setText(current + " mode" + (current == 1 ? "" : "s") + " set");
388
+            modeCount.setText(current + " mode" + (current == 1 ? "" : "s")
389
+                    + " set");
359 390
         } else {
360 391
             modeCount.setText(current + " mode" + (current == 1 ? "" : "s")
361 392
                     + " set (maximum of " + maxModes + ")");

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

@@ -170,7 +170,7 @@ public final class ChannelSettingsDialog extends StandardDialog implements
170 170
 
171 171
     /** Initialises the IRC Settings tab. */
172 172
     private void initListModesTab() {
173
-        channelListModesPane = new ChannelListModesPane(channel);
173
+        channelListModesPane = new ChannelListModesPane(channel, this);
174 174
         tabbedPane.addTab("List Modes", channelListModesPane);
175 175
     }
176 176
 

+ 32
- 6
src/com/dmdirc/addons/ui_swing/dialogs/profiles/ProfileDetailPanel.java View File

@@ -31,10 +31,12 @@ import com.dmdirc.config.prefs.validator.ValidationResponse;
31 31
 import com.dmdirc.addons.ui_swing.dialogs.StandardInputDialog;
32 32
 import com.dmdirc.addons.ui_swing.components.reorderablelist.ReorderableJList;
33 33
 import com.dmdirc.addons.ui_swing.components.validating.ValidatingJTextField;
34
+import com.dmdirc.addons.ui_swing.dialogs.StandardQuestionDialog;
34 35
 import com.dmdirc.config.prefs.validator.ValidatorChain;
35 36
 
36 37
 import java.awt.Color;
37 38
 import java.awt.Dialog.ModalityType;
39
+import java.awt.Window;
38 40
 import java.awt.event.ActionEvent;
39 41
 import java.awt.event.ActionListener;
40 42
 import java.util.ArrayList;
@@ -93,18 +95,22 @@ public final class ProfileDetailPanel extends JPanel implements ActionListener,
93 95
     private Border passBorder;
94 96
     /** Validation failed border. */
95 97
     private Border failBorder;
98
+    /** Parent window. */
99
+    private Window parentWindow;
96 100
 
97 101
     /**
98 102
      * Creates a new profile detail panel.
99 103
      * 
100 104
      * @param model The list model to use to validate names
101 105
      * @param mainFrame Main frame
106
+     * @param parentWindow Parent window
102 107
      */
103 108
     @SuppressWarnings("unchecked")
104 109
     public ProfileDetailPanel(final ProfileListModel model,
105
-            final MainFrame mainFrame) {
110
+            final MainFrame mainFrame, final Window parentWindow) {
106 111
         super();
107 112
         this.mainFrame = mainFrame;
113
+        this.parentWindow = parentWindow;
108 114
 
109 115
         this.model = model;
110 116
         this.nicknameModel = new DefaultListModel();
@@ -309,11 +315,31 @@ public final class ProfileDetailPanel extends JPanel implements ActionListener,
309 315
             };
310 316
             dialog.setText((String) nicknames.getSelectedValue());
311 317
             dialog.display();
312
-        } else if (e.getSource() == delButton && JOptionPane.showConfirmDialog(this,
313
-                "Are you sure you want to delete this nickname?",
314
-                "Delete Confirmaton", JOptionPane.YES_NO_OPTION) ==
315
-                JOptionPane.YES_OPTION) {
316
-            nicknames.getModel().removeElementAt(nicknames.getSelectedIndex());
318
+        } else if (e.getSource() == delButton) {
319
+            new StandardQuestionDialog(parentWindow, ModalityType.DOCUMENT_MODAL,
320
+                    "Delete Confirmaton",
321
+                    "Are you sure you want to delete this nickname?") {
322
+
323
+                /**
324
+                 * A version number for this class. It should be changed whenever the class
325
+                 * structure is changed (or anything else that would prevent serialized
326
+                 * objects being unserialized with the new class).
327
+                 */
328
+                private static final long serialVersionUID = 1;
329
+
330
+                /** {@inheritDoc} */
331
+                @Override
332
+                public boolean save() {
333
+                    nicknames.getModel().removeElementAt(nicknames.getSelectedIndex());
334
+                    return true;
335
+                }
336
+
337
+                /** {@inheritDoc} */
338
+                @Override
339
+                public void cancelled() {
340
+                    return;
341
+                }
342
+            }.display();
317 343
         }
318 344
     }
319 345
 

+ 48
- 25
src/com/dmdirc/addons/ui_swing/dialogs/profiles/ProfileManagerDialog.java View File

@@ -28,6 +28,7 @@ import com.dmdirc.addons.ui_swing.dialogs.StandardDialog;
28 28
 import com.dmdirc.addons.ui_swing.components.renderers.ProfileListCellRenderer;
29 29
 import com.dmdirc.addons.ui_swing.components.text.TextLabel;
30 30
 import com.dmdirc.addons.ui_swing.dialogs.NewServerDialog;
31
+import com.dmdirc.addons.ui_swing.dialogs.StandardQuestionDialog;
31 32
 import com.dmdirc.config.Identity;
32 33
 import com.dmdirc.config.IdentityManager;
33 34
 
@@ -40,7 +41,6 @@ import java.util.List;
40 41
 
41 42
 import javax.swing.JButton;
42 43
 import javax.swing.JList;
43
-import javax.swing.JOptionPane;
44 44
 import javax.swing.JScrollPane;
45 45
 import javax.swing.ListSelectionModel;
46 46
 import javax.swing.WindowConstants;
@@ -50,7 +50,8 @@ import javax.swing.event.ListSelectionListener;
50 50
 import net.miginfocom.swing.MigLayout;
51 51
 
52 52
 /** Profile editing dialog. */
53
-public final class ProfileManagerDialog extends StandardDialog implements ActionListener,
53
+public final class ProfileManagerDialog extends StandardDialog implements
54
+        ActionListener,
54 55
         ListSelectionListener {
55 56
 
56 57
     /**
@@ -102,7 +103,7 @@ public final class ProfileManagerDialog extends StandardDialog implements Action
102 103
             selectedIndex = -1;
103 104
         }
104 105
     }
105
-    
106
+
106 107
     /** 
107 108
      * Creates the dialog if one doesn't exist, and displays it. 
108 109
      * 
@@ -122,7 +123,8 @@ public final class ProfileManagerDialog extends StandardDialog implements Action
122 123
      *
123 124
      * @return The current ProfileManagerDialog instance
124 125
      */
125
-    public static ProfileManagerDialog getProfileManagerDialog(final MainFrame mainFrame) {
126
+    public static ProfileManagerDialog getProfileManagerDialog(
127
+            final MainFrame mainFrame) {
126 128
         synchronized (ProfileManagerDialog.class) {
127 129
             if (me == null) {
128 130
                 me = new ProfileManagerDialog(mainFrame);
@@ -142,13 +144,13 @@ public final class ProfileManagerDialog extends StandardDialog implements Action
142 144
 
143 145
         model = new ProfileListModel();
144 146
         profileList = new JList(model);
145
-        details = new ProfileDetailPanel(model, mainFrame);
147
+        details = new ProfileDetailPanel(model, mainFrame, this);
146 148
         addButton = new JButton("Add");
147 149
         deleteButton = new JButton("Delete");
148 150
         infoLabel =
149
-                new TextLabel("Profiles describe information needed to " +
150
-                "connect to a server.  You can use a different profile for " +
151
-                "each connection.");
151
+                new TextLabel("Profiles describe information needed to "
152
+                + "connect to a server.  You can use a different profile for "
153
+                + "each connection.");
152 154
 
153 155
         profileList.setCellRenderer(new ProfileListCellRenderer());
154 156
         profileList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
@@ -230,23 +232,44 @@ public final class ProfileManagerDialog extends StandardDialog implements Action
230 232
             dispose();
231 233
         } else if (e.getSource().equals(addButton)) {
232 234
             addProfile();
233
-        } else if (e.getSource().equals(deleteButton) && JOptionPane.showConfirmDialog(this,
234
-                "Are you sure you want to delete this profile?",
235
-                "Delete Confirmaton", JOptionPane.YES_NO_OPTION) ==
236
-                JOptionPane.YES_OPTION) {
237
-            final Profile selectedProfile = (Profile) profileList.getSelectedValue();
238
-            int selected = profileList.getSelectedIndex();
239
-            deletedProfiles.add(selectedProfile);
240
-            model.remove(selectedProfile);
241
-            final int profilesSize = profileList.getModel().getSize();
242
-            if (profilesSize == 0) {
243
-                selected = -1;
244
-            } else if (selected >= profilesSize) {
245
-                selected = profilesSize - 1;
246
-            } else if (selected <= 0) {
247
-                selected = 0;
248
-            }
249
-            profileList.setSelectedIndex(selected);
235
+        } else if (e.getSource().equals(deleteButton)) {
236
+            new StandardQuestionDialog(this, ModalityType.DOCUMENT_MODAL,
237
+                    "Delete Confirmaton",
238
+                    "Are you sure you want to delete this profile?") {
239
+
240
+                /**
241
+                 * A version number for this class. It should be changed whenever the class
242
+                 * structure is changed (or anything else that would prevent serialized
243
+                 * objects being unserialized with the new class).
244
+                 */
245
+                private static final long serialVersionUID = 1;
246
+
247
+                /** {@inheritDoc} */
248
+                @Override
249
+                public boolean save() {
250
+                    final Profile selectedProfile = (Profile) profileList.
251
+                            getSelectedValue();
252
+                    int selected = profileList.getSelectedIndex();
253
+                    deletedProfiles.add(selectedProfile);
254
+                    model.remove(selectedProfile);
255
+                    final int profilesSize = profileList.getModel().getSize();
256
+                    if (profilesSize == 0) {
257
+                        selected = -1;
258
+                    } else if (selected >= profilesSize) {
259
+                        selected = profilesSize - 1;
260
+                    } else if (selected <= 0) {
261
+                        selected = 0;
262
+                    }
263
+                    profileList.setSelectedIndex(selected);
264
+                    return true;
265
+                }
266
+
267
+                /** {@inheritDoc} */
268
+                @Override
269
+                public void cancelled() {
270
+                    return;
271
+                }
272
+            }.display();
250 273
         }
251 274
     }
252 275
 

+ 35
- 10
src/com/dmdirc/addons/ui_swing/dialogs/serversetting/IgnoreListPanel.java View File

@@ -19,6 +19,7 @@
19 19
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 20
  * SOFTWARE.
21 21
  */
22
+
22 23
 package com.dmdirc.addons.ui_swing.dialogs.serversetting;
23 24
 
24 25
 import com.dmdirc.Server;
@@ -27,6 +28,7 @@ import com.dmdirc.config.prefs.validator.RegexValidator;
27 28
 import com.dmdirc.config.prefs.validator.ValidatorChain;
28 29
 import com.dmdirc.addons.ui_swing.dialogs.StandardInputDialog;
29 30
 import com.dmdirc.addons.ui_swing.UIUtilities;
31
+import com.dmdirc.addons.ui_swing.dialogs.StandardQuestionDialog;
30 32
 import com.dmdirc.parser.common.IgnoreList;
31 33
 
32 34
 import java.awt.Dialog.ModalityType;
@@ -38,7 +40,6 @@ import javax.swing.JButton;
38 40
 import javax.swing.JCheckBox;
39 41
 import javax.swing.JLabel;
40 42
 import javax.swing.JList;
41
-import javax.swing.JOptionPane;
42 43
 import javax.swing.JPanel;
43 44
 import javax.swing.JScrollPane;
44 45
 import javax.swing.ListSelectionModel;
@@ -126,7 +127,8 @@ public final class IgnoreListPanel extends JPanel implements ActionListener,
126 127
 
127 128
     /** Updates the size label. */
128 129
     private void updateSizeLabel() {
129
-        sizeLabel.setText(cachedIgnoreList.count() + " entr" + (cachedIgnoreList.count() == 1 ? "y" : "ies"));
130
+        sizeLabel.setText(cachedIgnoreList.count() + " entr" + (cachedIgnoreList.
131
+                count() == 1 ? "y" : "ies"));
130 132
     }
131 133
 
132 134
     /** Adds listeners to the components. */
@@ -165,16 +167,16 @@ public final class IgnoreListPanel extends JPanel implements ActionListener,
165 167
         server.saveIgnoreList();
166 168
     }
167 169
 
168
-    /** 
170
+    /**
169 171
      * {@inheritDoc}
170
-     * 
172
+     *
171 173
      * @param e Action event
172 174
      */
173 175
     @SuppressWarnings("unchecked")
174 176
     @Override
175 177
     public void actionPerformed(final ActionEvent e) {
176 178
         if (e.getSource() == addButton) {
177
-            new StandardInputDialog(parentWindow, ModalityType.MODELESS, 
179
+            new StandardInputDialog(parentWindow, ModalityType.MODELESS,
178 180
                     "New ignore list entry",
179 181
                     "Please enter the new ignore list entry",
180 182
                     viewToggle.isSelected() ? new ValidatorChain<String>(
@@ -207,12 +209,35 @@ public final class IgnoreListPanel extends JPanel implements ActionListener,
207 209
                     //Ignore
208 210
                 }
209 211
             }.display();
210
-        } else if (e.getSource() == delButton && list.getSelectedIndex() != -1 && JOptionPane.showConfirmDialog(this,
211
-                "Are you sure you want to delete this item?",
212
-                "Delete Confirmation", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
213
-            cachedIgnoreList.remove(list.getSelectedIndex());
212
+        } else if (e.getSource() == delButton && list.getSelectedIndex()
213
+                != -1) {
214
+            new StandardQuestionDialog(parentWindow,
215
+                    ModalityType.APPLICATION_MODAL,
216
+                    "Confirm deletion",
217
+                    "Are you sure you want to delete this item?") {
218
+
219
+                /**
220
+                 * A version number for this class. It should be changed whenever the class
221
+                 * structure is changed (or anything else that would prevent serialized
222
+                 * objects being unserialized with the new class).
223
+                 */
224
+                private static final long serialVersionUID = 1;
225
+
226
+                /** {@inheritDoc} */
227
+                @Override
228
+                public boolean save() {
229
+                    cachedIgnoreList.remove(list.getSelectedIndex());
230
+
231
+                    updateList();
232
+                    return true;
233
+                }
214 234
 
215
-            updateList();
235
+                /** {@inheritDoc} */
236
+                @Override
237
+                public void cancelled() {
238
+                    return;
239
+                }
240
+            }.display();
216 241
         } else if (e.getSource() == viewToggle) {
217 242
             listModel.setIsSimple(!viewToggle.isSelected());
218 243
         }

Loading…
Cancel
Save