Browse Source

Adds crazy checks to save methods in AMD + SID (fixes issue 3492)

Adds stupid code to discard perfectly valid events for people who can't let go of buttons quick enough (fixes issue 3489 fixes issue 3493)

Change-Id: Ie3969f9a39499b75ba713ae0a0d9f274a9acda3f
Reviewed-on: http://gerrit.dmdirc.com/440
Tested-by: Gregory Holmes <greboid@dmdirc.com>
Reviewed-by: Shane Mc Cormack <shane@dmdirc.com>
tags/0.6.3
Gregory Holmes 14 years ago
parent
commit
056664b40a

+ 6
- 1
src/com/dmdirc/addons/ui_swing/SwingController.java View File

@@ -447,8 +447,13 @@ public final class SwingController extends Plugin implements UIController {
447 447
         return me.getActiveFrame();
448 448
     }
449 449
 
450
-    /** {@inheritDoc} */
450
+    /**
451
+     * {@inheritDoc}
452
+     * 
453
+     * @deprecated 
454
+     */
451 455
     @Override
456
+    @Deprecated
452 457
     public Server getActiveServer() {
453 458
         if (!mainFrameCreated.get()) {
454 459
             return null;

+ 25
- 17
src/com/dmdirc/addons/ui_swing/dialogs/DialogKeyListener.java View File

@@ -36,28 +36,36 @@ import javax.swing.JButton;
36 36
  */
37 37
 public class DialogKeyListener implements KeyEventDispatcher {
38 38
 
39
+    /** Repeat delay to prevent rapid firing of the events. */
40
+    private static final int REPEAT_DELAY = 750;
41
+    /** Last key press. */
42
+    private long lastKeyPress = System.currentTimeMillis();
43
+
39 44
     /** {@inheritDoc} */
40 45
     @Override
41 46
     public boolean dispatchKeyEvent(final KeyEvent e) {
42
-        if (KeyboardFocusManager.getCurrentKeyboardFocusManager().
43
-                getFocusedWindow() instanceof StandardDialog) {
44
-            final StandardDialog dialog = (StandardDialog) KeyboardFocusManager.
45
-                    getCurrentKeyboardFocusManager().getFocusedWindow();
46
-            if (e.getKeyCode() == KeyEvent.VK_ENTER && e.getModifiers() == UIUtilities.
47
-                    getCtrlMask()) {
48
-                dialog.ctrlEnterPressed();
49
-            }
50
-            if (e.getKeyCode() == KeyEvent.VK_ENTER && e.getModifiers() != UIUtilities.
51
-                    getCtrlMask()) {
52
-                if (dialog.getFocusOwner() instanceof JButton) {
53
-                    dialog.executeAction(((JButton) dialog.getFocusOwner()));
54
-                } else {
55
-                    return dialog.enterPressed();
47
+        if (lastKeyPress + REPEAT_DELAY <= System.currentTimeMillis()) {
48
+            if (KeyboardFocusManager.getCurrentKeyboardFocusManager().
49
+                    getFocusedWindow() instanceof StandardDialog) {
50
+                final StandardDialog dialog = (StandardDialog) KeyboardFocusManager.
51
+                        getCurrentKeyboardFocusManager().getFocusedWindow();
52
+                if (e.getKeyCode() == KeyEvent.VK_ENTER && e.getModifiers() == UIUtilities.
53
+                        getCtrlMask()) {
54
+                    dialog.ctrlEnterPressed();
55
+                }
56
+                if (e.getKeyCode() == KeyEvent.VK_ENTER && e.getModifiers() != UIUtilities.
57
+                        getCtrlMask()) {
58
+                    if (dialog.getFocusOwner() instanceof JButton) {
59
+                        dialog.executeAction(((JButton) dialog.getFocusOwner()));
60
+                    } else {
61
+                        return dialog.enterPressed();
62
+                    }
63
+                }
64
+                if (e.getKeyCode() == KeyEvent.VK_ESCAPE) {
65
+                    return dialog.escapePressed();
56 66
                 }
57 67
             }
58
-            if (e.getKeyCode() == KeyEvent.VK_ESCAPE) {
59
-                return dialog.escapePressed();
60
-            }
68
+            lastKeyPress = System.currentTimeMillis();
61 69
         }
62 70
         return false;
63 71
     }

+ 3
- 0
src/com/dmdirc/addons/ui_swing/dialogs/StandardInputDialog.java View File

@@ -32,6 +32,7 @@ import java.awt.event.ActionEvent;
32 32
 import java.awt.event.ActionListener;
33 33
 import java.awt.event.WindowAdapter;
34 34
 import java.awt.event.WindowEvent;
35
+import java.util.concurrent.atomic.AtomicBoolean;
35 36
 
36 37
 import javax.swing.JButton;
37 38
 import javax.swing.event.DocumentEvent;
@@ -52,6 +53,8 @@ public abstract class StandardInputDialog extends StandardDialog {
52 53
     private TextLabel blurb;
53 54
     /** Message. */
54 55
     private String message;
56
+    /** Are we saving? */
57
+    protected AtomicBoolean saving = new AtomicBoolean(false);
55 58
 
56 59
     /**
57 60
      * Instantiates a new standard input dialog.

+ 59
- 42
src/com/dmdirc/addons/ui_swing/dialogs/actionsmanager/ActionsManagerDialog.java View File

@@ -48,6 +48,7 @@ import java.awt.event.ActionEvent;
48 48
 import java.awt.event.ActionListener;
49 49
 import java.util.HashMap;
50 50
 import java.util.Map;
51
+import java.util.concurrent.atomic.AtomicBoolean;
51 52
 
52 53
 import javax.swing.BorderFactory;
53 54
 import javax.swing.DefaultListModel;
@@ -98,6 +99,8 @@ public final class ActionsManagerDialog extends StandardDialog implements
98 99
     private ActionGroupSettingsPanel activeSettings;
99 100
     /** Group panel. */
100 101
     private JPanel groupPanel;
102
+    /** Are we saving? */
103
+    private AtomicBoolean saving = new AtomicBoolean(false);
101 104
 
102 105
     /** 
103 106
      * Creates a new instance of ActionsManagerDialog.
@@ -167,10 +170,10 @@ public final class ActionsManagerDialog extends StandardDialog implements
167 170
      */
168 171
     private void initComponents() {
169 172
         orderButtons(new JButton(), new JButton());
170
-        infoLabel = new TextLabel("Actions allow you to make DMDirc" +
171
-                " intelligently respond to various events.  Action groups are " +
172
-                "there for you to organise groups, add or remove them " +
173
-                "to suit your needs.");
173
+        infoLabel = new TextLabel("Actions allow you to make DMDirc"
174
+                + " intelligently respond to various events.  Action groups are "
175
+                + "there for you to organise groups, add or remove them "
176
+                + "to suit your needs.");
174 177
         groups = new JList(new SortedListModel<ActionGroup>(
175 178
                 new ActionGroupNameComparator()));
176 179
         actions = new ActionsGroupPanel(this, null);
@@ -239,7 +242,8 @@ public final class ActionsManagerDialog extends StandardDialog implements
239 242
      */
240 243
     private void layoutComponents() {
241 244
 
242
-        getContentPane().setLayout(new MigLayout("fill, wrap 2, hidemode 3, wmax 800"));
245
+        getContentPane().setLayout(new MigLayout(
246
+                "fill, wrap 2, hidemode 3, wmax 800"));
243 247
 
244 248
         getContentPane().add(infoLabel, "spanx 2, growx");
245 249
         if (info.isVisible() && activeSettings.isVisible()) {
@@ -316,24 +320,29 @@ public final class ActionsManagerDialog extends StandardDialog implements
316 320
             editGroup();
317 321
         } else if (e.getSource() == delete) {
318 322
             delGroup();
319
-        } else if (e.getSource() == getOkButton() || e.getSource() ==
320
-                getCancelButton()) {
321
-            if (ActionEditorDialog.isOpen()) {
322
-                if (JOptionPane.showConfirmDialog(this,
323
-                        "The action editor is currently open, do you want to cotinue and lose any unsaved changes?",
324
-                        "Confirm close?", JOptionPane.YES_NO_OPTION,
325
-                        JOptionPane.QUESTION_MESSAGE) == JOptionPane.YES_OPTION) {
326
-                    ActionEditorDialog.getActionEditorDialog(this, "").dispose();
327
-                } else {
328
-                    return;
323
+        } else if (e.getSource() == getOkButton() || e.getSource()
324
+                == getCancelButton()) {
325
+            if (!saving.get()) {
326
+                saving.set(true);
327
+                if (ActionEditorDialog.isOpen()) {
328
+                    if (JOptionPane.showConfirmDialog(this,
329
+                            "The action editor is currently open, do you want to cotinue and lose any unsaved changes?",
330
+                            "Confirm close?", JOptionPane.YES_NO_OPTION,
331
+                            JOptionPane.QUESTION_MESSAGE)
332
+                            == JOptionPane.YES_OPTION) {
333
+                        ActionEditorDialog.getActionEditorDialog(this, "").
334
+                                dispose();
335
+                    } else {
336
+                        return;
337
+                    }
329 338
                 }
339
+                for (ActionGroupSettingsPanel loopSettings : settings.values()) {
340
+                    loopSettings.save();
341
+                }
342
+                IdentityManager.getConfigIdentity().setOption("dialogstate",
343
+                        "actionsmanagerdialog", groups.getSelectedIndex());
344
+                dispose();
330 345
             }
331
-            for (ActionGroupSettingsPanel loopSettings : settings.values()) {
332
-                loopSettings.save();
333
-            }
334
-            IdentityManager.getConfigIdentity().setOption("dialogstate",
335
-                    "actionsmanagerdialog", groups.getSelectedIndex());
336
-            dispose();
337 346
         }
338 347
     }
339 348
 
@@ -358,16 +367,20 @@ public final class ActionsManagerDialog extends StandardDialog implements
358 367
             /** {@inheritDoc} */
359 368
             @Override
360 369
             public boolean save() {
361
-                if (getText() == null || getText().isEmpty() && !ActionManager.
362
-                        getGroups().
363
-                        containsKey(getText())) {
364
-                    return false;
365
-                } else {
366
-                    final ActionGroup group =
367
-                            ActionManager.makeGroup(getText());
368
-                    reloadGroups(group);
369
-                    return true;
370
+                if (!saving.get()) {
371
+                    saving.set(true);
372
+                    if (getText() == null || getText().isEmpty() && !ActionManager.
373
+                            getGroups().
374
+                            containsKey(getText())) {
375
+                        return false;
376
+                    } else {
377
+                        final ActionGroup group =
378
+                                ActionManager.makeGroup(getText());
379
+                        reloadGroups(group);
380
+                        return true;
381
+                    }
370 382
                 }
383
+                return false;
371 384
             }
372 385
 
373 386
             /** {@inheritDoc} */
@@ -403,13 +416,17 @@ public final class ActionsManagerDialog extends StandardDialog implements
403 416
             /** {@inheritDoc} */
404 417
             @Override
405 418
             public boolean save() {
406
-                if (getText() == null || getText().isEmpty()) {
407
-                    return false;
408
-                } else {
409
-                    ActionManager.renameGroup(oldName, getText());
410
-                    reloadGroups();
411
-                    return true;
419
+                if (!saving.get()) {
420
+                    saving.set(true);
421
+                    if (getText() == null || getText().isEmpty()) {
422
+                        return false;
423
+                    } else {
424
+                        ActionManager.renameGroup(oldName, getText());
425
+                        reloadGroups();
426
+                        return true;
427
+                    }
412 428
                 }
429
+                return false;
413 430
             }
414 431
 
415 432
             /** {@inheritDoc} */
@@ -429,8 +446,8 @@ public final class ActionsManagerDialog extends StandardDialog implements
429 446
         final String group =
430 447
                 ((ActionGroup) groups.getSelectedValue()).getName();
431 448
         final int response = JOptionPane.showConfirmDialog(this,
432
-                "Are you sure you wish to delete the '" + group +
433
-                "' group and all actions within it?",
449
+                "Are you sure you wish to delete the '" + group
450
+                + "' group and all actions within it?",
434 451
                 "Confirm deletion", JOptionPane.YES_NO_OPTION);
435 452
         if (response == JOptionPane.YES_OPTION) {
436 453
             int location =
@@ -457,8 +474,8 @@ public final class ActionsManagerDialog extends StandardDialog implements
457 474
         }
458 475
 
459 476
         changeActiveGroup((ActionGroup) groups.getSelectedValue());
460
-        if (groups.getSelectedIndex() == -1 ||
461
-                !((ActionGroup) groups.getSelectedValue()).isDelible()) {
477
+        if (groups.getSelectedIndex() == -1 || !((ActionGroup) groups.
478
+                getSelectedValue()).isDelible()) {
462 479
             edit.setEnabled(false);
463 480
             delete.setEnabled(false);
464 481
         } else {
@@ -474,8 +491,8 @@ public final class ActionsManagerDialog extends StandardDialog implements
474 491
         if (groups.getSelectedValue() == null) {
475 492
             return;
476 493
         }
477
-        if (type.equals(CoreActionType.ACTION_CREATED) ||
478
-                type.equals(CoreActionType.ACTION_UPDATED)) {
494
+        if (type.equals(CoreActionType.ACTION_CREATED) || type.equals(
495
+                CoreActionType.ACTION_UPDATED)) {
479 496
             final Action action = (Action) arguments[0];
480 497
             if (action.getGroup().equals(((ActionGroup) groups.getSelectedValue()).
481 498
                     getName())) {

Loading…
Cancel
Save