Search in sources :

Example 11 with XTableColumnModel

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);
}
Also used : ButtonEditor(jmri.util.table.ButtonEditor) JButton(javax.swing.JButton) TableCellEditor(javax.swing.table.TableCellEditor) XTableColumnModel(jmri.util.swing.XTableColumnModel) ButtonRenderer(jmri.util.table.ButtonRenderer)

Example 12 with XTableColumnModel

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);
}
Also used : EnablingCheckboxRenderer(jmri.jmrit.beantable.EnablingCheckboxRenderer) XTableColumnModel(jmri.util.swing.XTableColumnModel)

Example 13 with XTableColumnModel

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);
    }
}
Also used : RowSorter(javax.swing.RowSorter) HashMap(java.util.HashMap) TableColumnModel(javax.swing.table.TableColumnModel) XTableColumnModel(jmri.util.swing.XTableColumnModel) XTableColumnModel(jmri.util.swing.XTableColumnModel) TableColumn(javax.swing.table.TableColumn)

Example 14 with XTableColumnModel

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);
}
Also used : XTableColumnModel(jmri.util.swing.XTableColumnModel) TableColumn(javax.swing.table.TableColumn)

Example 15 with XTableColumnModel

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);
}
Also used : XTableColumnModel(jmri.util.swing.XTableColumnModel) TableColumn(javax.swing.table.TableColumn)

Aggregations

XTableColumnModel (jmri.util.swing.XTableColumnModel)28 TableColumn (javax.swing.table.TableColumn)12 JButton (javax.swing.JButton)9 JTable (javax.swing.JTable)8 ButtonEditor (jmri.util.table.ButtonEditor)7 ButtonRenderer (jmri.util.table.ButtonRenderer)7 TableCellEditor (javax.swing.table.TableCellEditor)6 JLabel (javax.swing.JLabel)5 ActionEvent (java.awt.event.ActionEvent)3 ActionListener (java.awt.event.ActionListener)3 MouseEvent (java.awt.event.MouseEvent)3 JComboBox (javax.swing.JComboBox)3 JPanel (javax.swing.JPanel)3 RowSorter (javax.swing.RowSorter)3 TableColumnModel (javax.swing.table.TableColumnModel)3 TableRowSorter (javax.swing.table.TableRowSorter)3 MouseAdapter (java.awt.event.MouseAdapter)2 Hashtable (java.util.Hashtable)2 BoxLayout (javax.swing.BoxLayout)2 DefaultCellEditor (javax.swing.DefaultCellEditor)2