Search in sources :

Example 56 with TableCellEditor

use of javax.swing.table.TableCellEditor in project JMRI by JMRI.

the class AlignTablePane method initComponents.

/**
     * Initialize the window
     */
public void initComponents() {
    setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
    alignModel = new AlignModel();
    JTable alignTable = new JTable(alignModel);
    // install a button renderer & editor
    ButtonRenderer buttonRenderer = new ButtonRenderer();
    alignTable.setDefaultRenderer(JButton.class, buttonRenderer);
    TableCellEditor buttonEditor = new ButtonEditor(new JButton());
    alignTable.setDefaultEditor(JButton.class, buttonEditor);
    TableRowSorter<AlignModel> sorter = new TableRowSorter<>(alignModel);
    RowSorterUtil.setSortOrder(sorter, AlignModel.NUMCOL, SortOrder.ASCENDING);
    alignTable.setRowSelectionAllowed(false);
    alignTable.setPreferredScrollableViewportSize(new java.awt.Dimension(580, 80));
    JScrollPane scrollPane = new JScrollPane(alignTable);
    add(scrollPane);
    // status info on bottom
    JPanel p = new JPanel() {

        @Override
        public Dimension getMaximumSize() {
            int height = getPreferredSize().height;
            int width = super.getMaximumSize().width;
            return new Dimension(width, height);
        }
    };
    p.setLayout(new FlowLayout());
    p.add(new JLabel(rb.getString("LabelNumCol")));
    num.setText("" + Engine.instance().getMaxReceiverNumber());
    p.add(num);
    JButton b = new JButton(rb.getString("ButtonSet"));
    b.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent event) {
            // set number of columns
            Engine.instance().setMaxReceiverNumber(Integer.parseInt(num.getText()));
            // mark modification
            flag.setModifiedFlag(true);
            // resize table
            alignModel.fireTableStructureChanged();
        }
    });
    p.add(b);
    add(p);
    p = new JPanel() {

        @Override
        public Dimension getMaximumSize() {
            int height = getPreferredSize().height;
            int width = super.getMaximumSize().width;
            return new Dimension(width, height);
        }
    };
    p.setLayout(new FlowLayout());
    p.add(new JLabel(rb.getString("LabelVSound")));
    vsound.setText("" + Engine.instance().getVSound());
    p.add(vsound);
    p.add(new JLabel(rb.getString("LabelOffset")));
    offset.setText("" + Engine.instance().getOffset());
    p.add(offset);
    p.add(new JLabel(rb.getString("LabelAlgorithm")));
    p.add(algorithmBox);
    b = new JButton(rb.getString("ButtonSet"));
    b.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent event) {
            // set number of vsound, offset
            Engine.instance().setOffset(Integer.parseInt(offset.getText()));
            Engine.instance().setVSound(Double.parseDouble(vsound.getText()));
            Engine.instance().setAlgorithm((String) algorithmBox.getSelectedItem());
            // mark modification
            flag.setModifiedFlag(true);
        }
    });
    p.add(b);
    add(p);
    //
    add(loadStore = new jmri.jmrix.rps.swing.LoadStorePanel() {

        // make sure we redisplay if changed
        @Override
        public void load() {
            super.load();
            alignModel.fireTableStructureChanged();
            // modified (to force store of default after load new values)
            flag.setModifiedFlag(true);
        }

        @Override
        public void storeDefault() {
            super.storeDefault();
            // no longer modified after storeDefault
            flag.setModifiedFlag(false);
        }
    });
    // add sound listener
    Engine.instance().addPropertyChangeListener(new PropertyChangeListener() {

        @Override
        public void propertyChange(java.beans.PropertyChangeEvent e) {
            if (e.getPropertyName().equals("vSound")) {
                // update sound display
                vsound.setText("" + e.getNewValue());
            }
        }
    });
}
Also used : JPanel(javax.swing.JPanel) ButtonEditor(jmri.util.table.ButtonEditor) FlowLayout(java.awt.FlowLayout) PropertyChangeListener(java.beans.PropertyChangeListener) ActionEvent(java.awt.event.ActionEvent) BoxLayout(javax.swing.BoxLayout) JButton(javax.swing.JButton) TableCellEditor(javax.swing.table.TableCellEditor) TableRowSorter(javax.swing.table.TableRowSorter) JScrollPane(javax.swing.JScrollPane) JLabel(javax.swing.JLabel) Dimension(java.awt.Dimension) Dimension(java.awt.Dimension) ActionListener(java.awt.event.ActionListener) JTable(javax.swing.JTable) ButtonRenderer(jmri.util.table.ButtonRenderer)

