Search in sources :

Example 6 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)

Example 7 with ButtonRenderer

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

Example 8 with ButtonRenderer

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

the class DispatcherFrame method openDispatcherWindow.

void openDispatcherWindow() {
    if (dispatcherFrame == null) {
        dispatcherFrame = this;
        dispatcherFrame.setTitle(Bundle.getMessage("TitleDispatcher"));
        JMenuBar menuBar = new JMenuBar();
        optionsMenu = new OptionsMenu(this);
        menuBar.add(optionsMenu);
        setJMenuBar(menuBar);
        dispatcherFrame.addHelpMenu("package.jmri.jmrit.dispatcher.Dispatcher", true);
        contentPane = dispatcherFrame.getContentPane();
        contentPane.setLayout(new BoxLayout(contentPane, BoxLayout.Y_AXIS));
        // set up active trains table
        JPanel p11 = new JPanel();
        p11.setLayout(new FlowLayout());
        p11.add(new JLabel(Bundle.getMessage("ActiveTrainTableTitle")));
        contentPane.add(p11);
        JPanel p12 = new JPanel();
        p12.setLayout(new FlowLayout());
        activeTrainsTableModel = new ActiveTrainsTableModel();
        JTable activeTrainsTable = new JTable(activeTrainsTableModel);
        activeTrainsTable.setRowSelectionAllowed(false);
        activeTrainsTable.setPreferredScrollableViewportSize(new java.awt.Dimension(950, 160));
        TableColumnModel activeTrainsColumnModel = activeTrainsTable.getColumnModel();
        TableColumn transitColumn = activeTrainsColumnModel.getColumn(ActiveTrainsTableModel.TRANSIT_COLUMN);
        transitColumn.setResizable(true);
        transitColumn.setMinWidth(140);
        transitColumn.setMaxWidth(220);
        TableColumn trainColumn = activeTrainsColumnModel.getColumn(ActiveTrainsTableModel.TRAIN_COLUMN);
        trainColumn.setResizable(true);
        trainColumn.setMinWidth(90);
        trainColumn.setMaxWidth(160);
        TableColumn typeColumn = activeTrainsColumnModel.getColumn(ActiveTrainsTableModel.TYPE_COLUMN);
        typeColumn.setResizable(true);
        typeColumn.setMinWidth(130);
        typeColumn.setMaxWidth(190);
        TableColumn statusColumn = activeTrainsColumnModel.getColumn(ActiveTrainsTableModel.STATUS_COLUMN);
        statusColumn.setResizable(true);
        statusColumn.setMinWidth(90);
        statusColumn.setMaxWidth(140);
        TableColumn modeColumn = activeTrainsColumnModel.getColumn(ActiveTrainsTableModel.MODE_COLUMN);
        modeColumn.setResizable(true);
        modeColumn.setMinWidth(90);
        modeColumn.setMaxWidth(140);
        TableColumn allocatedColumn = activeTrainsColumnModel.getColumn(ActiveTrainsTableModel.ALLOCATED_COLUMN);
        allocatedColumn.setResizable(true);
        allocatedColumn.setMinWidth(120);
        allocatedColumn.setMaxWidth(200);
        TableColumn nextSectionColumn = activeTrainsColumnModel.getColumn(ActiveTrainsTableModel.NEXTSECTION_COLUMN);
        nextSectionColumn.setResizable(true);
        nextSectionColumn.setMinWidth(120);
        nextSectionColumn.setMaxWidth(200);
        TableColumn allocateButtonColumn = activeTrainsColumnModel.getColumn(ActiveTrainsTableModel.ALLOCATEBUTTON_COLUMN);
        allocateButtonColumn.setCellEditor(new ButtonEditor(new JButton()));
        allocateButtonColumn.setMinWidth(110);
        allocateButtonColumn.setMaxWidth(190);
        allocateButtonColumn.setResizable(false);
        ButtonRenderer buttonRenderer = new ButtonRenderer();
        activeTrainsTable.setDefaultRenderer(JButton.class, buttonRenderer);
        JButton sampleButton = new JButton(Bundle.getMessage("AllocateButtonName"));
        activeTrainsTable.setRowHeight(sampleButton.getPreferredSize().height);
        allocateButtonColumn.setPreferredWidth((sampleButton.getPreferredSize().width) + 2);
        JScrollPane activeTrainsTableScrollPane = new JScrollPane(activeTrainsTable);
        p12.add(activeTrainsTableScrollPane, BorderLayout.CENTER);
        contentPane.add(p12);
        JPanel p13 = new JPanel();
        p13.setLayout(new FlowLayout());
        p13.add(addTrainButton = new JButton(Bundle.getMessage("InitiateTrain") + "..."));
        addTrainButton.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                if (!newTrainActive) {
                    atFrame.initiateTrain(e);
                    newTrainActive = true;
                } else {
                    atFrame.showActivateFrame();
                }
            }
        });
        addTrainButton.setToolTipText(Bundle.getMessage("InitiateTrainButtonHint"));
        p13.add(new JLabel("   "));
        p13.add(new JLabel("   "));
        p13.add(allocateExtraButton = new JButton(Bundle.getMessage("AllocateExtra") + "..."));
        allocateExtraButton.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                allocateExtraSection(e);
            }
        });
        allocateExtraButton.setToolTipText(Bundle.getMessage("AllocateExtraButtonHint"));
        p13.add(new JLabel("   "));
        p13.add(cancelRestartButton = new JButton(Bundle.getMessage("CancelRestart") + "..."));
        cancelRestartButton.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                if (!newTrainActive) {
                    cancelRestart(e);
                } else if (restartingTrainsList.size() > 0) {
                    atFrame.showActivateFrame();
                    JOptionPane.showMessageDialog(dispatcherFrame, Bundle.getMessage("Message2"), Bundle.getMessage("MessageTitle"), JOptionPane.INFORMATION_MESSAGE);
                } else {
                    atFrame.showActivateFrame();
                }
            }
        });
        cancelRestartButton.setToolTipText(Bundle.getMessage("CancelRestartButtonHint"));
        p13.add(new JLabel("   "));
        p13.add(terminateTrainButton = new JButton(Bundle.getMessage("TerminateTrain") + "..."));
        terminateTrainButton.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                if (!newTrainActive) {
                    terminateTrain(e);
                } else if (activeTrainsList.size() > 0) {
                    atFrame.showActivateFrame();
                    JOptionPane.showMessageDialog(dispatcherFrame, Bundle.getMessage("Message1"), Bundle.getMessage("MessageTitle"), JOptionPane.INFORMATION_MESSAGE);
                } else {
                    atFrame.showActivateFrame();
                }
            }
        });
        terminateTrainButton.setToolTipText(Bundle.getMessage("TerminateTrainButtonHint"));
        contentPane.add(p13);
        // set up pending allocations table
        contentPane.add(new JSeparator());
        JPanel p21 = new JPanel();
        p21.setLayout(new FlowLayout());
        p21.add(new JLabel(Bundle.getMessage("RequestedAllocationsTableTitle")));
        contentPane.add(p21);
        JPanel p22 = new JPanel();
        p22.setLayout(new FlowLayout());
        allocationRequestTableModel = new AllocationRequestTableModel();
        JTable allocationRequestTable = new JTable(allocationRequestTableModel);
        allocationRequestTable.setRowSelectionAllowed(false);
        allocationRequestTable.setPreferredScrollableViewportSize(new java.awt.Dimension(950, 100));
        TableColumnModel allocationRequestColumnModel = allocationRequestTable.getColumnModel();
        TableColumn activeColumn = allocationRequestColumnModel.getColumn(AllocationRequestTableModel.ACTIVE_COLUMN);
        activeColumn.setResizable(true);
        activeColumn.setMinWidth(210);
        activeColumn.setMaxWidth(260);
        TableColumn priorityColumn = allocationRequestColumnModel.getColumn(AllocationRequestTableModel.PRIORITY_COLUMN);
        priorityColumn.setResizable(true);
        priorityColumn.setMinWidth(40);
        priorityColumn.setMaxWidth(60);
        TableColumn trainTypColumn = allocationRequestColumnModel.getColumn(AllocationRequestTableModel.TRAINTYPE_COLUMN);
        trainTypColumn.setResizable(true);
        trainTypColumn.setMinWidth(130);
        trainTypColumn.setMaxWidth(190);
        TableColumn sectionColumn = allocationRequestColumnModel.getColumn(AllocationRequestTableModel.SECTION_COLUMN);
        sectionColumn.setResizable(true);
        sectionColumn.setMinWidth(140);
        sectionColumn.setMaxWidth(210);
        TableColumn secStatusColumn = allocationRequestColumnModel.getColumn(AllocationRequestTableModel.STATUS_COLUMN);
        secStatusColumn.setResizable(true);
        secStatusColumn.setMinWidth(90);
        secStatusColumn.setMaxWidth(150);
        TableColumn occupancyColumn = allocationRequestColumnModel.getColumn(AllocationRequestTableModel.OCCUPANCY_COLUMN);
        occupancyColumn.setResizable(true);
        occupancyColumn.setMinWidth(80);
        occupancyColumn.setMaxWidth(130);
        TableColumn secLengthColumn = allocationRequestColumnModel.getColumn(AllocationRequestTableModel.SECTIONLENGTH_COLUMN);
        secLengthColumn.setResizable(true);
        secLengthColumn.setMinWidth(40);
        secLengthColumn.setMaxWidth(60);
        TableColumn allocateColumn = allocationRequestColumnModel.getColumn(AllocationRequestTableModel.ALLOCATEBUTTON_COLUMN);
        allocateColumn.setCellEditor(new ButtonEditor(new JButton()));
        allocateColumn.setMinWidth(90);
        allocateColumn.setMaxWidth(170);
        allocateColumn.setResizable(false);
        allocationRequestTable.setDefaultRenderer(JButton.class, buttonRenderer);
        sampleButton = new JButton(Bundle.getMessage("AllocateButton"));
        allocationRequestTable.setRowHeight(sampleButton.getPreferredSize().height);
        allocateColumn.setPreferredWidth((sampleButton.getPreferredSize().width) + 2);
        TableColumn cancelButtonColumn = allocationRequestColumnModel.getColumn(AllocationRequestTableModel.CANCELBUTTON_COLUMN);
        cancelButtonColumn.setCellEditor(new ButtonEditor(new JButton()));
        cancelButtonColumn.setMinWidth(75);
        cancelButtonColumn.setMaxWidth(170);
        cancelButtonColumn.setResizable(false);
        cancelButtonColumn.setPreferredWidth((sampleButton.getPreferredSize().width) + 2);
        JScrollPane allocationRequestTableScrollPane = new JScrollPane(allocationRequestTable);
        p22.add(allocationRequestTableScrollPane, BorderLayout.CENTER);
        contentPane.add(p22);
        // set up allocated sections table
        contentPane.add(new JSeparator());
        JPanel p30 = new JPanel();
        p30.setLayout(new FlowLayout());
        p30.add(new JLabel(Bundle.getMessage("AllocatedSectionsTitle") + "    "));
        autoReleaseBox = new JCheckBox(Bundle.getMessage("AutoReleaseBoxLabel"));
        p30.add(autoReleaseBox);
        autoReleaseBox.setToolTipText(Bundle.getMessage("AutoReleaseBoxHint"));
        autoReleaseBox.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                handleAutoReleaseChanged(e);
            }
        });
        // initiallize autoRelease to match autoAllocate
        autoReleaseBox.setSelected(_AutoAllocate);
        autoAllocateBox = new JCheckBox(Bundle.getMessage("AutoDispatchItem"));
        p30.add(autoAllocateBox);
        autoAllocateBox.setToolTipText(Bundle.getMessage("AutoAllocateBoxHint"));
        autoAllocateBox.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                handleAutoAllocateChanged(e);
            }
        });
        contentPane.add(p30);
        autoAllocateBox.setSelected(_AutoAllocate);
        JPanel p31 = new JPanel();
        p31.setLayout(new FlowLayout());
        allocatedSectionTableModel = new AllocatedSectionTableModel();
        JTable allocatedSectionTable = new JTable(allocatedSectionTableModel);
        allocatedSectionTable.setRowSelectionAllowed(false);
        allocatedSectionTable.setPreferredScrollableViewportSize(new java.awt.Dimension(730, 200));
        TableColumnModel allocatedSectionColumnModel = allocatedSectionTable.getColumnModel();
        TableColumn activeAColumn = allocatedSectionColumnModel.getColumn(AllocatedSectionTableModel.ACTIVE_COLUMN);
        activeAColumn.setResizable(true);
        activeAColumn.setMinWidth(250);
        activeAColumn.setMaxWidth(350);
        TableColumn sectionAColumn = allocatedSectionColumnModel.getColumn(AllocatedSectionTableModel.SECTION_COLUMN);
        sectionAColumn.setResizable(true);
        sectionAColumn.setMinWidth(200);
        sectionAColumn.setMaxWidth(350);
        TableColumn occupancyAColumn = allocatedSectionColumnModel.getColumn(AllocatedSectionTableModel.OCCUPANCY_COLUMN);
        occupancyAColumn.setResizable(true);
        occupancyAColumn.setMinWidth(80);
        occupancyAColumn.setMaxWidth(140);
        TableColumn useStatusColumn = allocatedSectionColumnModel.getColumn(AllocatedSectionTableModel.USESTATUS_COLUMN);
        useStatusColumn.setResizable(true);
        useStatusColumn.setMinWidth(90);
        useStatusColumn.setMaxWidth(150);
        TableColumn releaseColumn = allocatedSectionColumnModel.getColumn(AllocatedSectionTableModel.RELEASEBUTTON_COLUMN);
        releaseColumn.setCellEditor(new ButtonEditor(new JButton()));
        releaseColumn.setMinWidth(90);
        releaseColumn.setMaxWidth(170);
        releaseColumn.setResizable(false);
        allocatedSectionTable.setDefaultRenderer(JButton.class, buttonRenderer);
        JButton sampleAButton = new JButton(Bundle.getMessage("ReleaseButton"));
        allocatedSectionTable.setRowHeight(sampleAButton.getPreferredSize().height);
        releaseColumn.setPreferredWidth((sampleAButton.getPreferredSize().width) + 2);
        JScrollPane allocatedSectionTableScrollPane = new JScrollPane(allocatedSectionTable);
        p31.add(allocatedSectionTableScrollPane, BorderLayout.CENTER);
        contentPane.add(p31);
    }
    dispatcherFrame.pack();
    dispatcherFrame.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) TableColumn(javax.swing.table.TableColumn) JSeparator(javax.swing.JSeparator) JCheckBox(javax.swing.JCheckBox) ActionListener(java.awt.event.ActionListener) JTable(javax.swing.JTable) JMenuBar(javax.swing.JMenuBar) ButtonRenderer(jmri.util.table.ButtonRenderer)

