Browse Source

Merge pull request #99 from greboid/standarddialogs

Add lambdas to StandardQuestionDialog.
pull/101/head
Chris Smith 9 years ago
parent
commit
5b5960d656

+ 21
- 16
ui_swing/src/com/dmdirc/addons/ui_swing/components/menubar/ChannelMenu.java View File

@@ -23,16 +23,21 @@
23 23
 package com.dmdirc.addons.ui_swing.components.menubar;
24 24
 
25 25
 import com.dmdirc.Channel;
26
+import com.dmdirc.ClientModule;
26 27
 import com.dmdirc.FrameContainer;
27 28
 import com.dmdirc.ServerState;
29
+import com.dmdirc.addons.ui_swing.MainFrame;
28 30
 import com.dmdirc.addons.ui_swing.components.frames.TextFrame;
29
-import com.dmdirc.addons.ui_swing.dialogs.ChannelJoinDialogFactory;
31
+import com.dmdirc.addons.ui_swing.dialogs.StandardInputDialog;
30 32
 import com.dmdirc.addons.ui_swing.dialogs.channellist.ChannelListDialog;
31 33
 import com.dmdirc.addons.ui_swing.dialogs.channelsetting.ChannelSettingsDialog;
32 34
 import com.dmdirc.addons.ui_swing.injection.DialogProvider;
33 35
 import com.dmdirc.addons.ui_swing.injection.KeyedDialogProvider;
34 36
 import com.dmdirc.addons.ui_swing.interfaces.ActiveFrameManager;
37
+import com.dmdirc.parser.common.ChannelJoinRequest;
38
+import com.dmdirc.ui.IconManager;
35 39
 
40
+import java.awt.Dialog;
36 41
 import java.awt.event.ActionEvent;
37 42
 import java.awt.event.ActionListener;
38 43
 
@@ -52,12 +57,14 @@ public class ChannelMenu extends JMenu implements ActionListener,
52 57
 
53 58
     /** A version number for this class. */
54 59
     private static final long serialVersionUID = 1;
60
+    /** Icon manager. */
61
+    private final IconManager iconManager;
62
+    /** Main frame. */
63
+    private final MainFrame mainFrame;
55 64
     /** Dialog provider. */
56 65
     private final KeyedDialogProvider<Channel, ChannelSettingsDialog> dialogProvider;
57 66
     /** Channel list dialog provider. */
58 67
     private final DialogProvider<ChannelListDialog> channelListDialogProvider;
59
-    /** Channel join dialog factory. */
60
-    private final ChannelJoinDialogFactory channelJoinDialogFactory;
61 68
     /** Active frame manager. */
62 69
     private final ActiveFrameManager activeFrameManager;
63 70
     /** Menu items to be disabled/enabled. */
@@ -65,24 +72,18 @@ public class ChannelMenu extends JMenu implements ActionListener,
65 72
     private JMenuItem join;
66 73
     private JMenuItem list;
67 74
 
68
-    /**
69
-     * Creates a new channel menu.
70
-     *
71
-     * @param activeFrameManager        Active frame manager.
72
-     * @param dialogProvider            Channel settings dialog provider
73
-     * @param channelJoinDialogFactory  Channel join dialog factory
74
-     * @param channelListDialogProvider Channel list dialog provider
75
-     */
76 75
     @Inject
