From: Jani Laakso Date: Thu, 20 Sep 2007 08:10:43 +0000 (+0000) Subject: com.itmill.toolkit.terminal.gwt.client.* packages and classes are now refactored... X-Git-Tag: 6.7.0.beta1~5970 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=f82c0659ca8e57f42439170c7ba99685091d2ba1;p=vaadin-framework.git com.itmill.toolkit.terminal.gwt.client.* packages and classes are now refactored as described on changeset 2344 svn changeset:2350/svn branch:trunk --- diff --git a/src/com/itmill/toolkit/terminal/gwt/client/ui/ShortcutActionHandler.java b/src/com/itmill/toolkit/terminal/gwt/client/ui/ShortcutActionHandler.java index 5710f1c7ea..08fcf40662 100644 --- a/src/com/itmill/toolkit/terminal/gwt/client/ui/ShortcutActionHandler.java +++ b/src/com/itmill/toolkit/terminal/gwt/client/ui/ShortcutActionHandler.java @@ -8,9 +8,9 @@ import com.itmill.toolkit.terminal.gwt.client.ApplicationConnection; import com.itmill.toolkit.terminal.gwt.client.UIDL; /** - * A helper class to implement keyboard shorcut handling. Keeps - * a list of owners actions and fires actions to server. User class - * needs to delegate keyboard events to handleKeyboardEvents function. + * A helper class to implement keyboard shorcut handling. Keeps a list of owners + * actions and fires actions to server. User class needs to delegate keyboard + * events to handleKeyboardEvents function. * * @author IT Mill ltd */ @@ -18,12 +18,16 @@ public class ShortcutActionHandler { private ArrayList actions = new ArrayList(); private ApplicationConnection client; private String paintableId; - - private ShortcutActionHandler() {} + + private ShortcutActionHandler() { + } + /** * - * @param pid Paintable id - * @param c reference to application connections + * @param pid + * Paintable id + * @param c + * reference to application connections */ public ShortcutActionHandler(String pid, ApplicationConnection c) { paintableId = pid; @@ -33,85 +37,87 @@ public class ShortcutActionHandler { /** * Updates list of actions this handler listens to. * - * @param c UIDL snippet containing actions + * @param c + * UIDL snippet containing actions */ public void updateActionMap(UIDL c) { actions.clear(); Iterator it = c.getChildIterator(); - while(it.hasNext()) { + while (it.hasNext()) { UIDL action = (UIDL) it.next(); - + int[] modifiers = null; - if(action.hasAttribute("mk")) + if (action.hasAttribute("mk")) modifiers = action.getIntArrayAttribute("mk"); - - ShortcutKeyCombination kc = new ShortcutKeyCombination( - action.getIntAttribute("kc"), - modifiers); + + ShortcutKeyCombination kc = new ShortcutKeyCombination(action + .getIntAttribute("kc"), modifiers); String key = action.getStringAttribute("key"); String caption = action.getStringAttribute("caption"); - actions.add(new IShortcutAction(key,kc, caption)); + actions.add(new ShortcutAction(key, kc, caption)); } } /** - * This method compares given key code and modifier keys to - * internal list of actions. If matching action is found it - * is fired. + * This method compares given key code and modifier keys to internal list of + * actions. If matching action is found it is fired. * - * @param keyCode character typed - * @param modifiers modifier keys (bitmask like in {@link KeyboardListener}) + * @param keyCode + * character typed + * @param modifiers + * modifier keys (bitmask like in {@link KeyboardListener}) */ public void handleKeyboardEvent(char keyCode, int modifiers) { - ShortcutKeyCombination kc = - new ShortcutKeyCombination(keyCode, modifiers); + ShortcutKeyCombination kc = new ShortcutKeyCombination(keyCode, + modifiers); Iterator it = actions.iterator(); - while(it.hasNext()) { - IShortcutAction a = (IShortcutAction) it.next(); - if(a.getShortcutCombination().equals(kc)) { + while (it.hasNext()) { + ShortcutAction a = (ShortcutAction) it.next(); + if (a.getShortcutCombination().equals(kc)) { client.updateVariable(paintableId, "action", a.getKey(), true); break; } } } - + } class ShortcutKeyCombination { - + public static final int SHIFT = 16; public static final int CTRL = 17; public static final int ALT = 18; - - - + char keyCode = 0; private int modifiersMask; - + public ShortcutKeyCombination() { } - + ShortcutKeyCombination(char kc, int modifierMask) { keyCode = kc; this.modifiersMask = modifierMask; } - + ShortcutKeyCombination(int kc, int[] modifiers) { keyCode = (char) kc; keyCode = Character.toUpperCase(keyCode); - + this.modifiersMask = 0; - if(modifiers != null) { + if (modifiers != null) { for (int i = 0; i < modifiers.length; i++) { switch (modifiers[i]) { case ALT: - modifiersMask = modifiersMask | KeyboardListener.MODIFIER_ALT; + modifiersMask = modifiersMask + | KeyboardListener.MODIFIER_ALT; break; case CTRL: - modifiersMask = modifiersMask | KeyboardListener.MODIFIER_CTRL; + modifiersMask = modifiersMask + | KeyboardListener.MODIFIER_CTRL; break; case SHIFT: - modifiersMask = modifiersMask | KeyboardListener.MODIFIER_SHIFT; + modifiersMask = modifiersMask + | KeyboardListener.MODIFIER_SHIFT; break; default: break; @@ -119,38 +125,37 @@ class ShortcutKeyCombination { } } } - + public boolean equals(ShortcutKeyCombination other) { - if( this.keyCode == other.keyCode && - this.modifiersMask == other.modifiersMask) + if (this.keyCode == other.keyCode + && this.modifiersMask == other.modifiersMask) return true; return false; } } -class IShortcutAction { +class ShortcutAction { private ShortcutKeyCombination sc; private String caption; private String key; - public IShortcutAction(String key, ShortcutKeyCombination sc, String caption) { + public ShortcutAction(String key, ShortcutKeyCombination sc, String caption) { this.sc = sc; this.key = key; this.caption = caption; } - + public ShortcutKeyCombination getShortcutCombination() { return sc; } - + public String getCaption() { return caption; } - + public String getKey() { return key; } } -