Search in sources :

Example 96 with TableCellEditor

use of javax.swing.table.TableCellEditor in project jmeter-plugins by undera.

the class CopyRowAction method actionPerformed.

public void actionPerformed(ActionEvent e) {
    if (grid.isEditing()) {
        TableCellEditor cellEditor = grid.getCellEditor(grid.getEditingRow(), grid.getEditingColumn());
        cellEditor.stopCellEditing();
    }
    final int selectedRow = grid.getSelectedRow();
    if (tableModel.getRowCount() == 0 || selectedRow < 0) {
        return;
    }
    tableModel.addRow(tableModel.getRowData(selectedRow));
    tableModel.fireTableDataChanged();
    // Enable DELETE (which may already be enabled, but it won't hurt)
    deleteRowButton.setEnabled(true);
    // Highlight (select) the appropriate row.
    int rowToSelect = selectedRow + 1;
    grid.setRowSelectionInterval(rowToSelect, rowToSelect);
    sender.updateUI();
}
Also used : TableCellEditor(javax.swing.table.TableCellEditor)

Example 97 with TableCellEditor

use of javax.swing.table.TableCellEditor in project jmeter-plugins by undera.

the class DeleteRowAction method actionPerformed.

public void actionPerformed(ActionEvent e) {
    if (grid.isEditing()) {
        TableCellEditor cellEditor = grid.getCellEditor(grid.getEditingRow(), grid.getEditingColumn());
        cellEditor.cancelCellEditing();
    }
    int rowSelected = grid.getSelectedRow();
    if (rowSelected >= 0) {
        tableModel.removeRow(rowSelected);
        tableModel.fireTableDataChanged();
        // Disable DELETE if there are no rows in the table to delete.
        if (tableModel.getRowCount() == 0) {
            deleteRowButton.setEnabled(false);
        } else // Table still contains one or more rows, so highlight (select)
        // the appropriate one.
        {
            int rowToSelect = rowSelected;
            if (rowSelected >= tableModel.getRowCount()) {
                rowToSelect = rowSelected - 1;
            }
            grid.setRowSelectionInterval(rowToSelect, rowToSelect);
        }
        sender.updateUI();
    }
}
Also used : TableCellEditor(javax.swing.table.TableCellEditor)

Example 98 with TableCellEditor

use of javax.swing.table.TableCellEditor in project jmeter-plugins by undera.

the class MergeResultsGui method actionPerformed.

