use of javax.swing.JComboBox in project JMRI by JMRI.
the class LightTableAction method addEditControlWindow.
/**
* Creates the Add/Edit control window
*/
private void addEditControlWindow() {
if (addControlFrame == null) {
addControlFrame = new JmriJFrame(Bundle.getMessage("TitleAddLightControl"), false, true);
addControlFrame.addHelpMenu("package.jmri.jmrit.beantable.LightAddEdit", true);
addControlFrame.setLocation(120, 40);
Container contentPane = addControlFrame.getContentPane();
contentPane.setLayout(new BoxLayout(contentPane, BoxLayout.Y_AXIS));
JPanel panel3 = new JPanel();
panel3.setLayout(new BoxLayout(panel3, BoxLayout.Y_AXIS));
JPanel panel31 = new JPanel();
panel31.setLayout(new FlowLayout());
panel31.add(typeBoxLabel);
panel31.add(typeBox = new JComboBox<>(new String[] { noControl, sensorControl, fastClockControl, turnoutStatusControl, timedOnControl, twoSensorControl }));
noControlIndex = 0;
sensorControlIndex = 1;
fastClockControlIndex = 2;
turnoutStatusControlIndex = 3;
timedOnControlIndex = 4;
twoSensorControlIndex = 5;
typeBox.addActionListener((ActionEvent e) -> {
controlTypeChanged();
});
typeBox.setToolTipText(Bundle.getMessage("LightControlTypeHint"));
JPanel panel32 = new JPanel();
panel32.setLayout(new FlowLayout());
panel32.add(f1Label);
panel32.add(field1a);
panel32.add(field1a2);
panel32.add(field1b);
panel32.add(field1c);
panel32.add(field1d);
field1a.setText("");
field1a2.setText("");
field1b.setText("00:00");
field1c.setText("");
field1d.setText("");
field1b.setVisible(false);
field1c.setVisible(false);
field1d.setVisible(false);
field1a.setToolTipText(Bundle.getMessage("LightSensorHint"));
field1a2.setToolTipText(Bundle.getMessage("LightTwoSensorHint"));
JPanel panel33 = new JPanel();
panel33.setLayout(new FlowLayout());
panel33.add(f2Label);
panel33.add(stateBox = new JComboBox<>(new String[] { Bundle.getMessage("SensorStateActive"), Bundle.getMessage("SensorStateInactive") }));
stateBox.setToolTipText(Bundle.getMessage("LightSensorSenseHint"));
panel33.add(field2a);
panel33.add(field2b);
field2a.setText("00:00");
field2a.setVisible(false);
field2b.setText("0");
field2b.setVisible(false);
panel3.add(panel31);
panel3.add(panel32);
panel3.add(panel33);
Border panel3Border = BorderFactory.createEtchedBorder();
panel3.setBorder(panel3Border);
contentPane.add(panel3);
JPanel panel5 = new JPanel();
panel5.setLayout(new FlowLayout(FlowLayout.TRAILING));
panel5.add(cancelControl = new JButton(Bundle.getMessage("ButtonCancel")));
cancelControl.addActionListener(this::cancelControlPressed);
cancelControl.setToolTipText(Bundle.getMessage("LightCancelButtonHint"));
panel5.add(createControl = new JButton(Bundle.getMessage("ButtonCreate")));
createControl.addActionListener(this::createControlPressed);
createControl.setToolTipText(Bundle.getMessage("LightCreateControlButtonHint"));
panel5.add(updateControl = new JButton(Bundle.getMessage("ButtonUpdate")));
updateControl.addActionListener(this::updateControlPressed);
updateControl.setToolTipText(Bundle.getMessage("LightUpdateControlButtonHint"));
cancelControl.setVisible(true);
updateControl.setVisible(false);
createControl.setVisible(true);
contentPane.add(panel5);
addControlFrame.addWindowListener(new java.awt.event.WindowAdapter() {
@Override
public void windowClosing(java.awt.event.WindowEvent e) {
cancelControlPressed(null);
}
});
}
// force GUI status consistent
typeBox.setSelectedIndex(defaultControlIndex);
addControlFrame.pack();
addControlFrame.setVisible(true);
}
use of javax.swing.JComboBox in project JMRI by JMRI.
the class TurnoutTableAction method makeAutomationBox.
/**
* Create a {@literal JComboBox<String>} containing all the options for
* turnout automation parameters for this turnout
*
* @param t the turnout
* @return the JComboBox
*/
protected JComboBox<String> makeAutomationBox(Turnout t) {
String[] str = new String[] { "empty" };
final JComboBox<String> cb = new JComboBox<String>(str);
final Turnout myTurnout = t;
updateAutomationBox(t, cb);
cb.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
setTurnoutOperation(myTurnout, cb);
// avoid recursion
cb.removeActionListener(this);
updateAutomationBox(myTurnout, cb);
cb.addActionListener(this);
}
});
return cb;
}
use of javax.swing.JComboBox in project JMRI by JMRI.
the class TableFrames method makePathTurnoutFrame.
/*
* ********************* PathTurnoutFrame *****************************
*/
protected JInternalFrame makePathTurnoutFrame(OBlock block, String pathName) {
String title = Bundle.getMessage("TitlePathTurnoutTable", block.getDisplayName(), pathName);
JInternalFrame frame = new JInternalFrame(title, true, true, false, true);
if (log.isDebugEnabled()) {
log.debug("makePathTurnoutFrame for Block " + block.getDisplayName() + " and Path " + pathName);
}
frame.setName(makePathTurnoutName(block.getSystemName(), pathName));
OPath path = block.getPathByName(pathName);
if (path == null) {
return null;
}
PathTurnoutTableModel PathTurnoutModel = new PathTurnoutTableModel(path);
PathTurnoutModel.init();
JTable PathTurnoutTable = new JTable(PathTurnoutModel);
PathTurnoutTable.setTransferHandler(new jmri.util.DnDTableImportExportHandler(new int[] { PathTurnoutTableModel.SETTINGCOLUMN, PathTurnoutTableModel.DELETE_COL }));
PathTurnoutTable.setDragEnabled(true);
JComboBox<String> box = new JComboBox<String>(PathTurnoutTableModel.turnoutStates);
PathTurnoutTable.getColumnModel().getColumn(PathTurnoutTableModel.SETTINGCOLUMN).setCellEditor(new DefaultCellEditor(box));
PathTurnoutTable.getColumnModel().getColumn(PathTurnoutTableModel.DELETE_COL).setCellEditor(new ButtonEditor(new JButton()));
PathTurnoutTable.getColumnModel().getColumn(PathTurnoutTableModel.DELETE_COL).setCellRenderer(new ButtonRenderer());
//PathTurnoutTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
for (int i = 0; i < PathTurnoutModel.getColumnCount(); i++) {
int width = PathTurnoutModel.getPreferredWidth(i);
PathTurnoutTable.getColumnModel().getColumn(i).setPreferredWidth(width);
}
PathTurnoutTable.sizeColumnsToFit(-1);
int tableWidth = PathTurnoutTable.getPreferredSize().width;
PathTurnoutTable.setPreferredScrollableViewportSize(new java.awt.Dimension(tableWidth, ROW_HEIGHT * 5));
JScrollPane tablePane = new JScrollPane(PathTurnoutTable);
JPanel contentPane = new JPanel();
contentPane.setLayout(new BorderLayout(5, 5));
JLabel prompt = new JLabel(Bundle.getMessage("AddTurnoutPrompt"));
contentPane.add(prompt, BorderLayout.NORTH);
contentPane.add(tablePane, BorderLayout.CENTER);
frame.addInternalFrameListener(this);
frame.setContentPane(contentPane);
frame.setLocation(10, 270);
frame.pack();
return frame;
}
use of javax.swing.JComboBox in project JMRI by JMRI.
the class AddSignalMastPanel method copyFromMastSelection.
JComboBox<String> copyFromMastSelection() {
JComboBox<String> mastSelect = new JComboBox<String>();
List<String> names = InstanceManager.getDefault(jmri.SignalMastManager.class).getSystemNameList();
for (String name : names) {
if ((Bundle.getMessage("DCCMast").equals(signalMastDriver.getSelectedItem())) || (Bundle.getMessage("LNCPMast").equals(signalMastDriver.getSelectedItem()))) {
if ((InstanceManager.getDefault(jmri.SignalMastManager.class).getNamedBean(name) instanceof DccSignalMast) && InstanceManager.getDefault(jmri.SignalMastManager.class).getSignalMast(name).getSignalSystem().getSystemName().equals(sigsysname) && !InstanceManager.getDefault(jmri.SignalMastManager.class).getNamedBean(name).getDisplayName().equals(userName.getText())) {
// don't copy yourself
mastSelect.addItem(InstanceManager.getDefault(jmri.SignalMastManager.class).getNamedBean(name).getDisplayName());
}
} else if ((Bundle.getMessage("MatrixCtlMast").equals(signalMastDriver.getSelectedItem()))) {
if ((InstanceManager.getDefault(jmri.SignalMastManager.class).getNamedBean(name) instanceof MatrixSignalMast) && InstanceManager.getDefault(jmri.SignalMastManager.class).getSignalMast(name).getSignalSystem().getSystemName().equals(sigsysname) && !InstanceManager.getDefault(jmri.SignalMastManager.class).getNamedBean(name).getDisplayName().equals(userName.getText())) {
// don't copy yourself
mastSelect.addItem(InstanceManager.getDefault(jmri.SignalMastManager.class).getNamedBean(name).getDisplayName());
}
}
}
if (mastSelect.getItemCount() == 0) {
mastSelect.setEnabled(false);
} else {
mastSelect.insertItemAt("", 0);
mastSelect.setSelectedIndex(0);
mastSelect.addActionListener(new ActionListener() {
// e.getSource() cast from mastSelect source
@SuppressWarnings("unchecked")
@Override
public void actionPerformed(ActionEvent e) {
JComboBox<String> eb = (JComboBox<String>) e.getSource();
String sourceMast = (String) eb.getSelectedItem();
if (sourceMast != null && !sourceMast.equals("")) {
if ((Bundle.getMessage("DCCMast").equals(signalMastDriver.getSelectedItem())) || (Bundle.getMessage("LNCPMast").equals(signalMastDriver.getSelectedItem()))) {
copyFromAnotherDCCMastAspect(sourceMast);
} else if ((Bundle.getMessage("MatrixCtlMast").equals(signalMastDriver.getSelectedItem()))) {
copyFromAnotherMatrixMastAspect(sourceMast);
}
}
}
});
}
return mastSelect;
}
use of javax.swing.JComboBox in project JMRI by JMRI.
the class SensorTableDataModel method setValueAt.
@Override
public void setValueAt(Object value, int row, int col) {
if (row >= sysNameList.size()) {
log.debug("row is greater than name list");
return;
}
String name = sysNameList.get(row);
Sensor s = senManager.getBySystemName(name);
if (s == null) {
log.debug("error null sensor!");
return;
}
if (col == INVERTCOL) {
boolean b = ((Boolean) value).booleanValue();
s.setInverted(b);
} else if (col == USEGLOBALDELAY) {
boolean b = ((Boolean) value).booleanValue();
s.useDefaultTimerSettings(b);
} else if (col == ACTIVEDELAY) {
String val = (String) value;
long goingActive = Long.valueOf(val);
s.setSensorDebounceGoingActiveTimer(goingActive);
} else if (col == INACTIVEDELAY) {
String val = (String) value;
long goingInActive = Long.valueOf(val);
s.setSensorDebounceGoingInActiveTimer(goingInActive);
} else if (col == EDITCOL) {
class WindowMaker implements Runnable {
Sensor s;
WindowMaker(Sensor s) {
this.s = s;
}
@Override
public void run() {
editButton(s);
}
}
WindowMaker w = new WindowMaker(s);
javax.swing.SwingUtilities.invokeLater(w);
} else if (col == PULLUPCOL) {
JComboBox<Sensor.PullResistance> cb = (JComboBox<Sensor.PullResistance>) value;
s.setPullResistance((Sensor.PullResistance) cb.getSelectedItem());
} else if (col == VALUECOL && _graphicState) {
// respond to clicking on ImageIconRenderer CellEditor
clickOn(s);
fireTableRowsUpdated(row, row);
} else {
super.setValueAt(value, row, col);
}
}
Aggregations