/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
- package com.emis.caesarui.webccr.listener;
- import com.emis.caesar.emisComponents;
- import com.emis.caesarui.webccr.webccr;
- import com.vaadin.event.Action;
- import com.vaadin.event.ShortcutAction;
- import com.vaadin.ui.Button;
- import com.vaadin.ui.UI;
- /**
- * 監控鍵盤按鈕
- */
- public class TSettleKeyPressHandler implements Action.Handler {
- Action esc = new ShortcutAction("ESC", ShortcutAction.KeyCode.ESCAPE, null);
- Action f1 = new ShortcutAction("F1", ShortcutAction.KeyCode.F1, null);
- Action f2 = new ShortcutAction("F2", ShortcutAction.KeyCode.F2, null);
- Action f3 = new ShortcutAction("F3", ShortcutAction.KeyCode.F3, null);
- emisComponents bindComponent = null;
- public TSettleKeyPressHandler() {
- }
- /**
- * 綁定當鍵盤輸入資料時,同步顯示的元件
- *
- * @param bindcomponent 同步顯示的元件物件
- */
- public void bindComponent(emisComponents bindcomponent) {
- bindComponent = bindcomponent;
- }
- @Override
- public Action[] getActions(Object target, Object sender) {
- return new Action[]{
- esc, f1, f2, f3
- };
- }
- @Override
- public void handleAction(Action action, Object sender, Object target) {
- try {
- System.out.println("Action:"+action.getCaption());
- onFunction(action.getCaption());
- } catch (Exception e) {
- ((webccr) UI.getCurrent()).getlog().error(webccr.class, e);
- }
- }
- private void onFunction(String caption) throws Exception {
- if(bindComponent == null ) return;
- Button _oBtn =null;
- //取消[ESC]
- if("ESC".equalsIgnoreCase(caption)) {
- _oBtn = (Button) bindComponent.getComponent("btnEsc");
- _oBtn.click();
- return;
- }
- //清帳[F1]
- if("F1".equalsIgnoreCase(caption)) {
- _oBtn = (Button) bindComponent.getComponent("btnColse");
- _oBtn.click();
- return;
- }
- //列印[F2]
- if("F2".equalsIgnoreCase(caption)) {
- _oBtn = (Button) bindComponent.getComponent("btnRpt");
- _oBtn.click();
- return;
- }
- //交班[F3]
- if ("F3".equalsIgnoreCase(caption)) {
- _oBtn = (Button) bindComponent.getComponent("btnChange");
- _oBtn.click();
- return;
- }
- }
- }