use of javax.swing.JComboBox in project jdk8u_jdk by JetBrains.
the class ColumnLayout method buildConnectingPanel.
public JPanel buildConnectingPanel() {
JPanel connectPanel = new JPanel();
connectPanel.setLayout(new ColumnLayout());
JPanel protoPanel = new JPanel();
JLabel protoLabel = new JLabel("Protocol");
JComboBox protocol = new JComboBox();
protocol.addItem("SMTP");
protocol.addItem("IMAP");
protocol.addItem("Other...");
protoPanel.add(protoLabel);
protoPanel.add(protocol);
JPanel attachmentPanel = new JPanel();
JLabel attachmentLabel = new JLabel("Attachments");
JComboBox attach = new JComboBox();
attach.addItem("Download Always");
attach.addItem("Ask size > 1 Meg");
attach.addItem("Ask size > 5 Meg");
attach.addItem("Ask Always");
attachmentPanel.add(attachmentLabel);
attachmentPanel.add(attach);
JCheckBox autoConn = new JCheckBox("Auto Connect");
JCheckBox compress = new JCheckBox("Use Compression");
autoConn.setSelected(true);
connectPanel.add(protoPanel);
connectPanel.add(attachmentPanel);
connectPanel.add(autoConn);
connectPanel.add(compress);
return connectPanel;
}
use of javax.swing.JComboBox in project JMRI by JMRI.
the class TurnoutTableWindowTest method testShowAndClose.
public void testShowAndClose() throws Exception {
if (GraphicsEnvironment.isHeadless()) {
// can't Assume in TestCase
return;
}
// ask for the window to open
TurnoutTableAction a = new TurnoutTableAction();
a.actionPerformed(new java.awt.event.ActionEvent(a, 1, ""));
// Find new table window by name
JmriJFrame ft = JmriJFrame.getFrame(Bundle.getMessage("TitleTurnoutTable"));
flushAWT();
// Find the Automatic retry checkbox
AbstractButtonFinder arfinder = new AbstractButtonFinder(Bundle.getMessage("AutomaticRetry"));
JCheckBox ar = (JCheckBox) arfinder.find(ft, 0);
Assert.assertNotNull(ar);
// Click checkbox to select Automatic retry
getHelper().enterClickAndLeave(new MouseEventData(this, ar));
Assert.assertNotNull("AR selected", ar.getSelectedObjects());
// Find the Show Feedback information checkbox
AbstractButtonFinder fbfinder = new AbstractButtonFinder(Bundle.getMessage("ShowFeedbackInfo"));
JCheckBox fb = (JCheckBox) fbfinder.find(ft, 0);
Assert.assertNotNull(fb);
// Click checkbox to select Show feedback information
getHelper().enterClickAndLeave(new MouseEventData(this, fb));
Assert.assertNotNull("FBbox selected", fb.getSelectedObjects());
// Find the Show Lock information checkbox
AbstractButtonFinder lkfinder = new AbstractButtonFinder(Bundle.getMessage("ShowLockInfo"));
JCheckBox lk = (JCheckBox) lkfinder.find(ft, 0);
Assert.assertNotNull(lk);
// Click checkbox to select Show feedback information
getHelper().enterClickAndLeave(new MouseEventData(this, lk));
Assert.assertNotNull("LKbox selected", lk.getSelectedObjects());
// Find the Show Turnout Speed details checkbox
AbstractButtonFinder tsfinder = new AbstractButtonFinder(Bundle.getMessage("ShowTurnoutSpeedDetails"));
JCheckBox ts = (JCheckBox) tsfinder.find(ft, 0);
Assert.assertNotNull(ts);
// Click checkbox to select Show feedback information
getHelper().enterClickAndLeave(new MouseEventData(this, ts));
Assert.assertNotNull("TSbox selected", ts.getSelectedObjects());
// Find the Add... button
AbstractButtonFinder abfinder = new AbstractButtonFinder(Bundle.getMessage("ButtonAdd"));
JButton ad = (JButton) abfinder.find(ft, 0);
Assert.assertNotNull(ad);
// Click button to open Add Turnout pane
getHelper().enterClickAndLeave(new MouseEventData(this, ad));
// Find Add Turnout pane by name
JmriJFrame fa = JmriJFrame.getFrame(Bundle.getMessage("TitleAddTurnout"));
Assert.assertNotNull("Add window found", fa);
// Find hardware number field
NamedComponentFinder ncfinder = new NamedComponentFinder(JComponent.class, "sysName");
JTextField sysNameField = (JTextField) ncfinder.find(fa, 0);
Assert.assertNotNull(sysNameField);
// set to "1"
// The following line works on the CI servers, but not in some standalone cases
//getHelper().sendString(new StringEventData(this, sysNameField, "1"));
// workaround
sysNameField.setText("1");
flushAWT();
Assert.assertEquals("name content", "1", sysNameField.getText());
// Find system combobox
ncfinder = new NamedComponentFinder(JComponent.class, "prefixBox");
JComboBox<?> prefixBox = (JComboBox<?>) ncfinder.find(fa, 0);
Assert.assertNotNull(prefixBox);
// set to "Internal"
prefixBox.setSelectedItem("Internal");
// this connection type is always available
Assert.assertEquals("Selected system item", "Internal", prefixBox.getSelectedItem());
// Find the Add OK button
AbstractButtonFinder okfinder = new AbstractButtonFinder(Bundle.getMessage("ButtonOK"));
JButton okbutton = (JButton) okfinder.find(fa, 0);
Assert.assertNotNull(okbutton);
// Click button to add turnout
getHelper().enterClickAndLeave(new MouseEventData(this, okbutton));
// Ask to close Add pane
TestHelper.disposeWindow(fa, this);
// Open the Edit Turnout IT1 pane, how to find & click the LT1 Edit col button?
// Find the Edit button in EDITCOL of line 0 (for LT1)
//AbstractButtonFinder edfinder = new AbstractButtonFinder("Edit");
//JButton editbutton = (JButton) edfinder.find(ft, 0);
//Assert.assertNotNull(editbutton);
// Click button to edit turnout
//getHelper().enterClickAndLeave(new MouseEventData(this, editbutton));
// open Edit pane by method instead
Turnout it1 = InstanceManager.turnoutManagerInstance().getTurnout("IT1");
// open edit pane
a.editButton(it1);
// Find Edit Turnout pane by name
JmriJFrame fe = JmriJFrame.getFrame("Edit Turnout IT1");
Assert.assertNotNull("Edit window", fe);
// Find the Edit Cancel button
AbstractButtonFinder canceleditfinder = new AbstractButtonFinder(Bundle.getMessage("ButtonCancel"));
JButton cancelbutton = (JButton) canceleditfinder.find(fe, 0);
Assert.assertNotNull(cancelbutton);
// Click button to cancel edit turnout
getHelper().enterClickAndLeave(new MouseEventData(this, cancelbutton));
// Ask to close Edit pane
TestHelper.disposeWindow(fe, this);
// Ask to close turnout table window
TestHelper.disposeWindow(ft, this);
flushAWT();
// check that turnout was created
Assert.assertNotNull(jmri.InstanceManager.turnoutManagerInstance().getTurnout("IT1"));
}
use of javax.swing.JComboBox in project JMRI by JMRI.
the class BlockTableAction method createModel.
/**
* Create the JTable DataModel, along with the changes for the specific case
* of Block objects.
*/
@Override
protected void createModel() {
// load graphic state column display preference
_graphicState = InstanceManager.getDefault(GuiLafPreferencesManager.class).isGraphicTableState();
m = new BeanTableDataModel() {
public static final int EDITCOL = NUMCOLUMN;
public static final int DIRECTIONCOL = EDITCOL + 1;
public static final int LENGTHCOL = DIRECTIONCOL + 1;
public static final int CURVECOL = LENGTHCOL + 1;
public static final int STATECOL = CURVECOL + 1;
public static final int SENSORCOL = STATECOL + 1;
public static final int REPORTERCOL = SENSORCOL + 1;
public static final int CURRENTREPCOL = REPORTERCOL + 1;
public static final int PERMISCOL = CURRENTREPCOL + 1;
public static final int SPEEDCOL = PERMISCOL + 1;
@Override
public String getValue(String name) {
if (name == null) {
log.warn("requested getValue(null)");
return "(no name)";
}
Block b = InstanceManager.getDefault(jmri.BlockManager.class).getBySystemName(name);
if (b == null) {
log.debug("requested getValue(\"" + name + "\"), Block doesn't exist");
return "(no Block)";
}
Object m = b.getValue();
if (m != null) {
return m.toString();
} else {
return "";
}
}
@Override
public Manager getManager() {
return InstanceManager.getDefault(jmri.BlockManager.class);
}
@Override
public NamedBean getBySystemName(String name) {
return InstanceManager.getDefault(jmri.BlockManager.class).getBySystemName(name);
}
@Override
public NamedBean getByUserName(String name) {
return InstanceManager.getDefault(jmri.BlockManager.class).getByUserName(name);
}
@Override
protected String getMasterClassName() {
return getClassName();
}
@Override
public void clickOn(NamedBean t) {
// don't do anything on click; not used in this class, because
// we override setValueAt
}
//Permissive and speed columns are temp disabled
@Override
public int getColumnCount() {
return SPEEDCOL + 1;
}
@Override
public Object getValueAt(int row, int col) {
// some error checking
if (row >= sysNameList.size()) {
log.debug("requested getValueAt(\"" + row + "\"), row outside of range");
return "Error table size";
}
Block b = (Block) getBySystemName(sysNameList.get(row));
if (b == null) {
log.debug("requested getValueAt(\"" + row + "\"), Block doesn't exist");
return "(no Block)";
}
if (col == DIRECTIONCOL) {
return jmri.Path.decodeDirection(b.getDirection());
} else if (col == CURVECOL) {
JComboBox<String> c = new JComboBox<String>(curveOptions);
if (b.getCurvature() == Block.NONE) {
c.setSelectedItem(0);
} else if (b.getCurvature() == Block.GRADUAL) {
c.setSelectedItem(gradualText);
} else if (b.getCurvature() == Block.TIGHT) {
c.setSelectedItem(tightText);
} else if (b.getCurvature() == Block.SEVERE) {
c.setSelectedItem(severeText);
}
return c;
} else if (col == LENGTHCOL) {
double len = 0.0;
if (inchBox.isSelected()) {
len = b.getLengthIn();
} else {
len = b.getLengthCm();
}
return (twoDigit.format(len));
} else if (col == PERMISCOL) {
boolean val = b.getPermissiveWorking();
return Boolean.valueOf(val);
} else if (col == SPEEDCOL) {
String speed = b.getBlockSpeed();
if (!speedList.contains(speed)) {
speedList.add(speed);
}
JComboBox<String> c = new JComboBox<String>(speedList);
c.setEditable(true);
c.setSelectedItem(speed);
return c;
} else if (col == STATECOL) {
switch(b.getState()) {
case (Block.OCCUPIED):
return Bundle.getMessage("BlockOccupied");
case (Block.UNOCCUPIED):
return Bundle.getMessage("BlockUnOccupied");
case (Block.UNKNOWN):
return Bundle.getMessage("BlockUnknown");
default:
return Bundle.getMessage("BlockInconsistent");
}
} else if (col == SENSORCOL) {
Sensor sensor = b.getSensor();
JComboBox<String> c = new JComboBox<String>(sensorList);
String name = "";
if (sensor != null) {
name = sensor.getDisplayName();
}
c.setSelectedItem(name);
return c;
} else if (col == REPORTERCOL) {
Reporter r = b.getReporter();
return (r != null) ? r.getDisplayName() : null;
} else if (col == CURRENTREPCOL) {
return Boolean.valueOf(b.isReportingCurrent());
} else if (col == EDITCOL) {
//
return Bundle.getMessage("ButtonEdit");
} else {
return super.getValueAt(row, col);
}
}
@Override
public void setValueAt(Object value, int row, int col) {
// no setting of block state from table
Block b = (Block) getBySystemName(sysNameList.get(row));
if (col == VALUECOL) {
b.setValue(value);
fireTableRowsUpdated(row, row);
} else if (col == LENGTHCOL) {
float len = 0.0f;
try {
len = jmri.util.IntlUtilities.floatValue(value.toString());
} catch (java.text.ParseException ex2) {
log.error("Error parsing length value of \"{}\"", value);
}
if (inchBox.isSelected()) {
b.setLength(len * 25.4f);
} else {
b.setLength(len * 10.0f);
}
fireTableRowsUpdated(row, row);
} else if (col == CURVECOL) {
@SuppressWarnings("unchecked") String cName = (String) ((JComboBox<String>) value).getSelectedItem();
if (cName.equals(noneText)) {
b.setCurvature(Block.NONE);
} else if (cName.equals(gradualText)) {
b.setCurvature(Block.GRADUAL);
} else if (cName.equals(tightText)) {
b.setCurvature(Block.TIGHT);
} else if (cName.equals(severeText)) {
b.setCurvature(Block.SEVERE);
}
fireTableRowsUpdated(row, row);
} else if (col == PERMISCOL) {
boolean boo = ((Boolean) value).booleanValue();
b.setPermissiveWorking(boo);
fireTableRowsUpdated(row, row);
} else if (col == SPEEDCOL) {
@SuppressWarnings("unchecked") String speed = (String) ((JComboBox<String>) value).getSelectedItem();
try {
b.setBlockSpeed(speed);
} catch (jmri.JmriException ex) {
JOptionPane.showMessageDialog(null, ex.getMessage() + "\n" + speed);
return;
}
if (!speedList.contains(speed) && !speed.contains("Global")) {
// NOI18N
speedList.add(speed);
}
fireTableRowsUpdated(row, row);
} else if (col == REPORTERCOL) {
Reporter r = null;
if (value != null && !value.equals("")) {
r = jmri.InstanceManager.getDefault(jmri.ReporterManager.class).provideReporter((String) value);
}
b.setReporter(r);
fireTableRowsUpdated(row, row);
} else if (col == SENSORCOL) {
@SuppressWarnings("unchecked") String strSensor = (String) ((JComboBox<String>) value).getSelectedItem();
b.setSensor(strSensor);
return;
} else if (col == CURRENTREPCOL) {
boolean boo = ((Boolean) value).booleanValue();
b.setReportingCurrent(boo);
fireTableRowsUpdated(row, row);
} else if (col == EDITCOL) {
class WindowMaker implements Runnable {
Block b;
WindowMaker(Block b) {
this.b = b;
}
@Override
public void run() {
// don't really want to stop Route w/o user action
editButton(b);
}
}
WindowMaker t = new WindowMaker(b);
javax.swing.SwingUtilities.invokeLater(t);
//editButton(b);
} else {
super.setValueAt(value, row, col);
}
}
@Override
public String getColumnName(int col) {
if (col == DIRECTIONCOL) {
return Bundle.getMessage("BlockDirection");
}
if (col == VALUECOL) {
return Bundle.getMessage("BlockValue");
}
if (col == CURVECOL) {
return Bundle.getMessage("BlockCurveColName");
}
if (col == LENGTHCOL) {
return Bundle.getMessage("BlockLengthColName");
}
if (col == PERMISCOL) {
return Bundle.getMessage("BlockPermColName");
}
if (col == SPEEDCOL) {
return Bundle.getMessage("BlockSpeedColName");
}
if (col == STATECOL) {
return Bundle.getMessage("BlockState");
}
if (col == REPORTERCOL) {
return Bundle.getMessage("BlockReporter");
}
if (col == SENSORCOL) {
return Bundle.getMessage("BlockSensor");
}
if (col == CURRENTREPCOL) {
return Bundle.getMessage("BlockReporterCurrent");
}
if (col == EDITCOL) {
return Bundle.getMessage("ButtonEdit");
}
return super.getColumnName(col);
}
@Override
public Class<?> getColumnClass(int col) {
if (col == DIRECTIONCOL) {
return String.class;
}
if (col == VALUECOL) {
// not a button
return String.class;
}
if (col == CURVECOL) {
return JComboBox.class;
}
if (col == LENGTHCOL) {
return String.class;
}
if (col == PERMISCOL) {
return Boolean.class;
}
if (col == SPEEDCOL) {
return JComboBox.class;
}
if (col == STATECOL) {
if (_graphicState) {
// use an image to show block state
return JLabel.class;
} else {
return String.class;
}
}
if (col == REPORTERCOL) {
return String.class;
}
if (col == SENSORCOL) {
return JComboBox.class;
}
if (col == CURRENTREPCOL) {
return Boolean.class;
}
if (col == EDITCOL) {
return JButton.class;
} else {
return super.getColumnClass(col);
}
}
@Override
public int getPreferredWidth(int col) {
if (col == DIRECTIONCOL) {
return new JTextField(7).getPreferredSize().width;
}
if (col == CURVECOL) {
return new JTextField(8).getPreferredSize().width;
}
if (col == LENGTHCOL) {
return new JTextField(7).getPreferredSize().width;
}
if (col == PERMISCOL) {
return new JTextField(7).getPreferredSize().width;
}
if (col == SPEEDCOL) {
return new JTextField(7).getPreferredSize().width;
}
if (col == STATECOL) {
return new JTextField(8).getPreferredSize().width;
}
if (col == REPORTERCOL) {
return new JTextField(8).getPreferredSize().width;
}
if (col == SENSORCOL) {
return new JTextField(8).getPreferredSize().width;
}
if (col == CURRENTREPCOL) {
return new JTextField(7).getPreferredSize().width;
}
if (col == EDITCOL) {
return new JTextField(7).getPreferredSize().width;
} else {
return super.getPreferredWidth(col);
}
}
@Override
public void configValueColumn(JTable table) {
// value column isn't button, so config is null
}
@Override
public boolean isCellEditable(int row, int col) {
if (col == CURVECOL) {
return true;
} else if (col == LENGTHCOL) {
return true;
} else if (col == PERMISCOL) {
return true;
} else if (col == SPEEDCOL) {
return true;
} else if (col == STATECOL) {
return false;
} else if (col == REPORTERCOL) {
return true;
} else if (col == SENSORCOL) {
return true;
} else if (col == CURRENTREPCOL) {
return true;
} else if (col == EDITCOL) {
return true;
} else {
return super.isCellEditable(row, col);
}
}
@Override
public void configureTable(JTable table) {
table.setDefaultRenderer(JComboBox.class, new jmri.jmrit.symbolicprog.ValueRenderer());
table.setDefaultEditor(JComboBox.class, new jmri.jmrit.symbolicprog.ValueEditor());
table.setDefaultRenderer(Boolean.class, new EnablingCheckboxRenderer());
jmri.InstanceManager.sensorManagerInstance().addPropertyChangeListener(this);
configStateColumn(table);
super.configureTable(table);
}
@Override
protected boolean matchPropertyName(java.beans.PropertyChangeEvent e) {
return true;
// return (e.getPropertyName().indexOf("alue")>=0);
}
@Override
public JButton configureButton() {
log.error("configureButton should not have been called");
return null;
}
@Override
public void propertyChange(java.beans.PropertyChangeEvent e) {
if (e.getSource() instanceof jmri.SensorManager) {
if (e.getPropertyName().equals("length") || e.getPropertyName().equals("DisplayListName")) {
updateSensorList();
}
}
if (e.getPropertyName().equals("DefaultBlockSpeedChange")) {
updateSpeedList();
} else {
super.propertyChange(e);
}
}
@Override
protected String getBeanType() {
return Bundle.getMessage("BeanNameBlock");
}
@Override
public synchronized void dispose() {
super.dispose();
jmri.InstanceManager.sensorManagerInstance().removePropertyChangeListener(this);
}
/**
* Customize the block table State column to show an appropriate graphic for the block occupancy state
* if _graphicState = true, or (default) just show the localized state text
* when the TableDataModel is being called from ListedTableAction.
*
* @param table a JTable of Blocks
*/
protected void configStateColumn(JTable table) {
// have the state column hold a JPanel (icon)
//setColumnToHoldButton(table, VALUECOL, new JLabel("1234")); // for small round icon, but cannot be converted to JButton
// add extras, override BeanTableDataModel
log.debug("Block configStateColumn (I am {})", super.toString());
if (_graphicState) {
// load icons, only once
//table.setDefaultEditor(JLabel.class, new ImageIconRenderer()); // there's no editor for state column in BlockTable
// item class copied from SwitchboardEditor panel
table.setDefaultRenderer(JLabel.class, new ImageIconRenderer());
// else, classic text style state indication, do nothing extra
}
}
/**
* Visualize state in table as a graphic, customized for Blocks (2 states).
* Renderer and Editor are identical, as the cell contents are not actually edited.
* @see jmri.jmrit.beantable.sensor.SensorTableDataModel.ImageIconRenderer
* @see jmri.jmrit.beantable.TurnoutTableAction#createModel()
* @see jmri.jmrit.beantable.LightTableAction#createModel()
*/
class ImageIconRenderer extends AbstractCellEditor implements TableCellEditor, TableCellRenderer {
protected JLabel label;
// also used in display.switchboardEditor
protected String rootPath = "resources/icons/misc/switchboard/";
// reuse Sensor icon for block state
protected char beanTypeChar = 'S';
protected String onIconPath = rootPath + beanTypeChar + "-on-s.png";
protected String offIconPath = rootPath + beanTypeChar + "-off-s.png";
protected BufferedImage onImage;
protected BufferedImage offImage;
protected ImageIcon onIcon;
protected ImageIcon offIcon;
protected int iconHeight = -1;
@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
log.debug("Renderer Item = {}, State = {}", row, value);
if (iconHeight < 0) {
// load resources only first time, either for renderer or editor
loadIcons();
log.debug("icons loaded");
}
return updateLabel((String) value, row);
}
@Override
public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) {
log.debug("Renderer Item = {}, State = {}", row, value);
if (iconHeight < 0) {
// load resources only first time, either for renderer or editor
loadIcons();
log.debug("icons loaded");
}
return updateLabel((String) value, row);
}
public JLabel updateLabel(String value, int row) {
if (iconHeight > 0) {
// if necessary, increase row height;
//table.setRowHeight(row, Math.max(table.getRowHeight(), iconHeight - 5)); // TODO adjust table row height for Block icons
}
if (value.equals(Bundle.getMessage("BlockUnOccupied")) && offIcon != null) {
label = new JLabel(offIcon);
label.setVerticalAlignment(JLabel.BOTTOM);
log.debug("offIcon set");
} else if (value.equals(Bundle.getMessage("BlockOccupied")) && onIcon != null) {
label = new JLabel(onIcon);
label.setVerticalAlignment(JLabel.BOTTOM);
log.debug("onIcon set");
} else if (value.equals(Bundle.getMessage("BlockInconsistent"))) {
// centered text alignment
label = new JLabel("X", JLabel.CENTER);
label.setForeground(Color.red);
log.debug("Block state inconsistent");
iconHeight = 0;
} else if (value.equals(Bundle.getMessage("BlockUnknown"))) {
// centered text alignment
label = new JLabel("?", JLabel.CENTER);
log.debug("Block state in transition");
iconHeight = 0;
} else {
// failed to load icon
// centered text alignment
label = new JLabel(value, JLabel.CENTER);
log.warn("Error reading icons for BlockTable");
iconHeight = 0;
}
label.setToolTipText(value);
label.addMouseListener(new MouseAdapter() {
@Override
public final void mousePressed(MouseEvent evt) {
log.debug("Clicked on icon in row {}", row);
stopCellEditing();
}
});
return label;
}
@Override
public Object getCellEditorValue() {
log.debug("getCellEditorValue, me = {})", this.toString());
return this.toString();
}
/**
* Read and buffer graphics. Only called once for this table.
* @see #getTableCellEditorComponent(JTable, Object, boolean, int, int)
*/
protected void loadIcons() {
try {
onImage = ImageIO.read(new File(onIconPath));
offImage = ImageIO.read(new File(offIconPath));
} catch (IOException ex) {
log.error("error reading image from {} or {}", onIconPath, offIconPath, ex);
}
log.debug("Success reading images");
int imageWidth = onImage.getWidth();
int imageHeight = onImage.getHeight();
// scale icons 50% to fit in table rows
Image smallOnImage = onImage.getScaledInstance(imageWidth / 2, imageHeight / 2, Image.SCALE_DEFAULT);
Image smallOffImage = offImage.getScaledInstance(imageWidth / 2, imageHeight / 2, Image.SCALE_DEFAULT);
onIcon = new ImageIcon(smallOnImage);
offIcon = new ImageIcon(smallOffImage);
iconHeight = onIcon.getIconHeight();
}
}
};
// end of custom data model
}
use of javax.swing.JComboBox in project JMRI by JMRI.
the class LogixTableAction method createModel.
// *********** Methods for Logix Table Window ********************
/**
* Create the JTable DataModel, along with the changes (overrides of
* BeanTableDataModel) for the specific case of a Logix table.
* <p>
* Note: Table Models for the Conditional table in the Edit Logix window,
* and the State Variable table in the Edit Conditional window are at
* the end of this module.
*/
@Override
protected void createModel() {
m = new BeanTableDataModel() {
// overlay the state column with the edit column
public static final int ENABLECOL = VALUECOL;
public static final int EDITCOL = DELETECOL;
protected String enabledString = Bundle.getMessage("ColumnHeadEnabled");
@Override
public String getColumnName(int col) {
if (col == EDITCOL) {
// no heading on "Edit"
return "";
}
if (col == ENABLECOL) {
return enabledString;
}
return super.getColumnName(col);
}
@Override
public Class<?> getColumnClass(int col) {
if (col == EDITCOL) {
return String.class;
}
if (col == ENABLECOL) {
return Boolean.class;
}
return super.getColumnClass(col);
}
@Override
public int getPreferredWidth(int col) {
// override default value for SystemName and UserName columns
if (col == SYSNAMECOL) {
return new JTextField(12).getPreferredSize().width;
}
if (col == USERNAMECOL) {
return new JTextField(17).getPreferredSize().width;
}
if (col == EDITCOL) {
return new JTextField(12).getPreferredSize().width;
}
if (col == ENABLECOL) {
return new JTextField(5).getPreferredSize().width;
}
return super.getPreferredWidth(col);
}
@Override
public boolean isCellEditable(int row, int col) {
if (col == EDITCOL) {
return true;
}
if (col == ENABLECOL) {
return true;
}
return super.isCellEditable(row, col);
}
@Override
public Object getValueAt(int row, int col) {
if (col == EDITCOL) {
return Bundle.getMessage("ButtonSelect");
} else if (col == ENABLECOL) {
Logix logix = (Logix) getBySystemName((String) getValueAt(row, SYSNAMECOL));
if (logix == null) {
return null;
}
return Boolean.valueOf(logix.getEnabled());
} else {
return super.getValueAt(row, col);
}
}
@Override
public void setValueAt(Object value, int row, int col) {
if (col == EDITCOL) {
// set up to edit
String sName = (String) getValueAt(row, SYSNAMECOL);
if (Bundle.getMessage("ButtonEdit").equals(value)) {
editPressed(sName);
} else if (rbx.getString("BrowserButton").equals(value)) {
conditionalRowNumber = row;
browserPressed(sName);
} else if (Bundle.getMessage("ButtonCopy").equals(value)) {
copyPressed(sName);
} else if (Bundle.getMessage("ButtonDelete").equals(value)) {
deletePressed(sName);
}
} else if (col == ENABLECOL) {
// alternate
Logix x = (Logix) getBySystemName((String) getValueAt(row, SYSNAMECOL));
boolean v = x.getEnabled();
x.setEnabled(!v);
} else {
super.setValueAt(value, row, col);
}
}
/**
* Delete the bean after all the checking has been done.
* <p>
* Deactivates the Logix and remove it's conditionals.
*
* @param bean of the Logix to delete
*/
@Override
void doDelete(NamedBean bean) {
Logix l = (Logix) bean;
l.deActivateLogix();
// delete the Logix and all its Conditionals
_logixManager.deleteLogix(l);
}
@Override
protected boolean matchPropertyName(java.beans.PropertyChangeEvent e) {
if (e.getPropertyName().equals(enabledString)) {
return true;
}
return super.matchPropertyName(e);
}
@Override
public Manager getManager() {
return InstanceManager.getDefault(jmri.LogixManager.class);
}
@Override
public NamedBean getBySystemName(String name) {
return InstanceManager.getDefault(jmri.LogixManager.class).getBySystemName(name);
}
@Override
public NamedBean getByUserName(String name) {
return InstanceManager.getDefault(jmri.LogixManager.class).getByUserName(name);
}
@Override
protected String getMasterClassName() {
return getClassName();
}
@Override
public void configureTable(JTable table) {
table.setDefaultRenderer(Boolean.class, new EnablingCheckboxRenderer());
table.setDefaultRenderer(JComboBox.class, new jmri.jmrit.symbolicprog.ValueRenderer());
table.setDefaultEditor(JComboBox.class, new jmri.jmrit.symbolicprog.ValueEditor());
super.configureTable(table);
}
/**
* Replace delete button with comboBox to edit/delete/copy/select Logix.
*
* @param table name of the Logix JTable holding the column
*/
@Override
protected void configDeleteColumn(JTable table) {
JComboBox<String> editCombo = new JComboBox<String>();
editCombo.addItem(Bundle.getMessage("ButtonSelect"));
editCombo.addItem(Bundle.getMessage("ButtonEdit"));
editCombo.addItem(rbx.getString("BrowserButton"));
editCombo.addItem(Bundle.getMessage("ButtonCopy"));
editCombo.addItem(Bundle.getMessage("ButtonDelete"));
TableColumn col = table.getColumnModel().getColumn(BeanTableDataModel.DELETECOL);
col.setCellEditor(new DefaultCellEditor(editCombo));
}
// Not needed - here for interface compatibility
@Override
public void clickOn(NamedBean t) {
}
@Override
public String getValue(String s) {
return "";
}
@Override
protected String getBeanType() {
return Bundle.getMessage("BeanNameLogix");
}
};
}
use of javax.swing.JComboBox in project JMRI by JMRI.
the class SignalHeadTableAction method addPressed.
/**
* Provide GUI for adding a new SignalHead.
* <p>
* Because there are multiple options, each of which requires different
* inputs, we directly manipulate which parts of the GUI are displayed when
* the selected type is changed.
*
* @param e name of the event heard
*/
@Override
protected void addPressed(ActionEvent e) {
if (addFrame == null) {
for (Object obj : jmri.InstanceManager.getList(jmri.CommandStation.class)) {
jmri.CommandStation station = (jmri.CommandStation) obj;
prefixBox.addItem(station.getUserName());
}
dccSignalPanel();
to1 = new BeanSelectCreatePanel(InstanceManager.turnoutManagerInstance(), null);
to2 = new BeanSelectCreatePanel(InstanceManager.turnoutManagerInstance(), null);
to3 = new BeanSelectCreatePanel(InstanceManager.turnoutManagerInstance(), null);
to4 = new BeanSelectCreatePanel(InstanceManager.turnoutManagerInstance(), null);
to5 = new BeanSelectCreatePanel(InstanceManager.turnoutManagerInstance(), null);
to6 = new BeanSelectCreatePanel(InstanceManager.turnoutManagerInstance(), null);
to7 = new BeanSelectCreatePanel(InstanceManager.turnoutManagerInstance(), null);
addFrame = new JmriJFrame(Bundle.getMessage("TitleAddSignalHead"), false, true);
addFrame.addHelpMenu("package.jmri.jmrit.beantable.SignalAddEdit", true);
addFrame.getContentPane().setLayout(new BorderLayout());
JPanel panelHeader = new JPanel();
panelHeader.setLayout(new BoxLayout(panelHeader, BoxLayout.Y_AXIS));
panelHeader.add(typeBox = new JComboBox<String>(new String[] { acelaAspect, dccSignalDecoder, doubleTurnout, lsDec, mergSignalDriver, quadOutput, singleTurnout, se8c4Aspect, tripleTurnout, tripleOutput, virtualHead }));
//If no DCC Comand station is found remove the DCC Signal Decoder option.
if (prefixBox.getItemCount() == 0) {
typeBox.removeItem(dccSignalDecoder);
}
List<jmri.jmrix.grapevine.GrapevineSystemConnectionMemo> memos = InstanceManager.getList(jmri.jmrix.grapevine.GrapevineSystemConnectionMemo.class);
if (!memos.isEmpty()) {
typeBox.addItem(grapevine);
}
typeBox.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
typeChanged();
}
});
JPanel p = new JPanel();
p.setLayout(new FlowLayout());
p.add(prefixBoxLabel);
p.add(prefixBox);
panelHeader.add(p);
p = new JPanel();
p.setLayout(new FlowLayout());
p.add(systemNameLabel);
p.add(systemName);
systemName.setToolTipText(Bundle.getMessage("SignalHeadSysNameTooltip"));
p.add(dccOffSetAddress);
dccOffSetAddress.setToolTipText(Bundle.getMessage("DccOffsetTooltip"));
panelHeader.add(p);
p = new JPanel();
p.setLayout(new FlowLayout());
p.add(userNameLabel);
p.add(userName);
userName.setToolTipText(Bundle.getMessage("SignalHeadUserNameTooltip"));
panelHeader.add(p);
addFrame.getContentPane().add(panelHeader, BorderLayout.PAGE_START);
JPanel panelCentre = new JPanel();
panelCentre.setLayout(new BoxLayout(panelCentre, BoxLayout.Y_AXIS));
//typeBox.setSelectedIndex(7);
//typeChanged();
// create seven boxes for input information, and put into pane
v1Panel = new JPanel();
v1Panel.setLayout(new FlowLayout());
v1Panel.add(ato1);
v1Panel.add(to1);
v1Panel.add(stateLabel1);
v1Panel.add(s1Box);
s1Box.setToolTipText(Bundle.getMessage("SignalHeadStateTooltip"));
v1Panel.add(msaBox);
v1Panel.setBorder(v1Border);
panelCentre.add(v1Panel);
v2Panel = new JPanel();
v2Panel.setLayout(defaultFlow);
v2Panel.add(to2);
v2Panel.add(stateLabel2);
v2Panel.add(s2Box);
s2Box.setToolTipText(Bundle.getMessage("SignalHeadStateTooltip"));
v2Panel.add(s2aBox);
v2Panel.add(mstBox);
v2Panel.add(dccSignalPanel);
v2Panel.setBorder(v2Border);
panelCentre.add(v2Panel);
v3Panel = new JPanel();
v3Panel.setLayout(defaultFlow);
v3Panel.add(to3);
v3Panel.add(stateLabel3);
v3Panel.add(s3Box);
s3Box.setToolTipText(Bundle.getMessage("SignalHeadStateTooltip"));
v3Panel.add(s3aBox);
v3Panel.setBorder(v3Border);
panelCentre.add(v3Panel);
v4Panel = new JPanel();
v4Panel.setLayout(defaultFlow);
v4Panel.add(to4);
v4Panel.add(stateLabel4);
v4Panel.add(s4Box);
s4Box.setToolTipText(Bundle.getMessage("SignalHeadStateTooltip"));
v4Panel.setBorder(v4Border);
panelCentre.add(v4Panel);
v5Panel = new JPanel();
v5Panel.setLayout(defaultFlow);
v5Panel.add(to5);
v5Panel.add(stateLabel5);
v5Panel.add(s5Box);
s5Box.setToolTipText(Bundle.getMessage("SignalHeadStateTooltip"));
v5Panel.setBorder(v5Border);
panelCentre.add(v5Panel);
v6Panel = new JPanel();
v6Panel.setLayout(defaultFlow);
v6Panel.add(to6);
v6Panel.add(stateLabel6);
v6Panel.add(s6Box);
s6Box.setToolTipText(Bundle.getMessage("SignalHeadStateTooltip"));
v6Panel.setBorder(v6Border);
panelCentre.add(v6Panel);
v7Panel = new JPanel();
v7Panel.setLayout(defaultFlow);
v7Panel.add(to7);
v7Panel.add(stateLabel7);
v7Panel.add(s7Box);
s7Box.setToolTipText(Bundle.getMessage("SignalHeadStateTooltip"));
v7Panel.setBorder(v7Border);
panelCentre.add(v7Panel);
p = new JPanel();
p.setLayout(defaultFlow);
p.add(vtLabel);
p.add(stBox);
panelCentre.add(p);
JScrollPane scrollPane = new JScrollPane(panelCentre);
addFrame.getContentPane().add(scrollPane, BorderLayout.CENTER);
// buttons at bottom of panel
JPanel panelBottom = new JPanel();
panelBottom.setLayout(new FlowLayout(FlowLayout.TRAILING));
// Cancel button
JButton cancelNew = new JButton(Bundle.getMessage("ButtonCancel"));
panelBottom.add(cancelNew);
cancelNew.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
cancelNewPressed(e);
}
});
//OK button
JButton ok;
panelBottom.add(ok = new JButton(Bundle.getMessage("ButtonCreate")));
ok.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
okPressed(e);
}
});
addFrame.getContentPane().add(panelBottom, BorderLayout.PAGE_END);
} else {
// clear older entries
systemName.setText("");
userName.setText("");
to1.refresh();
to2.refresh();
to3.refresh();
to4.refresh();
to5.refresh();
to6.refresh();
to7.refresh();
}
// force GUI status consistent. Default set to Double Head type
typeBox.setSelectedIndex(2);
addFrame.pack();
addFrame.setVisible(true);
}
Aggregations