Search in sources :

Example 51 with FocusListener

use of java.awt.event.FocusListener in project JMRI by JMRI.

the class LocoIOPanel method initComponents.

@Override
public void initComponents(LocoNetSystemConnectionMemo memo) {
    setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
    ln = memo.getLnTrafficController();
    // creating the table (done here to ensure order OK)
    data = new LocoIOData(Integer.valueOf(addrField.getText(), 16).intValue(), Integer.valueOf(subAddrField.getText(), 16).intValue(), memo.getLnTrafficController());
    model = new LocoIOTableModel(data);
    table = new JTable(model);
    scroll = new JScrollPane(table);
    data.addPropertyChangeListener(this);
    // have to shut off autoResizeMode to get horizontal scroll to work (JavaSwing p 541)
    // table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
    table.setShowHorizontalLines(true);
    table.setAutoCreateColumnsFromModel(true);
    TableColumnModel tcm = table.getColumnModel();
    // install a ComboBox editor on the OnMode column
    JComboBox<String> comboOnBox = new JComboBox<String>(data.getLocoIOModeList().getValidModes());
    comboOnBox.setEditable(true);
    DefaultCellEditor modeEditor = new DefaultCellEditor(comboOnBox);
    tcm.getColumn(LocoIOTableModel.MODECOLUMN).setCellEditor(modeEditor);
    // install a button renderer & editor in the Read, Write and Compare columns
    ButtonRenderer buttonRenderer = new ButtonRenderer();
    tcm.getColumn(LocoIOTableModel.READCOLUMN).setCellRenderer(buttonRenderer);
    tcm.getColumn(LocoIOTableModel.WRITECOLUMN).setCellRenderer(buttonRenderer);
    tcm.getColumn(LocoIOTableModel.CAPTURECOLUMN).setCellRenderer(buttonRenderer);
    TableCellEditor buttonEditor = new ButtonEditor(new JButton());
    tcm.getColumn(LocoIOTableModel.READCOLUMN).setCellEditor(buttonEditor);
    tcm.getColumn(LocoIOTableModel.WRITECOLUMN).setCellEditor(buttonEditor);
    tcm.getColumn(LocoIOTableModel.CAPTURECOLUMN).setCellEditor(buttonEditor);
    // ensure the table rows, columns have enough room for buttons and comboBox contents
    table.setRowHeight(new JButton("Capture").getPreferredSize().height);
    for (int col = 0; col < LocoIOTableModel.HIGHESTCOLUMN; col++) {
        table.getColumnModel().getColumn(col).setPreferredWidth(model.getPreferredWidth(col));
    }
    // A pane for SV0, SV1, SV2, the board sub address and the PIC version
    JPanel p1 = new JPanel();
    p1.setLayout(new BoxLayout(p1, BoxLayout.X_AXIS));
    p1.add(new JLabel("LocoIO address: 0x"));
    addrField.setMaximumSize(addrField.getPreferredSize());
    subAddrField.setMaximumSize(subAddrField.getPreferredSize());
    p1.add(addrField);
    p1.add(new JLabel("/"));
    p1.add(subAddrField);
    // -------------------
    p1.add(Box.createGlue());
    probeButton = new JButton("Probe");
    probeButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent a) {
            data.setLIOVersion("<Not found>");
            LocoIO.probeLocoIOs(ln);
        }
    });
    p1.add(probeButton);
    // -------------------
    p1.add(Box.createGlue());
    readAllButton = new JButton("Read All");
    readAllButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent a) {
            data.readAll();
        }
    });
    p1.add(readAllButton);
    writeAllButton = new JButton("Write All");
    writeAllButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent a) {
            data.writeAll();
        }
    });
    p1.add(writeAllButton);
    // -------------------
    p1.add(Box.createGlue());
    addrSetButton = new JButton("Set address");
    p1.add(addrSetButton);
    addrSetButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent a) {
            addrSet();
        }
    });
    // -------------------
    p1.add(Box.createGlue());
    /*
         openButton = new JButton("Load...");
         openButton.setEnabled(false);
         p1.add(openButton);

         saveButton = new JButton("Save...");
         saveButton.setEnabled(false);
         p1.add(saveButton);
         */
    JPanel p2 = new JPanel();
    p2.setLayout(new BoxLayout(p2, BoxLayout.X_AXIS));
    p2.add(new JLabel("Locobuffer rev: "));
    p2.add(locobuffer);
    // -------------------
    p2.add(Box.createGlue());
    p2.add(new JLabel("Status: "));
    p2.add(status);
    // -------------------
    p2.add(Box.createGlue());
    p2.add(new JLabel("LocoIO Firmware rev: "));
    p2.add(firmware);
    JPanel p3 = new JPanel();
    p3.setLayout(new BoxLayout(p3, BoxLayout.Y_AXIS));
    p3.add(p1);
    p3.add(table);
    add(p3);
    add(p2);
    // updating the Board address needs to be conveyed to the table
    ActionListener al4UnitAddress = new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent a) {
            try {
                data.setUnitAddress(Integer.valueOf(addrField.getText(), 16).intValue(), Integer.valueOf(subAddrField.getText(), 16).intValue());
            } catch (NullPointerException e) {
                // NOI18N
                log.error("Caught NullPointerException", e);
            }
        }
    };
    FocusListener fl4UnitAddress = new FocusListener() {

        @Override
        public void focusGained(FocusEvent event) {
        }

        @Override
        public void focusLost(FocusEvent event) {
            try {
                data.setUnitAddress(Integer.valueOf(addrField.getText(), 16).intValue(), Integer.valueOf(subAddrField.getText(), 16).intValue());
            } catch (NullPointerException e) {
                // NOI18N
                log.error("Caught NullPointerException", e);
            }
        }
    };
    addrField.addActionListener(al4UnitAddress);
    subAddrField.addActionListener(al4UnitAddress);
    addrField.addFocusListener(fl4UnitAddress);
    subAddrField.addFocusListener(fl4UnitAddress);
    try {
        data.setUnitAddress(0x51, 0x00);
    } catch (NullPointerException e) {
        // NOI18N
        log.error("Caught NullPointerException", e);
    }
}
Also used : JScrollPane(javax.swing.JScrollPane) JPanel(javax.swing.JPanel) ButtonEditor(jmri.util.table.ButtonEditor) JComboBox(javax.swing.JComboBox) ActionEvent(java.awt.event.ActionEvent) BoxLayout(javax.swing.BoxLayout) JButton(javax.swing.JButton) TableColumnModel(javax.swing.table.TableColumnModel) JLabel(javax.swing.JLabel) FocusEvent(java.awt.event.FocusEvent) DefaultCellEditor(javax.swing.DefaultCellEditor) ActionListener(java.awt.event.ActionListener) JTable(javax.swing.JTable) TableCellEditor(javax.swing.table.TableCellEditor) FocusListener(java.awt.event.FocusListener) ButtonRenderer(jmri.util.table.ButtonRenderer)

