Search in sources :

Example 36 with ButtonRenderer

use of jmri.util.table.ButtonRenderer 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();
}
Also used : JScrollPane(javax.swing.JScrollPane) JPanel(javax.swing.JPanel) ButtonEditor(jmri.util.table.ButtonEditor) ActionEvent(java.awt.event.ActionEvent) BoxLayout(javax.swing.BoxLayout) JButton(javax.swing.JButton) JLabel(javax.swing.JLabel) Dimension(java.awt.Dimension) Dimension(java.awt.Dimension) ActionListener(java.awt.event.ActionListener) JTable(javax.swing.JTable) TableCellEditor(javax.swing.table.TableCellEditor) ButtonRenderer(jmri.util.table.ButtonRenderer) TableRowSorter(javax.swing.table.TableRowSorter)

Example 37 with ButtonRenderer

use of jmri.util.table.ButtonRenderer in project JMRI by JMRI.

the class StackMonDataModel method initTable.

void initTable(JTable stackTable, StackMonFrame stackFrame) {
    // Install the button handlers for the Delete Buttons
    TableColumnModel tcm = stackTable.getColumnModel();
    ButtonRenderer buttonRenderer = new ButtonRenderer();
    tcm.getColumn(DELCOLUMN).setCellRenderer(buttonRenderer);
    TableCellEditor buttonEditor = new ButtonEditor(new javax.swing.JButton());
    tcm.getColumn(DELCOLUMN).setCellEditor(buttonEditor);
    _stackFrame = stackFrame;
}
Also used : ButtonEditor(jmri.util.table.ButtonEditor) TableColumnModel(javax.swing.table.TableColumnModel) TableCellEditor(javax.swing.table.TableCellEditor) ButtonRenderer(jmri.util.table.ButtonRenderer)

Example 38 with ButtonRenderer

use of jmri.util.table.ButtonRenderer in project JMRI by JMRI.

the class SlotMonDataModel method setColumnToHoldButton.

void setColumnToHoldButton(JTable slotTable, int column) {
    TableColumnModel tcm = slotTable.getColumnModel();
    // install the button renderers & editors in this column
    ButtonRenderer buttonRenderer = new ButtonRenderer();
    tcm.getColumn(column).setCellRenderer(buttonRenderer);
    TableCellEditor buttonEditor = new ButtonEditor(new JButton());
    tcm.getColumn(column).setCellEditor(buttonEditor);
    // ensure the table rows, columns have enough room for buttons
    slotTable.setRowHeight(new JButton("  " + getValueAt(1, column)).getPreferredSize().height);
    slotTable.getColumnModel().getColumn(column).setPreferredWidth(new JButton("  " + getValueAt(1, column)).getPreferredSize().width);
}
Also used : ButtonEditor(jmri.util.table.ButtonEditor) JButton(javax.swing.JButton) TableColumnModel(javax.swing.table.TableColumnModel) TableCellEditor(javax.swing.table.TableCellEditor) ButtonRenderer(jmri.util.table.ButtonRenderer)

Example 39 with ButtonRenderer

use of jmri.util.table.ButtonRenderer 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());
            }
        }
    });
}
Also used : JPanel(javax.swing.JPanel) ButtonEditor(jmri.util.table.ButtonEditor) FlowLayout(java.awt.FlowLayout) PropertyChangeListener(java.beans.PropertyChangeListener) ActionEvent(java.awt.event.ActionEvent) BoxLayout(javax.swing.BoxLayout) JButton(javax.swing.JButton) TableCellEditor(javax.swing.table.TableCellEditor) TableRowSorter(javax.swing.table.TableRowSorter) JScrollPane(javax.swing.JScrollPane) JLabel(javax.swing.JLabel) Dimension(java.awt.Dimension) Dimension(java.awt.Dimension) ActionListener(java.awt.event.ActionListener) JTable(javax.swing.JTable) ButtonRenderer(jmri.util.table.ButtonRenderer)

Example 40 with ButtonRenderer

use of jmri.util.table.ButtonRenderer in project JMRI by JMRI.

the class AddEntryExitPairPanel method setColumnToHoldButton.

/**
     * Service method to set up a column so that it will hold a button for it's
     * values.
     *
     * @param table  the table
     * @param column the column
     * @param sample Typical button, used for size
     */
protected void setColumnToHoldButton(JTable table, int column, JButton sample) {
    //TableColumnModel tcm = table.getColumnModel();
    // install a button renderer & editor
    ButtonRenderer buttonRenderer = new ButtonRenderer();
    table.setDefaultRenderer(JButton.class, buttonRenderer);
    TableCellEditor buttonEditor = new ButtonEditor(new JButton());
    table.setDefaultEditor(JButton.class, buttonEditor);
    // ensure the table rows, columns have enough room for buttons
    table.setRowHeight(sample.getPreferredSize().height);
    table.getColumnModel().getColumn(column).setPreferredWidth((sample.getPreferredSize().width) + 4);
}
Also used : ButtonEditor(jmri.util.table.ButtonEditor) JButton(javax.swing.JButton) TableCellEditor(javax.swing.table.TableCellEditor) ButtonRenderer(jmri.util.table.ButtonRenderer)

Aggregations

ButtonEditor (jmri.util.table.ButtonEditor)41 ButtonRenderer (jmri.util.table.ButtonRenderer)41 JButton (javax.swing.JButton)40 TableCellEditor (javax.swing.table.TableCellEditor)33 TableColumnModel (javax.swing.table.TableColumnModel)23 JLabel (javax.swing.JLabel)17 JPanel (javax.swing.JPanel)15 JScrollPane (javax.swing.JScrollPane)15 JTable (javax.swing.JTable)15 ActionEvent (java.awt.event.ActionEvent)10 BoxLayout (javax.swing.BoxLayout)10 Dimension (java.awt.Dimension)9 ActionListener (java.awt.event.ActionListener)9 FlowLayout (java.awt.FlowLayout)7 XTableColumnModel (jmri.util.swing.XTableColumnModel)7 TableColumn (javax.swing.table.TableColumn)6 TableRowSorter (javax.swing.table.TableRowSorter)6 BorderLayout (java.awt.BorderLayout)5 Point (java.awt.Point)5 DefaultCellEditor (javax.swing.DefaultCellEditor)5