Search in sources :

Example 16 with XTableColumnModel

use of jmri.util.swing.XTableColumnModel in project JMRI by JMRI.

the class LocationTrackBlockingOrderTableModel method initTable.

private void initTable() {
    // Use XTableColumnModel so we can control which columns are visible
    XTableColumnModel tcm = new XTableColumnModel();
    _table.setColumnModel(tcm);
    _table.createDefaultColumnsFromModel();
    ButtonRenderer buttonRenderer = new ButtonRenderer();
    TableCellEditor buttonEditor = new ButtonEditor(new javax.swing.JButton());
    tcm.getColumn(UP_COLUMN).setCellRenderer(buttonRenderer);
    tcm.getColumn(UP_COLUMN).setCellEditor(buttonEditor);
    tcm.getColumn(DOWN_COLUMN).setCellRenderer(buttonRenderer);
    tcm.getColumn(DOWN_COLUMN).setCellEditor(buttonEditor);
    // set column preferred widths
    tcm.getColumn(ID_COLUMN).setPreferredWidth(40);
    tcm.getColumn(NAME_COLUMN).setPreferredWidth(200);
    tcm.getColumn(TYPE_COLUMN).setPreferredWidth(80);
    tcm.getColumn(ORDER_COLUMN).setPreferredWidth(60);
    tcm.getColumn(UP_COLUMN).setPreferredWidth(60);
    tcm.getColumn(DOWN_COLUMN).setPreferredWidth(70);
}
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 17 with XTableColumnModel

use of jmri.util.swing.XTableColumnModel in project JMRI by JMRI.

the class BeanTableDataModel method showTableHeaderPopup.

protected void showTableHeaderPopup(MouseEvent e, JTable table) {
    JPopupMenu popupMenu = new JPopupMenu();
    XTableColumnModel tcm = (XTableColumnModel) table.getColumnModel();
    for (int i = 0; i < tcm.getColumnCount(false); i++) {
        TableColumn tc = tcm.getColumnByModelIndex(i);
        String columnName = table.getModel().getColumnName(i);
        if (columnName != null && !columnName.equals("")) {
            JCheckBoxMenuItem menuItem = new JCheckBoxMenuItem(table.getModel().getColumnName(i), tcm.isColumnVisible(tc));
            menuItem.addActionListener(new headerActionListener(tc, tcm));
            popupMenu.add(menuItem);
        }
    }
    popupMenu.show(e.getComponent(), e.getX(), e.getY());
}
Also used : XTableColumnModel(jmri.util.swing.XTableColumnModel) TableColumn(javax.swing.table.TableColumn) JPopupMenu(javax.swing.JPopupMenu) JCheckBoxMenuItem(javax.swing.JCheckBoxMenuItem)

Example 18 with XTableColumnModel

use of jmri.util.swing.XTableColumnModel in project JMRI by JMRI.

the class WarrantTableFrame method initComponents.

/**
     * By default, Swing components should be created an installed in this
     * method, rather than in the ctor itself.
     */
