diff options
Diffstat (limited to 'server/src/com/vaadin/event')
-rw-r--r-- | server/src/com/vaadin/event/ShortcutAction.java | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/server/src/com/vaadin/event/ShortcutAction.java b/server/src/com/vaadin/event/ShortcutAction.java index 09accae1c7..32b909e9f2 100644 --- a/server/src/com/vaadin/event/ShortcutAction.java +++ b/server/src/com/vaadin/event/ShortcutAction.java @@ -17,6 +17,8 @@ package com.vaadin.event; import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -237,6 +239,42 @@ public class ShortcutAction extends Action { } /** + * Checks whether the shortcut can be triggered with the given combination + * of keys. + * + * @param keyCode + * potential match for the {@link KeyCode} that this shortcut + * reacts to + * @param modifierKeys + * (optional) potential matches for the {@link ModifierKey}s + * required for this shortcut to react + * @return <code>true</code> if keyCode and modifierKeys are a match, + * <code>false</code> otherwise + */ + public boolean isTriggeredBy(int keyCode, int... modifierKeys) { + boolean result = false; + if (keyCode == this.keyCode) { + if (modifierKeys == null) { + result = (modifiers == null); + } else if (modifiers != null) { + List<Integer> modifierList = new ArrayList<Integer>(); + for (int modifier : modifiers) { + modifierList.add(modifier); + } + for (int modifierKey : modifierKeys) { + if (modifierList.contains(modifierKey)) { + modifierList.remove(modifierKey); + } else { + return false; + } + } + result = modifierList.isEmpty(); + } + } + return result; + } + + /** * Key codes that can be used for shortcuts * */ |