Example 52 with FocusListener

use of java.awt.event.FocusListener in project JMRI by JMRI.

the class ConnectionConfig method checkInitDone.

@Override
protected void checkInitDone() {
    if (log.isDebugEnabled()) {
        log.debug("init called for " + name());
    }
    if (init) {
        return;
    }
    if (adapter.getSystemConnectionMemo() != null) {
        systemPrefixField.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                if (!adapter.getSystemConnectionMemo().setSystemPrefix(systemPrefixField.getText())) {
                    JOptionPane.showMessageDialog(null, "System Prefix " + systemPrefixField.getText() + " is already assigned");
                    systemPrefixField.setText(adapter.getSystemConnectionMemo().getSystemPrefix());
                }
            }
        });
        systemPrefixField.addFocusListener(new FocusListener() {

            @Override
            public void focusLost(FocusEvent e) {
                if (!adapter.getSystemConnectionMemo().setSystemPrefix(systemPrefixField.getText())) {
                    JOptionPane.showMessageDialog(null, "System Prefix " + systemPrefixField.getText() + " is already assigned");
                    systemPrefixField.setText(adapter.getSystemConnectionMemo().getSystemPrefix());
                }
            }

            @Override
            public void focusGained(FocusEvent e) {
            }
        });
        connectionNameField.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                if (!adapter.getSystemConnectionMemo().setUserName(connectionNameField.getText())) {
                    JOptionPane.showMessageDialog(null, "Connection Name " + connectionNameField.getText() + " is already assigned");
                    connectionNameField.setText(adapter.getSystemConnectionMemo().getUserName());
                }
            }
        });
        connectionNameField.addFocusListener(new FocusListener() {

            @Override
            public void focusLost(FocusEvent e) {
                if (!adapter.getSystemConnectionMemo().setUserName(connectionNameField.getText())) {
                    JOptionPane.showMessageDialog(null, "Connection Name " + connectionNameField.getText() + " is already assigned");
                    connectionNameField.setText(adapter.getSystemConnectionMemo().getUserName());
                }
            }

            @Override
            public void focusGained(FocusEvent e) {
            }
        });
    }
    init = true;
}
Also used : ActionListener(java.awt.event.ActionListener) ActionEvent(java.awt.event.ActionEvent) FocusListener(java.awt.event.FocusListener) FocusEvent(java.awt.event.FocusEvent)