@Override
public void initComponents() throws Exception {
    //Casts at getTableCellEditorComponent() now fails with 3.0 ??
    JTable table = new JTable(_model);
    ComboBoxCellEditor comboEd;
    TableRowSorter<WarrantTableModel> sorter = new TableRowSorter<>(_model);
    comboEd = new ComboBoxCellEditor(new JComboBox<>());
    table.setRowSorter(sorter);
    // Use XTableColumnModel so we can control which columns are visible
    XTableColumnModel tcm = new XTableColumnModel();
    table.setColumnModel(tcm);
    table.getTableHeader().setReorderingAllowed(true);
    table.createDefaultColumnsFromModel();
    _model.addHeaderListener(table);
    table.setDefaultRenderer(Boolean.class, new ButtonRenderer());
    table.setDefaultRenderer(JComboBox.class, new jmri.jmrit.symbolicprog.ValueRenderer());
    table.setDefaultEditor(JComboBox.class, new jmri.jmrit.symbolicprog.ValueEditor());
    JComboBox<String> box = new JComboBox<>(controls);
    box.setFont(new Font(null, Font.PLAIN, 12));
    table.getColumnModel().getColumn(WarrantTableModel.CONTROL_COLUMN).setCellEditor(new DefaultCellEditor(box));
    table.getColumnModel().getColumn(WarrantTableModel.ROUTE_COLUMN).setCellEditor(comboEd);
    table.getColumnModel().getColumn(WarrantTableModel.ALLOCATE_COLUMN).setCellEditor(new ButtonEditor(new JButton()));
    table.getColumnModel().getColumn(WarrantTableModel.ALLOCATE_COLUMN).setCellRenderer(new ButtonRenderer());
    table.getColumnModel().getColumn(WarrantTableModel.DEALLOC_COLUMN).setCellEditor(new ButtonEditor(new JButton()));
    table.getColumnModel().getColumn(WarrantTableModel.DEALLOC_COLUMN).setCellRenderer(new ButtonRenderer());
    table.getColumnModel().getColumn(WarrantTableModel.SET_COLUMN).setCellEditor(new ButtonEditor(new JButton()));
    table.getColumnModel().getColumn(WarrantTableModel.SET_COLUMN).setCellRenderer(new ButtonRenderer());
    table.getColumnModel().getColumn(WarrantTableModel.AUTO_RUN_COLUMN).setCellEditor(new ButtonEditor(new JButton()));
    table.getColumnModel().getColumn(WarrantTableModel.AUTO_RUN_COLUMN).setCellRenderer(new ButtonRenderer());
    table.getColumnModel().getColumn(WarrantTableModel.MANUAL_RUN_COLUMN).setCellEditor(new ButtonEditor(new JButton()));
    table.getColumnModel().getColumn(WarrantTableModel.MANUAL_RUN_COLUMN).setCellRenderer(new ButtonRenderer());
    table.getColumnModel().getColumn(WarrantTableModel.EDIT_COLUMN).setCellEditor(new ButtonEditor(new JButton()));
    table.getColumnModel().getColumn(WarrantTableModel.EDIT_COLUMN).setCellRenderer(new ButtonRenderer());
    table.getColumnModel().getColumn(WarrantTableModel.DELETE_COLUMN).setCellEditor(new ButtonEditor(new JButton()));
    table.getColumnModel().getColumn(WarrantTableModel.DELETE_COLUMN).setCellRenderer(new ButtonRenderer());
    //table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
    for (int i = 0; i < _model.getColumnCount(); i++) {
        int width = _model.getPreferredWidth(i);
        table.getColumnModel().getColumn(i).setPreferredWidth(width);
    }
    tcm.setColumnVisible(tcm.getColumnByModelIndex(WarrantTableModel.MANUAL_RUN_COLUMN), false);
    _rowHeight = box.getPreferredSize().height;
    table.setRowHeight(_rowHeight);
    table.setDragEnabled(true);
    table.setTransferHandler(new jmri.util.DnDTableExportHandler());
    _tablePane = new JScrollPane(table);
    JPanel tablePanel = new JPanel();
    tablePanel.setLayout(new BoxLayout(tablePanel, BoxLayout.Y_AXIS));
    tablePanel.add(Box.createVerticalGlue());
    JLabel title = new JLabel(Bundle.getMessage("ShowWarrants"));
    tablePanel.add(title);
    tablePanel.add(_tablePane);
    JPanel bottom = new JPanel();
    JPanel panel = new JPanel();
    JButton nxButton = new JButton(Bundle.getMessage("CreateNXWarrant"));
    nxButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            nxAction();
        }
    });
    panel.add(nxButton);
    panel.add(Box.createGlue());
    panel.add(new JLabel("status"));
    _status.addMouseListener(this);
    _status.setBackground(Color.white);
    _status.setFont(_status.getFont().deriveFont(Font.BOLD));
    _status.setEditable(false);
    setStatusText(BLANK.substring(0, 90), null, false);
    panel.add(_status);
    JButton haltAllButton = new JButton(Bundle.getMessage("HaltAllTrains"));
    haltAllButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            haltAllAction();
        }
    });
    haltAllButton.setForeground(Color.RED);
    panel.add(Box.createGlue());
    panel.add(haltAllButton);
    ///
    bottom.add(panel);
    tablePanel.add(bottom);
    addWindowListener(new java.awt.event.WindowAdapter() {

        @Override
        public void windowClosing(java.awt.event.WindowEvent e) {
            dispose();
        }
    });
    JMenuBar menuBar = new JMenuBar();
    JMenu fileMenu = new JMenu(Bundle.getMessage("MenuFile"));
    fileMenu.add(new jmri.configurexml.SaveMenu());
    menuBar.add(fileMenu);
    JMenu warrantMenu = new JMenu(Bundle.getMessage("MenuWarrant"));
    warrantMenu.add(new AbstractAction(Bundle.getMessage("ConcatWarrants")) {

        @Override
        public void actionPerformed(ActionEvent e) {
            concatMenuAction();
        }
    });
    warrantMenu.add(new jmri.jmrit.logix.WarrantTableAction("CreateWarrant"));
    warrantMenu.add(WarrantTableAction._trackerTable);
    warrantMenu.add(new AbstractAction(Bundle.getMessage("CreateNXWarrant")) {

        @Override
        public void actionPerformed(ActionEvent e) {
            nxAction();
        }
    });
    warrantMenu.add(WarrantTableAction.makeLogMenu());
    menuBar.add(warrantMenu);
    setJMenuBar(menuBar);
    addHelpMenu("package.jmri.jmrit.logix.WarrantTable", true);
    getContentPane().add(tablePanel);
    //        setLocation(50,0);
    pack();
}
Also used : JPanel(javax.swing.JPanel) ButtonEditor(jmri.util.table.ButtonEditor) ActionEvent(java.awt.event.ActionEvent) BoxLayout(javax.swing.BoxLayout) JButton(javax.swing.JButton) Font(java.awt.Font) AbstractAction(javax.swing.AbstractAction) TableRowSorter(javax.swing.table.TableRowSorter) JScrollPane(javax.swing.JScrollPane) JComboBox(javax.swing.JComboBox) JLabel(javax.swing.JLabel) XTableColumnModel(jmri.util.swing.XTableColumnModel) DefaultCellEditor(javax.swing.DefaultCellEditor) ActionListener(java.awt.event.ActionListener) JTable(javax.swing.JTable) ButtonRenderer(jmri.util.table.ButtonRenderer) JMenuBar(javax.swing.JMenuBar) JMenu(javax.swing.JMenu)

