Search in sources :

Example 41 with TableCellRenderer

use of javax.swing.table.TableCellRenderer in project MassBank-web by MassBank.

the class TableSorter method setTableHeader.

public void setTableHeader(JTableHeader tableHeader) {
    if (this.tableHeader != null) {
        this.tableHeader.removeMouseListener(mouseListener);
        TableCellRenderer defaultRenderer = this.tableHeader.getDefaultRenderer();
        if (defaultRenderer instanceof SortableHeaderRenderer) {
            this.tableHeader.setDefaultRenderer(((SortableHeaderRenderer) defaultRenderer).tableCellRenderer);
        }
    }
    this.tableHeader = tableHeader;
    if (this.tableHeader != null) {
        this.tableHeader.addMouseListener(mouseListener);
        this.tableHeader.setDefaultRenderer(new SortableHeaderRenderer(this.tableHeader.getDefaultRenderer()));
    }
}
Also used : TableCellRenderer(javax.swing.table.TableCellRenderer)

Example 42 with TableCellRenderer

use of javax.swing.table.TableCellRenderer in project knime-core by knime.

the class RuleEngine2PortsSimpleNodeDialog method createSettingsPanel.

/**
 * @param settingsType The kind of the dialog.
 * @return The "Settings" panel.
 */
protected JPanel createSettingsPanel(final RuleNodeSettings settingsType) {
    JPanel panel = new JPanel(new GridBagLayout());
    GridBagConstraints gbc = new GridBagConstraints();
    gbc.ipadx = 4;
    gbc.ipady = 4;
    gbc.insets = new Insets(1, 2, 0, 2);
    gbc.fill = GridBagConstraints.HORIZONTAL;
    gbc.gridx = 0;
    gbc.gridy = 0;
    gbc.gridwidth = 1;
    gbc.weightx = 0;
    panel.add(new JLabel("Rules column:"), gbc);
    gbc.gridx++;
    gbc.weightx = 1;
    panel.add(m_ruleColumn, gbc);
    gbc.gridx++;
    gbc.weightx = 0;
    panel.add(new JLabel("=>"), gbc);
    gbc.gridx++;
    gbc.weightx = 1;
    panel.add(m_outcomeColumn, gbc);
    gbc.weightx = 0;
    gbc.gridx++;
    panel.add(m_outcomeType, gbc);
    gbc.gridy++;
    gbc.gridx--;
    panel.add(m_treatOutcomesWithDollarAsReferences, gbc);
    gbc.gridx = 0;
    gbc.gridy++;
    gbc.gridwidth = 1;
    addAppendOrReplace(panel, gbc);
    gbc.gridx = 0;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    gbc.weighty = 1;
    gbc.gridwidth = 5;
    m_errorPanel = new JScrollPane(m_errors);
    m_errorPanel.setBorder(new TitledBorder("Errors"));
    panel.add(m_errorPanel, gbc);
    panel.add(m_noErrors, gbc);
    m_errors.getColumnModel().getColumn(0).setMaxWidth(1000);
    m_errors.getColumnModel().getColumn(0).setPreferredWidth(44);
    final TableColumn contentColumn = m_errors.getColumnModel().getColumn(1);
    final DefaultTableCellRenderer origRenderer = new DefaultTableCellRenderer();
    contentColumn.setCellRenderer(new TableCellRenderer() {

        @Override
        public Component getTableCellRendererComponent(final JTable table, final Object value, final boolean isSelected, final boolean hasFocus, final int row, final int column) {
            Component ret = origRenderer.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
            if (value instanceof MissingValue) {
                MissingValue mv = (MissingValue) value;
                if (ret instanceof JLabel) {
                    JLabel retLabel = (JLabel) ret;
                    retLabel.setText(mv.getError());
                }
                ret.setBackground(Color.RED);
            }
            return ret;
        }
    });
    gbc.gridy++;
    gbc.weighty = 0;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    JScrollPane warningPanel = new JScrollPane(m_warnings);
    warningPanel.setBorder(new TitledBorder("Warnings"));
    m_warnings.setFont(UIManager.getFont("TextField.font"));
    panel.add(warningPanel, gbc);
    return panel;
}
Also used : JScrollPane(javax.swing.JScrollPane) JPanel(javax.swing.JPanel) TableCellRenderer(javax.swing.table.TableCellRenderer) DefaultTableCellRenderer(javax.swing.table.DefaultTableCellRenderer) GridBagConstraints(java.awt.GridBagConstraints) Insets(java.awt.Insets) GridBagLayout(java.awt.GridBagLayout) MissingValue(org.knime.core.data.MissingValue) JLabel(javax.swing.JLabel) TitledBorder(javax.swing.border.TitledBorder) TableColumn(javax.swing.table.TableColumn) DefaultTableCellRenderer(javax.swing.table.DefaultTableCellRenderer) JTable(javax.swing.JTable) PortObject(org.knime.core.node.port.PortObject) Component(java.awt.Component)

