use of javax.swing.JComboBox in project JMRI by JMRI.
the class AbstractNetworkConnectionConfig method loadDetails.
@Override
public void loadDetails(final JPanel details) {
_details = details;
setInstance();
if (!init) {
//Build up list of options
//Hashtable<String, AbstractPortController.Option> adapterOptions = ((AbstractPortController)adapter).getOptionList();
String[] optionsAvailable = adapter.getOptions();
options = new Hashtable<String, Option>();
for (String i : optionsAvailable) {
JComboBox<String> opt = new JComboBox<String>(adapter.getOptionChoices(i));
opt.setSelectedItem(adapter.getOptionState(i));
// check that it worked
if (!adapter.getOptionState(i).equals(opt.getSelectedItem())) {
// no, set 1st option choice
opt.setSelectedIndex(0);
// log before setting new value to show old value
log.warn("Loading found invalid value for option {}, found \"{}\", setting to \"{}\"", i, adapter.getOptionState(i), opt.getSelectedItem());
adapter.setOptionState(i, (String) opt.getSelectedItem());
}
options.put(i, new Option(adapter.getOptionDisplayName(i), opt, adapter.isOptionAdvanced(i)));
}
}
if (hostNameField.getActionListeners().length > 0) {
hostNameField.removeActionListener(hostNameField.getActionListeners()[0]);
}
if (adapter.getSystemConnectionMemo() != null) {
systemPrefixField.setText(adapter.getSystemConnectionMemo().getSystemPrefix());
connectionNameField.setText(adapter.getSystemConnectionMemo().getUserName());
NUMOPTIONS = NUMOPTIONS + 2;
}
NUMOPTIONS = NUMOPTIONS + options.size();
hostNameField.setText(adapter.getHostName());
hostNameFieldLabel = new JLabel(rb.getString("HostFieldLabel"));
hostNameField.setToolTipText(rb.getString("HostFieldToolTip"));
if (adapter.getHostName() == null || adapter.getHostName().equals("")) {
hostNameField.setText(p.getComboBoxLastSelection(adapter.getClass().getName() + ".hostname"));
adapter.setHostName(hostNameField.getText());
}
portField.setToolTipText(rb.getString("PortFieldToolTip"));
portField.setEnabled(true);
portField.setText("" + adapter.getPort());
portFieldLabel = new JLabel(rb.getString("PortFieldLabel"));
adNameField.setToolTipText(rb.getString("AdNameFieldToolTip"));
adNameField.setEnabled(false);
adNameField.setText("" + adapter.getAdvertisementName());
adNameFieldLabel = new JLabel(rb.getString("AdNameFieldLabel"));
adNameFieldLabel.setEnabled(false);
serviceTypeField.setToolTipText(rb.getString("ServiceTypeFieldToolTip"));
serviceTypeField.setEnabled(false);
serviceTypeField.setText("" + adapter.getServiceType());
serviceTypeFieldLabel = new JLabel(rb.getString("ServiceTypeFieldLabel"));
serviceTypeFieldLabel.setEnabled(false);
showAutoConfig.setFont(showAutoConfig.getFont().deriveFont(9f));
showAutoConfig.setForeground(Color.blue);
showAutoConfig.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent e) {
setAutoNetworkConfig();
}
});
showAutoConfig.setSelected(adapter.getMdnsConfigure());
setAutoNetworkConfig();
showAdvanced.setFont(showAdvanced.getFont().deriveFont(9f));
showAdvanced.setForeground(Color.blue);
showAdvanced.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent e) {
showAdvancedItems();
}
});
showAdvancedItems();
// need to reload action listeners
init = false;
checkInitDone();
}
use of javax.swing.JComboBox in project JMRI by JMRI.
the class AbstractSimulatorConnectionConfig method loadDetails.
@Override
public void loadDetails(final JPanel details) {
_details = details;
setInstance();
if (!init) {
String[] optionsAvailable = adapter.getOptions();
options = new Hashtable<String, Option>();
for (String i : optionsAvailable) {
JComboBox<String> opt = new JComboBox<String>(adapter.getOptionChoices(i));
opt.setSelectedItem(adapter.getOptionState(i));
// check that it worked
if (!adapter.getOptionState(i).equals(opt.getSelectedItem())) {
// no, set 1st option choice
opt.setSelectedIndex(0);
// log before setting new value to show old value
log.warn("Loading found invalid value for option {}, found \"{}\", setting to \"{}\"", i, adapter.getOptionState(i), opt.getSelectedItem());
adapter.setOptionState(i, (String) opt.getSelectedItem());
}
options.put(i, new Option(adapter.getOptionDisplayName(i), opt, adapter.isOptionAdvanced(i)));
}
}
if (adapter.getSystemConnectionMemo() != null) {
systemPrefixField.setText(adapter.getSystemConnectionMemo().getSystemPrefix());
connectionNameField.setText(adapter.getSystemConnectionMemo().getUserName());
}
NUMOPTIONS = NUMOPTIONS + options.size();
showAdvanced.setFont(showAdvanced.getFont().deriveFont(9f));
showAdvanced.setForeground(Color.blue);
showAdvanced.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent e) {
showAdvancedItems();
}
});
showAdvancedItems();
// need to reload action listeners
init = false;
checkInitDone();
}
use of javax.swing.JComboBox in project JMRI by JMRI.
the class AbstractStreamConnectionConfig method loadDetails.
@Override
public void loadDetails(final JPanel details) {
_details = details;
setInstance();
if (!init) {
String[] optionsAvailable = adapter.getOptions();
options = new Hashtable<String, Option>();
for (String i : optionsAvailable) {
JComboBox<String> opt = new JComboBox<String>(adapter.getOptionChoices(i));
opt.setSelectedItem(adapter.getOptionState(i));
// check that it worked
if (!adapter.getOptionState(i).equals(opt.getSelectedItem())) {
// no, set 1st option choice
opt.setSelectedIndex(0);
// log before setting new value to show old value
log.warn("Loading found invalid value for option {}, found \"{}\", setting to \"{}\"", i, adapter.getOptionState(i), opt.getSelectedItem());
adapter.setOptionState(i, (String) opt.getSelectedItem());
}
options.put(i, new Option(adapter.getOptionDisplayName(i), opt, adapter.isOptionAdvanced(i)));
}
}
if (adapter.getSystemConnectionMemo() != null) {
systemPrefixField.setText(adapter.getSystemConnectionMemo().getSystemPrefix());
connectionNameField.setText(adapter.getSystemConnectionMemo().getUserName());
}
NUMOPTIONS = NUMOPTIONS + options.size();
showAdvanced.setFont(showAdvanced.getFont().deriveFont(9f));
showAdvanced.setForeground(Color.blue);
showAdvanced.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent e) {
showAdvancedItems();
}
});
showAdvancedItems();
// need to reload action listeners
init = false;
checkInitDone();
}
use of javax.swing.JComboBox in project JMRI by JMRI.
the class AbstractStreamConnectionConfig 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 javax.swing.JComboBox in project JMRI by JMRI.
the class ConnectionConfig method checkInitDone.
@SuppressWarnings("unchecked")
@Override
protected void checkInitDone() {
if (log.isDebugEnabled()) {
log.debug("init called for " + name());
}
if (init) {
return;
}
super.checkInitDone();
updateUserNameField();
((JComboBox<Option>) options.get("Protocol").getComponent()).addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
updateUserNameField();
}
});
}
Aggregations