Example 57 with TableCellEditor

use of javax.swing.table.TableCellEditor in project JMRI by JMRI.

the class AddEntryExitPairPanel method setColumnToHoldButton.

/**
     * Service method to set up a column so that it will hold a button for it's
     * values.
     *
     * @param table  the table
     * @param column the column
     * @param sample Typical button, used for size
     */
protected void setColumnToHoldButton(JTable table, int column, JButton sample) {
    //TableColumnModel tcm = table.getColumnModel();
    // install a button renderer & editor
    ButtonRenderer buttonRenderer = new ButtonRenderer();
    table.setDefaultRenderer(JButton.class, buttonRenderer);
    TableCellEditor buttonEditor = new ButtonEditor(new JButton());
    table.setDefaultEditor(JButton.class, buttonEditor);
    // ensure the table rows, columns have enough room for buttons
    table.setRowHeight(sample.getPreferredSize().height);
    table.getColumnModel().getColumn(column).setPreferredWidth((sample.getPreferredSize().width) + 4);
}
Also used : ButtonEditor(jmri.util.table.ButtonEditor) JButton(javax.swing.JButton) TableCellEditor(javax.swing.table.TableCellEditor) ButtonRenderer(jmri.util.table.ButtonRenderer)

Example 58 with TableCellEditor

use of javax.swing.table.TableCellEditor 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 59 with TableCellEditor

use of javax.swing.table.TableCellEditor in project jmeter by apache.

the class GuiUtils method cancelEditing.

/**
     * cancel any editing that is currently being done on the table.
     *
     * @param table the table to cancel on editing
     * @since 3.1
     */
public static void cancelEditing(JTable table) {
    // If a table cell is being edited, we must cancel the editing
    if (table != null && table.isEditing()) {
        TableCellEditor cellEditor = table.getCellEditor(table.getEditingRow(), table.getEditingColumn());
        cellEditor.cancelCellEditing();
    }
}
Also used : TableCellEditor(javax.swing.table.TableCellEditor)

Example 60 with TableCellEditor

use of javax.swing.table.TableCellEditor in project beast-mcmc by beast-dev.

the class TableEditorStopper method focusLost.

public void focusLost(FocusEvent e) {
    if (focused != null) {
        focused.removeFocusListener(this);
        focused = e.getOppositeComponent();
        if (table == focused || table.isAncestorOf(focused)) {
            focused.addFocusListener(this);
        } else {
            focused = null;
            TableCellEditor editor = table.getCellEditor();
            if (editor != null) {
                editor.stopCellEditing();
            }
        }
    }
}
Also used : TableCellEditor(javax.swing.table.TableCellEditor)

Aggregations

TableCellEditor (javax.swing.table.TableCellEditor)62 JButton (javax.swing.JButton)37 ButtonEditor (jmri.util.table.ButtonEditor)33 ButtonRenderer (jmri.util.table.ButtonRenderer)33 TableColumnModel (javax.swing.table.TableColumnModel)23 JLabel (javax.swing.JLabel)14 JTable (javax.swing.JTable)13 ActionEvent (java.awt.event.ActionEvent)11 ActionListener (java.awt.event.ActionListener)9 BoxLayout (javax.swing.BoxLayout)9 JPanel (javax.swing.JPanel)9 JScrollPane (javax.swing.JScrollPane)9 TableColumn (javax.swing.table.TableColumn)9 TableCellRenderer (javax.swing.table.TableCellRenderer)8 FlowLayout (java.awt.FlowLayout)6 MouseEvent (java.awt.event.MouseEvent)6 XTableColumnModel (jmri.util.swing.XTableColumnModel)6 Container (java.awt.Container)5 JTextField (javax.swing.JTextField)5 JmriJFrame (jmri.util.JmriJFrame)5