Search in sources :

Example 1 with ButtonRenderer

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

the class LocoDataModel 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 2 with ButtonRenderer

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

the class LocoDataModel 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 3 with ButtonRenderer

use of jmri.util.table.ButtonRenderer 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 4 with ButtonRenderer

use of jmri.util.table.ButtonRenderer 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)

Example 5 with ButtonRenderer

use of jmri.util.table.ButtonRenderer 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)

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