77 76
     public ChannelMenu(
78 77
             final ActiveFrameManager activeFrameManager,
79 78
             final KeyedDialogProvider<Channel, ChannelSettingsDialog> dialogProvider,
80
-            final ChannelJoinDialogFactory channelJoinDialogFactory,
79
+            final MainFrame mainFrame,
80
+            @ClientModule.GlobalConfig final IconManager iconManager,
81 81
             final DialogProvider<ChannelListDialog> channelListDialogProvider) {
82 82
         super("Channel");
83
+        this.mainFrame = mainFrame;
84
+        this.iconManager = iconManager;
83 85
         this.activeFrameManager = activeFrameManager;
84 86
         this.dialogProvider = dialogProvider;
85
-        this.channelJoinDialogFactory = channelJoinDialogFactory;
86 87
         this.channelListDialogProvider = channelListDialogProvider;
87 88
         setMnemonic('c');
88 89
         addMenuListener(this);
@@ -120,14 +121,18 @@ public class ChannelMenu extends JMenu implements ActionListener,
120 121
     public void actionPerformed(final ActionEvent e) {
121 122
         switch (e.getActionCommand()) {
122 123
             case "JoinChannel":
123
-                channelJoinDialogFactory.getChannelJoinDialog("Join channel",
124
-                        "Enter the name of the channel to join.").displayOrRequestFocus();
124
+                // TODO: This can NPE on both getActiveFrame and getConnection fix me.
125
+                new StandardInputDialog(mainFrame, Dialog.ModalityType.MODELESS, iconManager,
126
+                        "Join Channel", "Enter the name of the channel to join.",
127
+                        (String s) -> activeFrameManager.getActiveFrame().getContainer()
128
+                                .getConnection().join(new ChannelJoinRequest(s)))
129
+                        .displayOrRequestFocus();
125 130
                 break;
126 131
             case "ChannelSettings":
127 132
                 final FrameContainer activeWindow = activeFrameManager.getActiveFrame().
128 133
                         getContainer();
129 134
                 if (activeWindow instanceof Channel) {
130
-                    dialogProvider.displayOrRequestFocus(((Channel) activeWindow));
135
+                    dialogProvider.displayOrRequestFocus((Channel) activeWindow);
131 136
                 }
132 137
                 break;
133 138
             case "ListChannels":

+ 0
- 73
ui_swing/src/com/dmdirc/addons/ui_swing/dialogs/ChannelJoinDialog.java View File

@@ -1,73 +0,0 @@
1
-/*
2
- * Copyright (c) 2006-2014 DMDirc Developers
3
- *
4
- * Permission is hereby granted, free of charge, to any person obtaining a copy
5
- * of this software and associated documentation files (the "Software"), to deal
6
- * in the Software without restriction, including without limitation the rights
7
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
- * copies of the Software, and to permit persons to whom the Software is
9
- * furnished to do so, subject to the following conditions:
10
- *
11
- * The above copyright notice and this permission notice shall be included in
12
- * all copies or substantial portions of the Software.
13
- *
14
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
- * SOFTWARE.
21
- */
22
-
23
-package com.dmdirc.addons.ui_swing.dialogs;
24
-
25
-import com.dmdirc.addons.ui_swing.interfaces.ActiveFrameManager;
26
-import com.dmdirc.parser.common.ChannelJoinRequest;
27
-import com.dmdirc.ui.IconManager;
28
-
29
-import java.awt.Window;
30
-
31
-/**
32
- * A dialog to prompt the user for a channel and then join that channel.
33
- */
34
-public class ChannelJoinDialog extends StandardInputDialog {
35
-
36
-    /** Serial version UID. */
37
-    private static final long serialVersionUID = 1;
38
-    /** Active frame manager. */
39
-    private final ActiveFrameManager activeFrameManager;
40
-
41
-    /**
42
-     * Creates a new dialog which prompts a user and then joins the channel they specify.
43
-     *
44
-     * @param mainWindow         Main window to use as a parent.
45
-     * @param activeFrameManager The active window manager
46
-     * @param iconManager        The icon manager to use for validating text fields.
47
-     * @param title              Window title
48
-     * @param message            Window message
49
-     */
50
-    public ChannelJoinDialog(
51
-            final Window mainWindow,
52
-            final ActiveFrameManager activeFrameManager,
53
-            final IconManager iconManager,
54
-            final String title,
55
-            final String message) {
56
-        super(mainWindow, ModalityType.APPLICATION_MODAL, iconManager, title, message);
57
-
58
-        this.activeFrameManager = activeFrameManager;
59
-    }
60
-
61
-    @Override
62
-    public boolean save() {
63
-        activeFrameManager.getActiveFrame().getContainer().getConnection()
64
-                .join(new ChannelJoinRequest(getText()));
65
-        return true;
66
-    }
67
-
68
-    @Override
69
-    public void cancelled() {
70
-        //Ignore
71
-    }
72
-
73
-}

+ 0
- 59
ui_swing/src/com/dmdirc/addons/ui_swing/dialogs/ChannelJoinDialogFactory.java View File

@@ -1,59 +0,0 @@
1
-/*
2
- * Copyright (c) 2006-2014 DMDirc Developers
3
- *
4
- * Permission is hereby granted, free of charge, to any person obtaining a copy
5
- * of this software and associated documentation files (the "Software"), to deal
6
- * in the Software without restriction, including without limitation the rights
7
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
- * copies of the Software, and to permit persons to whom the Software is
9
- * furnished to do so, subject to the following conditions:
10
- *
11
- * The above copyright notice and this permission notice shall be included in
12
- * all copies or substantial portions of the Software.
13
- *
14
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
- * SOFTWARE.
21
- */
22
-
23
-package com.dmdirc.addons.ui_swing.dialogs;
24
-
25
-import com.dmdirc.ClientModule;
26
-import com.dmdirc.addons.ui_swing.injection.MainWindow;
27
-import com.dmdirc.addons.ui_swing.interfaces.ActiveFrameManager;
28
-import com.dmdirc.ui.IconManager;
29
-
30
-import java.awt.Window;
31
-
32
-import javax.inject.Inject;
33
-import javax.inject.Singleton;
34
-
35
-/**
36
- * Factory for {@link ChannelJoinDialog}s.
37
- */
38
-@Singleton
39
-public class ChannelJoinDialogFactory {
40
-
41
-    private final Window mainWindow;
42
-    private final ActiveFrameManager activeFrameManager;
43
-    private final IconManager iconManager;
44
-
45
-    @Inject
46
-    public ChannelJoinDialogFactory(
47
-            @MainWindow final Window mainWindow,
48
-            final ActiveFrameManager activeFrameManager,
49
-            @ClientModule.GlobalConfig final IconManager iconManager) {
50
-        this.mainWindow = mainWindow;
51
-        this.activeFrameManager = activeFrameManager;
52
-        this.iconManager = iconManager;
53
-    }
54
-
55
-    public ChannelJoinDialog getChannelJoinDialog(final String title, final String message) {
56
-        return new ChannelJoinDialog(mainWindow, activeFrameManager, iconManager, title, message);
57
-    }
58
-
59
-}

+ 111
- 19
ui_swing/src/com/dmdirc/addons/ui_swing/dialogs/StandardInputDialog.java View File

@@ -28,10 +28,14 @@ import com.dmdirc.ui.IconManager;
28 28
 import com.dmdirc.util.validators.ValidationResponse;
29 29
 import com.dmdirc.util.validators.Validator;
30 30
 
31
+import com.google.common.util.concurrent.Runnables;
32
+
31 33
 import java.awt.Window;
32 34
 import java.awt.event.WindowAdapter;
33 35
 import java.awt.event.WindowEvent;
34 36
 import java.util.concurrent.atomic.AtomicBoolean;
37
+import java.util.function.Consumer;
38
+import java.util.function.Function;
35 39
 
36 40
 import javax.swing.JButton;
37 41
 import javax.swing.WindowConstants;
@@ -45,7 +49,7 @@ import net.miginfocom.swing.MigLayout;
45 49
 /**
46 50
  * Standard input dialog.
47 51
  */
48
-public abstract class StandardInputDialog extends StandardDialog {
52
+public class StandardInputDialog extends StandardDialog {
49 53
 
50 54
     /** Serial version UID. */
51 55
     private static final long serialVersionUID = 1;
@@ -61,6 +65,10 @@ public abstract class StandardInputDialog extends StandardDialog {
61 65
     private final IconManager iconManager;
62 66
     /** Are we saving? */
63 67
     protected final AtomicBoolean saving = new AtomicBoolean(false);
68
+    /** Function to call when the dialog is saved. */
69
+    private final Function<String, Boolean> save;
70
+    /** Function to call when the dialog is cancelled. */
71
+    private final Runnable cancel;
64 72
 
65 73
     /**
66 74
      * Instantiates a new standard input dialog.
@@ -73,8 +81,44 @@ public abstract class StandardInputDialog extends StandardDialog {
73 81
      */
74 82
     public StandardInputDialog(
75 83
             final Window owner, final ModalityType modal, final IconManager iconManager,
76
-            final String title, final String message) {
77
-        this(owner, modal, iconManager, title, message, o -> new ValidationResponse());
84
+            final String title, final String message,
85
+            final Consumer<String> save) {
86
+        this(owner, modal, iconManager, title, message,
87
+                s -> { save.accept(s); return true; }, Runnables.doNothing());
88
+    }
89
+
90
+    /**
91
+     * Instantiates a new standard input dialog.
92
+     *
93
+     * @param owner       Dialog owner
94
+     * @param modal       modality type
95
+     * @param iconManager The icon manager to use for validating text fields.
96
+     * @param title       Dialog title
97
+     * @param message     Dialog message
98
+     */
99
+    public StandardInputDialog(
100
+            final Window owner, final ModalityType modal, final IconManager iconManager,
101
+            final String title, final String message,
102
+            final Function<String, Boolean> save) {
103
+        this(owner, modal, iconManager, title, message, save, Runnables.doNothing());
104
+    }
105
+
106
+    /**
107
+     * Instantiates a new standard input dialog.
108
+     *
109
+     * @param owner       Dialog owner
110
+     * @param modal       modality type
111
+     * @param iconManager The icon manager to use for validating text fields.
112
+     * @param title       Dialog title
113
+     * @param message     Dialog message
114
+     */
115
+    public StandardInputDialog(
116
+            final Window owner, final ModalityType modal, final IconManager iconManager,
117
+            final String title, final String message,
118
+            final Function<String, Boolean> save,
119
+            final Runnable cancel) {
120
+        this(owner, modal, iconManager, title, message, o -> new ValidationResponse(), save,
121
+                cancel);
78 122
     }
79 123
 
80 124
     /**
@@ -90,12 +134,72 @@ public abstract class StandardInputDialog extends StandardDialog {
90 134
     public StandardInputDialog(
91 135
             final Window owner, final ModalityType modal, final IconManager iconManager,
92 136
             final String title, final String message,
93
-            final Validator<String> validator) {
137
+            final Validator<String> validator,
138
+            final Consumer<String> save) {
139
+        this(owner, modal, iconManager, title, message, validator,
140
+                (String s) -> { save.accept(s); return true; }, Runnables.doNothing());
141
+    }
142
+
143
+    /**
144
+     * Instantiates a new standard input dialog.
145
+     *
146
+     * @param owner       Dialog owner
147
+     * @param modal       modality type
148
+     * @param iconManager The icon manager to use for validating text fields.
149
+     * @param validator   Textfield validator
150
+     * @param title       Dialog title
151
+     * @param message     Dialog message
152
+     */
153
+    public StandardInputDialog(
154
+            final Window owner, final ModalityType modal, final IconManager iconManager,
155
+            final String title, final String message,
156
+            final Validator<String> validator,
157
+            final Function<String, Boolean> save) {
158
+        this(owner, modal, iconManager, title, message, validator, save, Runnables.doNothing());
159
+    }
160
+    /**
161
+     * Instantiates a new standard input dialog.
162
+     *
163
+     * @param owner       Dialog owner
164
+     * @param modal       modality type
165
+     * @param iconManager The icon manager to use for validating text fields.
166
+     * @param validator   Textfield validator
167
+     * @param title       Dialog title
168
+     * @param message     Dialog message
169
+     */
170
+    public StandardInputDialog(
171
+            final Window owner, final ModalityType modal, final IconManager iconManager,
172
+            final String title, final String message,
173
+            final Validator<String> validator,
174
+            final Consumer<String> save,
175
+            final Runnable cancel) {
176
+        this(owner, modal, iconManager, title, message, validator,
177
+                (String s) -> { save.accept(s); return true; }, cancel);
178
+    }
179
+
180
+    /**
181
+     * Instantiates a new standard input dialog.
182
+     *
183
+     * @param owner       Dialog owner
184
+     * @param modal       modality type
185
+     * @param iconManager The icon manager to use for validating text fields.
186
+     * @param validator   Textfield validator
187
+     * @param title       Dialog title
188
+     * @param message     Dialog message
189
+     */
190
+    public StandardInputDialog(
191
+            final Window owner, final ModalityType modal, final IconManager iconManager,
192
+            final String title, final String message,
193
+            final Validator<String> validator,
194
+            final Function<String, Boolean> save,
195
+            final Runnable cancel) {
94 196
         super(owner, modal);
95 197
 
96 198
         this.validator = validator;
97 199
         this.message = message;
98 200
         this.iconManager = iconManager;
201
+        this.save = save;
202
+        this.cancel = cancel;
99 203
 
100 204
         setTitle(title);
101 205
         setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
@@ -105,18 +209,6 @@ public abstract class StandardInputDialog extends StandardDialog {
105 209
         layoutComponents();
106 210
     }
107 211
 
108
-    /**
109
-     * Called when the dialog's OK button is clicked.
110
-     *
111
-     * @return whether the dialog can close
112
-     */
113
-    public abstract boolean save();
114
-
115
-    /**
116
-     * Called when the dialog's cancel button is clicked, or otherwise closed.
117
-     */
118
-    public abstract void cancelled();
119
-
120 212
     /**
121 213
      * Initialises the components.
122 214
      */
@@ -132,12 +224,12 @@ public abstract class StandardInputDialog extends StandardDialog {
132 224
      */
133 225
     private void addListeners() {
134 226
         getOkButton().addActionListener(e -> {
135
-            if (save()) {
227
+            if (save.apply(getText())) {
136 228
                 dispose();
137 229
             }
138 230
         });
139 231
         getCancelButton().addActionListener(e -> {
140
-            cancelled();
232
+            cancel.run();
141 233
             dispose();
142 234
         });
143 235
         addWindowListener(new WindowAdapter() {
@@ -149,7 +241,7 @@ public abstract class StandardInputDialog extends StandardDialog {
149 241
 
150 242
             @Override
151 243
             public void windowClosed(final WindowEvent e) {
152
-                cancelled();
244
+                cancel.run();
153 245
                 //dispose();
154 246
             }
155 247
         });

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

@@ -316,33 +316,28 @@ public class ActionsManagerDialog extends StandardDialog implements
316 316
         final int index = groups.getSelectedIndex();
317 317
         groups.getSelectionModel().clearSelection();
318 318
         new StandardInputDialog(this, ModalityType.DOCUMENT_MODAL, iconManager, "New action group",
319
-                "Please enter the name of the new action group", validator) {
320
-                    /** Java Serialisation version ID. */
321
-                    private static final long serialVersionUID = 1;
322
-
323
-                    @Override
324
-                    public boolean save() {
325
-                        if (!saving.getAndSet(true)) {
326
-                            groups.setSelectedIndex(index);
327
-                            if (getText() == null || getText().isEmpty()
328
-                            && !ActionManager.getActionManager().getGroupsMap()
329
-                            .containsKey(getText())) {
330
-                                return false;
331
-                            } else {
332
-                                final ActionGroup group = ActionManager
333
-                                .getActionManager().createGroup(getText());
334
-                                reloadGroups(group);
335
-                                return true;
336
-                            }
337
-                        }
338
-                        return false;
339
-                    }
340
-
341
-                    @Override
342
-                    public void cancelled() {
343
-                        groups.setSelectedIndex(index);
344
-                    }
345
-                }.display(this);
319
+                "Please enter the name of the new action group", validator,
320
+                (String s) -> doSaveAddGroup(s, index), () -> doCancelledAddGroup(index))
321
+                .display(this);
322
+    }
323
+
324
+    private boolean doSaveAddGroup(final String text, final int index) {
325
+        if (!saving.getAndSet(true)) {
326
+            groups.setSelectedIndex(index);
327
+            if (text == null || text.isEmpty()
328
+                    && !ActionManager.getActionManager().getGroupsMap().containsKey(text)) {
329
+                return false;
330
+            } else {
331
+                final ActionGroup group = ActionManager.getActionManager().createGroup(text);
332
+                reloadGroups(group);
333
+                return true;
334
+            }
335
+        }
336
+        return false;
337
+    }
338
+
339
+    private void doCancelledAddGroup(final int index) {
340
+        groups.setSelectedIndex(index);
346 341
     }
347 342
 
348 343
     /**
@@ -352,34 +347,25 @@ public class ActionsManagerDialog extends StandardDialog implements
352 347
         final String oldName = groups.getSelectedValue().getName();
353 348
         final StandardInputDialog inputDialog = new StandardInputDialog(
354 349
                 this, ModalityType.DOCUMENT_MODAL, iconManager, "Edit action group",
355
-                "Please enter the new name of the action group", validator) {
356
-                    /** Java Serialisation version ID. */
357
-                    private static final long serialVersionUID = 1;
358
-
359
-                    @Override
360
-                    public boolean save() {
361
-                        if (!saving.getAndSet(true)) {
362
-                            if (getText() == null || getText().isEmpty()) {
363
-                                return false;
364
-                            } else {
365
-                                ActionManager.getActionManager().changeGroupName(
366
-                                        oldName, getText());
367
-                                reloadGroups();
368
-                                return true;
369
-                            }
370
-                        }
371
-                        return false;
372
-                    }
373
-
374
-                    @Override
375
-                    public void cancelled() {
376
-                        //Ignore
377
-                    }
378
-                };
350
+                "Please enter the new name of the action group", validator,
351
+                (String s) -> doSaveEditGroup(oldName, s), () -> {});
379 352
         inputDialog.setText(oldName);
380 353
         inputDialog.display(this);
381 354
     }
382 355
 
356
+    private boolean doSaveEditGroup(final String oldText, final String text) {
357
+        if (!saving.getAndSet(true)) {
358
+            if (text == null || text.isEmpty()) {
359
+                return false;
360
+            } else {
361
+                ActionManager.getActionManager().changeGroupName(oldText, text);
362
+                reloadGroups();
363
+                return true;
364
+            }
365
+        }
366
+        return false;
367
+    }
368
+
383 369
     /**
384 370
      * Prompts then deletes an action group.
385 371
      */

+ 2
- 14
ui_swing/src/com/dmdirc/addons/ui_swing/dialogs/aliases/AliasManagerLinker.java View File

@@ -251,20 +251,8 @@ public class AliasManagerLinker {
251 251
             @Override
252 252
             public void actionPerformed(final ActionEvent e) {
253 253
                 new StandardInputDialog(dialog, Dialog.ModalityType.DOCUMENT_MODAL, iconManager,
254
-                        "Add Alias", "Enter the alias name", model.getNewCommandValidator()) {
255
-
256
-                            private static final long serialVersionUID = 3;
257
-
258
-                    @Override
259
-                    public boolean save() {
260
-                        model.addAlias(getText(), 0, getText());
261
-                        return true;
262
-                            }
263
-
264
-                    @Override
265
-                    public void cancelled() {
266
-                            }
267
-                        }.display();
254
+                        "Add Alias", "Enter the alias name", model.getNewCommandValidator(),
255
+                        (String s) -> model.addAlias(s, 0, s)).display();
268 256
             }
269 257
         });
270 258
     }

+ 8
- 24
ui_swing/src/com/dmdirc/addons/ui_swing/dialogs/channelsetting/ChannelListModesPane.java View File

@@ -291,30 +291,14 @@ public final class ChannelListModesPane extends JPanel implements ActionListener
291 291
         new StandardInputDialog(parentWindow, ModalityType.DOCUMENT_MODAL,
292 292
                 iconManager, "Add new " + modeText,
293 293
                 "Please enter the hostmask for the new " + modeText,
294
-                new NotEmptyValidator()) {
295
-                    /**
296
-                     * A version number for this class. It should be changed whenever the class
297
-                     * structure is changed (or anything else that would prevent serialized objects
298
-                     * being unserialized with the new class).
299
-                     */
300
-                    private static final long serialVersionUID = 1;
301
-
302
-                    @Override
303
-                    public boolean save() {
304
-                        final DefaultListModel<ChannelListModeItem> model
305
-                        = (DefaultListModel<ChannelListModeItem>) listModesPanels.get(selectedIndex).
306
-                        getModel();
307
-                        model.addElement(new ChannelListModeItem(getText(), "",
308
-                                        System.currentTimeMillis() / 1000));
309
-                        updateModeCount();
310
-                        return true;
311
-                    }
312
-
313
-                    @Override
314
-                    public void cancelled() {
315
-                        //Ignore
316
-                    }
317
-                }.display();
294
+                new NotEmptyValidator(), (String s) -> doSaveAddListMode(s, selectedIndex)).display();
295
+    }
296
+
297
+    private void doSaveAddListMode(final String text, final int index) {
298
+        final DefaultListModel<ChannelListModeItem> model =
299
+                (DefaultListModel<ChannelListModeItem>) listModesPanels.get(index).getModel();
300
+        model.addElement(new ChannelListModeItem(text, "",System.currentTimeMillis() / 1000));
301
+        updateModeCount();
318 302
     }
319 303
 
320 304
     /** Removes a list mode. */

+ 12
- 22
ui_swing/src/com/dmdirc/addons/ui_swing/dialogs/prefs/URLConfigPanel.java View File

@@ -264,32 +264,22 @@ public class URLConfigPanel extends JPanel implements
264 264
             new StandardInputDialog(parentWindow,
265 265
                     ModalityType.MODELESS, iconManager, "New URL handler",
266 266
                     "Please enter the name of the new protocol.",
267
-                    new URLProtocolValidator(globalConfig)) {
268
-                        /** Serial version UID. */
269
-                        private static final long serialVersionUID = 1;
270
-
271
-                        @Override
272
-                        public boolean save() {
273
-                            try {
274
-                                final URI uri = new URI(getText() + "://example.test.com");
275
-                                model.addURI(uri);
276
-                                details.put(uri, new URLProtocolPanel(globalConfig, userConfig, uri,
277
-                                                true));
278
-                                return true;
279
-                            } catch (final URISyntaxException ex) {
280
-                                return false;
281
-                            }
282
-                        }
283
-
284
-                        @Override
285
-                        public void cancelled() {
286
-                            //Ignore
287
-                        }
288
-                    }.display();
267
+                    new URLProtocolValidator(globalConfig), this::saveAddNewURLHandler).display();
289 268
 
