}
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);
}
/**
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) {
}
public void removeActionHandler(Action.Handler actionHandler) {
-
if (actionHandlers != null && actionHandlers.contains(actionHandler)) {
if (actionHandlers.remove(actionHandler)) {
/**
* 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
*/
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();
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;
}
}\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
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 {
* 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;
}
}
protected ActionManager getActionManager() {
if (actionManager == null) {
- actionManager = new ActionManager();
- actionManager.setViewer(this);
+ actionManager = new ActionManager(this);
}
return actionManager;
}
*/
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) {
/*
* 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;
}
}