TavernerPOS - Source Code
Clone:
git clone http://www.librarysmith.co.uk/tavernerPOS
package com.floreantpos.swing;
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.KeyboardFocusManager;
import java.awt.event.ActionEvent;
import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.event.EventListenerList;
import javax.swing.text.JTextComponent;
import com.floreantpos.Messages;
import com.floreantpos.swing.event.KeypadEvent;
import com.floreantpos.swing.event.KeypadEventListener;
/**
*
* @author seliger (github: https://github.com/coresoftwaresystems/Restaurant-OPEN/blob/b875efbc2b6f66556062e93c4b61b90dd21c6429/src/com/coresoftwaresystems/swing/NumericKeypad.java)
*/
public class NumericKeypad extends javax.swing.JComponent {
private EventListenerList eventListeners = new EventListenerList();
private String text = ""; //$NON-NLS-1$
private KeypadEvent keypadEvent = null;
private boolean isProtected = false;
/** Creates new form PasswordForm */
public NumericKeypad() {
initComponents();
}
public synchronized void removeKeypadEventListener(KeypadEventListener listener) {
eventListeners.remove(KeypadEventListener.class, listener);
}
public synchronized void addKeypadEventListener(KeypadEventListener listener) {
eventListeners.add(KeypadEventListener.class, listener);
}
protected synchronized void fireKeypadEvent(int eventId) {
Object[] listeners = eventListeners.getListenerList();
for (int i = listeners.length - 2; i >= 0; i -= 2) {
if (listeners[i] == KeypadEventListener.class) {
keypadEvent = new KeypadEvent(this, eventId);
((KeypadEventListener) listeners[i + 1]).receiveKeypadEvent(keypadEvent);
}
}
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
// GEN-BEGIN:initComponents
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
keypadPanel = new javax.swing.JPanel();
posButton7 = new com.floreantpos.swing.PosButton();
posButton7.setFocusable(false);
posButton8 = new com.floreantpos.swing.PosButton();
posButton8.setFocusable(false);
posButton9 = new com.floreantpos.swing.PosButton();
posButton9.setFocusable(false);
posButton4 = new com.floreantpos.swing.PosButton();
posButton4.setFocusable(false);
posButton5 = new com.floreantpos.swing.PosButton();
posButton5.setFocusable(false);
posButton6 = new com.floreantpos.swing.PosButton();
posButton6.setFocusable(false);
posButton1 = new com.floreantpos.swing.PosButton();
posButton1.setFocusable(false);
posButton2 = new com.floreantpos.swing.PosButton();
posButton2.setFocusable(false);
posButton3 = new com.floreantpos.swing.PosButton();
posButton3.setFocusable(false);
posButton0 = new com.floreantpos.swing.PosButton();
posButton0.setFocusable(false);
keypadPanel.setLayout(new java.awt.GridLayout(4, 3, 5, 5));
posButton7.setAction(goAction);
posButton7.setIcon(com.floreantpos.IconFactory.getIcon("7.png")); //$NON-NLS-1$
posButton7.setActionCommand("7"); //$NON-NLS-1$
keypadPanel.add(posButton7);
posButton8.setAction(goAction);
posButton8.setIcon(com.floreantpos.IconFactory.getIcon("8.png")); //$NON-NLS-1$
posButton8.setActionCommand("8"); //$NON-NLS-1$
keypadPanel.add(posButton8);
posButton9.setAction(goAction);
posButton9.setIcon(com.floreantpos.IconFactory.getIcon("9.png")); //$NON-NLS-1$
posButton9.setActionCommand("9"); //$NON-NLS-1$
keypadPanel.add(posButton9);
posButton4.setAction(goAction);
posButton4.setIcon(com.floreantpos.IconFactory.getIcon("4.png")); //$NON-NLS-1$
posButton4.setActionCommand("4"); //$NON-NLS-1$
keypadPanel.add(posButton4);
posButton5.setAction(goAction);
posButton5.setIcon(com.floreantpos.IconFactory.getIcon("5.png")); //$NON-NLS-1$
posButton5.setActionCommand("5"); //$NON-NLS-1$
keypadPanel.add(posButton5);
posButton6.setAction(goAction);
posButton6.setIcon(com.floreantpos.IconFactory.getIcon("6.png")); //$NON-NLS-1$
posButton6.setActionCommand("6"); //$NON-NLS-1$
keypadPanel.add(posButton6);
posButton1.setAction(goAction);
posButton1.setIcon(com.floreantpos.IconFactory.getIcon("1.png")); //$NON-NLS-1$
posButton1.setActionCommand("1"); //$NON-NLS-1$
keypadPanel.add(posButton1);
posButton2.setAction(goAction);
posButton2.setIcon(com.floreantpos.IconFactory.getIcon("2.png")); //$NON-NLS-1$
posButton2.setActionCommand("2"); //$NON-NLS-1$
keypadPanel.add(posButton2);
posButton3.setAction(goAction);
posButton3.setIcon(com.floreantpos.IconFactory.getIcon("3.png")); //$NON-NLS-1$
posButton3.setActionCommand("3"); //$NON-NLS-1$
keypadPanel.add(posButton3);
btnDot = new PosButton();
btnDot.setFocusable(false);
btnDot.setAction(goAction);
btnDot.setActionCommand("."); //$NON-NLS-1$
btnDot.setIcon(com.floreantpos.IconFactory.getIcon("dot.png")); //$NON-NLS-1$
keypadPanel.add(btnDot);
posButton0.setAction(goAction);
posButton0.setIcon(com.floreantpos.IconFactory.getIcon("0.png")); //$NON-NLS-1$
posButton0.setActionCommand("0"); //$NON-NLS-1$
keypadPanel.add(posButton0);
setLayout(new BorderLayout(0, 0));
posButton10 = new com.floreantpos.swing.PosButton();
posButton10.setFocusable(false);
keypadPanel.add(posButton10);
posButton10.setAction(goAction);
posButton10.setIcon(com.floreantpos.IconFactory.getIcon("clear.png")); //$NON-NLS-1$
posButton10.setText(Messages.getString("NumericKeypad.0")); //$NON-NLS-1$
add(keypadPanel, BorderLayout.CENTER);
}// </editor-fold>
private javax.swing.JPanel keypadPanel;
private com.floreantpos.swing.PosButton posButton0;
private com.floreantpos.swing.PosButton posButton1;
private com.floreantpos.swing.PosButton posButton10;
private com.floreantpos.swing.PosButton posButton2;
private com.floreantpos.swing.PosButton posButton3;
private com.floreantpos.swing.PosButton posButton4;
private com.floreantpos.swing.PosButton posButton5;
private com.floreantpos.swing.PosButton posButton6;
private com.floreantpos.swing.PosButton posButton7;
private com.floreantpos.swing.PosButton posButton8;
private com.floreantpos.swing.PosButton posButton9;
// End of variables declaration//GEN-END:variables
Action goAction = new AbstractAction() {
public void actionPerformed(ActionEvent e) {
Component focusOwner = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner();
JTextComponent focusedTextComponent = null;
if (!(focusOwner instanceof JTextComponent)) {
return;
}
focusedTextComponent = (JTextComponent) focusOwner;
String command = e.getActionCommand();
if (com.floreantpos.POSConstants.CLEAR.equals(command)) {
focusedTextComponent.setText(""); //$NON-NLS-1$
}
else {
focusedTextComponent.setText(focusedTextComponent.getText() + command);
}
}
};
private PosButton btnDot;
public String getText() {
return text;
}
public void setProtected(boolean isProtected) {
this.isProtected = isProtected;
}
public boolean isProtected() {
return isProtected;
}
public static void main(String[] args) {
JPanel p = new JPanel(new BorderLayout());
p.add(new NumericKeypad());
JFrame frame = new JFrame();
frame.getContentPane().add(p);
frame.pack();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}
- Details
- Last Updated: Monday, 04 April 2016 02:04
- Hits: 35759851