use of javax.swing.JComboBox in project JMRI by JMRI.
the class TableFrames method makeBlockFrame.
/*
* ********************* BlockFrame *****************************
*/
protected JInternalFrame makeBlockFrame() {
JInternalFrame frame = new JInternalFrame(Bundle.getMessage("TitleBlockTable"), true, false, false, true);
_oBlockModel = new OBlockTableModel(this);
_oBlockTable = new JTable(_oBlockModel);
TableRowSorter<OBlockTableModel> sorter = new TableRowSorter<>(_oBlockModel);
sorter.setComparator(OBlockTableModel.SYSNAMECOL, new jmri.util.SystemNameComparator());
_oBlockTable.setRowSorter(sorter);
_oBlockTable.setTransferHandler(new jmri.util.DnDTableImportExportHandler(new int[] { OBlockTableModel.EDIT_COL, OBlockTableModel.DELETE_COL, OBlockTableModel.REPORT_CURRENTCOL, OBlockTableModel.SPEEDCOL, OBlockTableModel.PERMISSIONCOL, OBlockTableModel.UNITSCOL }));
_oBlockTable.setDragEnabled(true);
// Use XTableColumnModel so we can control which columns are visible
XTableColumnModel tcm = new XTableColumnModel();
_oBlockTable.setColumnModel(tcm);
_oBlockTable.getTableHeader().setReorderingAllowed(true);
_oBlockTable.createDefaultColumnsFromModel();
_oBlockModel.addHeaderListener(_oBlockTable);
_oBlockTable.setDefaultEditor(JComboBox.class, new jmri.jmrit.symbolicprog.ValueEditor());
_oBlockTable.getColumnModel().getColumn(OBlockTableModel.EDIT_COL).setCellEditor(new ButtonEditor(new JButton()));
_oBlockTable.getColumnModel().getColumn(OBlockTableModel.EDIT_COL).setCellRenderer(new ButtonRenderer());
_oBlockTable.getColumnModel().getColumn(OBlockTableModel.DELETE_COL).setCellEditor(new ButtonEditor(new JButton()));
_oBlockTable.getColumnModel().getColumn(OBlockTableModel.DELETE_COL).setCellRenderer(new ButtonRenderer());
_oBlockTable.getColumnModel().getColumn(OBlockTableModel.UNITSCOL).setCellRenderer(new MyBooleanRenderer(Bundle.getMessage("cm"), Bundle.getMessage("in")));
JComboBox<String> box = new JComboBox<String>(OBlockTableModel.curveOptions);
_oBlockTable.getColumnModel().getColumn(OBlockTableModel.CURVECOL).setCellEditor(new DefaultCellEditor(box));
_oBlockTable.getColumnModel().getColumn(OBlockTableModel.REPORT_CURRENTCOL).setCellRenderer(new MyBooleanRenderer(Bundle.getMessage("Current"), Bundle.getMessage("Last")));
box = new JComboBox<String>(jmri.InstanceManager.getDefault(SignalSpeedMap.class).getValidSpeedNames());
box.addItem("");
_oBlockTable.getColumnModel().getColumn(OBlockTableModel.SPEEDCOL).setCellEditor(new DefaultCellEditor(box));
_oBlockTable.getColumnModel().getColumn(OBlockTableModel.PERMISSIONCOL).setCellRenderer(new MyBooleanRenderer(Bundle.getMessage("Permissive"), Bundle.getMessage("Absolute")));
_oBlockTable.addMouseListener(new MouseAdapter() {
@Override
public void mousePressed(MouseEvent me) {
showPopup(me);
}
@Override
public void mouseReleased(MouseEvent me) {
showPopup(me);
}
});
for (int i = 0; i < _oBlockModel.getColumnCount(); i++) {
int width = _oBlockModel.getPreferredWidth(i);
_oBlockTable.getColumnModel().getColumn(i).setPreferredWidth(width);
}
_oBlockTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
ROW_HEIGHT = _oBlockTable.getRowHeight();
int tableWidth = _desktop.getPreferredSize().width;
_oBlockTable.setPreferredScrollableViewportSize(new java.awt.Dimension(tableWidth, ROW_HEIGHT * 10));
_blockTablePane = new JScrollPane(_oBlockTable);
tcm.setColumnVisible(tcm.getColumnByModelIndex(OBlockTableModel.REPORTERCOL), false);
tcm.setColumnVisible(tcm.getColumnByModelIndex(OBlockTableModel.REPORT_CURRENTCOL), false);
tcm.setColumnVisible(tcm.getColumnByModelIndex(OBlockTableModel.PERMISSIONCOL), false);
// tcm.setColumnVisible(tcm.getColumnByModelIndex(OBlockTableModel.SPEEDCOL), false);
// tcm.setColumnVisible(tcm.getColumnByModelIndex(OBlockTableModel.ERR_SENSORCOL), false);
tcm.setColumnVisible(tcm.getColumnByModelIndex(OBlockTableModel.CURVECOL), false);
JPanel contentPane = new JPanel();
contentPane.setLayout(new BorderLayout(5, 5));
JLabel prompt = new JLabel(Bundle.getMessage("AddBlockPrompt"));
contentPane.add(prompt, BorderLayout.NORTH);
contentPane.add(_blockTablePane, BorderLayout.CENTER);
frame.setContentPane(contentPane);
frame.pack();
return frame;
}
use of javax.swing.JComboBox in project JMRI by JMRI.
the class SwitchboardEditor method init.
/**
* Initialize the newly created SwitchBoard.
*
* @param name name of the switchboard frame
*/
@Override
protected void init(String name) {
//setVisible(false);
// Editor
Container contentPane = getContentPane();
contentPane.setLayout(new BoxLayout(contentPane, BoxLayout.Y_AXIS));
// make menus
setGlobalSetsLocalFlag(false);
setUseGlobalFlag(false);
_menuBar = new JMenuBar();
makeOptionMenu();
//makeEditMenu();
makeFileMenu();
setJMenuBar(_menuBar);
addHelpMenu("package.jmri.jmrit.display.SwitchboardEditor", true);
//super.setTargetPanel(null, makeFrame(name)); // original CPE version
//extends JLayeredPane();
switchboardLayeredPane = new TargetPane();
switchboardLayeredPane.setPreferredSize(new Dimension(300, 310));
switchboardLayeredPane.setBorder(BorderFactory.createTitledBorder(BorderFactory.createLineBorder(defaultTextColor), Bundle.getMessage("SwitchboardBanner"), TitledBorder.LEADING, TitledBorder.ABOVE_BOTTOM, getFont(), defaultTextColor));
// create contrast with background, should also specify border style
// specify title for turnout, sensor, light, mixed? (wait for the Editor to be created)
switchboardLayeredPane.addMouseMotionListener(this);
//Add control pane and layered pane to this JPanel
JPanel beanSetupPane = new JPanel();
beanSetupPane.setLayout(new FlowLayout(FlowLayout.TRAILING));
JLabel beanTypeTitle = new JLabel(Bundle.getMessage("MakeLabel", Bundle.getMessage("BeanTypeLabel")));
beanSetupPane.add(beanTypeTitle);
beanTypeList = new JComboBox(beanTypeStrings);
// select Turnout in comboBox
beanTypeList.setSelectedIndex(0);
beanTypeList.setActionCommand(LAYER_COMMAND);
beanTypeList.addActionListener(this);
beanSetupPane.add(beanTypeList);
//Add connection selection comboBox
// translate from selectedIndex to char
beanTypeChar = getSwitchType().charAt(0);
log.debug("beanTypeChar set to [{}]", beanTypeChar);
JLabel beanManuTitle = new JLabel(Bundle.getMessage("MakeLabel", Bundle.getMessage("ConnectionLabel")));
beanSetupPane.add(beanManuTitle);
beanManuNames = new JComboBox();
if (getManager(beanTypeChar) instanceof jmri.managers.AbstractProxyManager) {
// from abstractTableTabAction
jmri.managers.AbstractProxyManager proxy = (jmri.managers.AbstractProxyManager) getManager(beanTypeChar);
List<jmri.Manager> managerList = proxy.getManagerList();
for (int x = 0; x < managerList.size(); x++) {
String manuPrefix = managerList.get(x).getSystemPrefix();
log.debug("Prefix = [{}]", manuPrefix);
String manuName = ConnectionNameFromSystemName.getConnectionName(manuPrefix);
log.debug("Connection name = [{}]", manuName);
// add to comboBox
beanManuNames.addItem(manuName);
// add to list
beanManuPrefixes.add(manuPrefix);
}
} else {
String manuPrefix = getManager(beanTypeChar).getSystemPrefix();
String manuName = ConnectionNameFromSystemName.getConnectionName(manuPrefix);
beanManuNames.addItem(manuName);
// add to list (as only item)
beanManuPrefixes.add(manuPrefix);
}
beanManuNames.setSelectedIndex(0);
beanManuNames.setActionCommand(MANU_COMMAND);
beanManuNames.addActionListener(this);
beanSetupPane.add(beanManuNames);
add(beanSetupPane);
// add shape combobox
JPanel switchShapePane = new JPanel();
switchShapePane.setLayout(new FlowLayout(FlowLayout.TRAILING));
JLabel switchShapeTitle = new JLabel(Bundle.getMessage("MakeLabel", Bundle.getMessage("SwitchShape")));
switchShapePane.add(switchShapeTitle);
switchShapeList = new JComboBox(switchShapeStrings);
// select Button in comboBox
switchShapeList.setSelectedIndex(0);
switchShapeList.setActionCommand(SWITCHTYPE_COMMAND);
switchShapeList.addActionListener(this);
switchShapePane.add(switchShapeList);
// add column spinner
JLabel columnLabel = new JLabel(Bundle.getMessage("NumberOfColumns"));
switchShapePane.add(columnLabel);
switchShapePane.add(Columns);
add(switchShapePane);
JCheckBox hideUnconnected = new JCheckBox(Bundle.getMessage("CheckBoxHideUnconnected"));
hideUnconnected.setSelected(hideUnconnected());
hideUnconnected.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent event) {
setHideUnconnected(hideUnconnected.isSelected());
}
});
add(hideUnconnected);
// Next, add the buttons to the layered pane.
switchboardLayeredPane.setLayout(new GridLayout(java.lang.Math.max(2, _range % ((Integer) Columns.getValue())), (Integer) Columns.getValue()));
// vertical (at least 2 rows), horizontal
// TODO do some calculation from JPanel size, icon size and determine optimal cols/rows
addSwitchRange((Integer) minSpinner.getValue(), (Integer) maxSpinner.getValue(), beanTypeList.getSelectedIndex(), beanManuPrefixes.get(beanManuNames.getSelectedIndex()), switchShapeList.getSelectedIndex());
// provide a JLayeredPane to place the switches on
super.setTargetPanel(switchboardLayeredPane, makeFrame(name));
// width x height
super.getTargetFrame().setSize(550, 330);
// To do: Add component listener to handle frame resizing event
// set scrollbar initial state
setScroll(SCROLL_NONE);
scrollNone.setSelected(true);
super.setDefaultToolTip(new ToolTip(null, 0, 0, new Font("Serif", Font.PLAIN, 12), Color.black, new Color(255, 250, 210), Color.black));
// register the resulting panel for later configuration
ConfigureManager cm = InstanceManager.getNullableDefault(jmri.ConfigureManager.class);
if (cm != null) {
cm.registerUser(this);
}
add(createControlPanel());
JPanel updatePanel = new JPanel();
JButton updateButton = new JButton(Bundle.getMessage("ButtonUpdate"));
updateButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent event) {
log.debug("Update clicked");
updatePressed();
}
});
updatePanel.add(updateButton);
contentPane.setLayout(new BoxLayout(contentPane, BoxLayout.PAGE_AXIS));
contentPane.add(updatePanel);
//re-layout all the toolbar items
setupToolBar();
// refresh default Switchboard
updatePressed();
pack();
setVisible(true);
// TODO choose your own icons
// class makeCatalog extends SwingWorker<CatalogPanel, Object> {
//
// @Override
// public CatalogPanel doInBackground() {
// return CatalogPanel.makeDefaultCatalog();
// }
// }
// (new makeCatalog()).execute();
// log.debug("Init SwingWorker launched");
}
use of javax.swing.JComboBox in project JMRI by JMRI.
the class ScheduleTableModel method getTrackComboBox.
private JComboBox<Track> getTrackComboBox(ScheduleItem si) {
// log.debug("getTrackComboBox for ScheduleItem "+si.getType());
JComboBox<Track> cb = new JComboBox<>();
if (si.getDestination() != null) {
Location dest = si.getDestination();
dest.updateComboBox(cb);
filterTracks(dest, cb, si.getTypeName(), si.getRoadName(), si.getShipLoadName());
cb.setSelectedItem(si.getDestinationTrack());
if (si.getDestinationTrack() != null && cb.getSelectedIndex() == -1) {
// user deleted track at destination, this is self correcting, when user restarts program, track
// assignment will be gone.
cb.addItem(si.getDestinationTrack());
cb.setSelectedItem(si.getDestinationTrack());
}
}
return cb;
}
use of javax.swing.JComboBox in project JMRI by JMRI.
the class TrainPrintUtilities method getPrinterJComboBox.
public static JComboBox<String> getPrinterJComboBox() {
JComboBox<String> box = new JComboBox<>();
PrintService[] services = PrintServiceLookup.lookupPrintServices(null, null);
for (PrintService printService : services) {
box.addItem(printService.getName());
}
// Set to default printer
box.setSelectedItem(getDefaultPrinterName());
return box;
}
use of javax.swing.JComboBox in project JMRI by JMRI.
the class RosterGroupTableAction method actionPerformed.
public void actionPerformed() {
// create the JTable model, with changes for specific NamedBean
createModel();
// create the frame
f = new RosterGroupTableFrame(m, helpTarget()) {
/**
* Include an "add" button
*/
@Override
void extras() {
final JComboBox<String> selectCombo = new RosterGroupComboBox();
selectCombo.insertItemAt("", 0);
selectCombo.setSelectedIndex(-1);
JPanel p25 = new JPanel();
p25.add(new JLabel(Bundle.getMessage("SelectRosterGroup")));
p25.add(selectCombo);
addToTopBox(p25);
selectCombo.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
comboSelected(e, selectCombo.getSelectedItem().toString());
}
});
selectCombo.setVisible(true);
}
};
setTitle();
addToFrame(f);
f.pack();
f.setVisible(true);
}
Aggregations