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();
}
});
}
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();
}
});
}
use of javax.swing.JComboBox in project JMRI by JMRI.
the class RouteTableAction method addPressed.
@Override
protected void addPressed(ActionEvent e) {
pref = jmri.InstanceManager.getDefault(jmri.UserPreferencesManager.class);
if (editMode) {
cancelEdit();
}
jmri.TurnoutManager tm = InstanceManager.turnoutManagerInstance();
List<String> systemNameList = tm.getSystemNameList();
_turnoutList = new ArrayList<>(systemNameList.size());
Iterator<String> iter = systemNameList.iterator();
while (iter.hasNext()) {
String systemName = iter.next();
String userName = tm.getBySystemName(systemName).getUserName();
_turnoutList.add(new RouteTurnout(systemName, userName));
}
jmri.SensorManager sm = InstanceManager.sensorManagerInstance();
systemNameList = sm.getSystemNameList();
_sensorList = new ArrayList<>(systemNameList.size());
iter = systemNameList.iterator();
while (iter.hasNext()) {
String systemName = iter.next();
Sensor s = sm.getBySystemName(systemName);
if (s != null) {
String userName = s.getUserName();
_sensorList.add(new RouteSensor(systemName, userName));
} else {
log.error("Failed to get sensor {}", systemName);
}
}
initializeIncludedList();
// Set up window
if (addFrame == null) {
turnoutsAlignedSensor = new JmriBeanComboBox(InstanceManager.sensorManagerInstance());
sensor1 = new JmriBeanComboBox(InstanceManager.sensorManagerInstance());
sensor2 = new JmriBeanComboBox(InstanceManager.sensorManagerInstance());
sensor3 = new JmriBeanComboBox(InstanceManager.sensorManagerInstance());
cTurnout = new JmriBeanComboBox(InstanceManager.turnoutManagerInstance());
cLockTurnout = new JmriBeanComboBox(InstanceManager.turnoutManagerInstance());
addFrame = new JmriJFrame(Bundle.getMessage("TitleAddRoute"), false, true);
addFrame.addHelpMenu("package.jmri.jmrit.beantable.RouteAddEdit", true);
addFrame.setLocation(100, 30);
JPanel contentPanel = new JPanel();
contentPanel.setLayout(new BoxLayout(contentPanel, BoxLayout.Y_AXIS));
// add system name
JPanel ps = new JPanel();
ps.setLayout(new FlowLayout());
ps.add(nameLabel);
ps.add(_systemName);
ps.add(_autoSystemName);
_autoSystemName.addActionListener((ActionEvent e1) -> {
autoSystemName();
});
if (pref.getSimplePreferenceState(systemNameAuto)) {
_autoSystemName.setSelected(true);
}
_systemName.setToolTipText(Bundle.getMessage("TooltipRouteSystemName"));
ps.add(fixedSystemName);
fixedSystemName.setVisible(false);
contentPanel.add(ps);
// add user name
JPanel p = new JPanel();
p.setLayout(new FlowLayout());
p.add(userLabel);
p.add(_userName);
_userName.setToolTipText(Bundle.getMessage("TooltipRouteUserName"));
contentPanel.add(p);
// add Turnout Display Choice
JPanel py = new JPanel();
py.add(new JLabel(Bundle.getMessage("Show") + ":"));
selGroup = new ButtonGroup();
allButton = new JRadioButton(Bundle.getMessage("All"), true);
selGroup.add(allButton);
py.add(allButton);
allButton.addActionListener((ActionEvent e1) -> {
// Setup for display of all Turnouts, if needed
if (!showAll) {
showAll = true;
_routeTurnoutModel.fireTableDataChanged();
_routeSensorModel.fireTableDataChanged();
}
});
includedButton = new JRadioButton(Bundle.getMessage("Included"), false);
selGroup.add(includedButton);
py.add(includedButton);
includedButton.addActionListener((ActionEvent e1) -> {
// Setup for display of included Turnouts only, if needed
if (showAll) {
showAll = false;
initializeIncludedList();
_routeTurnoutModel.fireTableDataChanged();
_routeSensorModel.fireTableDataChanged();
}
});
py.add(new JLabel(Bundle.getMessage("_and_", Bundle.getMessage("Turnouts"), Bundle.getMessage("Sensors"))));
// keys are in jmri.jmrit.Bundle
contentPanel.add(py);
// add Turnout table
p2xt = new JPanel();
JPanel p2xtSpace = new JPanel();
p2xtSpace.setLayout(new BoxLayout(p2xtSpace, BoxLayout.Y_AXIS));
p2xtSpace.add(new JLabel("XXX"));
p2xt.add(p2xtSpace);
JPanel p21t = new JPanel();
p21t.setLayout(new BoxLayout(p21t, BoxLayout.Y_AXIS));
p21t.add(new JLabel(Bundle.getMessage("SelectInRoute", Bundle.getMessage("Turnouts"))));
p2xt.add(p21t);
_routeTurnoutModel = new RouteTurnoutModel();
JTable routeTurnoutTable = new JTable(_routeTurnoutModel);
TableRowSorter<RouteTurnoutModel> rtSorter = new TableRowSorter<>(_routeTurnoutModel);
rtSorter.setComparator(RouteTurnoutModel.SNAME_COLUMN, new SystemNameComparator());
RowSorterUtil.setSortOrder(rtSorter, RouteTurnoutModel.SNAME_COLUMN, SortOrder.ASCENDING);
routeTurnoutTable.setRowSorter(rtSorter);
routeTurnoutTable.setRowSelectionAllowed(false);
routeTurnoutTable.setPreferredScrollableViewportSize(new java.awt.Dimension(480, 80));
ROW_HEIGHT = routeTurnoutTable.getRowHeight();
JComboBox<String> stateTCombo = new JComboBox<>();
stateTCombo.addItem(SET_TO_CLOSED);
stateTCombo.addItem(SET_TO_THROWN);
stateTCombo.addItem(SET_TO_TOGGLE);
TableColumnModel routeTurnoutColumnModel = routeTurnoutTable.getColumnModel();
TableColumn includeColumnT = routeTurnoutColumnModel.getColumn(RouteTurnoutModel.INCLUDE_COLUMN);
includeColumnT.setResizable(false);
includeColumnT.setMinWidth(50);
includeColumnT.setMaxWidth(60);
TableColumn sNameColumnT = routeTurnoutColumnModel.getColumn(RouteTurnoutModel.SNAME_COLUMN);
sNameColumnT.setResizable(true);
sNameColumnT.setMinWidth(75);
sNameColumnT.setMaxWidth(95);
TableColumn uNameColumnT = routeTurnoutColumnModel.getColumn(RouteTurnoutModel.UNAME_COLUMN);
uNameColumnT.setResizable(true);
uNameColumnT.setMinWidth(210);
uNameColumnT.setMaxWidth(260);
TableColumn stateColumnT = routeTurnoutColumnModel.getColumn(RouteTurnoutModel.STATE_COLUMN);
stateColumnT.setCellEditor(new DefaultCellEditor(stateTCombo));
stateColumnT.setResizable(false);
stateColumnT.setMinWidth(90);
stateColumnT.setMaxWidth(100);
_routeTurnoutScrollPane = new JScrollPane(routeTurnoutTable);
p2xt.add(_routeTurnoutScrollPane, BorderLayout.CENTER);
contentPanel.add(p2xt);
p2xt.setVisible(true);
// add Sensor table
p2xs = new JPanel();
JPanel p2xsSpace = new JPanel();
p2xsSpace.setLayout(new BoxLayout(p2xsSpace, BoxLayout.Y_AXIS));
p2xsSpace.add(new JLabel("XXX"));
p2xs.add(p2xsSpace);
JPanel p21s = new JPanel();
p21s.setLayout(new BoxLayout(p21s, BoxLayout.Y_AXIS));
p21s.add(new JLabel(Bundle.getMessage("SelectInRoute", Bundle.getMessage("Sensors"))));
p2xs.add(p21s);
_routeSensorModel = new RouteSensorModel();
JTable routeSensorTable = new JTable(_routeSensorModel);
TableRowSorter<RouteSensorModel> rsSorter = new TableRowSorter<>(_routeSensorModel);
rsSorter.setComparator(RouteSensorModel.SNAME_COLUMN, new SystemNameComparator());
RowSorterUtil.setSortOrder(rsSorter, RouteSensorModel.SNAME_COLUMN, SortOrder.ASCENDING);
routeSensorTable.setRowSorter(rsSorter);
routeSensorTable.setRowSelectionAllowed(false);
routeSensorTable.setPreferredScrollableViewportSize(new java.awt.Dimension(480, 80));
JComboBox<String> stateSCombo = new JComboBox<>();
stateSCombo.addItem(SET_TO_ACTIVE);
stateSCombo.addItem(SET_TO_INACTIVE);
stateSCombo.addItem(SET_TO_TOGGLE);
TableColumnModel routeSensorColumnModel = routeSensorTable.getColumnModel();
TableColumn includeColumnS = routeSensorColumnModel.getColumn(RouteSensorModel.INCLUDE_COLUMN);
includeColumnS.setResizable(false);
includeColumnS.setMinWidth(50);
includeColumnS.setMaxWidth(60);
TableColumn sNameColumnS = routeSensorColumnModel.getColumn(RouteSensorModel.SNAME_COLUMN);
sNameColumnS.setResizable(true);
sNameColumnS.setMinWidth(75);
sNameColumnS.setMaxWidth(95);
TableColumn uNameColumnS = routeSensorColumnModel.getColumn(RouteSensorModel.UNAME_COLUMN);
uNameColumnS.setResizable(true);
uNameColumnS.setMinWidth(210);
uNameColumnS.setMaxWidth(260);
TableColumn stateColumnS = routeSensorColumnModel.getColumn(RouteSensorModel.STATE_COLUMN);
stateColumnS.setCellEditor(new DefaultCellEditor(stateSCombo));
stateColumnS.setResizable(false);
stateColumnS.setMinWidth(90);
stateColumnS.setMaxWidth(100);
_routeSensorScrollPane = new JScrollPane(routeSensorTable);
p2xs.add(_routeSensorScrollPane, BorderLayout.CENTER);
contentPanel.add(p2xs);
p2xs.setVisible(true);
// Enter filenames for sound, script
JPanel p25 = new JPanel();
p25.setLayout(new FlowLayout());
p25.add(new JLabel(Bundle.getMessage("LabelPlaySound")));
p25.add(soundFile);
//NO18N
JButton ss = new JButton("...");
ss.addActionListener((ActionEvent e1) -> {
setSoundPressed();
});
ss.setToolTipText(Bundle.getMessage("TooltipOpenFile", Bundle.getMessage("BeanNameAudio")));
p25.add(ss);
p25.add(new JLabel(Bundle.getMessage("LabelRunScript")));
p25.add(scriptFile);
//NO18N
ss = new JButton("...");
ss.addActionListener((ActionEvent e1) -> {
setScriptPressed();
});
ss.setToolTipText(Bundle.getMessage("TooltipOpenFile", Bundle.getMessage("Script")));
p25.add(ss);
contentPanel.add(p25);
//add turnouts aligned Sensor
JPanel p27 = new JPanel();
p27.setLayout(new FlowLayout());
p27.add(new JLabel(Bundle.getMessage("LabelEnterSensorAligned")));
p27.add(turnoutsAlignedSensor);
turnoutsAlignedSensor.setFirstItemBlank(true);
turnoutsAlignedSensor.setSelectedBean(null);
turnoutsAlignedSensor.setToolTipText(Bundle.getMessage("TooltipEnterSensor"));
contentPanel.add(p27);
// add Control Sensor table
JPanel p3 = new JPanel();
p3.setLayout(new BoxLayout(p3, BoxLayout.Y_AXIS));
JPanel p31 = new JPanel();
p31.add(new JLabel(Bundle.getMessage("LabelEnterSensors")));
p3.add(p31);
JPanel p32 = new JPanel();
//Sensor 1
JPanel pS = new JPanel();
pS.setBorder(BorderFactory.createTitledBorder(Bundle.getMessage("BeanNameSensor") + " 1"));
pS.add(sensor1);
pS.add(sensor1mode);
p32.add(pS);
//Sensor 2
pS = new JPanel();
pS.setBorder(BorderFactory.createTitledBorder(Bundle.getMessage("BeanNameSensor") + " 2"));
pS.add(sensor2);
pS.add(sensor2mode);
p32.add(pS);
//Sensor 3
pS = new JPanel();
pS.setBorder(BorderFactory.createTitledBorder(Bundle.getMessage("BeanNameSensor") + " 3"));
pS.add(sensor3);
pS.add(sensor3mode);
p32.add(pS);
sensor1.setFirstItemBlank(true);
sensor2.setFirstItemBlank(true);
sensor3.setFirstItemBlank(true);
sensor1.setSelectedBean(null);
sensor2.setSelectedBean(null);
sensor3.setSelectedBean(null);
String sensorHint = Bundle.getMessage("TooltipEnterSensors");
sensor1.setToolTipText(sensorHint);
sensor2.setToolTipText(sensorHint);
sensor3.setToolTipText(sensorHint);
p3.add(p32);
// add control turnout
JPanel p33 = new JPanel();
p33.add(new JLabel(Bundle.getMessage("LabelEnterTurnout")));
p3.add(p33);
JPanel p34 = new JPanel();
p34.add(new JLabel(Bundle.getMessage("BeanNameTurnout") + ":"));
p34.add(cTurnout);
cTurnout.setFirstItemBlank(true);
cTurnout.setSelectedBean(null);
cTurnout.setToolTipText(Bundle.getMessage("TooltipEnterTurnout"));
p34.add(new JLabel(" " + Bundle.getMessage("LabelCondition") + ":"));
cTurnoutStateBox.setToolTipText(Bundle.getMessage("TooltipTurnoutCondition"));
p34.add(cTurnoutStateBox);
p3.add(p34);
// add added delay
JPanel p36 = new JPanel();
p36.add(new JLabel(Bundle.getMessage("LabelTurnoutDelay") + ":"));
p36.add(timeDelay);
timeDelay.setText("0");
timeDelay.setToolTipText(Bundle.getMessage("TooltipTurnoutDelay"));
p36.add(new JLabel(" " + Bundle.getMessage("LabelMilliseconds")));
p3.add(p36);
// complete this panel
Border p3Border = BorderFactory.createEtchedBorder();
p3.setBorder(p3Border);
contentPanel.add(p3);
// add lock control table
JPanel p4 = new JPanel();
p4.setLayout(new BoxLayout(p4, BoxLayout.Y_AXIS));
// add lock control turnout
JPanel p43 = new JPanel();
p43.add(new JLabel(Bundle.getMessage("LabelLockTurnout")));
p4.add(p43);
JPanel p44 = new JPanel();
p44.add(new JLabel(Bundle.getMessage("BeanNameTurnout") + ":"));
p44.add(cLockTurnout);
cLockTurnout.setFirstItemBlank(true);
cLockTurnout.setSelectedBean(null);
cLockTurnout.setToolTipText(Bundle.getMessage("TooltipEnterTurnout"));
p44.add(new JLabel(" " + Bundle.getMessage("LabelCondition") + ":"));
cLockTurnoutStateBox.setToolTipText(Bundle.getMessage("TooltipLockTurnout"));
p44.add(cLockTurnoutStateBox);
p4.add(p44);
// complete this panel
Border p4Border = BorderFactory.createEtchedBorder();
p4.setBorder(p4Border);
contentPanel.add(p4);
// add notes panel
JPanel pa = new JPanel();
pa.setLayout(new BoxLayout(pa, BoxLayout.Y_AXIS));
JPanel p1 = new JPanel();
p1.setLayout(new FlowLayout());
p1.add(status1);
JPanel p2 = new JPanel();
p2.setLayout(new FlowLayout());
p2.add(status2);
pa.add(p1);
pa.add(p2);
Border pBorder = BorderFactory.createEtchedBorder();
pa.setBorder(pBorder);
contentPanel.add(pa);
// add Buttons panel
JPanel pb = new JPanel();
pb.setLayout(new FlowLayout(FlowLayout.TRAILING));
// Cancel (Add) button
pb.add(cancelButton);
cancelButton.addActionListener(this::cancelAddPressed);
// CancelEdit button
pb.add(cancelEditButton);
cancelEditButton.addActionListener(this::cancelPressed);
cancelEditButton.setToolTipText(Bundle.getMessage("TooltipCancelRoute"));
// Add Create Route button
pb.add(createButton);
createButton.addActionListener(this::createPressed);
createButton.setToolTipText(Bundle.getMessage("TooltipCreateRoute"));
// Edit Route button
pb.add(editButton);
editButton.addActionListener(this::editPressed);
editButton.setToolTipText(Bundle.getMessage("TooltipEditRoute"));
// Delete Route button
pb.add(deleteButton);
deleteButton.addActionListener(this::deletePressed);
deleteButton.setToolTipText(Bundle.getMessage("TooltipDeleteRoute"));
// Update Route button
pb.add(updateButton);
updateButton.addActionListener((ActionEvent e1) -> {
updatePressed(e1, false);
});
updateButton.setToolTipText(Bundle.getMessage("TooltipUpdateRoute"));
// Export button
pb.add(exportButton);
exportButton.addActionListener(this::exportPressed);
exportButton.setToolTipText(Bundle.getMessage("TooltipExportRoute"));
// Show the initial buttons, and hide the others
exportButton.setVisible(false);
// show CancelAdd button
cancelButton.setVisible(true);
cancelEditButton.setVisible(false);
updateButton.setVisible(true);
editButton.setVisible(true);
createButton.setVisible(true);
deleteButton.setVisible(false);
contentPanel.add(pb);
addFrame.getContentPane().add(new JScrollPane(contentPanel), BorderLayout.CENTER);
// pack and release space
addFrame.pack();
p2xsSpace.setVisible(false);
p2xtSpace.setVisible(false);
}
// set listener for window closing
addFrame.addWindowListener(new java.awt.event.WindowAdapter() {
@Override
public void windowClosing(java.awt.event.WindowEvent e) {
// remind to save, if Route was created or edited
if (routeDirty) {
InstanceManager.getDefault(jmri.UserPreferencesManager.class).showInfoMessage(Bundle.getMessage("ReminderTitle"), Bundle.getMessage("ReminderSaveString", Bundle.getMessage("MenuItemRouteTable")), getClassName(), //NOI18N
"remindSaveRoute");
routeDirty = false;
}
// hide addFrame
if (addFrame != null) {
addFrame.setVisible(false);
// addFrame.dispose(); // causes multiple empty Routes next time
}
// if in Edit, cancel edit mode
if (editMode) {
cancelEdit();
}
_routeSensorModel.dispose();
_routeTurnoutModel.dispose();
}
});
// display the window
addFrame.setVisible(true);
autoSystemName();
}
Aggregations