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);
}
}
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();
}
}
});
}
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;
}
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;
}
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;
}
Aggregations