Search in sources :

Example 96 with DefaultCellEditor

use of javax.swing.DefaultCellEditor 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 97 with DefaultCellEditor

use of javax.swing.DefaultCellEditor in project JMRI by JMRI.

the class LogixTableAction method makeEditConditionalWindow.

// ********************* Edit Conditional Window and Methods *******************
/**
     * Create and/or initialize the Edit Conditional window.
     * <p>
     * Note: you can get here via the New Conditional button (newConditionalPressed)
     * or via an Edit button in the Conditional table of the Edit Logix window.
     */
void makeEditConditionalWindow() {
    // deactivate this Logix
    _curLogix.deActivateLogix();
    conditionalUserName.setText(_curConditional.getUserName());
    if (editConditionalFrame == null) {
        editConditionalFrame = new JmriJFrame(rbx.getString("TitleEditConditional"), false, false);
        editConditionalFrame.addHelpMenu("package.jmri.jmrit.beantable.ConditionalAddEdit", true);
        Container contentPane = editConditionalFrame.getContentPane();
        contentPane.setLayout(new BoxLayout(contentPane, BoxLayout.Y_AXIS));
        JPanel panel1 = new JPanel();
        panel1.setLayout(new FlowLayout());
        panel1.add(new JLabel(Bundle.getMessage("ColumnSystemName") + ":"));
        panel1.add(new JLabel(_curConditional.getSystemName()));
        contentPane.add(panel1);
        JPanel panel2 = new JPanel();
        panel2.setLayout(new FlowLayout());
        panel2.add(new JLabel(Bundle.getMessage("ColumnUserName") + ":"));
        panel2.add(conditionalUserName);
        conditionalUserName.setToolTipText(rbx.getString("ConditionalUserNameHint"));
        contentPane.add(panel2);
        // add Logical Expression Section
        JPanel logicPanel = new JPanel();
        logicPanel.setLayout(new BoxLayout(logicPanel, BoxLayout.Y_AXIS));
        // add Antecedent Expression Panel -ONLY appears for MIXED operator statements
        _antecedent = _curConditional.getAntecedentExpression();
        _logicType = _curConditional.getLogicType();
        _antecedentField = new JTextField(65);
        _antecedentField.setFont(new Font("SansSerif", Font.BOLD, 14));
        _antecedentField.setText(_antecedent);
        _antecedentPanel = makeEditPanel(_antecedentField, "LabelAntecedent", "LabelAntecedentHint");
        JButton helpButton = new JButton(Bundle.getMessage("MenuHelp"));
        _antecedentPanel.add(helpButton);
        helpButton.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                helpPressed(e);
            }
        });
        _antecedentPanel.add(helpButton);
        _antecedentPanel.setVisible(_logicType == Conditional.MIXED);
        logicPanel.add(_antecedentPanel);
        // add state variable table title
        JPanel varTitle = new JPanel();
        varTitle.setLayout(new FlowLayout());
        varTitle.add(new JLabel(rbx.getString("StateVariableTableTitle")));
        logicPanel.add(varTitle);
        // set up state variables table
        // initialize and populate Combo boxes for table of state variables
        _notOperatorBox = new JComboBox<String>();
        _notOperatorBox.addItem(" ");
        _notOperatorBox.addItem(Bundle.getMessage("LogicNOT"));
        _andOperatorBox = new JComboBox<String>();
        _andOperatorBox.addItem(Bundle.getMessage("LogicAND"));
        _andOperatorBox.addItem(Bundle.getMessage("LogicOR"));
        // initialize table of state variables
        _variableTableModel = new VariableTableModel();
        JTable variableTable = new JTable(_variableTableModel);
        variableTable.setRowHeight(_notOperatorBox.getPreferredSize().height);
        variableTable.setRowSelectionAllowed(false);
        int rowHeight = variableTable.getRowHeight();
        TableColumnModel variableColumnModel = variableTable.getColumnModel();
        TableColumn rowColumn = variableColumnModel.getColumn(VariableTableModel.ROWNUM_COLUMN);
        rowColumn.setResizable(false);
        rowColumn.setMaxWidth(new JTextField(3).getPreferredSize().width);
        TableColumn andColumn = variableColumnModel.getColumn(VariableTableModel.AND_COLUMN);
        andColumn.setResizable(false);
        andColumn.setCellEditor(new DefaultCellEditor(_andOperatorBox));
        andColumn.setMaxWidth(_andOperatorBox.getPreferredSize().width - 5);
        TableColumn notColumn = variableColumnModel.getColumn(VariableTableModel.NOT_COLUMN);
        notColumn.setCellEditor(new DefaultCellEditor(_notOperatorBox));
        notColumn.setMaxWidth(_notOperatorBox.getPreferredSize().width - 5);
        notColumn.setResizable(false);
        TableColumn descColumn = variableColumnModel.getColumn(VariableTableModel.DESCRIPTION_COLUMN);
        descColumn.setPreferredWidth(300);
        descColumn.setMinWidth(200);
        descColumn.setResizable(true);
        TableColumn stateColumn = variableColumnModel.getColumn(VariableTableModel.STATE_COLUMN);
        stateColumn.setResizable(true);
        stateColumn.setMinWidth(50);
        stateColumn.setMaxWidth(80);
        TableColumn triggerColumn = variableColumnModel.getColumn(VariableTableModel.TRIGGERS_COLUMN);
        triggerColumn.setResizable(true);
        triggerColumn.setMinWidth(30);
        triggerColumn.setMaxWidth(80);
        TableColumn editColumn = variableColumnModel.getColumn(VariableTableModel.EDIT_COLUMN);
        ButtonRenderer buttonRenderer = new ButtonRenderer();
        variableTable.setDefaultRenderer(JButton.class, buttonRenderer);
        TableCellEditor buttonEditor = new ButtonEditor(new JButton());
        variableTable.setDefaultEditor(JButton.class, buttonEditor);
        JButton testButton = new JButton("XXXXXX");
        variableTable.setRowHeight(testButton.getPreferredSize().height);
        editColumn.setMinWidth(testButton.getPreferredSize().width);
        editColumn.setMaxWidth(testButton.getPreferredSize().width);
        editColumn.setResizable(false);
        TableColumn deleteColumn = variableColumnModel.getColumn(VariableTableModel.DELETE_COLUMN);
        // ButtonRenderer and TableCellEditor already set
        deleteColumn.setMinWidth(testButton.getPreferredSize().width);
        deleteColumn.setMaxWidth(testButton.getPreferredSize().width);
        deleteColumn.setResizable(false);
        // add a scroll pane
        JScrollPane variableTableScrollPane = new JScrollPane(variableTable);
        Dimension dim = variableTable.getPreferredSize();
        dim.height = 7 * rowHeight;
        variableTableScrollPane.getViewport().setPreferredSize(dim);
        logicPanel.add(variableTableScrollPane);
        // set up state variable buttons and logic
        JPanel panel42 = new JPanel();
        panel42.setLayout(new FlowLayout());
        //  Add State Variable
        JButton addVariableButton = new JButton(rbx.getString("AddVariableButton"));
        panel42.add(addVariableButton);
        addVariableButton.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                addVariablePressed(e);
            }
        });
        addVariableButton.setToolTipText(rbx.getString("AddVariableButtonHint"));
        JButton checkVariableButton = new JButton(rbx.getString("CheckVariableButton"));
        panel42.add(checkVariableButton);
        checkVariableButton.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                checkVariablePressed(e);
            }
        });
        checkVariableButton.setToolTipText(rbx.getString("CheckVariableButtonHint"));
        logicPanel.add(panel42);
        // logic type area
        _operatorBox = new JComboBox<String>(new String[] { Bundle.getMessage("LogicAND"), Bundle.getMessage("LogicOR"), Bundle.getMessage("LogicMixed") });
        JPanel typePanel = makeEditPanel(_operatorBox, "LabelLogicType", "TypeLogicHint");
        _operatorBox.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                logicTypeChanged(e);
            }
        });
        _operatorBox.setSelectedIndex(_logicType - 1);
        logicPanel.add(typePanel);
        logicPanel.add(Box.createHorizontalStrut(STRUT));
        Border logicPanelBorder = BorderFactory.createEtchedBorder();
        Border logicPanelTitled = BorderFactory.createTitledBorder(logicPanelBorder, rbx.getString("TitleLogicalExpression") + " ");
        logicPanel.setBorder(logicPanelTitled);
        contentPane.add(logicPanel);
        // End of Logic Expression Section
        JPanel triggerPanel = new JPanel();
        triggerPanel.setLayout(new BoxLayout(triggerPanel, BoxLayout.Y_AXIS));
        ButtonGroup tGroup = new ButtonGroup();
        _triggerOnChangeButton = new JRadioButton(rbx.getString("triggerOnChange"));
        _triggerOnChangeButton.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                _actionTableModel.fireTableDataChanged();
            }
        });
        tGroup.add(_triggerOnChangeButton);
        triggerPanel.add(_triggerOnChangeButton);
        JRadioButton triggerOnAny = new JRadioButton(rbx.getString("triggerOnAny"));
        triggerOnAny.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                _actionTableModel.fireTableDataChanged();
            }
        });
        tGroup.add(triggerOnAny);
        triggerPanel.add(triggerOnAny);
        triggerOnAny.setSelected(true);
        JPanel trigPanel = new JPanel();
        trigPanel.add(triggerPanel);
        contentPane.add(trigPanel);
        _triggerOnChangeButton.setSelected(_curConditional.getTriggerOnChange());
        // add Action Consequents Section
        JPanel conseqentPanel = new JPanel();
        conseqentPanel.setLayout(new BoxLayout(conseqentPanel, BoxLayout.Y_AXIS));
        JPanel actTitle = new JPanel();
        actTitle.setLayout(new FlowLayout());
        actTitle.add(new JLabel(rbx.getString("ActionTableTitle")));
        conseqentPanel.add(actTitle);
        // set up action consequents table
        _actionTableModel = new ActionTableModel();
        JTable actionTable = new JTable(_actionTableModel);
        actionTable.setRowSelectionAllowed(false);
        actionTable.setRowHeight(testButton.getPreferredSize().height);
        JPanel actionPanel = new JPanel();
        actionPanel.setLayout(new BoxLayout(actionPanel, BoxLayout.Y_AXIS));
        JPanel actionTitle = new JPanel();
        actionTitle.setLayout(new FlowLayout());
        conseqentPanel.add(actionPanel);
        TableColumnModel actionColumnModel = actionTable.getColumnModel();
        TableColumn descriptionColumn = actionColumnModel.getColumn(ActionTableModel.DESCRIPTION_COLUMN);
        descriptionColumn.setResizable(true);
        descriptionColumn.setPreferredWidth(600);
        descriptionColumn.setMinWidth(300);
        //descriptionColumn.setMaxWidth(760);
        TableColumn actionEditColumn = actionColumnModel.getColumn(ActionTableModel.EDIT_COLUMN);
        // ButtonRenderer already exists
        actionTable.setDefaultRenderer(JButton.class, buttonRenderer);
        TableCellEditor editButEditor = new ButtonEditor(new JButton());
        actionTable.setDefaultEditor(JButton.class, editButEditor);
        actionEditColumn.setMinWidth(testButton.getPreferredSize().width);
        actionEditColumn.setMaxWidth(testButton.getPreferredSize().width);
        actionEditColumn.setResizable(false);
        TableColumn actionDeleteColumn = actionColumnModel.getColumn(ActionTableModel.DELETE_COLUMN);
        // ButtonRenderer and TableCellEditor already set
        actionDeleteColumn.setMinWidth(testButton.getPreferredSize().width);
        actionDeleteColumn.setMaxWidth(testButton.getPreferredSize().width);
        actionDeleteColumn.setResizable(false);
        // add a scroll pane
        JScrollPane actionTableScrollPane = new JScrollPane(actionTable);
        dim = actionTableScrollPane.getPreferredSize();
        dim.height = 7 * rowHeight;
        actionTableScrollPane.getViewport().setPreferredSize(dim);
        conseqentPanel.add(actionTableScrollPane);
        // add action buttons to Action Section
        JPanel panel43 = new JPanel();
        panel43.setLayout(new FlowLayout());
        JButton addActionButton = new JButton(rbx.getString("addActionButton"));
        panel43.add(addActionButton);
        addActionButton.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                addActionPressed(e);
            }
        });
        addActionButton.setToolTipText(rbx.getString("addActionButtonHint"));
        conseqentPanel.add(panel43);
        //  - Reorder action button
        JButton reorderButton = new JButton(rbx.getString("ReorderButton"));
        panel43.add(reorderButton);
        reorderButton.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                reorderActionPressed(e);
            }
        });
        reorderButton.setToolTipText(rbx.getString("ReorderButtonHint"));
        conseqentPanel.add(panel43);
        Border conseqentPanelBorder = BorderFactory.createEtchedBorder();
        Border conseqentPanelTitled = BorderFactory.createTitledBorder(conseqentPanelBorder, rbx.getString("TitleAction"));
        conseqentPanel.setBorder(conseqentPanelTitled);
        contentPane.add(conseqentPanel);
        // End of Action Consequents Section
        // Bottom Buttons - Update Conditional
        JPanel panel5 = new JPanel();
        panel5.setLayout(new FlowLayout());
        JButton updateConditional = new JButton(rbx.getString("UpdateConditionalButton"));
        panel5.add(updateConditional);
        updateConditional.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                updateConditionalPressed(e);
            }
        });
        updateConditional.setToolTipText(rbx.getString("UpdateConditionalButtonHint"));
        // Cancel
        JButton cancelConditional = new JButton(Bundle.getMessage("ButtonCancel"));
        panel5.add(cancelConditional);
        cancelConditional.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                cancelConditionalPressed(e);
            }
        });
        cancelConditional.setToolTipText(rbx.getString("CancelConditionalButtonHint"));
        // Delete Conditional
        JButton deleteConditional = new JButton(Bundle.getMessage("ButtonDelete"));
        panel5.add(deleteConditional);
        deleteConditional.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                deleteConditionalPressed(null);
            }
        });
        deleteConditional.setToolTipText(rbx.getString("DeleteConditionalButtonHint"));
        contentPane.add(panel5);
    }
    // setup window closing listener
    editConditionalFrame.addWindowListener(new java.awt.event.WindowAdapter() {

        @Override
        public void windowClosing(java.awt.event.WindowEvent e) {
            cancelConditionalPressed(null);
        }
    });
    // initialize state variable table
    _variableTableModel.fireTableDataChanged();
    // initialize action variables
    _actionTableModel.fireTableDataChanged();
    editConditionalFrame.pack();
    editConditionalFrame.setVisible(true);
    inEditConditionalMode = true;
    // update variables to their current states
    checkVariablePressed(null);
}
Also used : JPanel(javax.swing.JPanel) FlowLayout(java.awt.FlowLayout) ButtonEditor(jmri.util.table.ButtonEditor) JRadioButton(javax.swing.JRadioButton) ActionEvent(java.awt.event.ActionEvent) BoxLayout(javax.swing.BoxLayout) JButton(javax.swing.JButton) TableColumnModel(javax.swing.table.TableColumnModel) JTextField(javax.swing.JTextField) Font(java.awt.Font) Container(java.awt.Container) TableCellEditor(javax.swing.table.TableCellEditor) JScrollPane(javax.swing.JScrollPane) JLabel(javax.swing.JLabel) Dimension(java.awt.Dimension) TableColumn(javax.swing.table.TableColumn) DefaultCellEditor(javax.swing.DefaultCellEditor) ActionListener(java.awt.event.ActionListener) JmriJFrame(jmri.util.JmriJFrame) ButtonGroup(javax.swing.ButtonGroup) JTable(javax.swing.JTable) Border(javax.swing.border.Border) ButtonRenderer(jmri.util.table.ButtonRenderer)