290 269
         } else if (e.getSource() == remove) {
291 270
             model.removeURI(table.getRowSorter().convertRowIndexToModel(table.getSelectedRow()));
292 271
         }
293 272
     }
294 273
 
274
+    private boolean saveAddNewURLHandler(final String text) {
275
+        try {
276
+            final URI uri = new URI(text + "://example.test.com");
277
+            model.addURI(uri);
278
+            details.put(uri, new URLProtocolPanel(globalConfig, userConfig, uri, true));
279
+            return true;
280
+        } catch (final URISyntaxException ex) {
281
+            return false;
282
+        }
283
+    }
284
+
295 285
 }

+ 4
- 39
ui_swing/src/com/dmdirc/addons/ui_swing/dialogs/profiles/ProfileManagerDialogLinker.java View File

@@ -133,19 +133,8 @@ public class ProfileManagerDialogLinker {
133 133
      */
134 134
     public void bindAddNickname(final JButton addNickname) {
135 135
         addNickname.addActionListener(e -> new StandardInputDialog(dialog, ModalityType.DOCUMENT_MODAL, iconManager,
136
-                "Add nickname", "Enter nickname to add:", new AddNicknameValidator(model)) {
137
-                    private static final long serialVersionUID = 1L;
138
-
139
-                    @Override
140
-                    public boolean save() {
141
-                        controller.addNickname(getText());
142
-                        return true;
143
-                    }
144
-
145
-                    @Override
146
-                    public void cancelled() {
147
-                    }
148
-                }.display());
136
+                "Add nickname", "Enter nickname to add:", new AddNicknameValidator(model),
137
+                controller::addNickname).display());
149 138
         model.addPropertyChangeListener("selectedprofile",
150 139
                 evt -> addNickname.setEnabled(model.isManipulateProfileAllowed()));
