use of jmri.util.swing.XTableColumnModel in project JMRI by JMRI.
the class CarsTableModel method initTable.
void initTable() {
// Use XTableColumnModel so we can control which columns are visible
XTableColumnModel tcm = new XTableColumnModel();
_table.setColumnModel(tcm);
_table.createDefaultColumnsFromModel();
// Install the button handlers
ButtonRenderer buttonRenderer = new ButtonRenderer();
tcm.getColumn(SET_COLUMN).setCellRenderer(buttonRenderer);
TableCellEditor buttonEditor = new ButtonEditor(new javax.swing.JButton());
tcm.getColumn(SET_COLUMN).setCellEditor(buttonEditor);
tcm.getColumn(EDIT_COLUMN).setCellRenderer(buttonRenderer);
tcm.getColumn(EDIT_COLUMN).setCellEditor(buttonEditor);
// set column preferred widths
for (int i = 0; i < tcm.getColumnCount(); i++) {
tcm.getColumn(i).setPreferredWidth(tableColumnWidths[i]);
}
_frame.loadTableDetails(_table);
// turn off columns
tcm.setColumnVisible(tcm.getColumnByModelIndex(SELECT_COLUMN), isSelectVisible);
tcm.setColumnVisible(tcm.getColumnByModelIndex(COLOR_COLUMN), false);
tcm.setColumnVisible(tcm.getColumnByModelIndex(FINAL_DESTINATION_COLUMN), false);
tcm.setColumnVisible(tcm.getColumnByModelIndex(RWE_COLUMN), false);
tcm.setColumnVisible(tcm.getColumnByModelIndex(RWE_LOAD_COLUMN), false);
tcm.setColumnVisible(tcm.getColumnByModelIndex(BUILT_COLUMN), false);
tcm.setColumnVisible(tcm.getColumnByModelIndex(OWNER_COLUMN), false);
tcm.setColumnVisible(tcm.getColumnByModelIndex(VALUE_COLUMN), false);
tcm.setColumnVisible(tcm.getColumnByModelIndex(RFID_COLUMN), false);
tcm.setColumnVisible(tcm.getColumnByModelIndex(RFID_WHEN_LAST_SEEN_COLUMN), false);
tcm.setColumnVisible(tcm.getColumnByModelIndex(RFID_WHERE_LAST_SEEN_COLUMN), false);
tcm.setColumnVisible(tcm.getColumnByModelIndex(WAIT_COLUMN), false);
tcm.setColumnVisible(tcm.getColumnByModelIndex(PICKUP_COLUMN), false);
tcm.setColumnVisible(tcm.getColumnByModelIndex(LAST_COLUMN), false);
}
use of jmri.util.swing.XTableColumnModel in project JMRI by JMRI.
the class TrainsScheduleTableModel method initTable.
void initTable() {
if (_table == null) {
return;
}
// Save table column order
XTableColumnModel tcm = new XTableColumnModel();
_table.setColumnModel(tcm);
_table.createDefaultColumnsFromModel();
// Install the button handlers
_table.setDefaultRenderer(Boolean.class, new EnablingCheckboxRenderer());
// set column preferred widths
for (int i = 0; i < tableScheduleColumnWidths.length; i++) {
tcm.getColumn(i).setPreferredWidth(tableScheduleColumnWidths[i]);
}
_frame.loadTableDetails(_table);
}
use of jmri.util.swing.XTableColumnModel in project JMRI by JMRI.
the class JmriJTablePersistenceManager method resetState.
@Override
public void resetState(JTable table) {
Objects.requireNonNull(table.getName(), "table name must be nonnull");
boolean persisting = this.listeners.containsKey(table.getName());
// while setting table state, don't listen to changes in table state
this.stopPersisting(table);
TableColumnModel model = table.getColumnModel();
Objects.requireNonNull(model, "table " + table.getName() + " has a null columnModel");
RowSorter sorter = table.getRowSorter();
boolean isXModel = model instanceof XTableColumnModel;
Enumeration<TableColumn> e;
if (isXModel) {
e = ((XTableColumnModel) model).getColumns(false);
} else {
e = model.getColumns();
}
while (e.hasMoreElements()) {
TableColumn column = e.nextElement();
if (column.getIdentifier() == null) {
column.setIdentifier(column.getHeaderValue().toString());
}
}
Map<Integer, String> indexes = new HashMap<>();
if (this.columns.get(table.getName()) == null) {
this.columns.put(table.getName(), new HashMap<>());
}
this.columns.get(table.getName()).entrySet().stream().forEach((entry) -> {
int index = entry.getValue().getOrder();
indexes.put(index, entry.getKey());
});
// order columns
for (int i = 0; i < model.getColumnCount(); i++) {
String name = indexes.get(i);
if (name != null) {
int dataModelIndex = -1;
for (int j = 0; j < model.getColumnCount(); j++) {
if (table.getColumnName(j).equals(name)) {
dataModelIndex = j;
break;
}
}
if (dataModelIndex != -1 && (dataModelIndex != i)) {
model.moveColumn(dataModelIndex, i);
}
}
}
// configure columns
if (isXModel) {
e = ((XTableColumnModel) model).getColumns(false);
} else {
e = model.getColumns();
}
while (e.hasMoreElements()) {
TableColumn column = e.nextElement();
String name = column.getIdentifier().toString();
TableColumnPreferences preferences = this.columns.get(table.getName()).get(name);
if (preferences != null) {
column.setPreferredWidth(preferences.getWidth());
if (isXModel) {
((XTableColumnModel) model).setColumnVisible(column, !preferences.getHidden());
}
}
}
if (sorter != null && this.sortKeys.get(table.getName()) != null) {
sorter.setSortKeys(this.sortKeys.get(table.getName()));
}
if (persisting) {
this.persist(table);
}
}
use of jmri.util.swing.XTableColumnModel in project JMRI by JMRI.
the class TurnoutTableAction method showTurnoutSpeedChanged.
//boolean showTurnoutSpeed = false;
public void showTurnoutSpeedChanged() {
boolean showTurnoutSpeed = showTurnoutSpeedBox.isSelected();
XTableColumnModel columnModel = (XTableColumnModel) table.getColumnModel();
TableColumn column = ((XTableColumnModel) table.getColumnModel()).getColumnByModelIndex(STRAIGHTCOL);
columnModel.setColumnVisible(column, showTurnoutSpeed);
column = columnModel.getColumnByModelIndex(DIVERGCOL);
columnModel.setColumnVisible(column, showTurnoutSpeed);
}
use of jmri.util.swing.XTableColumnModel in project JMRI by JMRI.
the class SensorTableDataModel method showDebounce.
public void showDebounce(boolean show) {
XTableColumnModel columnModel = (XTableColumnModel) table.getColumnModel();
TableColumn column = columnModel.getColumnByModelIndex(USEGLOBALDELAY);
columnModel.setColumnVisible(column, show);
column = columnModel.getColumnByModelIndex(ACTIVEDELAY);
columnModel.setColumnVisible(column, show);
column = columnModel.getColumnByModelIndex(INACTIVEDELAY);
columnModel.setColumnVisible(column, show);
}
Aggregations