Search in sources :

Example 21 with ButtonEditor

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

the class AutomatTableDataModel method setColumnToHoldButton.

/**
     * Service method to setup a column so that it will hold a button for it's
     * values
     *
     * @param table the table in which to configure the column
     * @param column the position of the configured column
     * @param sample typical button, used for size
     */
void setColumnToHoldButton(JTable table, int column, JButton sample) {
    TableColumnModel tcm = table.getColumnModel();
    // install a button renderer & editor
    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
    table.setRowHeight(sample.getPreferredSize().height);
    table.getColumnModel().getColumn(column).setPreferredWidth(sample.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 22 with ButtonEditor

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

the class LightTableAction method addPressed.

@Override
protected void addPressed(ActionEvent e) {
    if (inEditMode) {
        // cancel Edit and reactivate the edited light
        cancelPressed(null);
    }
    if (addFrame == null) {
        addFrame = new JmriJFrame(Bundle.getMessage("TitleAddLight"), false, true);
        addFrame.addHelpMenu("package.jmri.jmrit.beantable.LightAddEdit", true);
        addFrame.setLocation(100, 30);
        Container contentPane = addFrame.getContentPane();
        contentPane.setLayout(new BoxLayout(contentPane, BoxLayout.Y_AXIS));
        JPanel panel1 = new JPanel();
        panel1.setLayout(new FlowLayout());
        initializePrefixCombo();
        panel1.add(systemLabel);
        panel1.add(prefixBox);
        panel1.add(new JLabel("   "));
        panel1.add(addRangeBox);
        addRangeBox.setToolTipText(Bundle.getMessage("LightAddRangeHint"));
        addRangeBox.addActionListener((ActionEvent e1) -> {
            addRangeChanged();
        });
        panel1.add(systemNameLabel);
        systemNameLabel.setVisible(false);
        panel1.add(fixedSystemName);
        fixedSystemName.setVisible(false);
        prefixBox.setToolTipText(Bundle.getMessage("LightSystemHint"));
        prefixBox.addActionListener((ActionEvent e1) -> {
            prefixChanged();
        });
        contentPane.add(panel1);
        panel1a = new JPanel();
        panel1a.setLayout(new FlowLayout());
        panel1a.add(new JLabel(Bundle.getMessage("LabelHardwareAddress")));
        panel1a.add(fieldHardwareAddress);
        fieldHardwareAddress.setToolTipText(Bundle.getMessage("LightHardwareAddressHint"));
        panel1a.add(labelNumToAdd);
        panel1a.add(fieldNumToAdd);
        fieldNumToAdd.setToolTipText(Bundle.getMessage("LightNumberToAddHint"));
        contentPane.add(panel1a);
        JPanel panel2 = new JPanel();
        panel2.setLayout(new FlowLayout());
        panel2.add(userNameLabel);
        panel2.add(userName);
        userName.setToolTipText(Bundle.getMessage("LightUserNameHint"));
        contentPane.add(panel2);
        // items for variable intensity lights
        varPanel = new JPanel();
        varPanel.setLayout(new BoxLayout(varPanel, BoxLayout.X_AXIS));
        varPanel.add(new JLabel(" "));
        varPanel.add(labelMinIntensity);
        fieldMinIntensity.setToolTipText(Bundle.getMessage("LightMinIntensityHint"));
        fieldMinIntensity.setHorizontalAlignment(JTextField.RIGHT);
        fieldMinIntensity.setText("  0");
        varPanel.add(fieldMinIntensity);
        varPanel.add(labelMinIntensityTail);
        varPanel.add(labelMaxIntensity);
        fieldMaxIntensity.setToolTipText(Bundle.getMessage("LightMaxIntensityHint"));
        fieldMaxIntensity.setHorizontalAlignment(JTextField.RIGHT);
        fieldMaxIntensity.setText("100");
        varPanel.add(fieldMaxIntensity);
        varPanel.add(labelMaxIntensityTail);
        varPanel.add(labelTransitionTime);
        fieldTransitionTime.setToolTipText(Bundle.getMessage("LightTransitionTimeHint"));
        fieldTransitionTime.setHorizontalAlignment(JTextField.RIGHT);
        fieldTransitionTime.setText("0");
        varPanel.add(fieldTransitionTime);
        varPanel.add(new JLabel(" "));
        Border varPanelBorder = BorderFactory.createEtchedBorder();
        Border varPanelTitled = BorderFactory.createTitledBorder(varPanelBorder, Bundle.getMessage("LightVariableBorder"));
        varPanel.setBorder(varPanelTitled);
        contentPane.add(varPanel);
        // light control table            
        JPanel panel3 = new JPanel();
        panel3.setLayout(new BoxLayout(panel3, BoxLayout.Y_AXIS));
        JPanel panel31 = new JPanel();
        lightControlTableModel = new LightControlTableModel();
        JTable lightControlTable = new JTable(lightControlTableModel);
        lightControlTable.setRowSelectionAllowed(false);
        lightControlTable.setPreferredScrollableViewportSize(new java.awt.Dimension(550, 100));
        TableColumnModel lightControlColumnModel = lightControlTable.getColumnModel();
        TableColumn typeColumn = lightControlColumnModel.getColumn(LightControlTableModel.TYPE_COLUMN);
        typeColumn.setResizable(true);
        typeColumn.setMinWidth(110);
        typeColumn.setMaxWidth(150);
        TableColumn descriptionColumn = lightControlColumnModel.getColumn(LightControlTableModel.DESCRIPTION_COLUMN);
        descriptionColumn.setResizable(true);
        descriptionColumn.setMinWidth(270);
        descriptionColumn.setMaxWidth(340);
        ButtonRenderer buttonRenderer = new ButtonRenderer();
        lightControlTable.setDefaultRenderer(JButton.class, buttonRenderer);
        TableCellEditor buttonEditor = new ButtonEditor(new JButton());
        lightControlTable.setDefaultEditor(JButton.class, buttonEditor);
        JButton testButton = new JButton(Bundle.getMessage("ButtonDelete"));
        lightControlTable.setRowHeight(testButton.getPreferredSize().height);
        TableColumn editColumn = lightControlColumnModel.getColumn(LightControlTableModel.EDIT_COLUMN);
        editColumn.setResizable(false);
        editColumn.setMinWidth(testButton.getPreferredSize().width);
        TableColumn removeColumn = lightControlColumnModel.getColumn(LightControlTableModel.REMOVE_COLUMN);
        removeColumn.setResizable(false);
        removeColumn.setMinWidth(testButton.getPreferredSize().width);
        JScrollPane lightControlTableScrollPane = new JScrollPane(lightControlTable);
        panel31.add(lightControlTableScrollPane, BorderLayout.CENTER);
        panel3.add(panel31);
        JPanel panel35 = new JPanel();
        panel35.setLayout(new FlowLayout());
        panel35.add(addControl = new JButton(Bundle.getMessage("LightAddControlButton")));
        addControl.addActionListener(this::addControlPressed);
        addControl.setToolTipText(Bundle.getMessage("LightAddControlButtonHint"));
        panel3.add(panel35);
        Border panel3Border = BorderFactory.createEtchedBorder();
        Border panel3Titled = BorderFactory.createTitledBorder(panel3Border, Bundle.getMessage("LightControlBorder"));
        panel3.setBorder(panel3Titled);
        contentPane.add(panel3);
        // message items
        JPanel panel4 = new JPanel();
        panel4.setLayout(new BoxLayout(panel4, BoxLayout.Y_AXIS));
        JPanel panel41 = new JPanel();
        panel41.setLayout(new FlowLayout());
        panel41.add(status1);
        status1.setText(Bundle.getMessage("LightCreateInst"));
        JPanel panel42 = new JPanel();
        panel42.setLayout(new FlowLayout());
        panel42.add(status2);
        status2.setText("");
        status2.setVisible(false);
        panel4.add(panel41);
        panel4.add(panel42);
        Border panel4Border = BorderFactory.createEtchedBorder();
        panel4.setBorder(panel4Border);
        contentPane.add(panel4);
        // buttons at bottom of window
        JPanel panel5 = new JPanel();
        panel5.setLayout(new FlowLayout(FlowLayout.TRAILING));
        panel5.add(cancel = new JButton(Bundle.getMessage("ButtonCancel")));
        cancel.addActionListener(this::cancelPressed);
        cancel.setToolTipText(Bundle.getMessage("LightCancelButtonHint"));
        panel5.add(create = new JButton(Bundle.getMessage("ButtonCreate")));
        create.addActionListener(this::createPressed);
        create.setToolTipText(Bundle.getMessage("LightCreateButtonHint"));
        panel5.add(update = new JButton(Bundle.getMessage("ButtonUpdate")));
        update.addActionListener(this::updatePressed);
        update.setToolTipText(Bundle.getMessage("LightUpdateButtonHint"));
        cancel.setVisible(true);
        create.setVisible(true);
        update.setVisible(false);
        contentPane.add(panel5);
    }
    prefixChanged();
    addFrame.addWindowListener(new java.awt.event.WindowAdapter() {

        @Override
        public void windowClosing(java.awt.event.WindowEvent e) {
            cancelPressed(null);
        }
    });
    addFrame.pack();
    addFrame.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) Container(java.awt.Container) JmriJFrame(jmri.util.JmriJFrame) JTable(javax.swing.JTable) TableCellEditor(javax.swing.table.TableCellEditor) Border(javax.swing.border.Border) ButtonRenderer(jmri.util.table.ButtonRenderer)

Example 23 with ButtonEditor

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

the class TableFrames method makePathTurnoutFrame.

/*
     * ********************* PathTurnoutFrame *****************************
     */
protected JInternalFrame makePathTurnoutFrame(OBlock block, String pathName) {
    String title = Bundle.getMessage("TitlePathTurnoutTable", block.getDisplayName(), pathName);
    JInternalFrame frame = new JInternalFrame(title, true, true, false, true);
    if (log.isDebugEnabled()) {
        log.debug("makePathTurnoutFrame for Block " + block.getDisplayName() + " and Path " + pathName);
    }
    frame.setName(makePathTurnoutName(block.getSystemName(), pathName));
    OPath path = block.getPathByName(pathName);
    if (path == null) {
        return null;
    }
    PathTurnoutTableModel PathTurnoutModel = new PathTurnoutTableModel(path);
    PathTurnoutModel.init();
    JTable PathTurnoutTable = new JTable(PathTurnoutModel);
    PathTurnoutTable.setTransferHandler(new jmri.util.DnDTableImportExportHandler(new int[] { PathTurnoutTableModel.SETTINGCOLUMN, PathTurnoutTableModel.DELETE_COL }));
    PathTurnoutTable.setDragEnabled(true);
    JComboBox<String> box = new JComboBox<String>(PathTurnoutTableModel.turnoutStates);
    PathTurnoutTable.getColumnModel().getColumn(PathTurnoutTableModel.SETTINGCOLUMN).setCellEditor(new DefaultCellEditor(box));
    PathTurnoutTable.getColumnModel().getColumn(PathTurnoutTableModel.DELETE_COL).setCellEditor(new ButtonEditor(new JButton()));
    PathTurnoutTable.getColumnModel().getColumn(PathTurnoutTableModel.DELETE_COL).setCellRenderer(new ButtonRenderer());
    //PathTurnoutTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
    for (int i = 0; i < PathTurnoutModel.getColumnCount(); i++) {
        int width = PathTurnoutModel.getPreferredWidth(i);
        PathTurnoutTable.getColumnModel().getColumn(i).setPreferredWidth(width);
    }
    PathTurnoutTable.sizeColumnsToFit(-1);
    int tableWidth = PathTurnoutTable.getPreferredSize().width;
    PathTurnoutTable.setPreferredScrollableViewportSize(new java.awt.Dimension(tableWidth, ROW_HEIGHT * 5));
    JScrollPane tablePane = new JScrollPane(PathTurnoutTable);
    JPanel contentPane = new JPanel();
    contentPane.setLayout(new BorderLayout(5, 5));
    JLabel prompt = new JLabel(Bundle.getMessage("AddTurnoutPrompt"));
    contentPane.add(prompt, BorderLayout.NORTH);
    contentPane.add(tablePane, BorderLayout.CENTER);
    frame.addInternalFrameListener(this);
    frame.setContentPane(contentPane);
    frame.setLocation(10, 270);
    frame.pack();
    return frame;
}
Also used : JScrollPane(javax.swing.JScrollPane) JPanel(javax.swing.JPanel) ButtonEditor(jmri.util.table.ButtonEditor) JComboBox(javax.swing.JComboBox) JButton(javax.swing.JButton) JLabel(javax.swing.JLabel) OPath(jmri.jmrit.logix.OPath) Point(java.awt.Point) DefaultCellEditor(javax.swing.DefaultCellEditor) Dimension(java.awt.Dimension) BorderLayout(java.awt.BorderLayout) JTable(javax.swing.JTable) JInternalFrame(javax.swing.JInternalFrame) ButtonRenderer(jmri.util.table.ButtonRenderer)

Example 24 with ButtonEditor

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

the class LocationTrackBlockingOrderTableModel method initTable.

private void initTable() {
    // Use XTableColumnModel so we can control which columns are visible
    XTableColumnModel tcm = new XTableColumnModel();
    _table.setColumnModel(tcm);
    _table.createDefaultColumnsFromModel();
    ButtonRenderer buttonRenderer = new ButtonRenderer();
    TableCellEditor buttonEditor = new ButtonEditor(new javax.swing.JButton());
    tcm.getColumn(UP_COLUMN).setCellRenderer(buttonRenderer);
    tcm.getColumn(UP_COLUMN).setCellEditor(buttonEditor);
    tcm.getColumn(DOWN_COLUMN).setCellRenderer(buttonRenderer);
    tcm.getColumn(DOWN_COLUMN).setCellEditor(buttonEditor);
    // set column preferred widths
    tcm.getColumn(ID_COLUMN).setPreferredWidth(40);
    tcm.getColumn(NAME_COLUMN).setPreferredWidth(200);
    tcm.getColumn(TYPE_COLUMN).setPreferredWidth(80);
    tcm.getColumn(ORDER_COLUMN).setPreferredWidth(60);
    tcm.getColumn(UP_COLUMN).setPreferredWidth(60);
    tcm.getColumn(DOWN_COLUMN).setPreferredWidth(70);
}
Also used : ButtonEditor(jmri.util.table.ButtonEditor) JButton(javax.swing.JButton) TableCellEditor(javax.swing.table.TableCellEditor) XTableColumnModel(jmri.util.swing.XTableColumnModel) ButtonRenderer(jmri.util.table.ButtonRenderer)

Example 25 with ButtonEditor

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

the class BeanTableDataModel method setColumnToHoldButton.

/**
     * Service method to setup a column so that it will hold a button for it's
     * values
     *
     * @param table  {@link JTable} to use
     * @param column Column to setup
     * @param sample Typical button, used for size
     */
protected 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