Search in sources :

Example 46 with FocusListener

use of java.awt.event.FocusListener in project ACS by ACS-Community.

the class TabPanel method validateAfterProgrammaticUpdate.

/**
	 * When the status or content of a Gui component has been modified programmatically,
	 * this method must be called to ensure the new contents are written through to the
	 * model.
	 * 
	 * @param trg a gui component that was programmatically updated
	 */
public void validateAfterProgrammaticUpdate(JComponent trg) {
    FocusEvent evt = new FocusEvent(trg, FocusEvent.FOCUS_LOST);
    FocusListener[] lis = trg.getFocusListeners();
    for (int i = 0; i < lis.length; i++) {
        lis[i].focusLost(evt);
    }
}
Also used : FocusEvent(java.awt.event.FocusEvent) FocusListener(java.awt.event.FocusListener)

Example 47 with FocusListener

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

the class CComboBox method init.

/**
	 *  Common Init
	 */
private void init() {
    FIELD_HIGHT = getPreferredSize().height;
    setEditable(true);
    setAutoReducible(true);
    addMouseListener(new MouseAdapter() {

        public void mousePressed(MouseEvent me) {
            if (SwingUtilities.isLeftMouseButton(me) && isAutoReducible())
                updateReducibleModel(false);
        }
    });
    // when auto-reducing, the focus listener will ensure all data choices
    // are shown on initial focus, and that a valid selection is in place
    // when focus is lost
    final JTextComponent textComponent = (JTextComponent) getEditor().getEditorComponent();
    textComponent.addFocusListener(new FocusListener() {

        public void focusGained(FocusEvent fe) {
            if (isEditable())
                textComponent.selectAll();
            textComponent.repaint();
        }

        public void focusLost(FocusEvent fe) {
            if (isAutoReducible()) {
                Object item = m_reducibleModel.getSelectedItem();
                item = (item == null && m_reducibleModel.getSize() != 0) ? m_reducibleModel.getElementAt(0) : item;
                if (item == null) {
                    updateReducibleModel(false);
                    if (m_reducibleModel.getSize() != 0)
                        item = m_reducibleModel.getElementAt(0);
                    else
                        return;
                }
                m_reducibleModel.setSelectedItem(item);
            }
            textComponent.setCaretPosition(0);
            hidePopup();
            textComponent.repaint();
        }
    });
    textComponent.addMouseListener(new MouseAdapter() {

        public void mouseClicked(MouseEvent me) {
            if (SwingUtilities.isLeftMouseButton(me) && isAutoReducible() && !isPopupVisible()) {
                updateReducibleModel(false);
                showPopup();
            }
        }
    });
}
Also used : MouseEvent(java.awt.event.MouseEvent) MouseAdapter(java.awt.event.MouseAdapter) JTextComponent(javax.swing.text.JTextComponent) FocusListener(java.awt.event.FocusListener) FocusEvent(java.awt.event.FocusEvent)

Example 48 with FocusListener

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

the class AbstractSerialConnectionConfig method checkInitDone.

@SuppressWarnings("unchecked")
@Override
protected void checkInitDone() {
    if (log.isDebugEnabled()) {
        log.debug("init called for " + name());
    }
    if (init) {
        return;
    }
    baudBox.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            adapter.configureBaudRate((String) baudBox.getSelectedItem());
            p.addComboBoxLastSelection(adapter.getClass().getName() + ".baud", (String) baudBox.getSelectedItem());
        }
    });
    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) {
            }
        });
    }
    portBox.addFocusListener(new FocusListener() {

        @Override
        public void focusGained(FocusEvent e) {
            refreshPortBox();
        }

        @Override
        public void focusLost(FocusEvent e) {
        }
    });
    for (String i : options.keySet()) {
        final String item = i;
        if (options.get(i).getComponent() instanceof JComboBox) {
            ((JComboBox<?>) options.get(i).getComponent()).addActionListener((ActionEvent e) -> {
                adapter.setOptionState(item, options.get(item).getItem());
            });
        }
    }
    init = true;
}
Also used : ActionListener(java.awt.event.ActionListener) JComboBox(javax.swing.JComboBox) ActionEvent(java.awt.event.ActionEvent) FocusListener(java.awt.event.FocusListener) FocusEvent(java.awt.event.FocusEvent)

