Search in sources :

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

Example 22 with DefaultCellEditor

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

the class NodeConfigFrame method initComponents.

/**
     * Initialize the config window
     */
@Override
public void initComponents() {
    setTitle(rb.getString("WindowTitle"));
    Container contentPane = getContentPane();
    contentPane.setLayout(new BoxLayout(contentPane, BoxLayout.Y_AXIS));
    // Set up node address and node type
    JPanel panel1 = new JPanel();
    panel1.setLayout(new BoxLayout(panel1, BoxLayout.Y_AXIS));
    JPanel panel11 = new JPanel();
    panel11.setLayout(new FlowLayout());
    // NOI18N
    panel11.add(new JLabel(rb.getString("LabelNodeAddress") + " "));
    panel11.add(nodeAddrField);
    // NOI18N
    nodeAddrField.setToolTipText(rb.getString("TipNodeAddress"));
    nodeAddrField.setText("0");
    panel11.add(nodeAddrStatic);
    nodeAddrStatic.setVisible(false);
    // NOI18N
    panel11.add(new JLabel("   " + rb.getString("LabelNodeType") + " "));
    nodeTypeBox = new JComboBox<>();
    panel11.add(nodeTypeBox);
    // NOI18N
    nodeTypeBox.addItem("SMINI");
    // NOI18N
    nodeTypeBox.addItem("USIC_SUSIC");
    // Here add code for other types of nodes
    nodeTypeBox.addActionListener(new java.awt.event.ActionListener() {

        @Override
        public void actionPerformed(java.awt.event.ActionEvent event) {
            String s = (String) nodeTypeBox.getSelectedItem();
            if (s.equals("SMINI")) {
                // NOI18N
                panel2.setVisible(false);
                panel2a.setVisible(true);
                cardSizeText.setVisible(false);
                cardSizeBox.setVisible(false);
                nodeType = SerialNode.SMINI;
            } else if (s.equals("USIC_SUSIC")) {
                // NOI18N
                panel2.setVisible(true);
                panel2a.setVisible(false);
                cardSizeText.setVisible(true);
                cardSizeBox.setVisible(true);
                nodeType = SerialNode.USIC_SUSIC;
            }
            // Here add code for other types of nodes
            // reset notes as appropriate
            resetNotes();
        }
    });
    // NOI18N
    nodeTypeBox.setToolTipText(rb.getString("TipNodeType"));
    JPanel panel12 = new JPanel();
    panel12.setLayout(new FlowLayout());
    // NOI18N
    panel12.add(new JLabel(rb.getString("LabelDelay") + " "));
    panel12.add(receiveDelayField);
    // NOI18N
    receiveDelayField.setToolTipText(rb.getString("TipDelay"));
    receiveDelayField.setText("0");
    panel12.add(cardSizeText);
    cardSizeBox = new JComboBox<>();
    panel12.add(cardSizeBox);
    // NOI18N
    cardSizeBox.addItem(rb.getString("CardSize24"));
    // NOI18N
    cardSizeBox.addItem(rb.getString("CardSize32"));
    // here add code for other node types, if required
    cardSizeBox.addActionListener(new java.awt.event.ActionListener() {

        @Override
        public void actionPerformed(java.awt.event.ActionEvent event) {
            String s = (String) cardSizeBox.getSelectedItem();
            if (s.equals(rb.getString("CardSize24"))) {
                // NOI18N
                bitsPerCard = 24;
            } else if (s.equals(rb.getString("CardSize32"))) {
                // NOI18N
                bitsPerCard = 32;
            }
        // here add code for other node types, if required
        }
    });
    // NOI18N
    cardSizeBox.setToolTipText(rb.getString("TipCardSize"));
    cardSizeText.setVisible(false);
    cardSizeBox.setVisible(false);
    JPanel panel13 = new JPanel();
    panel13.setLayout(new FlowLayout());
    // NOI18N
    panel13.add(new JLabel(rb.getString("LabelPulseWidth") + " "));
    panel13.add(pulseWidthField);
    // NOI18N
    pulseWidthField.setToolTipText(rb.getString("TipPulseWidth"));
    pulseWidthField.setText("500");
    // NOI18N
    panel13.add(new JLabel(rb.getString("LabelMilliseconds")));
    panel1.add(panel11);
    panel1.add(panel12);
    panel1.add(panel13);
    contentPane.add(panel1);
    // Set up USIC/SUSIC card type configuration table
    JPanel panel21 = new JPanel();
    panel21.setLayout(new BoxLayout(panel21, BoxLayout.Y_AXIS));
    // NOI18N
    panel21.add(new JLabel(rb.getString("HintCardTypePartA")));
    // NOI18N
    panel21.add(new JLabel(" " + rb.getString("HintCardTypePartB")));
    // NOI18N
    panel21.add(new JLabel(" " + rb.getString("HintCardTypePartC")));
    // NOI18N
    panel21.add(new JLabel("   "));
    // NOI18N
    panel21.add(new JLabel(rb.getString("HintCardTypePartD")));
    // NOI18N
    panel21.add(new JLabel(" " + rb.getString("HintCardTypePartE")));
    // NOI18N
    panel21.add(new JLabel(" " + rb.getString("HintCardTypePartF")));
    panel2.add(panel21);
    TableModel cardConfigModel = new CardConfigModel();
    JTable cardConfigTable = new JTable(cardConfigModel);
    cardConfigTable.setRowSelectionAllowed(false);
    cardConfigTable.setPreferredScrollableViewportSize(new java.awt.Dimension(180, 100));
    JComboBox<String> cardTypeCombo = new JComboBox<>();
    // NOI18N
    cardTypeCombo.addItem(rb.getString("CardTypeOutput"));
    // NOI18N
    cardTypeCombo.addItem(rb.getString("CardTypeInput"));
    // NOI18N
    cardTypeCombo.addItem(rb.getString("CardTypeNone"));
    TableColumnModel typeColumnModel = cardConfigTable.getColumnModel();
    TableColumn addressColumn = typeColumnModel.getColumn(CardConfigModel.ADDRESS_COLUMN);
    addressColumn.setMinWidth(70);
    addressColumn.setMaxWidth(80);
    TableColumn cardTypeColumn = typeColumnModel.getColumn(CardConfigModel.TYPE_COLUMN);
    cardTypeColumn.setCellEditor(new DefaultCellEditor(cardTypeCombo));
    cardTypeColumn.setResizable(false);
    cardTypeColumn.setMinWidth(90);
    cardTypeColumn.setMaxWidth(100);
    JScrollPane cardScrollPane = new JScrollPane(cardConfigTable);
    panel2.add(cardScrollPane, BorderLayout.CENTER);
    contentPane.add(panel2);
    panel2.setVisible(false);
    // Set up SMINI oscillating 2-lead searchlight configuration table
    JPanel panel2a1 = new JPanel();
    panel2a1.setLayout(new BoxLayout(panel2a1, BoxLayout.Y_AXIS));
    // NOI18N
    panel2a1.add(new JLabel(rb.getString("HintSearchlightPartA")));
    // NOI18N
    panel2a1.add(new JLabel(" " + rb.getString("HintSearchlightPartB")));
    // NOI18N
    panel2a1.add(new JLabel(" " + rb.getString("HintSearchlightPartC")));
    // NOI18N
    panel2a1.add(new JLabel("   "));
    // NOI18N
    panel2a1.add(new JLabel(rb.getString("HintSearchlightPartD")));
    // NOI18N
    panel2a1.add(new JLabel(" " + rb.getString("HintSearchlightPartE")));
    // NOI18N
    panel2a1.add(new JLabel(" " + rb.getString("HintSearchlightPartF")));
    panel2a.add(panel2a1);
    TableModel searchlightConfigModel = new SearchlightConfigModel();
    JTable searchlightConfigTable = new JTable(searchlightConfigModel);
    searchlightConfigTable.setRowSelectionAllowed(false);
    searchlightConfigTable.setPreferredScrollableViewportSize(new java.awt.Dimension(208, 100));
    TableColumnModel searchlightColumnModel = searchlightConfigTable.getColumnModel();
    TableColumn portColumn = searchlightColumnModel.getColumn(SearchlightConfigModel.PORT_COLUMN);
    portColumn.setMinWidth(90);
    portColumn.setMaxWidth(100);
    JScrollPane searchlightScrollPane = new JScrollPane(searchlightConfigTable);
    panel2a.add(searchlightScrollPane, BorderLayout.CENTER);
    contentPane.add(panel2a);
    // Set up the notes panel
    JPanel panel3 = new JPanel();
    panel3.setLayout(new BoxLayout(panel3, BoxLayout.Y_AXIS));
    JPanel panel31 = new JPanel();
    panel31.setLayout(new FlowLayout());
    statusText1.setText(stdStatus1);
    statusText1.setVisible(true);
    panel31.add(statusText1);
    JPanel panel32 = new JPanel();
    panel32.setLayout(new FlowLayout());
    statusText2.setText(stdStatus2);
    statusText2.setVisible(true);
    panel32.add(statusText2);
    JPanel panel33 = new JPanel();
    panel33.setLayout(new FlowLayout());
    statusText3.setText(stdStatus3);
    statusText3.setVisible(true);
    panel33.add(statusText3);
    panel3.add(panel31);
    panel3.add(panel32);
    panel3.add(panel33);
    Border panel3Border = BorderFactory.createEtchedBorder();
    Border panel3Titled = BorderFactory.createTitledBorder(panel3Border, rb.getString("BoxLabelNotes"));
    panel3.setBorder(panel3Titled);
    contentPane.add(panel3);
    // Set up buttons
    JPanel panel4 = new JPanel();
    panel4.setLayout(new FlowLayout());
    // NOI18N
    addButton.setText(rb.getString("ButtonAdd"));
    addButton.setVisible(true);
    // NOI18N
    addButton.setToolTipText(rb.getString("TipAddButton"));
    addButton.addActionListener(new java.awt.event.ActionListener() {

        @Override
        public void actionPerformed(java.awt.event.ActionEvent e) {
            addButtonActionPerformed();
        }
    });
    panel4.add(addButton);
    // NOI18N
    editButton.setText(rb.getString("ButtonEdit"));
    editButton.setVisible(true);
    // NOI18N
    editButton.setToolTipText(rb.getString("TipEditButton"));
    panel4.add(editButton);
    editButton.addActionListener(new java.awt.event.ActionListener() {

        @Override
        public void actionPerformed(java.awt.event.ActionEvent e) {
            editButtonActionPerformed();
        }
    });
    panel4.add(deleteButton);
    // NOI18N
    deleteButton.setText(rb.getString("ButtonDelete"));
    deleteButton.setVisible(true);
    // NOI18N
    deleteButton.setToolTipText(rb.getString("TipDeleteButton"));
    panel4.add(deleteButton);
    deleteButton.addActionListener(new java.awt.event.ActionListener() {

        @Override
        public void actionPerformed(java.awt.event.ActionEvent e) {
            deleteButtonActionPerformed();
        }
    });
    panel4.add(doneButton);
    // NOI18N
    doneButton.setText(rb.getString("ButtonDone"));
    doneButton.setVisible(true);
    // NOI18N
    doneButton.setToolTipText(rb.getString("TipDoneButton"));
    panel4.add(doneButton);
    doneButton.addActionListener(new java.awt.event.ActionListener() {

        @Override
        public void actionPerformed(java.awt.event.ActionEvent e) {
            doneButtonActionPerformed();
        }
    });
    panel4.add(updateButton);
    // NOI18N
    updateButton.setText(rb.getString("ButtonUpdate"));
    updateButton.setVisible(true);
    // NOI18N
    updateButton.setToolTipText(rb.getString("TipUpdateButton"));
    panel4.add(updateButton);
    updateButton.addActionListener(new java.awt.event.ActionListener() {

        @Override
        public void actionPerformed(java.awt.event.ActionEvent e) {
            updateButtonActionPerformed();
        }
    });
    updateButton.setVisible(false);
    panel4.add(cancelButton);
    // NOI18N
    cancelButton.setText(rb.getString("ButtonCancel"));
    cancelButton.setVisible(true);
    // NOI18N
    cancelButton.setToolTipText(rb.getString("TipCancelButton"));
    panel4.add(cancelButton);
    cancelButton.addActionListener(new java.awt.event.ActionListener() {

        @Override
        public void actionPerformed(java.awt.event.ActionEvent e) {
            cancelButtonActionPerformed();
        }
    });
    cancelButton.setVisible(false);
    contentPane.add(panel4);
    // pack for display
    pack();
}
Also used : JPanel(javax.swing.JPanel) FlowLayout(java.awt.FlowLayout) BoxLayout(javax.swing.BoxLayout) TableColumnModel(javax.swing.table.TableColumnModel) Container(java.awt.Container) JScrollPane(javax.swing.JScrollPane) JComboBox(javax.swing.JComboBox) JLabel(javax.swing.JLabel) TableColumn(javax.swing.table.TableColumn) DefaultCellEditor(javax.swing.DefaultCellEditor) JTable(javax.swing.JTable) Border(javax.swing.border.Border) AbstractTableModel(javax.swing.table.AbstractTableModel) TableModel(javax.swing.table.TableModel)

Example 23 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 24 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)

Aggregations

DefaultCellEditor (javax.swing.DefaultCellEditor)24 JComboBox (javax.swing.JComboBox)17 TableColumn (javax.swing.table.TableColumn)16 JTable (javax.swing.JTable)15 JScrollPane (javax.swing.JScrollPane)11 JLabel (javax.swing.JLabel)10 JPanel (javax.swing.JPanel)10 BoxLayout (javax.swing.BoxLayout)8 JButton (javax.swing.JButton)8 TableColumnModel (javax.swing.table.TableColumnModel)8 FlowLayout (java.awt.FlowLayout)6 ActionEvent (java.awt.event.ActionEvent)6 ActionListener (java.awt.event.ActionListener)5 Border (javax.swing.border.Border)5 ArrayList (java.util.ArrayList)4 ButtonGroup (javax.swing.ButtonGroup)4 TableRowSorter (javax.swing.table.TableRowSorter)4 JmriJFrame (jmri.util.JmriJFrame)4 ButtonEditor (jmri.util.table.ButtonEditor)4 ButtonRenderer (jmri.util.table.ButtonRenderer)4