Example 43 with TableCellRenderer

use of javax.swing.table.TableCellRenderer in project knime-core by knime.

the class RankCorrelationComputeNodeView method changeRenderer.

private void changeRenderer(final String renderer) {
    TableContentView tcv = m_tableView.getContentTable();
    tcv.changeRenderer(DoubleCell.TYPE, renderer);
    Component c = m_tableView.getCorner(ScrollPaneConstants.UPPER_LEFT_CORNER);
    LegendCornerAll cornerRenderer = null;
    if (c instanceof JTableHeader) {
        JTableHeader corner = (JTableHeader) c;
        TableCellRenderer ren = corner.getDefaultRenderer();
        if (ren instanceof LegendCornerAll) {
            cornerRenderer = (LegendCornerAll) ren;
        }
    }
    if (cornerRenderer != null) {
        if (renderer.equals(ColorRender.DESCRIPTION)) {
            cornerRenderer.setPaintLegend(true);
            // no need to set column header height, done by label UI
            tcv.setColumnWidth(15);
            TableCellRenderer r = m_tableView.getContentTable().getTableHeader().getDefaultRenderer();
            if (r instanceof JLabel) {
                ((JLabel) r).setUI(new VerticalLabelUI());
            }
        } else {
            cornerRenderer.setPaintLegend(false);
            m_tableView.setColumnHeaderViewHeight(16);
            tcv.setColumnWidth(75);
            TableCellRenderer r = m_tableView.getContentTable().getTableHeader().getDefaultRenderer();
            if (r instanceof JLabel) {
                ((JLabel) r).updateUI();
            }
        }
    }
    m_currentRendererID = renderer;
}
Also used : TableCellRenderer(javax.swing.table.TableCellRenderer) DefaultTableCellRenderer(javax.swing.table.DefaultTableCellRenderer) JTableHeader(javax.swing.table.JTableHeader) JLabel(javax.swing.JLabel) TableContentView(org.knime.core.node.tableview.TableContentView) Component(java.awt.Component) JComponent(javax.swing.JComponent)

Example 44 with TableCellRenderer

use of javax.swing.table.TableCellRenderer in project knime-core by knime.

the class OutFieldsTable method updateData.

/**
 * Set the table data.
 *
 * @param fields the fields
 * @param spec the input spec
 * @param flowVars the flow variables
 */