Example 19 with XTableColumnModel

use of jmri.util.swing.XTableColumnModel in project JMRI by JMRI.

the class TrackTableModel method initTable.

private void initTable() {
    // Use XTableColumnModel so we can control which columns are visible
    XTableColumnModel tcm = new XTableColumnModel();
    _table.setColumnModel(tcm);
    _table.createDefaultColumnsFromModel();
    // set column preferred widths
    tcm.getColumn(ID_COLUMN).setPreferredWidth(40);
    tcm.getColumn(NAME_COLUMN).setPreferredWidth(200);
    tcm.getColumn(LENGTH_COLUMN).setPreferredWidth(Math.max(50, new JLabel(getColumnName(LENGTH_COLUMN)).getPreferredSize().width + 10));
    tcm.getColumn(USED_LENGTH_COLUMN).setPreferredWidth(50);
    tcm.getColumn(RESERVED_COLUMN).setPreferredWidth(Math.max(65, new JLabel(getColumnName(RESERVED_COLUMN)).getPreferredSize().width + 10));
    tcm.getColumn(MOVES_COLUMN).setPreferredWidth(60);
    tcm.getColumn(LOCOS_COLUMN).setPreferredWidth(60);
    tcm.getColumn(CARS_COLUMN).setPreferredWidth(60);
    tcm.getColumn(PICKUPS_COLUMN).setPreferredWidth(Math.max(60, new JLabel(getColumnName(PICKUPS_COLUMN)).getPreferredSize().width + 10));
    tcm.getColumn(SETOUT_COLUMN).setPreferredWidth(Math.max(60, new JLabel(getColumnName(SETOUT_COLUMN)).getPreferredSize().width + 10));
    tcm.getColumn(RESTRICTION_COLUMN).setPreferredWidth(90);
    tcm.getColumn(LOAD_COLUMN).setPreferredWidth(50);
    tcm.getColumn(SHIP_COLUMN).setPreferredWidth(50);
    tcm.getColumn(ROAD_COLUMN).setPreferredWidth(50);
    tcm.getColumn(DESTINATION_COLUMN).setPreferredWidth(50);
    tcm.getColumn(POOL_COLUMN).setPreferredWidth(70);
    tcm.getColumn(PLANPICKUP_COLUMN).setPreferredWidth(70);
    tcm.getColumn(ALT_TRACK_COLUMN).setPreferredWidth(120);
    tcm.getColumn(EDIT_COLUMN).setPreferredWidth(80);
    tcm.getColumn(EDIT_COLUMN).setCellRenderer(new ButtonRenderer());
    tcm.getColumn(EDIT_COLUMN).setCellEditor(new ButtonEditor(new JButton()));
    setColumnsVisible();
}
Also used : ButtonEditor(jmri.util.table.ButtonEditor) JButton(javax.swing.JButton) JLabel(javax.swing.JLabel) XTableColumnModel(jmri.util.swing.XTableColumnModel) ButtonRenderer(jmri.util.table.ButtonRenderer)

Example 20 with XTableColumnModel

use of jmri.util.swing.XTableColumnModel in project JMRI by JMRI.

the class TrainsTableModel 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();
    TableCellEditor buttonEditor = new ButtonEditor(new javax.swing.JButton());
    tcm.getColumn(EDITCOLUMN).setCellRenderer(buttonRenderer);
    tcm.getColumn(EDITCOLUMN).setCellEditor(buttonEditor);
    tcm.getColumn(ACTIONCOLUMN).setCellRenderer(buttonRenderer);
    tcm.getColumn(ACTIONCOLUMN).setCellEditor(buttonEditor);
    tcm.getColumn(BUILDCOLUMN).setCellRenderer(buttonRenderer);
    tcm.getColumn(BUILDCOLUMN).setCellEditor(buttonEditor);
    _table.setDefaultRenderer(Boolean.class, new EnablingCheckboxRenderer());
    // set column preferred widths
    for (int i = 0; i < tcm.getColumnCount(); i++) {
        tcm.getColumn(i).setPreferredWidth(_tableColumnWidths[i]);
    }
    _frame.loadTableDetails(_table);
    // turn off column
    tcm.setColumnVisible(tcm.getColumnByModelIndex(IDCOLUMN), _sort == SORTBYID);
}
Also used : ButtonEditor(jmri.util.table.ButtonEditor) JButton(javax.swing.JButton) EnablingCheckboxRenderer(jmri.jmrit.beantable.EnablingCheckboxRenderer) TableCellEditor(javax.swing.table.TableCellEditor) XTableColumnModel(jmri.util.swing.XTableColumnModel) ButtonRenderer(jmri.util.table.ButtonRenderer)

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