/webccr/src/com/emis/caesarui/webccr/listener/TSettleKeyPressHandler.java

https://bitbucket.org/sanliou/synccr · Java · 84 lines · 58 code · 14 blank · 12 comment · 6 complexity · 748b6de78900e962d88213c7a269f130 MD5 · raw file

  1. package com.emis.caesarui.webccr.listener;
  2. import com.emis.caesar.emisComponents;
  3. import com.emis.caesarui.webccr.webccr;
  4. import com.vaadin.event.Action;
  5. import com.vaadin.event.ShortcutAction;
  6. import com.vaadin.ui.Button;
  7. import com.vaadin.ui.UI;
  8. /**
  9. * 監控鍵盤按鈕
  10. */
  11. public class TSettleKeyPressHandler implements Action.Handler {
  12. Action esc = new ShortcutAction("ESC", ShortcutAction.KeyCode.ESCAPE, null);
  13. Action f1 = new ShortcutAction("F1", ShortcutAction.KeyCode.F1, null);
  14. Action f2 = new ShortcutAction("F2", ShortcutAction.KeyCode.F2, null);
  15. Action f3 = new ShortcutAction("F3", ShortcutAction.KeyCode.F3, null);
  16. emisComponents bindComponent = null;
  17. public TSettleKeyPressHandler() {
  18. }
  19. /**
  20. * 綁定當鍵盤輸入資料時,同步顯示的元件
  21. *
  22. * @param bindcomponent 同步顯示的元件物件
  23. */
  24. public void bindComponent(emisComponents bindcomponent) {
  25. bindComponent = bindcomponent;
  26. }
  27. @Override
  28. public Action[] getActions(Object target, Object sender) {
  29. return new Action[]{
  30. esc, f1, f2, f3
  31. };
  32. }
  33. @Override
  34. public void handleAction(Action action, Object sender, Object target) {
  35. try {
  36. System.out.println("Action:"+action.getCaption());
  37. onFunction(action.getCaption());
  38. } catch (Exception e) {
  39. ((webccr) UI.getCurrent()).getlog().error(webccr.class, e);
  40. }
  41. }
  42. private void onFunction(String caption) throws Exception {
  43. if(bindComponent == null ) return;
  44. Button _oBtn =null;
  45. //取消[ESC]
  46. if("ESC".equalsIgnoreCase(caption)) {
  47. _oBtn = (Button) bindComponent.getComponent("btnEsc");
  48. _oBtn.click();
  49. return;
  50. }
  51. //清帳[F1]
  52. if("F1".equalsIgnoreCase(caption)) {
  53. _oBtn = (Button) bindComponent.getComponent("btnColse");
  54. _oBtn.click();
  55. return;
  56. }
  57. //列印[F2]
  58. if("F2".equalsIgnoreCase(caption)) {
  59. _oBtn = (Button) bindComponent.getComponent("btnRpt");
  60. _oBtn.click();
  61. return;
  62. }
  63. //交班[F3]
  64. if ("F3".equalsIgnoreCase(caption)) {
  65. _oBtn = (Button) bindComponent.getComponent("btnChange");
  66. _oBtn.click();
  67. return;
  68. }
  69. }
  70. }