lib.SerialStatus

Here are the examples of the java api lib.SerialStatus taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

1 Examples 7

19 Source : Principal.java
with MIT License
from anastaciocintra

public clreplaced Principal {

    SerialStatus serialStatus;

    private JFrame frame;

    public void showWindow() throws IOException {
        serialStatus = new SerialStatusTMT20("com1");
        frame = new JFrame("Printer Coffee");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        WindowListener wls = new WindowListener() {

            @Override
            public void windowOpened(WindowEvent windowEvent) {
            }

            @Override
            public void windowClosing(WindowEvent windowEvent) {
                serialStatus.finish();
                frame.dispose();
            }

            @Override
            public void windowClosed(WindowEvent windowEvent) {
            }

            @Override
            public void windowIconified(WindowEvent windowEvent) {
            }

            @Override
            public void windowDeiconified(WindowEvent windowEvent) {
            }

            @Override
            public void windowActivated(WindowEvent windowEvent) {
            }

            @Override
            public void windowDeactivated(WindowEvent windowEvent) {
            }
        };
        frame.addWindowListener(wls);
        frame.setLayout(new FlowLayout());
        JButton buttonPrint = new JButton("Print");
        buttonPrint.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent actionEvent) {
                try {
                    print();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        });
        JButton buttonFinish = new JButton("Finish");
        buttonFinish.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent actionEvent) {
                serialStatus.finish();
            }
        });
        frame.add(buttonPrint);
        frame.add(buttonFinish);
        JLabel labelStatus = new JLabel("Status");
        labelStatus.setOpaque(true);
        frame.add(labelStatus);
        JTextArea textArea = new JTextArea();
        textArea.setColumns(25);
        textArea.setRows(7);
        frame.add(textArea);
        serialStatus.addEventListener(new PrinterStatusEvent() {

            @Override
            public void onStatusChanged() {
                textArea.setText("");
                Map<Integer, SerialStatus.Status> mapErrors = serialStatus.getMapErrors();
                for (SerialStatus.Status error : mapErrors.values()) {
                    textArea.append(error.value + "\n");
                }
                Map<Integer, SerialStatus.Status> mapInfo = serialStatus.getMapInfo();
                for (SerialStatus.Status info : mapInfo.values()) {
                    textArea.append(info.value + "\n");
                }
            }
        });
        // just change color
        serialStatus.addEventListener(new PrinterStatusEvent() {

            @Override
            public void onStatusChanged() {
                if (serialStatus.haveAnyError()) {
                    labelStatus.setBackground(Color.red);
                } else {
                    labelStatus.setBackground(Color.green);
                }
            }
        });
        frame.pack();
        frame.setMinimumSize(frame.getPreferredSize());
        frame.setVisible(true);
    }

    private void print() throws IOException {
        OutputStream outputStream = serialStatus.getOutputStream();
        EscPos escPos = new EscPos(outputStream);
        escPos.info();
        escPos.close();
    }

    public static void main(String[] args) throws IOException, InterruptedException {
        SwingUtilities.invokeLater(new Runnable() {

            @Override
            public void run() {
                Principal principal = new Principal();
                try {
                    principal.showWindow();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        });
    }
}