Search in sources :

Example 16 with ButtonEditor

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

the class SlotMonDataModel method setColumnToHoldEStopButton.

void setColumnToHoldEStopButton(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()) {

        @Override
        public void mousePressed(MouseEvent e) {
            stopCellEditing();
        }
    };
    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) MouseEvent(java.awt.event.MouseEvent) JButton(javax.swing.JButton) TableColumnModel(javax.swing.table.TableColumnModel) TableCellEditor(javax.swing.table.TableCellEditor) ButtonRenderer(jmri.util.table.ButtonRenderer)

Example 17 with ButtonEditor

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

the class PacketDataModel 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 18 with ButtonEditor

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

the class SignalGroupSubTableAction method setColumnToHoldButton.

/**
     * Configure colum widths for the Turnout and Sensor Conditional tables.
     *
     * @param table JTable to put button in
     * @param column index of column in table
     * @param sample sample button to use as spacer
     */
void setColumnToHoldButton(JTable table, int column, JButton sample) {
    // 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)

Example 19 with ButtonEditor

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

the class TableFrames method makeBlockPathFrame.

/*
     * ********************* BlockPathFrame *****************************
     */
protected BlockPathFrame makeBlockPathFrame(OBlock block) {
    String title = Bundle.getMessage("TitleBlockPathTable", block.getDisplayName());
    BlockPathFrame frame = new BlockPathFrame(title, true, true, false, true);
    if (log.isDebugEnabled()) {
        log.debug("makeBlockPathFrame for Block " + block.getDisplayName());
    }
    frame.setName(block.getSystemName());
    frame.init(block, this);
    BlockPathTableModel blockPathModel = frame.getModel();
    blockPathModel.init();
    JTable blockPathTable = new JTable(blockPathModel);
    blockPathTable.setTransferHandler(new jmri.util.DnDTableImportExportHandler(new int[] { BlockPathTableModel.EDIT_COL, BlockPathTableModel.DELETE_COL, BlockPathTableModel.UNITSCOL }));
    blockPathTable.setDragEnabled(true);
    blockPathTable.getColumnModel().getColumn(BlockPathTableModel.UNITSCOL).setCellRenderer(new MyBooleanRenderer(Bundle.getMessage("cm"), Bundle.getMessage("in")));
    blockPathTable.getColumnModel().getColumn(BlockPathTableModel.EDIT_COL).setCellEditor(new ButtonEditor(new JButton()));
    blockPathTable.getColumnModel().getColumn(BlockPathTableModel.EDIT_COL).setCellRenderer(new ButtonRenderer());
    blockPathTable.getColumnModel().getColumn(BlockPathTableModel.DELETE_COL).setCellEditor(new ButtonEditor(new JButton()));
    blockPathTable.getColumnModel().getColumn(BlockPathTableModel.DELETE_COL).setCellRenderer(new ButtonRenderer());
    for (int i = 0; i < blockPathModel.getColumnCount(); i++) {
        int width = blockPathModel.getPreferredWidth(i);
        blockPathTable.getColumnModel().getColumn(i).setPreferredWidth(width);
    }
    blockPathTable.sizeColumnsToFit(-1);
    int tableWidth = blockPathTable.getPreferredSize().width;
    blockPathTable.setPreferredScrollableViewportSize(new java.awt.Dimension(tableWidth, ROW_HEIGHT * 10));
    JScrollPane tablePane = new JScrollPane(blockPathTable);
    JPanel contentPane = new JPanel();
    contentPane.setLayout(new BorderLayout(5, 5));
    JLabel prompt = new JLabel(Bundle.getMessage("AddPathPrompt"));
    contentPane.add(prompt, BorderLayout.NORTH);
    contentPane.add(tablePane, BorderLayout.CENTER);
    frame.addInternalFrameListener(this);
    frame.setContentPane(contentPane);
    frame.setLocation(50, 30);
    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) ButtonRenderer(jmri.util.table.ButtonRenderer)

Example 20 with ButtonEditor

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

the class TableFrames method makeSignalFrame.

/*
     * ********************* SignalFrame *****************************
     */
protected JInternalFrame makeSignalFrame() {
    JInternalFrame frame = new JInternalFrame(Bundle.getMessage("TitleSignalTable"), true, false, false, true);
    _signalModel = new SignalTableModel(this);
    _signalModel.init();
    _signalTable = new JTable(_signalModel);
    TableRowSorter<SignalTableModel> sorter = new TableRowSorter<>(_signalModel);
    _signalTable.setRowSorter(sorter);
    _signalTable.setTransferHandler(new jmri.util.DnDTableImportExportHandler(new int[] { SignalTableModel.UNITSCOL, SignalTableModel.DELETE_COL }));
    _signalTable.setDragEnabled(true);
    _signalTable.getColumnModel().getColumn(SignalTableModel.UNITSCOL).setCellRenderer(new MyBooleanRenderer(Bundle.getMessage("cm"), Bundle.getMessage("in")));
    _signalTable.getColumnModel().getColumn(SignalTableModel.DELETE_COL).setCellEditor(new ButtonEditor(new JButton()));
    _signalTable.getColumnModel().getColumn(SignalTableModel.DELETE_COL).setCellRenderer(new ButtonRenderer());
    for (int i = 0; i < _signalModel.getColumnCount(); i++) {
        int width = SignalTableModel.getPreferredWidth(i);
        _signalTable.getColumnModel().getColumn(i).setPreferredWidth(width);
    }
    _signalTable.sizeColumnsToFit(-1);
    int tableWidth = _signalTable.getPreferredSize().width;
    _signalTable.setPreferredScrollableViewportSize(new java.awt.Dimension(tableWidth, ROW_HEIGHT * 8));
    _signalTablePane = new JScrollPane(_signalTable);
    JPanel contentPane = new JPanel();
    contentPane.setLayout(new BorderLayout(5, 5));
    JLabel prompt = new JLabel(Bundle.getMessage("AddSignalPrompt"));
    contentPane.add(prompt, BorderLayout.NORTH);
    contentPane.add(_signalTablePane, BorderLayout.CENTER);
    frame.setContentPane(contentPane);
    frame.setLocation(200, 350);
    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

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