use of javax.swing.table.TableRowSorter in project JMRI by JMRI.
the class PaneProgPane method makeCvTable.
void makeCvTable(GridBagConstraints cs, GridBagLayout g, JPanel c) {
log.debug("starting to build CvTable pane");
TableRowSorter<TableModel> sorter = new TableRowSorter<>(_cvModel);
JTable cvTable = new JTable(_cvModel);
sorter.setComparator(CvTableModel.NUMCOLUMN, new jmri.util.PreferNumericComparator());
List<RowSorter.SortKey> sortKeys = new ArrayList<>();
sortKeys.add(new RowSorter.SortKey(0, SortOrder.ASCENDING));
sorter.setSortKeys(sortKeys);
cvTable.setRowSorter(sorter);
cvTable.setDefaultRenderer(JTextField.class, new ValueRenderer());
cvTable.setDefaultRenderer(JButton.class, new ValueRenderer());
cvTable.setDefaultEditor(JTextField.class, new ValueEditor());
cvTable.setDefaultEditor(JButton.class, new ValueEditor());
cvTable.setRowHeight(new JButton("X").getPreferredSize().height);
// have to shut off autoResizeMode to get horizontal scroll to work (JavaSwing p 541)
// instead of forcing the columns to fill the frame (and only fill)
cvTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
JScrollPane cvScroll = new JScrollPane(cvTable);
cvScroll.setColumnHeaderView(cvTable.getTableHeader());
cs.gridheight = GridBagConstraints.REMAINDER;
g.setConstraints(cvScroll, cs);
c.add(cvScroll);
cs.gridheight = 1;
// remember which CVs to read/write
isCvTablePane = true;
setCvListFromTable();
_cvTable = true;
log.debug("end of building CvTable pane");
}
use of javax.swing.table.TableRowSorter in project JMRI by JMRI.
the class AbstractTableAction method actionPerformed.
@Override
public void actionPerformed(ActionEvent e) {
// create the JTable model, with changes for specific NamedBean
createModel();
TableRowSorter<BeanTableDataModel> sorter = new TableRowSorter<>(m);
JTable dataTable = m.makeJTable(m.getMasterClassName(), m, sorter);
// allow reordering of the columns
dataTable.getTableHeader().setReorderingAllowed(true);
// create the frame
f = new BeanTableFrame(m, helpTarget(), dataTable) {
/**
* Include an "add" button
*/
@Override
void extras() {
if (includeAddButton) {
JButton addButton = new JButton(Bundle.getMessage("ButtonAdd"));
addToBottomBox(addButton, this.getClass().getName());
addButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
addPressed(e);
}
});
}
}
};
// comes after the Help menu is added by f = new BeanTableFrame(etc.) in stand alone application
setMenuBar(f);
setTitle();
addToFrame(f);
f.pack();
f.setVisible(true);
}
use of javax.swing.table.TableRowSorter in project JMRI by JMRI.
the class SignalMastLogicTableAction method actionPerformed.
@Override
public void actionPerformed(ActionEvent e) {
// create the JTable model, with changes for specific NamedBean
createModel();
TableRowSorter<BeanTableDataModel> sorter = new TableRowSorter<>(m);
JTable dataTable = m.makeJTable(m.getMasterClassName(), m, sorter);
// create the frame
f = new jmri.jmrit.beantable.BeanTableFrame(m, helpTarget(), dataTable) {
};
setMenuBar(f);
setTitle();
addToFrame(f);
f.pack();
f.setVisible(true);
}
use of javax.swing.table.TableRowSorter 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.table.TableRowSorter in project JMRI by JMRI.
the class TableFrames method makePortalFrame.
/*
* ********************* PortalFrame *****************************
*/
protected JInternalFrame makePortalFrame() {
JInternalFrame frame = new JInternalFrame(Bundle.getMessage("TitlePortalTable"), true, false, false, true);
_portalModel = new PortalTableModel(this);
_portalTable = new JTable(_portalModel);
TableRowSorter<PortalTableModel> sorter = new TableRowSorter<>(_portalModel);
sorter.setComparator(PortalTableModel.FROM_BLOCK_COLUMN, new jmri.util.SystemNameComparator());
sorter.setComparator(PortalTableModel.TO_BLOCK_COLUMN, new jmri.util.SystemNameComparator());
_portalTable.setRowSorter(sorter);
_portalTable.setTransferHandler(new jmri.util.DnDTableImportExportHandler(new int[] { PortalTableModel.DELETE_COL }));
_portalTable.setDragEnabled(true);
_portalTable.getColumnModel().getColumn(PortalTableModel.DELETE_COL).setCellEditor(new ButtonEditor(new JButton()));
_portalTable.getColumnModel().getColumn(PortalTableModel.DELETE_COL).setCellRenderer(new ButtonRenderer());
for (int i = 0; i < _portalModel.getColumnCount(); i++) {
int width = _portalModel.getPreferredWidth(i);
_portalTable.getColumnModel().getColumn(i).setPreferredWidth(width);
}
_portalTable.sizeColumnsToFit(-1);
int tableWidth = _portalTable.getPreferredSize().width;
_portalTable.setPreferredScrollableViewportSize(new java.awt.Dimension(tableWidth, ROW_HEIGHT * 10));
_portalTablePane = new JScrollPane(_portalTable);
JPanel contentPane = new JPanel();
contentPane.setLayout(new BorderLayout(5, 5));
JLabel prompt = new JLabel(Bundle.getMessage("AddPortalPrompt"));
contentPane.add(prompt, BorderLayout.NORTH);
contentPane.add(_portalTablePane, BorderLayout.CENTER);
frame.setContentPane(contentPane);
frame.setLocation(0, 200);
frame.pack();
return frame;
}
Aggregations