Example usage for java.awt.event KeyEvent setSource

List of usage examples for java.awt.event KeyEvent setSource

Introduction

In this page you can find the example usage for java.awt.event KeyEvent setSource.

Prototype

public void setSource(Object newSource) 

Source Link

Document

Retargets an event to a new source.

Usage

From source file:ru.codemine.pos.ui.keydispatcher.MainKeyDispatcher.java

@Override
public boolean dispatchKeyEvent(KeyEvent e) {
    WebTextField inputField = salesPanel.getChequeSetupPanel().getInputField();

    int tabIndex = mainWindow.getActiveTabIndex();
    boolean inputBlocked = mainWindow.isBarcodeInputBlocked();

    //?   ?,  ?   ????     - 
    //  ?  ? ?/* w w  w.  j  a v a 2s  . c  o  m*/
    if (tabIndex == 0 && !inputBlocked
            && application.getCurrentScanner()
                    .getType() == BarcodeScannerDevice.BarcodeScannerType.KEYBOARD_SCANNER
            && ("1234567890".indexOf(e.getKeyChar()) >= 0)) {
        e.setSource(inputField);
    }
    //?   Enter   ? ? - ?
    //     ??  
    else if (tabIndex == 0 && !inputBlocked && !"".equals(inputField.getText())
            && (e.getKeyCode() == KeyEvent.VK_ENTER)) {
        String barcode = inputField.getText();
        inputField.clear();
        salesPanel.addProductByBarcode(barcode);
    } else {
        if (tabIndex == 0 && !inputBlocked) {
            switch (e.getKeyCode()) {
            //case KeyEvent.VK_F2 : buttonsPanel.getOpenWorkdayButton().doClick();
            //    break;
            //case KeyEvent.VK_F3 : buttonsPanel.getCloseWorkdayButton().doClick();
            //    break;
            case KeyEvent.VK_F4:
                buttonsPanel.getQuantitySetupButton().doClick();
                break;
            case KeyEvent.VK_F5:
                buttonsPanel.getChequeProcessButton().doClick();
            }
        }
    }

    return false;
}