use of javax.swing.table.TableRowSorter in project JMRI by JMRI.
the class SignallingPanel method buildTurnoutPanel.
/**
* Compose GUI for setting up the Turnouts tab for an SML.
*
* @return a JPanel containing the SML control turnouts configuration interface
*/
JPanel buildTurnoutPanel() {
JPanel turnoutPanel = new JPanel();
turnoutPanel.setLayout(new BoxLayout(turnoutPanel, BoxLayout.Y_AXIS));
jmri.TurnoutManager bm = jmri.InstanceManager.turnoutManagerInstance();
List<String> systemNameList = bm.getSystemNameList();
_manualTurnoutList = new ArrayList<ManualTurnoutList>(systemNameList.size());
Iterator<String> iter = systemNameList.iterator();
while (iter.hasNext()) {
String systemName = iter.next();
String userName = bm.getBySystemName(systemName).getUserName();
_manualTurnoutList.add(new ManualTurnoutList(systemName, userName));
}
if ((sml != null) && (destMast != null)) {
ArrayList<Turnout> turnList = sml.getAutoTurnouts(destMast);
_automaticTurnoutList = new ArrayList<AutoTurnoutList>(turnList.size());
Iterator<Turnout> iterTurn = turnList.iterator();
while (iterTurn.hasNext()) {
Turnout turn = iterTurn.next();
String systemName = turn.getSystemName();
String userName = turn.getUserName();
AutoTurnoutList turnitem = new AutoTurnoutList(systemName, userName);
turnitem.setState(sml.getAutoTurnoutState(turn, destMast));
_automaticTurnoutList.add(turnitem);
}
}
p2xt = new JPanel();
JPanel p2xcSpace = new JPanel();
p2xcSpace.setLayout(new BoxLayout(p2xcSpace, BoxLayout.Y_AXIS));
p2xcSpace.add(new JLabel("XXX"));
p2xt.add(p2xcSpace);
JPanel p21c = new JPanel();
p21c.setLayout(new BoxLayout(p21c, BoxLayout.Y_AXIS));
p21c.add(new JLabel(Bundle.getMessage("LabelSelectChecked", Bundle.getMessage("Turnouts"))));
p2xt.add(p21c);
_turnoutModel = new TurnoutModel();
JTable manualTurnoutTable = new JTable(_turnoutModel);
TableRowSorter<TurnoutModel> manualTurnoutSorter = new TableRowSorter<>(_turnoutModel);
// configure row height for comboBox
// row height has to be greater than for plain tables
manualTurnoutTable.setRowHeight(Sizer.getPreferredSize().height - 2);
manualTurnoutSorter.setComparator(TurnoutModel.SNAME_COLUMN, new SystemNameComparator());
RowSorterUtil.setSortOrder(manualTurnoutSorter, TurnoutModel.SNAME_COLUMN, SortOrder.ASCENDING);
// create static comboBox in State column
_turnoutModel.configStateColumn(manualTurnoutTable);
manualTurnoutTable.setRowSorter(manualTurnoutSorter);
manualTurnoutTable.setRowSelectionAllowed(false);
manualTurnoutTable.setPreferredScrollableViewportSize(new java.awt.Dimension(480, 100));
// JComboBox<String> stateCCombo = new JComboBox<>(); // moved to ManualTurnoutTable class
TableColumnModel _manualTurnoutColumnModel = manualTurnoutTable.getColumnModel();
TableColumn includeColumnC = _manualTurnoutColumnModel.getColumn(TurnoutModel.INCLUDE_COLUMN);
includeColumnC.setResizable(false);
// was fixed 60
includeColumnC.setMinWidth(9 * Bundle.getMessage("Include").length());
includeColumnC.setMaxWidth(includeColumnC.getMinWidth() + 5);
TableColumn sNameColumnC = _manualTurnoutColumnModel.getColumn(TurnoutModel.SNAME_COLUMN);
sNameColumnC.setResizable(true);
sNameColumnC.setMinWidth(75);
sNameColumnC.setMaxWidth(95);
TableColumn stateColumnC = _manualTurnoutColumnModel.getColumn(TurnoutModel.STATE_COLUMN);
// stateColumnC.setCellEditor(new DefaultCellEditor(stateCCombo)); // moved to ManualTurnoutTable class
stateColumnC.setResizable(false);
log.debug("L = " + SET_TO_ANY.length());
stateColumnC.setMinWidth(9 * Math.max(SET_TO_ANY.length(), SET_TO_CLOSED.length()) + 30);
// was fixed 100
stateColumnC.setMaxWidth(stateColumnC.getMinWidth() + 10);
// remaining space is filled by UserName
_manualTurnoutScrollPane = new JScrollPane(manualTurnoutTable);
p2xt.add(_manualTurnoutScrollPane, BorderLayout.CENTER);
turnoutPanel.add(p2xt);
p2xt.setVisible(true);
ROW_HEIGHT = manualTurnoutTable.getRowHeight();
p2xcSpace.setVisible(false);
JPanel p2xaSpace = new JPanel();
p2xaSpace.setLayout(new BoxLayout(p2xaSpace, BoxLayout.Y_AXIS));
p2xaSpace.add(new JLabel("XXX"));
p2xa.add(p2xaSpace);
JPanel p21a = new JPanel();
p21a.setLayout(new BoxLayout(p21a, BoxLayout.Y_AXIS));
p21a.add(new JLabel(Bundle.getMessage("LabelAutogenerated", Bundle.getMessage("Turnouts"))));
p2xa.add(p21a);
_autoTurnoutModel = new AutoTurnoutModel();
JTable autoTurnoutTable = new JTable(_autoTurnoutModel);
TableRowSorter<AutoTurnoutModel> autoTurnoutSorter = new TableRowSorter<>(_autoTurnoutModel);
autoTurnoutSorter.setComparator(AutoTurnoutModel.SNAME_COLUMN, new SystemNameComparator());
RowSorterUtil.setSortOrder(autoTurnoutSorter, AutoTurnoutModel.SNAME_COLUMN, SortOrder.ASCENDING);
autoTurnoutTable.setRowSorter(autoTurnoutSorter);
autoTurnoutTable.setRowSelectionAllowed(false);
autoTurnoutTable.setPreferredScrollableViewportSize(new java.awt.Dimension(480, 100));
TableColumnModel _autoTurnoutColumnModel = autoTurnoutTable.getColumnModel();
TableColumn sNameColumnA = _autoTurnoutColumnModel.getColumn(AutoTurnoutModel.SNAME_COLUMN);
sNameColumnA.setResizable(true);
sNameColumnA.setMinWidth(75);
sNameColumnA.setMaxWidth(95);
TableColumn stateColumnA = _autoTurnoutColumnModel.getColumn(AutoTurnoutModel.STATE_COLUMN);
stateColumnA.setResizable(false);
stateColumnA.setMinWidth(90);
stateColumnA.setMaxWidth(100);
_autoTurnoutScrollPane = new JScrollPane(autoTurnoutTable);
p2xa.add(_autoTurnoutScrollPane, BorderLayout.CENTER);
turnoutPanel.add(p2xa);
p2xa.setVisible(true);
ROW_HEIGHT = autoTurnoutTable.getRowHeight();
p2xaSpace.setVisible(false);
return turnoutPanel;
}
use of javax.swing.table.TableRowSorter in project JMRI by JMRI.
the class SignallingPanel method buildSensorPanel.
/**
* Compose GUI for setting up the Sensors tab for an SML.
*
* @return a JPanel containing the SML control sensors configuration interface
*/
JPanel buildSensorPanel() {
JPanel sensorPanel = new JPanel();
sensorPanel.setLayout(new BoxLayout(sensorPanel, BoxLayout.Y_AXIS));
jmri.SensorManager bm = jmri.InstanceManager.sensorManagerInstance();
List<String> systemNameList = bm.getSystemNameList();
_manualSensorList = new ArrayList<ManualSensorList>(systemNameList.size());
Iterator<String> iter = systemNameList.iterator();
while (iter.hasNext()) {
String systemName = iter.next();
Sensor ss = bm.getBySystemName(systemName);
if (ss != null) {
String userName = ss.getUserName();
_manualSensorList.add(new ManualSensorList(systemName, userName));
} else {
log.error("Failed to get sensor {}", systemName);
}
}
p2xs = new JPanel();
JPanel p2xsSpace = new JPanel();
p2xsSpace.setLayout(new BoxLayout(p2xsSpace, BoxLayout.Y_AXIS));
p2xsSpace.add(new JLabel("XXX"));
p2xs.add(p2xsSpace);
JPanel p21c = new JPanel();
p21c.setLayout(new BoxLayout(p21c, BoxLayout.Y_AXIS));
p21c.add(new JLabel(Bundle.getMessage("LabelSelectChecked", Bundle.getMessage("Sensors"))));
p2xs.add(p21c);
_sensorModel = new SensorModel();
JTable manualSensorTable = new JTable(_sensorModel);
TableRowSorter<SensorModel> manualSensorSorter = new TableRowSorter<>(_sensorModel);
// configure row height for comboBox
// row height has to be greater than for plain tables
manualSensorTable.setRowHeight(Sizer.getPreferredSize().height - 2);
manualSensorSorter.setComparator(SensorModel.SNAME_COLUMN, new SystemNameComparator());
RowSorterUtil.setSortOrder(manualSensorSorter, SensorModel.SNAME_COLUMN, SortOrder.ASCENDING);
// create static comboBox in State column
_sensorModel.configStateColumn(manualSensorTable);
manualSensorTable.setRowSorter(manualSensorSorter);
manualSensorTable.setRowSelectionAllowed(false);
manualSensorTable.setPreferredScrollableViewportSize(new java.awt.Dimension(480, 100));
//stateCCombo = new JComboBox<>(); // moved to ManualSensorTable class
TableColumnModel _manualSensorColumnModel = manualSensorTable.getColumnModel();
TableColumn includeColumnC = _manualSensorColumnModel.getColumn(SensorModel.INCLUDE_COLUMN);
includeColumnC.setResizable(false);
// was fixed 60
includeColumnC.setMinWidth(9 * Bundle.getMessage("Include").length());
includeColumnC.setMaxWidth(includeColumnC.getMinWidth() + 5);
TableColumn sNameColumnC = _manualSensorColumnModel.getColumn(SensorModel.SNAME_COLUMN);
sNameColumnC.setResizable(true);
sNameColumnC.setMinWidth(75);
sNameColumnC.setMaxWidth(95);
TableColumn stateColumnC = _manualSensorColumnModel.getColumn(SensorModel.STATE_COLUMN);
stateColumnC.setResizable(false);
stateColumnC.setMinWidth(9 * SET_TO_INACTIVE.length() + 30);
// was fixed 100
stateColumnC.setMaxWidth(stateColumnC.getMinWidth() + 10);
// remaining space is filled by UserName
_manualSensorScrollPane = new JScrollPane(manualSensorTable);
p2xs.add(_manualSensorScrollPane, BorderLayout.CENTER);
sensorPanel.add(p2xs);
p2xs.setVisible(true);
ROW_HEIGHT = manualSensorTable.getRowHeight();
p2xsSpace.setVisible(false);
return sensorPanel;
}
use of javax.swing.table.TableRowSorter in project JMRI by JMRI.
the class NodeTablePane method initComponents.
/**
* Initialize the window
*/
public void initComponents() {
setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
nodesModel = new NodesModel();
JTable nodesTable = new JTable(nodesModel);
// install a button renderer & editor
ButtonRenderer buttonRenderer = new ButtonRenderer();
nodesTable.setDefaultRenderer(JButton.class, buttonRenderer);
TableCellEditor buttonEditor = new ButtonEditor(new JButton());
nodesTable.setDefaultEditor(JButton.class, buttonEditor);
TableRowSorter<NodesModel> sorter = new TableRowSorter<>(nodesModel);
RowSorterUtil.setSortOrder(sorter, NodesModel.STATUSCOL, SortOrder.DESCENDING);
nodesTable.setRowSorter(sorter);
nodesTable.setRowSelectionAllowed(false);
nodesTable.setPreferredScrollableViewportSize(new java.awt.Dimension(580, 80));
JScrollPane scrollPane = new JScrollPane(nodesTable);
add(scrollPane);
// status info on bottom
JPanel p = new JPanel() {
@Override
public Dimension getMaximumSize() {
int height = getPreferredSize().height;
int width = super.getMaximumSize().width;
return new Dimension(width, height);
}
};
p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS));
JButton b = new JButton(rb.getString("ButtonCheck"));
b.setToolTipText(rb.getString("TipCheck"));
b.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent event) {
startPoll();
}
});
p.add(b);
status = new JLabel("");
p.add(status);
p.add(Box.createHorizontalGlue());
// renumber button
b = new JButton(rb.getString("ButtonRenumber"));
b.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent event) {
renumber();
}
});
p.add(b);
add(p);
// start the search for nodes
startPoll();
}
use of javax.swing.table.TableRowSorter in project JMRI by JMRI.
the class AlignTablePane method initComponents.
/**
* Initialize the window
*/
public void initComponents() {
setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
alignModel = new AlignModel();
JTable alignTable = new JTable(alignModel);
// install a button renderer & editor
ButtonRenderer buttonRenderer = new ButtonRenderer();
alignTable.setDefaultRenderer(JButton.class, buttonRenderer);
TableCellEditor buttonEditor = new ButtonEditor(new JButton());
alignTable.setDefaultEditor(JButton.class, buttonEditor);
TableRowSorter<AlignModel> sorter = new TableRowSorter<>(alignModel);
RowSorterUtil.setSortOrder(sorter, AlignModel.NUMCOL, SortOrder.ASCENDING);
alignTable.setRowSelectionAllowed(false);
alignTable.setPreferredScrollableViewportSize(new java.awt.Dimension(580, 80));
JScrollPane scrollPane = new JScrollPane(alignTable);
add(scrollPane);
// status info on bottom
JPanel p = new JPanel() {
@Override
public Dimension getMaximumSize() {
int height = getPreferredSize().height;
int width = super.getMaximumSize().width;
return new Dimension(width, height);
}
};
p.setLayout(new FlowLayout());
p.add(new JLabel(rb.getString("LabelNumCol")));
num.setText("" + Engine.instance().getMaxReceiverNumber());
p.add(num);
JButton b = new JButton(rb.getString("ButtonSet"));
b.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent event) {
// set number of columns
Engine.instance().setMaxReceiverNumber(Integer.parseInt(num.getText()));
// mark modification
flag.setModifiedFlag(true);
// resize table
alignModel.fireTableStructureChanged();
}
});
p.add(b);
add(p);
p = new JPanel() {
@Override
public Dimension getMaximumSize() {
int height = getPreferredSize().height;
int width = super.getMaximumSize().width;
return new Dimension(width, height);
}
};
p.setLayout(new FlowLayout());
p.add(new JLabel(rb.getString("LabelVSound")));
vsound.setText("" + Engine.instance().getVSound());
p.add(vsound);
p.add(new JLabel(rb.getString("LabelOffset")));
offset.setText("" + Engine.instance().getOffset());
p.add(offset);
p.add(new JLabel(rb.getString("LabelAlgorithm")));
p.add(algorithmBox);
b = new JButton(rb.getString("ButtonSet"));
b.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent event) {
// set number of vsound, offset
Engine.instance().setOffset(Integer.parseInt(offset.getText()));
Engine.instance().setVSound(Double.parseDouble(vsound.getText()));
Engine.instance().setAlgorithm((String) algorithmBox.getSelectedItem());
// mark modification
flag.setModifiedFlag(true);
}
});
p.add(b);
add(p);
//
add(loadStore = new jmri.jmrix.rps.swing.LoadStorePanel() {
// make sure we redisplay if changed
@Override
public void load() {
super.load();
alignModel.fireTableStructureChanged();
// modified (to force store of default after load new values)
flag.setModifiedFlag(true);
}
@Override
public void storeDefault() {
super.storeDefault();
// no longer modified after storeDefault
flag.setModifiedFlag(false);
}
});
// add sound listener
Engine.instance().addPropertyChangeListener(new PropertyChangeListener() {
@Override
public void propertyChange(java.beans.PropertyChangeEvent e) {
if (e.getPropertyName().equals("vSound")) {
// update sound display
vsound.setText("" + e.getNewValue());
}
}
});
}
use of javax.swing.table.TableRowSorter in project jabref by JabRef.
the class IntegrityCheckAction method actionPerformed.
@Override
public void actionPerformed(ActionEvent e) {
IntegrityCheck check = new IntegrityCheck(frame.getCurrentBasePanel().getBibDatabaseContext(), Globals.prefs.getFileDirectoryPreferences(), Globals.prefs.getBibtexKeyPatternPreferences(), Globals.journalAbbreviationLoader.getRepository(Globals.prefs.getJournalAbbreviationPreferences()));
List<IntegrityMessage> messages = check.checkBibtexDatabase();
if (messages.isEmpty()) {
JOptionPane.showMessageDialog(frame.getCurrentBasePanel(), Localization.lang("No problems found."));
} else {
Map<String, Boolean> showMessage = new HashMap<>();
// prepare data model
Object[][] model = new Object[messages.size()][4];
int i = 0;
for (IntegrityMessage message : messages) {
model[i][0] = message.getEntry().getId();
model[i][1] = message.getEntry().getCiteKeyOptional().orElse("");
model[i][2] = message.getFieldName();
model[i][3] = message.getMessage();
showMessage.put(message.getMessage(), true);
i++;
}
// construct view
JTable table = new JTable(model, new Object[] { "ID", Localization.lang("BibTeX key"), Localization.lang("Field"), Localization.lang("Message") });
// hide IDs
TableColumnModel columnModel = table.getColumnModel();
columnModel.removeColumn(columnModel.getColumn(0));
RowFilter<Object, Object> filter = new RowFilter<Object, Object>() {
@Override
public boolean include(Entry<?, ?> entry) {
return showMessage.get(entry.getStringValue(3));
}
};
TableRowSorter<TableModel> sorter = new TableRowSorter<>(table.getModel());
sorter.setRowFilter(filter);
table.setRowSorter(sorter);
table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
table.setDefaultEditor(Object.class, null);
ListSelectionModel selectionModel = table.getSelectionModel();
selectionModel.addListSelectionListener(event -> {
if (!event.getValueIsAdjusting()) {
try {
String entryId = (String) model[table.convertRowIndexToModel(table.getSelectedRow())][0];
String fieldName = (String) model[table.convertRowIndexToModel(table.getSelectedRow())][2];
frame.getCurrentBasePanel().editEntryByIdAndFocusField(entryId, fieldName);
} catch (ArrayIndexOutOfBoundsException exception) {
}
}
});
// BibTeX key
table.getColumnModel().getColumn(0).setPreferredWidth(100);
// field name
table.getColumnModel().getColumn(1).setPreferredWidth(60);
// message
table.getColumnModel().getColumn(2).setPreferredWidth(400);
table.setAutoResizeMode(JTable.AUTO_RESIZE_LAST_COLUMN);
JScrollPane scrollPane = new JScrollPane(table);
String title = Localization.lang("%0 problem(s) found", String.valueOf(messages.size()));
JDialog dialog = new JDialog(frame, title, false);
JPopupMenu menu = new JPopupMenu();
for (String messageString : showMessage.keySet()) {
JCheckBoxMenuItem menuItem = new JCheckBoxMenuItem(messageString, true);
menuItem.addActionListener(event -> {
showMessage.put(messageString, menuItem.isSelected());
((AbstractTableModel) table.getModel()).fireTableDataChanged();
});
menu.add(menuItem);
}
JButton menuButton = new JButton(Localization.lang("Filter"));
menuButton.addActionListener(entry -> menu.show(menuButton, 0, menuButton.getHeight()));
FormBuilder builder = FormBuilder.create().layout(new FormLayout("fill:pref:grow", "fill:pref:grow, 2dlu, pref"));
builder.add(scrollPane).xy(1, 1);
builder.add(menuButton).xy(1, 3, "c, b");
dialog.add(builder.getPanel());
dialog.setSize(600, 600);
// show view
dialog.setVisible(true);
}
}
Aggregations