Example 98 with DefaultCellEditor

use of javax.swing.DefaultCellEditor in project JMRI by JMRI.

the class AddEntryExitPairPanel method configDeleteColumn.

// Picked up in setValueAt() to read back from table
protected void configDeleteColumn(JTable table) {
    // have the delete column hold a button
    setColumnToHoldButton(table, DELETECOL, new JButton(Bundle.getMessage("ButtonDelete")));
    setColumnToHoldButton(table, CLEARCOL, new JButton(Bundle.getMessage("ButtonClear")));
    JComboBox<String> typeCombo = new JComboBox<>(NXTYPE_NAMES);
    TableColumn col = table.getColumnModel().getColumn(TYPECOL);
    col.setCellEditor(new DefaultCellEditor(typeCombo));
}
Also used : JComboBox(javax.swing.JComboBox) JButton(javax.swing.JButton) TableColumn(javax.swing.table.TableColumn) DefaultCellEditor(javax.swing.DefaultCellEditor)

Example 99 with DefaultCellEditor

use of javax.swing.DefaultCellEditor in project JMRI by JMRI.

the class LocoIOPanel method initComponents.

@Override
public void initComponents(LocoNetSystemConnectionMemo memo) {
    setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
    ln = memo.getLnTrafficController();
    // creating the table (done here to ensure order OK)
    data = new LocoIOData(Integer.valueOf(addrField.getText(), 16).intValue(), Integer.valueOf(subAddrField.getText(), 16).intValue(), memo.getLnTrafficController());
    model = new LocoIOTableModel(data);
    table = new JTable(model);
    scroll = new JScrollPane(table);
    data.addPropertyChangeListener(this);
    // have to shut off autoResizeMode to get horizontal scroll to work (JavaSwing p 541)
    // table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
    table.setShowHorizontalLines(true);
    table.setAutoCreateColumnsFromModel(true);
    TableColumnModel tcm = table.getColumnModel();
    // install a ComboBox editor on the OnMode column
    JComboBox<String> comboOnBox = new JComboBox<String>(data.getLocoIOModeList().getValidModes());
    comboOnBox.setEditable(true);
    DefaultCellEditor modeEditor = new DefaultCellEditor(comboOnBox);
    tcm.getColumn(LocoIOTableModel.MODECOLUMN).setCellEditor(modeEditor);
    // install a button renderer & editor in the Read, Write and Compare columns
    ButtonRenderer buttonRenderer = new ButtonRenderer();
    tcm.getColumn(LocoIOTableModel.READCOLUMN).setCellRenderer(buttonRenderer);
    tcm.getColumn(LocoIOTableModel.WRITECOLUMN).setCellRenderer(buttonRenderer);
    tcm.getColumn(LocoIOTableModel.CAPTURECOLUMN).setCellRenderer(buttonRenderer);
    TableCellEditor buttonEditor = new ButtonEditor(new JButton());
    tcm.getColumn(LocoIOTableModel.READCOLUMN).setCellEditor(buttonEditor);
    tcm.getColumn(LocoIOTableModel.WRITECOLUMN).setCellEditor(buttonEditor);
    tcm.getColumn(LocoIOTableModel.CAPTURECOLUMN).setCellEditor(buttonEditor);
    // ensure the table rows, columns have enough room for buttons and comboBox contents
    table.setRowHeight(new JButton("Capture").getPreferredSize().height);
    for (int col = 0; col < LocoIOTableModel.HIGHESTCOLUMN; col++) {
        table.getColumnModel().getColumn(col).setPreferredWidth(model.getPreferredWidth(col));
    }
    // A pane for SV0, SV1, SV2, the board sub address and the PIC version
    JPanel p1 = new JPanel();
    p1.setLayout(new BoxLayout(p1, BoxLayout.X_AXIS));
    p1.add(new JLabel("LocoIO address: 0x"));
    addrField.setMaximumSize(addrField.getPreferredSize());
    subAddrField.setMaximumSize(subAddrField.getPreferredSize());
    p1.add(addrField);
    p1.add(new JLabel("/"));
    p1.add(subAddrField);
    // -------------------
    p1.add(Box.createGlue());
    probeButton = new JButton("Probe");
    probeButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent a) {
            data.setLIOVersion("<Not found>");
            LocoIO.probeLocoIOs(ln);
        }
    });
    p1.add(probeButton);
    // -------------------
    p1.add(Box.createGlue());
    readAllButton = new JButton("Read All");
    readAllButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent a) {
            data.readAll();
        }
    });
    p1.add(readAllButton);
    writeAllButton = new JButton("Write All");
    writeAllButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent a) {
            data.writeAll();
        }
    });
    p1.add(writeAllButton);
    // -------------------
    p1.add(Box.createGlue());
    addrSetButton = new JButton("Set address");
    p1.add(addrSetButton);
    addrSetButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent a) {
            addrSet();
        }
    });
    // -------------------
    p1.add(Box.createGlue());
    /*
         openButton = new JButton("Load...");
         openButton.setEnabled(false);
         p1.add(openButton);

         saveButton = new JButton("Save...");
         saveButton.setEnabled(false);
         p1.add(saveButton);
         */
    JPanel p2 = new JPanel();
    p2.setLayout(new BoxLayout(p2, BoxLayout.X_AXIS));
    p2.add(new JLabel("Locobuffer rev: "));
    p2.add(locobuffer);
    // -------------------
    p2.add(Box.createGlue());
    p2.add(new JLabel("Status: "));
    p2.add(status);
    // -------------------
    p2.add(Box.createGlue());
    p2.add(new JLabel("LocoIO Firmware rev: "));
    p2.add(firmware);
    JPanel p3 = new JPanel();
    p3.setLayout(new BoxLayout(p3, BoxLayout.Y_AXIS));
    p3.add(p1);
    p3.add(table);
    add(p3);
    add(p2);
    // updating the Board address needs to be conveyed to the table
    ActionListener al4UnitAddress = new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent a) {
            try {
                data.setUnitAddress(Integer.valueOf(addrField.getText(), 16).intValue(), Integer.valueOf(subAddrField.getText(), 16).intValue());
            } catch (NullPointerException e) {
                // NOI18N
                log.error("Caught NullPointerException", e);
            }
        }
    };
    FocusListener fl4UnitAddress = new FocusListener() {

        @Override
        public void focusGained(FocusEvent event) {
        }

        @Override
        public void focusLost(FocusEvent event) {
            try {
                data.setUnitAddress(Integer.valueOf(addrField.getText(), 16).intValue(), Integer.valueOf(subAddrField.getText(), 16).intValue());
            } catch (NullPointerException e) {
                // NOI18N
                log.error("Caught NullPointerException", e);
            }
        }
    };
    addrField.addActionListener(al4UnitAddress);
    subAddrField.addActionListener(al4UnitAddress);
    addrField.addFocusListener(fl4UnitAddress);
    subAddrField.addFocusListener(fl4UnitAddress);
    try {
        data.setUnitAddress(0x51, 0x00);
    } catch (NullPointerException e) {
        // NOI18N
        log.error("Caught NullPointerException", e);
    }
}
Also used : JScrollPane(javax.swing.JScrollPane) JPanel(javax.swing.JPanel) ButtonEditor(jmri.util.table.ButtonEditor) JComboBox(javax.swing.JComboBox) ActionEvent(java.awt.event.ActionEvent) BoxLayout(javax.swing.BoxLayout) JButton(javax.swing.JButton) TableColumnModel(javax.swing.table.TableColumnModel) JLabel(javax.swing.JLabel) FocusEvent(java.awt.event.FocusEvent) DefaultCellEditor(javax.swing.DefaultCellEditor) ActionListener(java.awt.event.ActionListener) JTable(javax.swing.JTable) TableCellEditor(javax.swing.table.TableCellEditor) FocusListener(java.awt.event.FocusListener) ButtonRenderer(jmri.util.table.ButtonRenderer)

