Example usage for javax.swing JTextField addFocusListener

List of usage examples for javax.swing JTextField addFocusListener

Introduction

In this page you can find the example usage for javax.swing JTextField addFocusListener.

Prototype

public synchronized void addFocusListener(FocusListener l) 

Source Link

Document

Adds the specified focus listener to receive focus events from this component when this component gains input focus.

Usage

From source file:visolate.Visolate.java

private JPanel getInitialYPanel() {
    if (myInitialYPanel == null) {
        myInitialYPanel = new JPanel();
        myInitialYPanel.setLayout(new BorderLayout());
        myInitialYPanel.add(new JLabel("Y"), BorderLayout.WEST);
        myInitialYPanel.setToolTipText("Upper side is at this coordinates (mm or inch)");
        myInitialYPanel.setEnabled(gCodeWriter.getIsAbsolute());
        final JTextField field = new JTextField(NumberFormat.getInstance().format(gCodeWriter.getYOffset()));
        myInitialYPanel.add(field, BorderLayout.CENTER);
        myInitialYPanel.addPropertyChangeListener("enabled", new PropertyChangeListener() {
            public void propertyChange(PropertyChangeEvent evt) {
                field.setEnabled(myInitialYPanel.isEnabled());
            }/*from   w  ww . j a v  a2  s. c  o m*/
        });
        field.setEnabled(myInitialYPanel.isEnabled());
        field.addFocusListener(new FocusAdapter() {
            public void focusLost(FocusEvent evt) {
                try {
                    gCodeWriter.setYOffset(NumberFormat.getInstance().parse(field.getText()).doubleValue());
                } catch (ParseException e) {
                }
                field.setText(NumberFormat.getInstance().format(gCodeWriter.getYOffset()));
            }
        });
    }
    return myInitialYPanel;
}

From source file:visolate.Visolate.java

private Component getZDownMovementPanel() {
    if (myZDownMovementPanel == null) {
        myZDownMovementPanel = new JPanel();
        myZDownMovementPanel.setLayout(new BorderLayout());
        myZDownMovementPanel.add(new JLabel("travel clearance"), BorderLayout.WEST);
        myZDownMovementPanel.setToolTipText(
                "When not cutting, lift the cutter to this above origin, in mm or inch. Decimals in native language (point or comma).");
        final JTextField field = new JTextField(NumberFormat.getInstance().format(gCodeWriter.getZClearance()));
        myZDownMovementPanel.add(field, BorderLayout.CENTER);
        field.addFocusListener(new FocusAdapter() {
            public void focusLost(FocusEvent evt) {
                try {
                    gCodeWriter.setZClearance(NumberFormat.getInstance().parse(field.getText()).doubleValue());
                } catch (ParseException e) {
                }/*from   w w  w .j  a  v  a  2 s.  com*/
                field.setText(NumberFormat.getInstance().format(gCodeWriter.getZClearance()));
            }
        });
    }
    return myZDownMovementPanel;
}

From source file:visolate.Visolate.java

private JPanel getMillingSpeedPanel() {
    if (myMillingSpeedPanel == null) {
        myMillingSpeedPanel = new JPanel();
        myMillingSpeedPanel.setLayout(new BorderLayout());
        myMillingSpeedPanel.add(new JLabel("cutting feedrate"), BorderLayout.WEST);
        myMillingSpeedPanel.setToolTipText("Feedrate during cutting in mm or inch per minute.");
        final JTextField field = new JTextField(
                NumberFormat.getInstance().format(gCodeWriter.getMillingFeedrate()));
        myMillingSpeedPanel.add(field, BorderLayout.CENTER);
        field.addFocusListener(new FocusAdapter() {
            public void focusLost(FocusEvent evt) {
                try {
                    gCodeWriter.setMillingFeedrate(
                            NumberFormat.getInstance().parse(field.getText()).doubleValue());
                } catch (ParseException e) {
                }//from   w w  w  .j ava2s .  co  m
                field.setText(NumberFormat.getInstance().format(gCodeWriter.getMillingFeedrate()));
            }
        });
    }
    return myMillingSpeedPanel;
}

From source file:visolate.Visolate.java

private JPanel getPlungeSpeedPanel() {
    if (myPlungeSpeedPanel == null) {
        myPlungeSpeedPanel = new JPanel();
        myPlungeSpeedPanel.setLayout(new BorderLayout());
        myPlungeSpeedPanel.add(new JLabel("plunge feedrate"), BorderLayout.WEST);
        myPlungeSpeedPanel/* w w  w  .java  2s. c o  m*/
                .setToolTipText("Feedrate when moving vertically into the workpiece in mm or inch per minute.");
        final JTextField field = new JTextField(
                NumberFormat.getInstance().format(gCodeWriter.getPlungeFeedrate()));
        myPlungeSpeedPanel.add(field, BorderLayout.CENTER);
        field.addFocusListener(new FocusAdapter() {
            public void focusLost(FocusEvent evt) {
                try {
                    gCodeWriter
                            .setPlungeFeedrate(NumberFormat.getInstance().parse(field.getText()).doubleValue());
                } catch (ParseException e) {
                }
                field.setText(NumberFormat.getInstance().format(gCodeWriter.getPlungeFeedrate()));
            }
        });
    }
    return myPlungeSpeedPanel;
}

From source file:visolate.Visolate.java

private JPanel getZCuttingHeightPanel() {
    if (myZCuttingHeightPanel == null) {
        myZCuttingHeightPanel = new JPanel();
        myZCuttingHeightPanel.setLayout(new BorderLayout());
        myZCuttingHeightPanel.add(new JLabel("cutting height"), BorderLayout.WEST);
        myZCuttingHeightPanel.setToolTipText(
                "When cutting, the head should have this z-coordinate, in mm or inch. Likely a negative value, decimals in native language (point or comma)");
        myZCuttingHeightPanel.setEnabled(gCodeWriter.getIsAbsolute());
        final JTextField field = new JTextField(
                NumberFormat.getInstance().format(gCodeWriter.getZCuttingHeight()));
        myZCuttingHeightPanel.add(field, BorderLayout.CENTER);
        myZCuttingHeightPanel.addPropertyChangeListener("enabled", new PropertyChangeListener() {
            public void propertyChange(PropertyChangeEvent evt) {
                field.setEnabled(myZCuttingHeightPanel.isEnabled());
            }/*ww w.ja va  2s. co  m*/
        });
        field.setEnabled(myZCuttingHeightPanel.isEnabled());
        field.addFocusListener(new FocusAdapter() {
            public void focusLost(FocusEvent evt) {
                try {
                    gCodeWriter
                            .setZCuttingHeight(NumberFormat.getInstance().parse(field.getText()).doubleValue());
                } catch (ParseException e) {
                }
                field.setText(NumberFormat.getInstance().format(gCodeWriter.getZCuttingHeight()));
            }
        });
    }
    return myZCuttingHeightPanel;
}