Example 53 with FocusListener

use of java.awt.event.FocusListener in project jdk8u_jdk by JetBrains.

the class bug4624207 method main.

public static void main(String[] args) throws Exception {
    SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit();
    Robot robot = new Robot();
    robot.setAutoDelay(50);
    SwingUtilities.invokeAndWait(new Runnable() {

        public void run() {
            createAndShowGUI();
        }
    });
    toolkit.realSync();
    SwingUtilities.invokeAndWait(new Runnable() {

        public void run() {
            txtField.requestFocus();
        }
    });
    toolkit.realSync();
    if (!focusGained) {
        throw new RuntimeException("Couldn't gain focus for text field");
    }
    SwingUtilities.invokeAndWait(new Runnable() {

        public void run() {
            tab.addChangeListener((ChangeListener) listener);
            txtField.removeFocusListener((FocusListener) listener);
        }
    });
    toolkit.realSync();
    if (OSInfo.getOSType() == OSInfo.OSType.MACOSX) {
        Util.hitKeys(robot, KeyEvent.VK_CONTROL, KeyEvent.VK_ALT, KeyEvent.VK_B);
    } else {
        Util.hitKeys(robot, KeyEvent.VK_ALT, KeyEvent.VK_B);
    }
    toolkit.realSync();
    if (!stateChanged || tab.getSelectedIndex() != 1) {
        throw new RuntimeException("JTabbedPane mnemonics don't work from outside the tabbed pane");
    }
}
Also used : SunToolkit(sun.awt.SunToolkit) ChangeListener(javax.swing.event.ChangeListener) FocusListener(java.awt.event.FocusListener)

Example 54 with FocusListener

use of java.awt.event.FocusListener in project JMRI by JMRI.

the class ConnectionConfig method checkInitDone.

@Override
protected void checkInitDone() {
    super.checkInitDone();
    if (adapter.getSystemConnectionMemo() != null) {
        transmitPrefixField.setText(((JMRIClientSystemConnectionMemo) adapter.getSystemConnectionMemo()).getTransmitPrefix());
        transmitPrefixField.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                ((JMRIClientSystemConnectionMemo) adapter.getSystemConnectionMemo()).setTransmitPrefix(transmitPrefixField.getText());
                transmitPrefixField.setText(((JMRIClientSystemConnectionMemo) adapter.getSystemConnectionMemo()).getTransmitPrefix());
            }
        });
        transmitPrefixField.addFocusListener(new FocusListener() {

            @Override
            public void focusLost(FocusEvent e) {
                ((JMRIClientSystemConnectionMemo) adapter.getSystemConnectionMemo()).setTransmitPrefix(transmitPrefixField.getText());
                transmitPrefixField.setText(((JMRIClientSystemConnectionMemo) adapter.getSystemConnectionMemo()).getTransmitPrefix());
            }

            @Override
            public void focusGained(FocusEvent e) {
            }
        });
    }
}
Also used : ActionListener(java.awt.event.ActionListener) ActionEvent(java.awt.event.ActionEvent) FocusListener(java.awt.event.FocusListener) FocusEvent(java.awt.event.FocusEvent) JMRIClientSystemConnectionMemo(jmri.jmrix.jmriclient.JMRIClientSystemConnectionMemo)

Example 55 with FocusListener

use of java.awt.event.FocusListener in project JMRI by JMRI.

the class LoaderPane method addOptionsPanel.

