summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMarc Englund <marc.englund@itmill.com>2010-03-23 10:05:45 +0000
committerMarc Englund <marc.englund@itmill.com>2010-03-23 10:05:45 +0000
commit486a2310ce0f812afbdb93db3f98963ea85d74d8 (patch)
treefaf628bb068ff9c43aa6bd1f8ba89eb4520d2dbb /src
parentbe1d9b2934dcc006ab84110c66d7a77f6ebeb8c6 (diff)
downloadvaadin-framework-486a2310ce0f812afbdb93db3f98963ea85d74d8.tar.gz
vaadin-framework-486a2310ce0f812afbdb93db3f98963ea85d74d8.zip
Refactored new actions api a little: removed mnemonics terminology, adding/removing stuff 'returns' void, shift shorthand in now _
svn changeset:12029/svn branch:6.3
Diffstat (limited to 'src')
-rw-r--r--src/com/vaadin/event/Action.java10
-rw-r--r--src/com/vaadin/event/ActionManager.java13
-rw-r--r--src/com/vaadin/event/ShortcutAction.java53
-rw-r--r--src/com/vaadin/terminal/gwt/client/ui/VForm.java2
-rw-r--r--src/com/vaadin/ui/AbstractField.java9
-rw-r--r--src/com/vaadin/ui/Button.java18
-rw-r--r--src/com/vaadin/ui/Form.java3
-rw-r--r--src/com/vaadin/ui/Panel.java12
-rw-r--r--src/com/vaadin/ui/Window.java18
9 files changed, 66 insertions, 72 deletions
diff --git a/src/com/vaadin/event/Action.java b/src/com/vaadin/event/Action.java
index 247def9ee6..b2e3f6a930 100644
--- a/src/com/vaadin/event/Action.java
+++ b/src/com/vaadin/event/Action.java
@@ -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);
}
/**
diff --git a/src/com/vaadin/event/ActionManager.java b/src/com/vaadin/event/ActionManager.java
index 4ff8a36121..84bc0d8277 100644
--- a/src/com/vaadin/event/ActionManager.java
+++ b/src/com/vaadin/event/ActionManager.java
@@ -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)) {
diff --git a/src/com/vaadin/event/ShortcutAction.java b/src/com/vaadin/event/ShortcutAction.java
index d3531ad7fa..25212bc590 100644
--- a/src/com/vaadin/event/ShortcutAction.java
+++ b/src/com/vaadin/event/ShortcutAction.java
@@ -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;
}
diff --git a/src/com/vaadin/terminal/gwt/client/ui/VForm.java b/src/com/vaadin/terminal/gwt/client/ui/VForm.java
index 9c4e6b87f8..dcc1a39b83 100644
--- a/src/com/vaadin/terminal/gwt/client/ui/VForm.java
+++ b/src/com/vaadin/terminal/gwt/client/ui/VForm.java
@@ -179,7 +179,7 @@ public class VForm extends ComplexPanel implements Container {
}
lo.updateFromUIDL(layoutUidl, client);
- // We may have actions attached to this panel
+ // We may have actions attached
if (uidl.getChildCount() > 1) {
final int cnt = uidl.getChildCount();
for (int i = 1; i < cnt; i++) {
diff --git a/src/com/vaadin/ui/AbstractField.java b/src/com/vaadin/ui/AbstractField.java
index 413916f298..7ea4f2471e 100644
--- a/src/com/vaadin/ui/AbstractField.java
+++ b/src/com/vaadin/ui/AbstractField.java
@@ -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 {
diff --git a/src/com/vaadin/ui/Button.java b/src/com/vaadin/ui/Button.java
index 156c942901..08fab9772a 100644
--- a/src/com/vaadin/ui/Button.java
+++ b/src/com/vaadin/ui/Button.java
@@ -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;
}
}
diff --git a/src/com/vaadin/ui/Form.java b/src/com/vaadin/ui/Form.java
index 7a4c8159ac..59d1b51481 100644
--- a/src/com/vaadin/ui/Form.java
+++ b/src/com/vaadin/ui/Form.java
@@ -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;
}
diff --git a/src/com/vaadin/ui/Panel.java b/src/com/vaadin/ui/Panel.java
index ee39a1797e..e23e38d56f 100644
--- a/src/com/vaadin/ui/Panel.java
+++ b/src/com/vaadin/ui/Panel.java
@@ -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) {
diff --git a/src/com/vaadin/ui/Window.java b/src/com/vaadin/ui/Window.java
index bc037c18fb..bfc36a5178 100644
--- a/src/com/vaadin/ui/Window.java
+++ b/src/com/vaadin/ui/Window.java
@@ -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;
}
}