]> source.dussan.org Git - vaadin-framework.git/commitdiff
Refactored new actions api a little: removed mnemonics terminology, adding/removing...
authorMarc Englund <marc.englund@itmill.com>
Tue, 23 Mar 2010 10:05:45 +0000 (10:05 +0000)
committerMarc Englund <marc.englund@itmill.com>
Tue, 23 Mar 2010 10:05:45 +0000 (10:05 +0000)
svn changeset:12029/svn branch:6.3

src/com/vaadin/event/Action.java
src/com/vaadin/event/ActionManager.java
src/com/vaadin/event/ShortcutAction.java
src/com/vaadin/terminal/gwt/client/ui/VForm.java
src/com/vaadin/ui/AbstractField.java
src/com/vaadin/ui/Button.java
src/com/vaadin/ui/Form.java
src/com/vaadin/ui/Panel.java
src/com/vaadin/ui/Window.java

index 247def9ee68062fca3e14bb8d6f4bc0711b018da..b2e3f6a9300f943500cca57e0aefaab6737d582d 100644 (file)
@@ -77,17 +77,15 @@ public class Action implements Serializable {
     }
 
     public interface Notifier extends Container {
-        public <T extends Action & Action.Listener> boolean addAction(T action);
+        public <T extends Action & Action.Listener> void addAction(T action);
 
-        public <T extends Action & Action.Listener> boolean removeAction(
-                T action);
+        public <T extends Action & Action.Listener> void removeAction(T action);
     }
 
     public interface NotifierProxy {
-        public <T extends Action & Action.Listener> boolean addAction(T action);
+        public <T extends Action & Action.Listener> void addAction(T action);
 
-        public <T extends Action & Action.Listener> boolean removeAction(
-                T action);
+        public <T extends Action & Action.Listener> void removeAction(T action);
     }
 
     /**
index 4ff8a361211341d7e46874d7dcfc629ce4f029cd..84bc0d8277524b67dee0a9262b23ea9adc4e2329 100644 (file)
@@ -67,28 +67,28 @@ public class ActionManager implements Action.Container, Action.Handler,
         requestRepaint(); // this goes to the new viewer
     }
 
-    public <T extends Action & Action.Listener> boolean addAction(T action) {
+    public <T extends Action & Action.Listener> void addAction(T action) {
         if (ownActions == null) {
             ownActions = new HashSet<Action>();
         }
         if (ownActions.add(action)) {
             requestRepaint();
-            return true;
         }
-        return false;
     }
 
-    public <T extends Action & Action.Listener> boolean removeAction(T action) {
+    public <T extends Action & Action.Listener> void removeAction(T action) {
         if (ownActions != null) {
             if (ownActions.remove(action)) {
                 requestRepaint();
-                return true;
             }
         }
-        return false;
     }
 
     public void addActionHandler(Handler actionHandler) {
+        if (actionHandler == this) {
+            // don't add the actionHandler to itself
+            return;
+        }
         if (actionHandler != null) {
 
             if (actionHandlers == null) {
@@ -102,7 +102,6 @@ public class ActionManager implements Action.Container, Action.Handler,
     }
 
     public void removeActionHandler(Action.Handler actionHandler) {
-
         if (actionHandlers != null && actionHandlers.contains(actionHandler)) {
 
             if (actionHandlers.remove(actionHandler)) {
index d3531ad7fa5ea7b55818307ce0e262154bd8d26a..25212bc59043fa33328698023adef0d3b849da54 100644 (file)
@@ -39,37 +39,38 @@ public class ShortcutAction extends Action {
     /**
      * Used in the caption shorthand notation to indicate the ALT modifier.
      */
-    public static final char MNEMONIC_CHAR_ALT = '&';
+    public static final char SHORTHAND_CHAR_ALT = '&';
     /**
      * Used in the caption shorthand notation to indicate the SHIFT modifier.
      */
-    public static final char MNEMONIC_CHAR_SHIFT = '%';
+    public static final char SHORTHAND_CHAR_SHIFT = '_';
     /**
      * Used in the caption shorthand notation to indicate the CTRL modifier.
      */
-    public static final char MNEMONIC_CHAR_CTRL = '^';
+    public static final char SHORTHAND_CHAR_CTRL = '^';
 
     // regex-quote (escape) the characters
-    private static final String MNEMONIC_ALT = Pattern.quote(Character
-            .toString(MNEMONIC_CHAR_ALT));
-    private static final String MNEMONIC_SHIFT = Pattern.quote(Character
-            .toString(MNEMONIC_CHAR_SHIFT));
-    private static final String MNEMONIC_CTRL = Pattern.quote(Character
-            .toString(MNEMONIC_CHAR_CTRL));
+    private static final String SHORTHAND_ALT = Pattern.quote(Character
+            .toString(SHORTHAND_CHAR_ALT));
+    private static final String SHORTHAND_SHIFT = Pattern.quote(Character
+            .toString(SHORTHAND_CHAR_SHIFT));
+    private static final String SHORTHAND_CTRL = Pattern.quote(Character
+            .toString(SHORTHAND_CHAR_CTRL));
     // Used for replacing escaped chars, e.g && with &