@Override
protected void addOptionsPanel() {
    {
        // create a panel for displaying/modifying the bootloader version
        JPanel p = new JPanel();
        p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS));
        p.add(new JLabel(Bundle.getMessage("LabelBootload") + " "));
        p.add(bootload);
        bootload.setToolTipText(Bundle.getMessage("TipValueRange", MIN_VALUE_ZERO, MAX_VALUE_255));
        bootload.addFocusListener(new FocusListener() {

            @Override
            public void focusGained(FocusEvent e) {
            }

            @Override
            public void focusLost(FocusEvent e) {
                intParameterIsValid(bootload, 0, 255);
                updateDownloadVerifyButtons();
            }
        });
        add(p);
    }
    {
        // create a panel for displaying/modifying the manufacturer number
        JPanel p = new JPanel();
        p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS));
        p.add(new JLabel(Bundle.getMessage("LabelMfg") + " "));
        mfg.setToolTipText(Bundle.getMessage("TipValueRange", MIN_VALUE_ZERO, MAX_VALUE_255));
        p.add(mfg);
        mfg.addFocusListener(new FocusListener() {

            @Override
            public void focusGained(FocusEvent e) {
            }

            @Override
            public void focusLost(FocusEvent e) {
                intParameterIsValid(mfg, 0, 255);
                updateDownloadVerifyButtons();
            }
        });
        add(p);
    }
    {
        // create a panel for displaying/modifying the developer number
        JPanel p = new JPanel();
        p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS));
        p.add(new JLabel(Bundle.getMessage("LabelDev") + //NOI18N
        " "));
        developer.setToolTipText(Bundle.getMessage("TipValueRange", MIN_VALUE_ZERO, MAX_VALUE_255));
        p.add(developer);
        developer.addFocusListener(new FocusListener() {

            @Override
            public void focusGained(FocusEvent e) {
            }

            @Override
            public void focusLost(FocusEvent e) {
                intParameterIsValid(developer, 0, 255);
                updateDownloadVerifyButtons();
            }
        });
        add(p);
    }
    {
        // create a panel for displaying/modifying the product number
        JPanel p = new JPanel();
        p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS));
        p.add(new JLabel(Bundle.getMessage("LabelProduct") + " "));
        product.setToolTipText(Bundle.getMessage("TipValueRange", MIN_VALUE_ZERO, MAX_VALUE_65535));
        p.add(product);
        product.addFocusListener(new FocusListener() {

            @Override
            public void focusGained(FocusEvent e) {
            }

            @Override
            public void focusLost(FocusEvent e) {
                intParameterIsValid(product, 0, 65535);
                updateDownloadVerifyButtons();
            }
        });
        add(p);
    }
    {
        // create a panel for displaying/modifying the hardware version
        JPanel p = new JPanel();
        p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS));
        hardware.setToolTipText(Bundle.getMessage("TipValueRange", MIN_VALUE_ZERO, MAX_VALUE_255));
        p.add(new JLabel(Bundle.getMessage("LabelHardware") + " "));
        p.add(hardware);
        hardware.addFocusListener(new FocusListener() {

            @Override
            public void focusGained(FocusEvent e) {
            }

            @Override
            public void focusLost(FocusEvent e) {
                intParameterIsValid(hardware, 0, 255);
                updateDownloadVerifyButtons();
            }
        });
        add(p);
    }
    {
        // create a panel for displaying/modifying the hardware options
        JPanel p = new JPanel();
        p.setLayout(new BoxLayout(p, BoxLayout.Y_AXIS));
        p.add(checkhardwareno);
        p.add(checkhardwareexact);
        p.add(checkhardwaregreater);
        hardgroup.add(checkhardwareno);
        hardgroup.add(checkhardwareexact);
        hardgroup.add(checkhardwaregreater);
        //            checkhardwareno.addFocusListener(new FocusListener() {
        //                @Override public void focusGained(FocusEvent e) {
        //                }
        //                @Override public void focusLost(FocusEvent e) {
        //                    updateDownloadVerifyButtons();
        //                }
        //            });
        //            checkhardwareexact.addFocusListener(new FocusListener() {
        //                @Override public void focusGained(FocusEvent e) {
        //                }
        //                @Override public void focusLost(FocusEvent e) {
        //                    updateDownloadVerifyButtons();
        //                }
        //            });
        //            checkhardwaregreater.addFocusListener(new FocusListener() {
        //                @Override public void focusGained(FocusEvent e) {
        //                }
        //                @Override public void focusLost(FocusEvent e) {
        //                    updateDownloadVerifyButtons();
        //                }
        //            });
        checkhardwareno.addActionListener(this);
        checkhardwareexact.addActionListener(this);
        checkhardwaregreater.addActionListener(this);
        add(p);
    }
    {
        // create a panel for displaying/modifying the software version
        JPanel p = new JPanel();
        p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS));
        p.add(new JLabel(Bundle.getMessage("LabelSoftware") + " "));
        software.setToolTipText(Bundle.getMessage("TipValueRange", MIN_VALUE_ZERO, MAX_VALUE_255));
        p.add(software);
        software.addFocusListener(new FocusListener() {

            @Override
            public void focusGained(FocusEvent e) {
            }

            @Override
            public void focusLost(FocusEvent e) {
                intParameterIsValid(software, 0, 255);
                updateDownloadVerifyButtons();
            }
        });
        add(p);
    }
    {
        // create a panel for displaying/modifying the software options
        JPanel p = new JPanel();
        p.setLayout(new BoxLayout(p, BoxLayout.Y_AXIS));
        p.add(checksoftwareno);
        p.add(checksoftwareless);
        softgroup.add(checksoftwareno);
        softgroup.add(checksoftwareless);
        checksoftwareno.addActionListener(this);
        checksoftwareless.addActionListener(this);
        add(p);
    }
    {
        // create a panel for displaying/modifying the delay value
        JPanel p = new JPanel();
        p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS));
        p.add(new JLabel(Bundle.getMessage("LabelDelay") + " "));
        delay.setToolTipText(Bundle.getMessage("TipValueRange", MIN_DELAY_VALUE, MAX_DELAY_VALUE));
        p.add(delay);
        delay.addFocusListener(new FocusListener() {

            @Override
            public void focusGained(FocusEvent e) {
            }

            @Override
            public void focusLost(FocusEvent e) {
                intParameterIsValid(hardware, Integer.parseInt(MIN_DELAY_VALUE), Integer.parseInt(MAX_DELAY_VALUE));
                updateDownloadVerifyButtons();
            }
        });
        add(p);
    }
    {
        // create a panel for displaying/modifying the EEPROM start address
        JPanel p = new JPanel();
        p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS));
        p.add(new JLabel(Bundle.getMessage("LabelEEStart") + " "));
        eestart.setToolTipText(Bundle.getMessage("TipValueRange", MIN_EESTART_VALUE, MAX_EESTART_VALUE));
        p.add(eestart);
        eestart.addFocusListener(new FocusListener() {

            @Override
            public void focusGained(FocusEvent e) {
            }

            @Override
            public void focusLost(FocusEvent e) {
                updateDownloadVerifyButtons();
            }
        });
        add(p);
    }
    add(new JSeparator());
}
Also used : JPanel(javax.swing.JPanel) BoxLayout(javax.swing.BoxLayout) JLabel(javax.swing.JLabel) FocusListener(java.awt.event.FocusListener) FocusEvent(java.awt.event.FocusEvent) JSeparator(javax.swing.JSeparator)

Aggregations

FocusListener (java.awt.event.FocusListener)87 FocusEvent (java.awt.event.FocusEvent)80 ActionEvent (java.awt.event.ActionEvent)24 ActionListener (java.awt.event.ActionListener)23 JLabel (javax.swing.JLabel)20 JTextField (javax.swing.JTextField)17 Dimension (java.awt.Dimension)16 JPanel (javax.swing.JPanel)16 JButton (javax.swing.JButton)15 KeyEvent (java.awt.event.KeyEvent)12 JComboBox (javax.swing.JComboBox)11 BorderLayout (java.awt.BorderLayout)9 Component (java.awt.Component)9 MouseEvent (java.awt.event.MouseEvent)9 KeyListener (java.awt.event.KeyListener)8 JCheckBox (javax.swing.JCheckBox)8 ChangeListener (javax.swing.event.ChangeListener)8 Color (java.awt.Color)7 GridBagConstraints (java.awt.GridBagConstraints)7 MouseAdapter (java.awt.event.MouseAdapter)7