Ver código fonte

Add lambdas to StandardQuestionDialog.

pull/99/head
Greg Holmes 9 anos atrás
pai
commit
3d88065f78

+ 18
- 16
ui_swing/src/com/dmdirc/addons/ui_swing/components/menubar/ChannelMenu.java Ver arquivo

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

+ 0
- 73
ui_swing/src/com/dmdirc/addons/ui_swing/dialogs/ChannelJoinDialog.java Ver arquivo

@@ -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 Ver arquivo

@@ -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
-}

+ 109
- 19
ui_swing/src/com/dmdirc/addons/ui_swing/dialogs/StandardInputDialog.java Ver arquivo

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

+ 37
- 51
ui_swing/src/com/dmdirc/addons/ui_swing/dialogs/actionsmanager/ActionsManagerDialog.java Ver arquivo

@@ -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 Ver arquivo

@@ -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 Ver arquivo

@@ -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 Ver arquivo

@@ -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 Ver arquivo

@@ -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 Ver arquivo

@@ -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) {

Carregando…
Cancelar
Salvar