151 140
         model.addPropertyChangeListener("profiles",
@@ -163,19 +152,7 @@ public class ProfileManagerDialogLinker {
163 152
             final StandardInputDialog inputDialog = new StandardInputDialog(dialog,
164 153
                     ModalityType.DOCUMENT_MODAL, iconManager,
165 154
                     "Add nickname", "Enter edited nickname:",
166
-                    new EditNicknameValidator(model)) {
167
-                        private static final long serialVersionUID = 1L;
168
-
169
-                        @Override
170
-                        public boolean save() {
171
-                            controller.editNickname(getText());
172
-                            return true;
173
-                        }
174
-
175
-                        @Override
176
-                        public void cancelled() {
177
-                        }
178
-                    };
155
+                    new EditNicknameValidator(model), controller::editNickname);
179 156
             inputDialog.setText((String) model.getSelectedNickname());
180 157
             inputDialog.display();
181 158
         });
@@ -314,19 +291,7 @@ public class ProfileManagerDialogLinker {
314 291
             final StandardInputDialog inputDialog = new StandardInputDialog(dialog,
315 292
                     ModalityType.DOCUMENT_MODAL, iconManager,
316 293
                     "Add profile", "New profile name:",
317
-                    new ProfileNameValidator(model.getProfiles())) {
318
-                        private static final long serialVersionUID = 1L;
319
-
320
-                        @Override
321
-                        public boolean save() {
322
-                            controller.addProfile(getText());
323
-                            return true;
324
-                        }
325
-
326
-                        @Override
327
-                        public void cancelled() {
328
-                        }
329
-                    };
294
+                    new ProfileNameValidator(model.getProfiles()), controller::addProfile);
330 295
             inputDialog.setDocumentFilter(new ProfileNameDocumentFilter());
