1 14 package wingset; 15 16 import org.wings.SComponent; 17 import org.wings.SForm; 18 import org.wings.SLabel; 19 import org.wings.STextField; 20 21 import javax.swing.*; 22 import java.awt.event.ActionEvent ; 23 import java.awt.event.KeyEvent ; 24 25 29 public class KeyboardBindingsExample extends WingSetPane { 30 private SLabel label = new SLabel(); 31 private STextField textField = new STextField(); 32 private SForm form = new SForm(); 33 34 public SComponent createExample() { 35 InputMap inputMap = new InputMap(); 36 inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_F1, 0, false), "f1"); 37 inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_F2, 0, false), "f2"); 38 inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_F3, 0, false), "f3"); 39 inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_F4, 0, false), "f4"); 40 inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_F5, 0, false), "f5"); 41 inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_F6, 0, false), "f6"); 42 inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_F7, 0, false), "f7"); 43 inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_F8, 0, false), "f8"); 44 inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_F9, 0, false), "f9"); 45 inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_F10, 0, false), "f10"); 46 47 InputMap formInputMap = new InputMap(); 48 formInputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_F1, KeyEvent.SHIFT_DOWN_MASK, false), "shift f1"); 49 formInputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_F2, KeyEvent.SHIFT_DOWN_MASK, false), "shift f2"); 50 formInputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_F3, KeyEvent.SHIFT_DOWN_MASK, false), "shift f3"); 51 formInputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_F4, KeyEvent.SHIFT_DOWN_MASK, false), "shift f4"); 52 formInputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_F5, KeyEvent.SHIFT_DOWN_MASK, false), "shift f5"); 53 formInputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_F6, KeyEvent.SHIFT_DOWN_MASK, false), "shift f6"); 54 formInputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_F7, KeyEvent.SHIFT_DOWN_MASK, false), "shift f7"); 55 formInputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_F8, KeyEvent.SHIFT_DOWN_MASK, false), "shift f8"); 56 formInputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_F9, KeyEvent.SHIFT_DOWN_MASK, false), "shift f9"); 57 formInputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_F10, KeyEvent.SHIFT_DOWN_MASK, false), "shift f10"); 58 59 60 Action action = new AbstractAction() { 61 public void actionPerformed(ActionEvent e) { 62 label.setText(e.getActionCommand()); 63 } 64 }; 65 66 ActionMap actionMap = new ActionMap(); 67 actionMap.put("f1", action); 68 actionMap.put("f2", action); 69 actionMap.put("f3", action); 70 actionMap.put("f4", action); 71 actionMap.put("f5", action); 72 actionMap.put("f6", action); 73 actionMap.put("f7", action); 74 actionMap.put("f8", action); 75 actionMap.put("f9", action); 76 actionMap.put("f10", action); 77 actionMap.put("shift f1", action); 78 actionMap.put("shift f2", action); 79 actionMap.put("shift f3", action); 80 actionMap.put("shift f4", action); 81 actionMap.put("shift f5", action); 82 actionMap.put("shift f6", action); 83 actionMap.put("shift f7", action); 84 actionMap.put("shift f8", action); 85 actionMap.put("shift f9", action); 86 actionMap.put("shift f10", action); 87 88 textField.setInputMap(inputMap); 89 textField.setActionMap(actionMap); 90 91 form.setInputMap(formInputMap); 92 form.setActionMap(actionMap); 93 94 form.add(new SLabel("<html>f1 through f10 are captured by the STextField<br/>" + 95 "shift f1 through shift f10 are bubbling up to the containing SForm")); 96 form.add(textField); 97 form.add(label); 98 99 return form; 100 } 101 } 102 | Popular Tags |