public void actionPerformed(ActionEvent action) {
    String command = action.getActionCommand();
    if (grid.isEditing()) {
        TableCellEditor cellEditor = grid.getCellEditor(grid.getEditingRow(), grid.getEditingColumn());
        cellEditor.stopCellEditing();
    }
    switch(command) {
        case ACTION_ADD:
            {
                tableModel.addRow(defaultValues);
                tableModel.fireTableDataChanged();
                if (tableModel.getRowCount() >= MAX_FILE_HANDLES) {
                    addRowButton.setEnabled(false);
                    copyRowButton.setEnabled(false);
                }
                // Enable DELETE and MERGE
                deleteRowButton.setEnabled(true);
                mergeButton.setEnabled(true);
                // Highlight (select) the appropriate row.
                int rowToSelect = tableModel.getRowCount() - 1;
                if (rowToSelect < grid.getRowCount()) {
                    grid.setRowSelectionInterval(rowToSelect, rowToSelect);
                }
                updateUI();
                break;
            }
        case ACTION_COPY:
            {
                final int selectedRow = grid.getSelectedRow();
                if (tableModel.getRowCount() == 0 || selectedRow < 0) {
                    return;
                }
                tableModel.addRow(tableModel.getRowData(selectedRow));
                tableModel.fireTableDataChanged();
                if (tableModel.getRowCount() >= MAX_FILE_HANDLES) {
                    addRowButton.setEnabled(false);
                    copyRowButton.setEnabled(false);
                }
                // Enable DELETE and MERGE
                deleteRowButton.setEnabled(true);
                mergeButton.setEnabled(true);
                // Highlight (select) the appropriate row.
                int rowToSelect = selectedRow + 1;
                grid.setRowSelectionInterval(rowToSelect, rowToSelect);
                updateUI();
                break;
            }
        case ACTION_DELETE:
            final int rowSelected = grid.getSelectedRow();
            if (rowSelected >= 0) {
                tableModel.removeRow(rowSelected);
                tableModel.fireTableDataChanged();
                if (tableModel.getRowCount() < MAX_FILE_HANDLES) {
                    addRowButton.setEnabled(true);
                    copyRowButton.setEnabled(true);
                }
                // table to delete.
                if (tableModel.getRowCount() == 0) {
                    deleteRowButton.setEnabled(false);
                    mergeButton.setEnabled(false);
                } else // Table still contains one or more rows, so highlight
                // (select) the appropriate one.
                {
                    int rowToSelect = rowSelected;
                    if (rowSelected >= tableModel.getRowCount()) {
                        rowToSelect = rowSelected - 1;
                    }
                    grid.setRowSelectionInterval(rowToSelect, rowToSelect);
                }
                updateUI();
            }
            break;
        case ACTION_MERGE:
            String output = getFile();
            if (output.isEmpty()) {
                GuiPackage.showErrorMessage("Error merging results files - empty output filename", "Output file error");
                return;
            }
            boolean isSuccess = loadFilesFromTable((CorrectedResultCollector) collector);
            if (isSuccess) {
                mergeService = new MergeResultsService();
                collector.setFilename(output);
                mergeService.mergeSamples((CorrectedResultCollector) collector, samples);
            }
            samples.clear();
            break;
        case ACTION_SAVE_CONFIG:
            SavePropertyDialog d = new SavePropertyDialog(GuiPackage.getInstance().getMainFrame(), JMeterUtils.getResString("sample_result_save_configuration"), true, collector.getSaveConfig());
            d.pack();
            ComponentUtil.centerComponentInComponent(GuiPackage.getInstance().getMainFrame(), d);
            d.setVisible(true);
            break;
    }
}
Also used : MergeResultsService(org.jmeterplugins.save.MergeResultsService) SavePropertyDialog(org.apache.jmeter.gui.SavePropertyDialog) TableCellEditor(javax.swing.table.TableCellEditor)

Example 99 with TableCellEditor

use of javax.swing.table.TableCellEditor in project cytoscape-impl by cytoscape.

the class GUIJobDialog method initUI.

public void initUI() {
    // Create table of jobs
    jobTableModel = new JobTableModel(this);
    JTable table = new JTable(jobTableModel);
    table.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);
    // Put in JScrollPane
    JScrollPane scrollPane = new JScrollPane(table);
    scrollPane.setPreferredSize(new Dimension(500, 100));
    // Set up our button renderer
    TableCellRenderer buttonRenderer = new JTableButtonRenderer();
    table.setDefaultRenderer(JButton.class, buttonRenderer);
    TableCellEditor buttonEditor = new ButtonEditor(new JCheckBox());
    table.setDefaultEditor(JButton.class, buttonEditor);
    table.setRowHeight(30);
    // Create bottom panel
    JButton closeButton = new JButton(new AbstractAction("Close") {

        @Override
        public void actionPerformed(ActionEvent e) {
            dispose();
        }
    });
    JPanel bottomPanel = LookAndFeelUtil.createOkCancelPanel(null, closeButton);
    LookAndFeelUtil.setDefaultOkCancelKeyStrokes(getRootPane(), null, closeButton.getAction());
    // add to dialog
    setLayout(new BorderLayout());
    add(scrollPane, BorderLayout.CENTER);
    add(bottomPanel, BorderLayout.SOUTH);
}
Also used : JScrollPane(javax.swing.JScrollPane) TableCellRenderer(javax.swing.table.TableCellRenderer) JPanel(javax.swing.JPanel) ActionEvent(java.awt.event.ActionEvent) JButton(javax.swing.JButton) Dimension(java.awt.Dimension) JCheckBox(javax.swing.JCheckBox) BorderLayout(java.awt.BorderLayout) JTable(javax.swing.JTable) TableCellEditor(javax.swing.table.TableCellEditor) AbstractAction(javax.swing.AbstractAction)