Example 100 with DefaultCellEditor

use of javax.swing.DefaultCellEditor in project JMRI by JMRI.

the class WarrantTableFrame method initComponents.

/**
     * By default, Swing components should be created an installed in this
     * method, rather than in the ctor itself.
     */
@Override
public void initComponents() throws Exception {
    //Casts at getTableCellEditorComponent() now fails with 3.0 ??
    JTable table = new JTable(_model);
    ComboBoxCellEditor comboEd;
    TableRowSorter<WarrantTableModel> sorter = new TableRowSorter<>(_model);
    comboEd = new ComboBoxCellEditor(new JComboBox<>());
    table.setRowSorter(sorter);
    // Use XTableColumnModel so we can control which columns are visible
    XTableColumnModel tcm = new XTableColumnModel();
    table.setColumnModel(tcm);
    table.getTableHeader().setReorderingAllowed(true);
    table.createDefaultColumnsFromModel();
    _model.addHeaderListener(table);
    table.setDefaultRenderer(Boolean.class, new ButtonRenderer());
    table.setDefaultRenderer(JComboBox.class, new jmri.jmrit.symbolicprog.ValueRenderer());
    table.setDefaultEditor(JComboBox.class, new jmri.jmrit.symbolicprog.ValueEditor());
    JComboBox<String> box = new JComboBox<>(controls);
    box.setFont(new Font(null, Font.PLAIN, 12));
    table.getColumnModel().getColumn(WarrantTableModel.CONTROL_COLUMN).setCellEditor(new DefaultCellEditor(box));
    table.getColumnModel().getColumn(WarrantTableModel.ROUTE_COLUMN).setCellEditor(comboEd);
    table.getColumnModel().getColumn(WarrantTableModel.ALLOCATE_COLUMN).setCellEditor(new ButtonEditor(new JButton()));
    table.getColumnModel().getColumn(WarrantTableModel.ALLOCATE_COLUMN).setCellRenderer(new ButtonRenderer());
    table.getColumnModel().getColumn(WarrantTableModel.DEALLOC_COLUMN).setCellEditor(new ButtonEditor(new JButton()));
    table.getColumnModel().getColumn(WarrantTableModel.DEALLOC_COLUMN).setCellRenderer(new ButtonRenderer());
    table.getColumnModel().getColumn(WarrantTableModel.SET_COLUMN).setCellEditor(new ButtonEditor(new JButton()));
    table.getColumnModel().getColumn(WarrantTableModel.SET_COLUMN).setCellRenderer(new ButtonRenderer());
    table.getColumnModel().getColumn(WarrantTableModel.AUTO_RUN_COLUMN).setCellEditor(new ButtonEditor(new JButton()));
    table.getColumnModel().getColumn(WarrantTableModel.AUTO_RUN_COLUMN).setCellRenderer(new ButtonRenderer());
    table.getColumnModel().getColumn(WarrantTableModel.MANUAL_RUN_COLUMN).setCellEditor(new ButtonEditor(new JButton()));
    table.getColumnModel().getColumn(WarrantTableModel.MANUAL_RUN_COLUMN).setCellRenderer(new ButtonRenderer());
    table.getColumnModel().getColumn(WarrantTableModel.EDIT_COLUMN).setCellEditor(new ButtonEditor(new JButton()));
    table.getColumnModel().getColumn(WarrantTableModel.EDIT_COLUMN).setCellRenderer(new ButtonRenderer());
    table.getColumnModel().getColumn(WarrantTableModel.DELETE_COLUMN).setCellEditor(new ButtonEditor(new JButton()));
    table.getColumnModel().getColumn(WarrantTableModel.DELETE_COLUMN).setCellRenderer(new ButtonRenderer());
    //table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
    for (int i = 0; i < _model.getColumnCount(); i++) {
        int width = _model.getPreferredWidth(i);
        table.getColumnModel().getColumn(i).setPreferredWidth(width);
    }
    tcm.setColumnVisible(tcm.getColumnByModelIndex(WarrantTableModel.MANUAL_RUN_COLUMN), false);
    _rowHeight = box.getPreferredSize().height;
    table.setRowHeight(_rowHeight);
    table.setDragEnabled(true);
    table.setTransferHandler(new jmri.util.DnDTableExportHandler());
    _tablePane = new JScrollPane(table);
    JPanel tablePanel = new JPanel();
    tablePanel.setLayout(new BoxLayout(tablePanel, BoxLayout.Y_AXIS));
    tablePanel.add(Box.createVerticalGlue());
    JLabel title = new JLabel(Bundle.getMessage("ShowWarrants"));
    tablePanel.add(title);
    tablePanel.add(_tablePane);
    JPanel bottom = new JPanel();
    JPanel panel = new JPanel();
    JButton nxButton = new JButton(Bundle.getMessage("CreateNXWarrant"));
    nxButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            nxAction();
        }
    });
    panel.add(nxButton);
    panel.add(Box.createGlue());
    panel.add(new JLabel("status"));
    _status.addMouseListener(this);
    _status.setBackground(Color.white);
    _status.setFont(_status.getFont().deriveFont(Font.BOLD));
    _status.setEditable(false);
    setStatusText(BLANK.substring(0, 90), null, false);
    panel.add(_status);
    JButton haltAllButton = new JButton(Bundle.getMessage("HaltAllTrains"));
    haltAllButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            haltAllAction();
        }
    });
    haltAllButton.setForeground(Color.RED);
    panel.add(Box.createGlue());
    panel.add(haltAllButton);
    ///
    bottom.add(panel);
    tablePanel.add(bottom);
    addWindowListener(new java.awt.event.WindowAdapter() {

        @Override
        public void windowClosing(java.awt.event.WindowEvent e) {
            dispose();
        }
    });
    JMenuBar menuBar = new JMenuBar();
    JMenu fileMenu = new JMenu(Bundle.getMessage("MenuFile"));
    fileMenu.add(new jmri.configurexml.SaveMenu());
    menuBar.add(fileMenu);
    JMenu warrantMenu = new JMenu(Bundle.getMessage("MenuWarrant"));
    warrantMenu.add(new AbstractAction(Bundle.getMessage("ConcatWarrants")) {

        @Override
        public void actionPerformed(ActionEvent e) {
            concatMenuAction();
        }
    });
    warrantMenu.add(new jmri.jmrit.logix.WarrantTableAction("CreateWarrant"));
    warrantMenu.add(WarrantTableAction._trackerTable);
    warrantMenu.add(new AbstractAction(Bundle.getMessage("CreateNXWarrant")) {

        @Override
        public void actionPerformed(ActionEvent e) {
            nxAction();
        }
    });
    warrantMenu.add(WarrantTableAction.makeLogMenu());
    menuBar.add(warrantMenu);
    setJMenuBar(menuBar);
    addHelpMenu("package.jmri.jmrit.logix.WarrantTable", true);
    getContentPane().add(tablePanel);
    //        setLocation(50,0);
    pack();
}
Also used : JPanel(javax.swing.JPanel) ButtonEditor(jmri.util.table.ButtonEditor) ActionEvent(java.awt.event.ActionEvent) BoxLayout(javax.swing.BoxLayout) JButton(javax.swing.JButton) Font(java.awt.Font) AbstractAction(javax.swing.AbstractAction) TableRowSorter(javax.swing.table.TableRowSorter) JScrollPane(javax.swing.JScrollPane) JComboBox(javax.swing.JComboBox) JLabel(javax.swing.JLabel) XTableColumnModel(jmri.util.swing.XTableColumnModel) DefaultCellEditor(javax.swing.DefaultCellEditor) ActionListener(java.awt.event.ActionListener) JTable(javax.swing.JTable) ButtonRenderer(jmri.util.table.ButtonRenderer) JMenuBar(javax.swing.JMenuBar) JMenu(javax.swing.JMenu)

Aggregations

DefaultCellEditor (javax.swing.DefaultCellEditor)191 JComboBox (javax.swing.JComboBox)119 JTable (javax.swing.JTable)61 TableColumn (javax.swing.table.TableColumn)61 ArrayList (java.util.ArrayList)47 TableCellEditor (javax.swing.table.TableCellEditor)35 JScrollPane (javax.swing.JScrollPane)33 JPanel (javax.swing.JPanel)26 ActionEvent (java.awt.event.ActionEvent)25 JTextField (javax.swing.JTextField)23 ProxyColumn (us.mn.state.dot.tms.client.proxy.ProxyColumn)23 JLabel (javax.swing.JLabel)22 DefaultTableCellRenderer (javax.swing.table.DefaultTableCellRenderer)22 Component (java.awt.Component)21 DefaultTableModel (javax.swing.table.DefaultTableModel)21 Dimension (java.awt.Dimension)17 ActionListener (java.awt.event.ActionListener)16 JButton (javax.swing.JButton)16 JCheckBox (javax.swing.JCheckBox)16 TableCellRenderer (javax.swing.table.TableCellRenderer)15