-    private static final Pattern MNEMONICS_ESCAPE = Pattern.compile("("
-            + MNEMONIC_ALT + "?)" + MNEMONIC_ALT + "|(" + MNEMONIC_SHIFT + "?)"
-            + MNEMONIC_SHIFT + "|(" + MNEMONIC_CTRL + "?)" + MNEMONIC_CTRL);
-    // Used for removing escaped chars, only leaving real mnemonics
-    private static final Pattern MNEMONICS_REMOVE = Pattern.compile("(["
-            + MNEMONIC_ALT + "|" + MNEMONIC_SHIFT + "|" + MNEMONIC_CTRL
+    private static final Pattern SHORTHAND_ESCAPE = Pattern.compile("("
+            + SHORTHAND_ALT + "?)" + SHORTHAND_ALT + "|(" + SHORTHAND_SHIFT
+            + "?)" + SHORTHAND_SHIFT + "|(" + SHORTHAND_CTRL + "?)"
+            + SHORTHAND_CTRL);
+    // Used for removing escaped chars, only leaving real shorthands
+    private static final Pattern SHORTHAND_REMOVE = Pattern.compile("(["
+            + SHORTHAND_ALT + "|" + SHORTHAND_SHIFT + "|" + SHORTHAND_CTRL
             + "])\\1");
     // Mnemonic char, optionally followed by another, and optionally a third
-    private static final Pattern MNEMONICS = Pattern.compile("(" + MNEMONIC_ALT
-            + "|" + MNEMONIC_SHIFT + "|" + MNEMONIC_CTRL + ")(?!\\1)(?:("
-            + MNEMONIC_ALT + "|" + MNEMONIC_SHIFT + "|" + MNEMONIC_CTRL
-            + ")(?!\\1|\\2))?(?:(" + MNEMONIC_ALT + "|" + MNEMONIC_SHIFT + "|"
-            + MNEMONIC_CTRL + ")(?!\\1|\\2|\\3))?.");
+    private static final Pattern SHORTHANDS = Pattern.compile("("
+            + SHORTHAND_ALT + "|" + SHORTHAND_SHIFT + "|" + SHORTHAND_CTRL
+            + ")(?!\\1)(?:(" + SHORTHAND_ALT + "|" + SHORTHAND_SHIFT + "|"
+            + SHORTHAND_CTRL + ")(?!\\1|\\2))?(?:(" + SHORTHAND_ALT + "|"
+            + SHORTHAND_SHIFT + "|" + SHORTHAND_CTRL + ")(?!\\1|\\2|\\3))?.");
 
     /**
      * Constructs a ShortcutAction using a shorthand notation to encode the
@@ -114,11 +115,11 @@ public class ShortcutAction extends Action {
      */
     public ShortcutAction(String shorthandCaption, int[] modifierKeys) {
         // && -> & etc
-        super(MNEMONICS_ESCAPE.matcher(shorthandCaption).replaceAll("$1$2$3"));
+        super(SHORTHAND_ESCAPE.matcher(shorthandCaption).replaceAll("$1$2$3"));
         // replace escaped chars with something that won't accidentally match
-        shorthandCaption = MNEMONICS_REMOVE.matcher(shorthandCaption)
+        shorthandCaption = SHORTHAND_REMOVE.matcher(shorthandCaption)
                 .replaceAll("\u001A");
-        Matcher matcher = MNEMONICS.matcher(shorthandCaption);
+        Matcher matcher = SHORTHANDS.matcher(shorthandCaption);
         if (matcher.find()) {
             String match = matcher.group();
 
@@ -135,13 +136,13 @@ public class ShortcutAction extends Action {
                 for (int i = 0; i < mod.length; i++) {
                     int kc = match.charAt(i);
                     switch (kc) {
-                    case MNEMONIC_CHAR_ALT:
+                    case SHORTHAND_CHAR_ALT:
                         mod[i] = ModifierKey.ALT;
                         break;
-                    case MNEMONIC_CHAR_CTRL:
+                    case SHORTHAND_CHAR_CTRL:
                         mod[i] = ModifierKey.CTRL;
                         break;
-                    case MNEMONIC_CHAR_SHIFT:
+                    case SHORTHAND_CHAR_SHIFT:
                         mod[i] = ModifierKey.SHIFT;
                         break;
                     }
index 9c4e6b87f8919c85caa4bc7b18ff244a10142776..dcc1a39b83c48303de5cb1059893559088865a4c 100644 (file)
@@ -179,7 +179,7 @@ public class VForm extends ComplexPanel implements Container {
         }\r
         lo.updateFromUIDL(layoutUidl, client);\r
 \r
-        // We may have actions attached to this panel\r
+        // We may have actions attached\r
         if (uidl.getChildCount() > 1) {\r
             final int cnt = uidl.getChildCount();\r
             for (int i = 1; i < cnt; i++) {\r
index 413916f298bb4268b04313db95f09db6dd88f333..7ea4f2471e83b7dc05bbb4b6c91d04f7fd1e14bd 100644 (file)
@@ -1199,15 +1199,14 @@ public abstract class AbstractField extends AbstractComponent implements Field,
         return actionManager;
     }
 
-    public <T extends Action & Action.Listener> boolean addAction(T action) {
-        return getActionManager().addAction(action);
+    public <T extends Action & Action.Listener> void addAction(T action) {
+        getActionManager().addAction(action);
     }
 
-    public <T extends Action & Action.Listener> boolean removeAction(T action) {
+    public <T extends Action & Action.Listener> void removeAction(T action) {
         if (actionManager == null) {
-            return actionManager.removeAction(action);
+            actionManager.removeAction(action);
         }
-        return false;
     }
 
     public static class FocusShortcut extends ShortcutListener {
index 156c9429014f45207eb8be032dcd97cb29f950b5..08fab9772a460eb83f588a5ac5a9e87bee51e8f9 100644 (file)
@@ -352,22 +352,22 @@ public class Button extends AbstractField {
      * Actions
      */
 
-    protected ClickShortcut clickMnemonic;
+    protected ClickShortcut clickShortcut;
 
-    public ClickShortcut setClickMnemonic(int keyCode, int... modifiers) {
-        ClickShortcut old = clickMnemonic;
+    public ClickShortcut setClickShortcut(int keyCode, int... modifiers) {
+        ClickShortcut old = clickShortcut;
         if (old != null) {
             removeAction(old);
         }
-        clickMnemonic = new ClickShortcut(this, keyCode, modifiers);
-        addAction(clickMnemonic);
+        clickShortcut = new ClickShortcut(this, keyCode, modifiers);
+        addAction(clickShortcut);
         return old;
     }
 
-    public void removeClickMnemonic() {
-        if (clickMnemonic != null) {
-            removeAction(clickMnemonic);
-            clickMnemonic = null;
+    public void removeClickShortcut() {
+        if (clickShortcut != null) {
+            removeAction(clickShortcut);
+            clickShortcut = null;
         }
     }
 
index 7a4c8159ac968931af2d9af5e493d8036e1cd61a..59d1b51481e4f61074ba40b08d35e1c475e69612 100644 (file)
@@ -1285,8 +1285,7 @@ public class Form extends AbstractField implements Item.Editor, Buffered, Item,
 
     protected ActionManager getActionManager() {
         if (actionManager == null) {
-            actionManager = new ActionManager();
-            actionManager.setViewer(this);
+            actionManager = new ActionManager(this);
         }
         return actionManager;
     }
index ee39a1797edaff7f7c71f2c4e3a58a45cadd899f..e23e38d56f928daa1aa9003bcdc35e7457608aba 100644 (file)
@@ -490,23 +490,21 @@ public class Panel extends AbstractComponentContainer implements Scrollable,
      */
     protected ActionManager getActionManager() {
         if (actionManager == null) {
-            actionManager = new ActionManager();
-            actionManager.setViewer(this);
+            actionManager = new ActionManager(this);
         }
         return actionManager;
     }
 
-    public <T extends Action & com.vaadin.event.Action.Listener> boolean addAction(
+    public <T extends Action & com.vaadin.event.Action.Listener> void addAction(
             T action) {
-        return getActionManager().addAction(action);
+        getActionManager().addAction(action);
     }
 
-    public <T extends Action & com.vaadin.event.Action.Listener> boolean removeAction(
+    public <T extends Action & com.vaadin.event.Action.Listener> void removeAction(
             T action) {
         if (actionManager == null) {
-            return actionManager.removeAction(action);
+            actionManager.removeAction(action);
         }
-        return false;
     }
 
     public void addActionHandler(Handler actionHandler) {
index bc037c18fb66aeef80a448e881b8b295ee654fe4..bfc36a5178ed1a6990a88efeda9e1a3189af6073 100644 (file)
@@ -1802,22 +1802,22 @@ public class Window extends Panel implements URIHandler, ParameterHandler {
     /*
      * Actions
      */
-    protected CloseShortcut closeMnemonic;
+    protected CloseShortcut closeShortcut;
 
-    public CloseShortcut setCloseMnemonic(int keyCode, int... modifiers) {
-        CloseShortcut old = closeMnemonic;
+    public CloseShortcut setCloseShortcut(int keyCode, int... modifiers) {
+        CloseShortcut old = closeShortcut;
         if (old != null) {
             removeAction(old);
         }
-        closeMnemonic = new CloseShortcut(this, keyCode, modifiers);
-        addAction(closeMnemonic);
+        closeShortcut = new CloseShortcut(this, keyCode, modifiers);
+        addAction(closeShortcut);
         return old;
     }
 
-    public void removeCloseMnemonic() {
-        if (closeMnemonic != null) {
-            removeAction(closeMnemonic);
-            closeMnemonic = null;
+    public void removeCloseShortcut() {
+        if (closeShortcut != null) {
+            removeAction(closeShortcut);
+            closeShortcut = null;
         }
     }