Example 100 with TableCellEditor

use of javax.swing.table.TableCellEditor in project cytoscape-impl by cytoscape.

the class BrowserTable method editCellAt.

@Override
public boolean editCellAt(int row, int column, EventObject e) {
    if (cellEditor != null && !cellEditor.stopCellEditing())
        return false;
    if (row < 0 || row >= getRowCount() || column < 0 || column >= getColumnCount())
        return false;
    if (!isCellEditable(row, column))
        return false;
    if (editorRemover == null) {
        KeyboardFocusManager fm = KeyboardFocusManager.getCurrentKeyboardFocusManager();
        editorRemover = new CellEditorRemover(fm);
        fm.addPropertyChangeListener("permanentFocusOwner", editorRemover);
    }
    TableCellEditor editor = getCellEditor(row, column);
    // remember the table row, because tableModel will disappear if
    // user click on open space on canvas, so we have to remember it before it is gone
    BrowserTableModel model = (BrowserTableModel) this.getModel();
    CyRow cyRow = model.getCyRow(convertRowIndexToModel(row));
    String columnName = model.getColumnName(convertColumnIndexToModel(column));
    editorRemover.setCellData(cyRow, columnName);
    if ((editor != null) && editor.isCellEditable(e)) {
        // Do this first so that the bounds of the JTextArea editor will be correct.
        setEditingRow(row);
        setEditingColumn(column);
        setCellEditor(editor);
        editor.addCellEditorListener(this);
        editorComp = prepareEditor(editor, row, column);
        if (editorComp == null) {
            removeEditor();
            return false;
        }
        Rectangle cellRect = getCellRect(row, column, false);
        if (editor instanceof MultiLineTableCellEditor) {
            Dimension prefSize = editorComp.getPreferredSize();
            ((JComponent) editorComp).putClientProperty(MultiLineTableCellEditor.UPDATE_BOUNDS, Boolean.TRUE);
            editorComp.setBounds(cellRect.x, cellRect.y, Math.max(cellRect.width, prefSize.width), Math.max(cellRect.height, prefSize.height));
            ((JComponent) editorComp).putClientProperty(MultiLineTableCellEditor.UPDATE_BOUNDS, Boolean.FALSE);
        } else {
            editorComp.setBounds(cellRect);
        }
        add(editorComp);
        editorComp.validate();
        return true;
    }
    return false;
}
Also used : Rectangle(java.awt.Rectangle) JComponent(javax.swing.JComponent) KeyboardFocusManager(java.awt.KeyboardFocusManager) TableCellEditor(javax.swing.table.TableCellEditor) ValidatedObjectAndEditString(org.cytoscape.browser.internal.util.ValidatedObjectAndEditString) Dimension(java.awt.Dimension) CyRow(org.cytoscape.model.CyRow)

Aggregations

TableCellEditor (javax.swing.table.TableCellEditor)129 JButton (javax.swing.JButton)41 ButtonEditor (jmri.util.table.ButtonEditor)33 ButtonRenderer (jmri.util.table.ButtonRenderer)33 TableColumnModel (javax.swing.table.TableColumnModel)24 JTable (javax.swing.JTable)22 ActionEvent (java.awt.event.ActionEvent)21 TableCellRenderer (javax.swing.table.TableCellRenderer)21 TableColumn (javax.swing.table.TableColumn)20 JLabel (javax.swing.JLabel)16 JScrollPane (javax.swing.JScrollPane)16 ActionListener (java.awt.event.ActionListener)15 MouseEvent (java.awt.event.MouseEvent)13 JPanel (javax.swing.JPanel)13 Component (java.awt.Component)11 Dimension (java.awt.Dimension)11 EventObject (java.util.EventObject)10 TableModel (javax.swing.table.TableModel)10 JComponent (javax.swing.JComponent)9 JTextField (javax.swing.JTextField)9