Search in sources :

Example 1 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 2 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 3 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)

Example 4 with ButtonEditor

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

the class LogixTableAction method makeEditLogixWindow.

/**
     * Create and/or initialize the Edit Logix pane.
     */
void makeEditLogixWindow() {
    // Setup the name box components.
    setNameBoxListeners();
    //if (log.isDebugEnabled()) log.debug("makeEditLogixWindow ");
    editUserName.setText(_curLogix.getUserName());
    // clear conditional table if needed
    if (conditionalTableModel != null) {
        conditionalTableModel.fireTableStructureChanged();
    }
    inEditMode = true;
    if (editLogixFrame == null) {
        editLogixFrame = new JmriJFrame(rbx.getString("TitleEditLogix"), false, false);
        editLogixFrame.addHelpMenu("package.jmri.jmrit.beantable.LogixAddEdit", true);
        editLogixFrame.setLocation(100, 30);
        Container contentPane = editLogixFrame.getContentPane();
        contentPane.setLayout(new BoxLayout(contentPane, BoxLayout.Y_AXIS));
        JPanel panel1 = new JPanel();
        panel1.setLayout(new FlowLayout());
        JLabel systemNameLabel = new JLabel(Bundle.getMessage("ColumnSystemName") + ":");
        panel1.add(systemNameLabel);
        JLabel fixedSystemName = new JLabel(_curLogix.getSystemName());
        panel1.add(fixedSystemName);
        contentPane.add(panel1);
        JPanel panel2 = new JPanel();
        panel2.setLayout(new FlowLayout());
        JLabel userNameLabel = new JLabel(Bundle.getMessage("ColumnUserName") + ":");
        panel2.add(userNameLabel);
        panel2.add(editUserName);
        editUserName.setToolTipText(rbx.getString("LogixUserNameHint2"));
        contentPane.add(panel2);
        // add table of Conditionals
        JPanel pctSpace = new JPanel();
        pctSpace.setLayout(new FlowLayout());
        pctSpace.add(new JLabel("   "));
        contentPane.add(pctSpace);
        JPanel pTitle = new JPanel();
        pTitle.setLayout(new FlowLayout());
        pTitle.add(new JLabel(rbx.getString("ConditionalTableTitle")));
        contentPane.add(pTitle);
        // initialize table of conditionals
        conditionalTableModel = new ConditionalTableModel();
        JTable conditionalTable = new JTable(conditionalTableModel);
        conditionalTable.setRowSelectionAllowed(false);
        TableColumnModel conditionalColumnModel = conditionalTable.getColumnModel();
        TableColumn sNameColumn = conditionalColumnModel.getColumn(ConditionalTableModel.SNAME_COLUMN);
        sNameColumn.setResizable(true);
        sNameColumn.setMinWidth(100);
        sNameColumn.setPreferredWidth(130);
        TableColumn uNameColumn = conditionalColumnModel.getColumn(ConditionalTableModel.UNAME_COLUMN);
        uNameColumn.setResizable(true);
        uNameColumn.setMinWidth(210);
        uNameColumn.setPreferredWidth(260);
        TableColumn stateColumn = conditionalColumnModel.getColumn(ConditionalTableModel.STATE_COLUMN);
        stateColumn.setResizable(true);
        stateColumn.setMinWidth(50);
        stateColumn.setMaxWidth(100);
        TableColumn buttonColumn = conditionalColumnModel.getColumn(ConditionalTableModel.BUTTON_COLUMN);
        // install button renderer and editor
        ButtonRenderer buttonRenderer = new ButtonRenderer();
        conditionalTable.setDefaultRenderer(JButton.class, buttonRenderer);
        TableCellEditor buttonEditor = new ButtonEditor(new JButton());
        conditionalTable.setDefaultEditor(JButton.class, buttonEditor);
        JButton testButton = new JButton("XXXXXX");
        conditionalTable.setRowHeight(testButton.getPreferredSize().height);
        buttonColumn.setMinWidth(testButton.getPreferredSize().width);
        buttonColumn.setMaxWidth(testButton.getPreferredSize().width);
        buttonColumn.setResizable(false);
        JScrollPane conditionalTableScrollPane = new JScrollPane(conditionalTable);
        Dimension dim = conditionalTable.getPreferredSize();
        dim.height = 450;
        conditionalTableScrollPane.getViewport().setPreferredSize(dim);
        contentPane.add(conditionalTableScrollPane);
        // add message area between table and buttons
        JPanel panel4 = new JPanel();
        panel4.setLayout(new BoxLayout(panel4, BoxLayout.Y_AXIS));
        JPanel panel41 = new JPanel();
        panel41.setLayout(new FlowLayout());
        panel41.add(status);
        panel4.add(panel41);
        JPanel panel42 = new JPanel();
        panel42.setLayout(new FlowLayout());
        // Conditional panel buttons - New Conditional
        JButton newConditionalButton = new JButton(rbx.getString("NewConditionalButton"));
        panel42.add(newConditionalButton);
        newConditionalButton.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                newConditionalPressed(e);
            }
        });
        newConditionalButton.setToolTipText(rbx.getString("NewConditionalButtonHint"));
        // Conditional panel buttons - Reorder
        JButton reorderButton = new JButton(rbx.getString("ReorderButton"));
        panel42.add(reorderButton);
        reorderButton.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                reorderPressed(e);
            }
        });
        reorderButton.setToolTipText(rbx.getString("ReorderButtonHint"));
        // Conditional panel buttons - Calculate
        JButton calculateButton = new JButton(rbx.getString("CalculateButton"));
        panel42.add(calculateButton);
        calculateButton.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                calculatePressed(e);
            }
        });
        calculateButton.setToolTipText(rbx.getString("CalculateButtonHint"));
        panel4.add(panel42);
        Border panel4Border = BorderFactory.createEtchedBorder();
        panel4.setBorder(panel4Border);
        contentPane.add(panel4);
        // add buttons at bottom of window
        JPanel panel5 = new JPanel();
        panel5.setLayout(new FlowLayout());
        // Bottom Buttons - Done Logix
        JButton done = new JButton(Bundle.getMessage("ButtonDone"));
        panel5.add(done);
        done.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                donePressed(e);
            }
        });
        done.setToolTipText(rbx.getString("DoneButtonHint"));
        // Delete Logix
        JButton delete = new JButton(Bundle.getMessage("ButtonDelete"));
        panel5.add(delete);
        delete.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                deletePressed(e);
            }
        });
        delete.setToolTipText(rbx.getString("DeleteLogixButtonHint"));
        contentPane.add(panel5);
    }
    editLogixFrame.addWindowListener(new java.awt.event.WindowAdapter() {

        @Override
        public void windowClosing(java.awt.event.WindowEvent e) {
            if (inEditMode) {
                donePressed(null);
            } else {
                finishDone();
            }
        }
    });
    editLogixFrame.pack();
    editLogixFrame.setVisible(true);
}
Also used : JScrollPane(javax.swing.JScrollPane) JPanel(javax.swing.JPanel) FlowLayout(java.awt.FlowLayout) ButtonEditor(jmri.util.table.ButtonEditor) ActionEvent(java.awt.event.ActionEvent) BoxLayout(javax.swing.BoxLayout) JButton(javax.swing.JButton) JLabel(javax.swing.JLabel) TableColumnModel(javax.swing.table.TableColumnModel) Dimension(java.awt.Dimension) TableColumn(javax.swing.table.TableColumn) Container(java.awt.Container) ActionListener(java.awt.event.ActionListener) JmriJFrame(jmri.util.JmriJFrame) JTable(javax.swing.JTable) TableCellEditor(javax.swing.table.TableCellEditor) Border(javax.swing.border.Border) ButtonRenderer(jmri.util.table.ButtonRenderer)

Example 5 with ButtonEditor

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

the class SignalGroupTableAction method setColumnToHoldButton.

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)

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