Example 49 with FocusListener

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

the class AbstractNetworkConnectionConfig method checkInitDone.

@SuppressWarnings("unchecked")
@Override
protected void checkInitDone() {
    if (log.isDebugEnabled()) {
        log.debug("init called for " + name());
    }
    if (init) {
        return;
    }
    hostNameField.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            adapter.setHostName(hostNameField.getText());
            p.addComboBoxLastSelection(adapter.getClass().getName() + ".hostname", hostNameField.getText());
        }
    });
    hostNameField.addKeyListener(new KeyListener() {

        @Override
        public void keyPressed(KeyEvent keyEvent) {
        }

        @Override
        public void keyReleased(KeyEvent keyEvent) {
            adapter.setHostName(hostNameField.getText());
            p.addComboBoxLastSelection(adapter.getClass().getName() + ".hostname", hostNameField.getText());
        }

        @Override
        public void keyTyped(KeyEvent keyEvent) {
        }
    });
    portField.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            try {
                adapter.setPort(Integer.parseInt(portField.getText()));
            } catch (java.lang.NumberFormatException ex) {
                log.warn("Could not parse port attribute");
            }
        }
    });
    portField.addKeyListener(new KeyListener() {

        @Override
        public void keyPressed(KeyEvent keyEvent) {
        }

        @Override
        public void keyReleased(KeyEvent keyEvent) {
            try {
                adapter.setPort(Integer.parseInt(portField.getText()));
            } catch (java.lang.NumberFormatException ex) {
                log.warn("Could not parse port attribute");
            }
        }

        @Override
        public void keyTyped(KeyEvent keyEvent) {
        }
    });
    adNameField.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            adapter.setAdvertisementName(adNameField.getText());
        }
    });
    adNameField.addKeyListener(new KeyListener() {

        @Override
        public void keyPressed(KeyEvent keyEvent) {
        }

        @Override
        public void keyReleased(KeyEvent keyEvent) {
            adapter.setAdvertisementName(adNameField.getText());
        }

        @Override
        public void keyTyped(KeyEvent keyEvent) {
        }
    });
    serviceTypeField.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            adapter.setServiceType(serviceTypeField.getText());
        }
    });
    serviceTypeField.addKeyListener(new KeyListener() {

        @Override
        public void keyPressed(KeyEvent keyEvent) {
        }

        @Override
        public void keyReleased(KeyEvent keyEvent) {
            adapter.setServiceType(serviceTypeField.getText());
        }

        @Override
        public void keyTyped(KeyEvent keyEvent) {
        }
    });
    for (String i : options.keySet()) {
        final String item = i;
        if (options.get(i).getComponent() instanceof JComboBox) {
            ((JComboBox<?>) options.get(i).getComponent()).addActionListener(new ActionListener() {

                @Override
                public void actionPerformed(ActionEvent e) {
                    adapter.setOptionState(item, options.get(item).getItem());
                }
            });
        }
    }
    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 : KeyEvent(java.awt.event.KeyEvent) ActionListener(java.awt.event.ActionListener) JComboBox(javax.swing.JComboBox) ActionEvent(java.awt.event.ActionEvent) KeyListener(java.awt.event.KeyListener) FocusListener(java.awt.event.FocusListener) FocusEvent(java.awt.event.FocusEvent)

Example 50 with FocusListener

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

the class AbstractSimulatorConnectionConfig method checkInitDone.

@SuppressWarnings("unchecked")
@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) {
            }
        });
        for (String i : options.keySet()) {
            final String item = i;
            if (options.get(i).getComponent() instanceof JComboBox) {
                ((JComboBox<?>) options.get(i).getComponent()).addActionListener(new ActionListener() {

                    @Override
                    public void actionPerformed(ActionEvent e) {
                        adapter.setOptionState(item, options.get(item).getItem());
                    }
                });
            }
        }
    }
    init = true;
}
Also used : ActionListener(java.awt.event.ActionListener) JComboBox(javax.swing.JComboBox) ActionEvent(java.awt.event.ActionEvent) FocusListener(java.awt.event.FocusListener) FocusEvent(java.awt.event.FocusEvent)

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