use of java.awt.event.FocusEvent 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.FocusEvent 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.FocusEvent 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;
}
use of java.awt.event.FocusEvent 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);
}
}
use of java.awt.event.FocusEvent 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;
}
Aggregations