331 296
             inputDialog.setText((String) model.getSelectedNickname());
332 297
             inputDialog.display();

+ 11
- 21
ui_swing/src/com/dmdirc/addons/ui_swing/dialogs/serversetting/IgnoreListPanel.java View File

@@ -179,27 +179,8 @@ public final class IgnoreListPanel extends JPanel implements ActionListener, Lis
179 179
 
180 180
             new StandardInputDialog(parentWindow,
181 181
                     ModalityType.MODELESS, iconManager, "New ignore list entry",
182
-                    "Please enter the new ignore list entry", validatorBuilder.build()) {
183
-                        /** A version number for this class. */
184
-                        private static final long serialVersionUID = 2;
185
-
186
-                        @Override
187
-                        public boolean save() {
188
-                            if (viewToggle.isSelected()) {
189
-                                cachedIgnoreList.add(getText());
190
-                            } else {
191
-                                cachedIgnoreList.addSimple(getText());
192
-                            }
193
-
194
-                            updateList();
195
-                            return true;
196
-                        }
197
-
198
-                        @Override
199
-                        public void cancelled() {
200
-                            //Ignore
201
-                        }
202
-                    }.display();
182
+                    "Please enter the new ignore list entry", validatorBuilder.build(),
183
+                    this::addNewIgnoreEntry).display();
203 184
         } else if (e.getSource() == delButton && list.getSelectedIndex() != -1) {
204 185
             new StandardQuestionDialog(parentWindow,
205 186
                     ModalityType.APPLICATION_MODAL,
@@ -214,6 +195,15 @@ public final class IgnoreListPanel extends JPanel implements ActionListener, Lis
214 195
         }
215 196
     }
216 197
 
198
+    private void addNewIgnoreEntry(final String text) {
199
+        if (viewToggle.isSelected()) {
200
+            cachedIgnoreList.add(text);
201
+        } else {
202
+            cachedIgnoreList.addSimple(text);
203
+        }
204
+        updateList();
205
+    }
206
+
217 207
     @Override
218 208
     public void valueChanged(final ListSelectionEvent e) {
219 209
         if (list.getSelectedIndex() == -1) {

Loading…
Cancel
Save