void updateData(final JavaSnippetFields fields, final DataTableSpec spec, final Map<String, FlowVariable> flowVars) {
    m_spec = spec;
    m_flowVars = flowVars;
    m_model.clear();
    fields.getOutColFields().forEach(field -> addRow(field));
    fields.getOutVarFields().forEach(field -> addRow(field));
    /*
         * There is no simple way of disabling a boolean cell renderer if the cell is not editable.
         *
         * Hence, here we wrap the hidden Default BooleanRenderer and disable if not editable.
         */
    final TableCellRenderer boolRenderer = new TableCellRenderer() {

        @Override
        public Component getTableCellRendererComponent(final JTable table, final Object value, final boolean isSelected, final boolean hasFocus, final int row, final int column) {
            final Component c = table.getDefaultRenderer(Boolean.class).getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
            c.setEnabled(table.isCellEditable(row, column));
            return c;
        }
    };
    final TableColumnModel columnModel = getTable().getColumnModel();
    columnModel.getColumn(m_model.getIndex(Column.REPLACE_EXISTING)).setCellEditor(new DefaultCellEditor(new JCheckBox()));
    columnModel.getColumn(m_model.getIndex(Column.REPLACE_EXISTING)).setCellRenderer(boolRenderer);
    if (!m_flowVarsOnly) {
        // Field type column does not exist for flowVarsOnly
        columnModel.getColumn(m_model.getIndex(Column.FIELD_TYPE)).setCellEditor(createFieldTypeCellEditor());
    }
    columnModel.getColumn(m_model.getIndex(Column.COLUMN)).setCellRenderer(new InputTableCellRenderer());
    columnModel.getColumn(m_model.getIndex(Column.COLUMN)).setCellEditor(new InputTableCellEditor(this, m_spec, m_flowVars));
    columnModel.getColumn(m_model.getIndex(Column.DATA_TYPE)).setCellRenderer(new DataTypeTableCellRenderer());
    columnModel.getColumn(m_model.getIndex(Column.DATA_TYPE)).setCellEditor(new DataTypeTableCellEditor(this, m_spec, m_flowVars));
    if (!m_flowVarsOnly) {
        // Field type column does not exist for flowVarsOnly
        columnModel.getColumn(m_model.getIndex(Column.IS_COLLECTION)).setCellEditor(new DefaultCellEditor(new JCheckBox()));
        columnModel.getColumn(m_model.getIndex(Column.IS_COLLECTION)).setCellRenderer(boolRenderer);
    }
    columnModel.getColumn(m_model.getIndex(Column.JAVA_TYPE)).setCellRenderer(FieldsTableUtil.createJavaTypeTableCellRenderer());
    columnModel.getColumn(m_model.getIndex(Column.JAVA_TYPE)).setCellEditor(FieldsTableUtil.createJavaTypeTableCellEditor());
    columnModel.getColumn(m_model.getIndex(Column.JAVA_FIELD)).setCellRenderer(FieldsTableUtil.createJavaFieldTableCellRenderer());
}
Also used : JCheckBox(javax.swing.JCheckBox) FlowVariableTableCellRenderer(org.knime.core.node.util.FlowVariableTableCellRenderer) TableCellRenderer(javax.swing.table.TableCellRenderer) JTable(javax.swing.JTable) TableColumnModel(javax.swing.table.TableColumnModel) Component(java.awt.Component) DefaultCellEditor(javax.swing.DefaultCellEditor)

Example 45 with TableCellRenderer

use of javax.swing.table.TableCellRenderer in project knime-core by knime.

the class TableContentView method setWrapColumnHeader.

// hiliteSelected()
/**
 * Should the column header names be wrapped if they are too long. Default is false.
 * @param value New value. If set, it makes sense to also set
 * {@link TableView#setColumnHeaderResizingAllowed(boolean)} to true.
 * @since 2.8
 */
public final void setWrapColumnHeader(final boolean value) {
    if (value != m_isWrapHeader) {
        m_isWrapHeader = value;
        JTableHeader header = getTableHeader();
        if (header == null) {
            return;
        }
        TableCellRenderer r = header.getDefaultRenderer();
        if (r instanceof ColumnHeaderRenderer) {
            ColumnHeaderRenderer cr = (ColumnHeaderRenderer) r;
            cr.setWrapHeader(value);
        }
    }
}
Also used : TableCellRenderer(javax.swing.table.TableCellRenderer) JTableHeader(javax.swing.table.JTableHeader)

Aggregations

TableCellRenderer (javax.swing.table.TableCellRenderer)122 TableColumn (javax.swing.table.TableColumn)50 Component (java.awt.Component)47 DefaultTableCellRenderer (javax.swing.table.DefaultTableCellRenderer)24 JComponent (javax.swing.JComponent)20 JTable (javax.swing.JTable)20 TableColumnModel (javax.swing.table.TableColumnModel)18 JLabel (javax.swing.JLabel)17 JTableHeader (javax.swing.table.JTableHeader)17 MouseEvent (java.awt.event.MouseEvent)11 ColumnInfo (com.intellij.util.ui.ColumnInfo)8 ActionEvent (java.awt.event.ActionEvent)8 JButton (javax.swing.JButton)8 DefaultTableColumnModel (javax.swing.table.DefaultTableColumnModel)8 MouseAdapter (java.awt.event.MouseAdapter)7 TableCellEditor (javax.swing.table.TableCellEditor)7 TableModel (javax.swing.table.TableModel)7 ActionListener (java.awt.event.ActionListener)6 List (java.util.List)6 JPanel (javax.swing.JPanel)6