Example 9 with ButtonRenderer

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

the class AutomationTableModel method initTable.

private void initTable(JTable table) {
    // Install the button handlers
    TableColumnModel tcm = table.getColumnModel();
    ButtonRenderer buttonRenderer = new ButtonRenderer();
    TableCellEditor buttonEditor = new ButtonEditor(new javax.swing.JButton());
    tcm.getColumn(MESSAGE_COLUMN).setCellRenderer(buttonRenderer);
    tcm.getColumn(MESSAGE_COLUMN).setCellEditor(buttonEditor);
    tcm.getColumn(UP_COLUMN).setCellRenderer(buttonRenderer);
    tcm.getColumn(UP_COLUMN).setCellEditor(buttonEditor);
    tcm.getColumn(DOWN_COLUMN).setCellRenderer(buttonRenderer);
    tcm.getColumn(DOWN_COLUMN).setCellEditor(buttonEditor);
    tcm.getColumn(DELETE_COLUMN).setCellRenderer(buttonRenderer);
    tcm.getColumn(DELETE_COLUMN).setCellEditor(buttonEditor);
    table.setDefaultRenderer(JComboBox.class, new jmri.jmrit.symbolicprog.ValueRenderer());
    table.setDefaultEditor(JComboBox.class, new jmri.jmrit.symbolicprog.ValueEditor());
    // set column preferred widths
    table.getColumnModel().getColumn(ID_COLUMN).setPreferredWidth(35);
    table.getColumnModel().getColumn(CURRENT_COLUMN).setPreferredWidth(60);
    table.getColumnModel().getColumn(ACTION_COLUMN).setPreferredWidth(200);
    table.getColumnModel().getColumn(TRAIN_COLUMN).setPreferredWidth(200);
    table.getColumnModel().getColumn(ROUTE_COLUMN).setPreferredWidth(200);
    table.getColumnModel().getColumn(AUTOMATION_COLUMN).setPreferredWidth(200);
    table.getColumnModel().getColumn(STATUS_COLUMN).setPreferredWidth(70);
    table.getColumnModel().getColumn(HIAF_COLUMN).setPreferredWidth(50);
    table.getColumnModel().getColumn(MESSAGE_COLUMN).setPreferredWidth(70);
    table.getColumnModel().getColumn(UP_COLUMN).setPreferredWidth(60);
    table.getColumnModel().getColumn(DOWN_COLUMN).setPreferredWidth(70);
    table.getColumnModel().getColumn(DELETE_COLUMN).setPreferredWidth(70);
    _frame.loadTableDetails(table);
    // does not use a table sorter
    table.setRowSorter(null);
    updateList();
}
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 10 with ButtonRenderer

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

the class NceShowCabPanel method setColumnToHoldButton.

void setColumnToHoldButton(JTable table, int column) {
    TableColumnModel tcm = table.getColumnModel();
    // install the button renderers & editors in this column
    ButtonRenderer buttonRenderer = new ButtonRenderer();
    tcm.getColumn(column).setCellRenderer(buttonRenderer);
    TableCellEditor buttonEditor = new ButtonEditor(new JButton(rb.getString("ButtonPurgeCab")));
    tcm.getColumn(column).setCellEditor(buttonEditor);
    // ensure the table rows, columns have enough room for buttons
    table.setRowHeight(new JButton("  " + cabModel.getValueAt(1, column)).getPreferredSize().height);
    table.getColumnModel().getColumn(column).setPreferredWidth(new JButton(rb.getString("ButtonPurgeCab")).getPreferredSize().width + 1);
}
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)

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