PageRenderTime 20ms CodeModel.GetById 14ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 0ms

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