Search in sources :

Example 11 with TableRowSorter

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");
}
Also used : JScrollPane(javax.swing.JScrollPane) RowSorter(javax.swing.RowSorter) TableRowSorter(javax.swing.table.TableRowSorter) ArrayList(java.util.ArrayList) ValueEditor(jmri.jmrit.symbolicprog.ValueEditor) JButton(javax.swing.JButton) ValueRenderer(jmri.jmrit.symbolicprog.ValueRenderer) JTable(javax.swing.JTable) TableRowSorter(javax.swing.table.TableRowSorter) VariableTableModel(jmri.jmrit.symbolicprog.VariableTableModel) TableModel(javax.swing.table.TableModel) CvTableModel(jmri.jmrit.symbolicprog.CvTableModel) IndexedCvTableModel(jmri.jmrit.symbolicprog.IndexedCvTableModel)

Example 12 with TableRowSorter

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);
}
Also used : ActionListener(java.awt.event.ActionListener) ActionEvent(java.awt.event.ActionEvent) JTable(javax.swing.JTable) JButton(javax.swing.JButton) TableRowSorter(javax.swing.table.TableRowSorter)

Example 13 with TableRowSorter

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);
}
Also used : JTable(javax.swing.JTable) TableRowSorter(javax.swing.table.TableRowSorter)

Example 14 with TableRowSorter

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;
}
Also used : JPanel(javax.swing.JPanel) ButtonEditor(jmri.util.table.ButtonEditor) JButton(javax.swing.JButton) SignalSpeedMap(jmri.implementation.SignalSpeedMap) BorderLayout(java.awt.BorderLayout) TableRowSorter(javax.swing.table.TableRowSorter) JScrollPane(javax.swing.JScrollPane) MouseEvent(java.awt.event.MouseEvent) JComboBox(javax.swing.JComboBox) MouseAdapter(java.awt.event.MouseAdapter) JLabel(javax.swing.JLabel) XTableColumnModel(jmri.util.swing.XTableColumnModel) Point(java.awt.Point) DefaultCellEditor(javax.swing.DefaultCellEditor) Dimension(java.awt.Dimension) JTable(javax.swing.JTable) JInternalFrame(javax.swing.JInternalFrame) ButtonRenderer(jmri.util.table.ButtonRenderer)

Example 15 with TableRowSorter

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;
}
Also used : JScrollPane(javax.swing.JScrollPane) JPanel(javax.swing.JPanel) ButtonEditor(jmri.util.table.ButtonEditor) JButton(javax.swing.JButton) JLabel(javax.swing.JLabel) Point(java.awt.Point) Dimension(java.awt.Dimension) BorderLayout(java.awt.BorderLayout) JTable(javax.swing.JTable) JInternalFrame(javax.swing.JInternalFrame) TableRowSorter(javax.swing.table.TableRowSorter) ButtonRenderer(jmri.util.table.ButtonRenderer)

Aggregations

TableRowSorter (javax.swing.table.TableRowSorter)32 JTable (javax.swing.JTable)23 JScrollPane (javax.swing.JScrollPane)22 JPanel (javax.swing.JPanel)17 JLabel (javax.swing.JLabel)15 BoxLayout (javax.swing.BoxLayout)13 JButton (javax.swing.JButton)13 TableColumnModel (javax.swing.table.TableColumnModel)10 Dimension (java.awt.Dimension)9 ActionEvent (java.awt.event.ActionEvent)9 SystemNameComparator (jmri.util.SystemNameComparator)9 ActionListener (java.awt.event.ActionListener)8 TableColumn (javax.swing.table.TableColumn)8 TableModel (javax.swing.table.TableModel)7 ButtonEditor (jmri.util.table.ButtonEditor)6 ButtonRenderer (jmri.util.table.ButtonRenderer)6 BorderLayout (java.awt.BorderLayout)5 FlowLayout (java.awt.FlowLayout)5 Point (java.awt.Point)5 JComboBox (javax.swing.JComboBox)5