Search in sources :

Example 56 with JTableHeader

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

the class MapperFrameOld method initializeComponents.

public void initializeComponents() {
    setSize(new java.awt.Dimension(1200, 800));
    mapperPanel = new MapperPanel(this);
    mapperPanel.setBorder(new BorderUIResource.EmptyBorderUIResource(new java.awt.Insets(12, 6, 12, 12)));
    traceTableModel = new TraceTableModel();
    traceTable = new JTable(traceTableModel);
    TableRenderer renderer = new TableRenderer(SwingConstants.LEFT, new Insets(0, 4, 0, 4));
    traceTable.getColumnModel().getColumn(0).setCellRenderer(renderer);
    traceTable.getColumnModel().getColumn(1).setPreferredWidth(50);
    traceTable.getColumnModel().getColumn(1).setCellRenderer(renderer);
    traceTable.getColumnModel().getColumn(2).setPreferredWidth(50);
    traceTable.getColumnModel().getColumn(2).setCellRenderer(renderer);
    traceTable.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
    traceTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() {

        public void valueChanged(ListSelectionEvent evt) {
            traceTableSelectionChanged();
        }
    });
    scrollPane1 = new JScrollPane(traceTable, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
    ActionPanel actionPanel1 = new ActionPanel(false);
    actionPanel1.setAddAction(getImportAction());
    actionPanel1.setRemoveAction(getRemoveTraceAction());
    getRemoveTraceAction().setEnabled(false);
    JPanel controlPanel1 = new JPanel(new FlowLayout(FlowLayout.LEFT));
    controlPanel1.add(actionPanel1);
    topPanel = new JPanel(new BorderLayout(0, 0));
    topPanel.setBorder(new BorderUIResource.EmptyBorderUIResource(new java.awt.Insets(0, 0, 6, 0)));
    topPanel.add(new JLabel("Trace Files:"), BorderLayout.NORTH);
    topPanel.add(scrollPane1, BorderLayout.CENTER);
    topPanel.add(controlPanel1, BorderLayout.SOUTH);
    layerTableModel = new LayerTableModel();
    layerTable = new JTable(layerTableModel) {

        //Implement table header tool tips.
        protected JTableHeader createDefaultTableHeader() {
            return new JTableHeader(columnModel) {

                public String getToolTipText(MouseEvent e) {
                    java.awt.Point p = e.getPoint();
                    int index = columnModel.getColumnIndexAtX(p.x);
                    int realIndex = columnModel.getColumn(index).getModelIndex();
                    return columnToolTips[realIndex];
                }
            };
        }
    };
    layerTable.getColumnModel().getColumn(0).setPreferredWidth(150);
    layerTable.getColumnModel().getColumn(0).setCellRenderer(renderer);
    layerTable.getColumnModel().getColumn(1).setPreferredWidth(70);
    layerTable.getColumnModel().getColumn(1).setCellRenderer(renderer);
    //        layerTable.getColumnModel().getColumn(2).setPreferredWidth(70);
    //        layerTable.getColumnModel().getColumn(2).setCellRenderer(renderer);
    //        ComboBoxRenderer comboBoxRenderer = new ComboBoxRenderer(TraceFactory.TraceType.values());
    //        comboBoxRenderer.putClientProperty("JComboBox.isTableCellEditor", Boolean.TRUE);
    //        layerTable.getColumnModel().getColumn(3).setPreferredWidth(20);
    //        layerTable.getColumnModel().getColumn(3).setCellRenderer(renderer);
    layerTable.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
    layerTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() {

        public void valueChanged(ListSelectionEvent evt) {
            layerTableSelectionChanged();
        }
    });
    TableEditorStopper.ensureEditingStopWhenTableLosesFocus(layerTable);
    JScrollPane scrollPane2 = new JScrollPane(layerTable, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
    JPanel bottomPanel = new JPanel(new BorderLayout(0, 0));
    bottomPanel.add(new JLabel("Layers:"), BorderLayout.NORTH);
    bottomPanel.add(scrollPane2, BorderLayout.CENTER);
    JPanel leftPanel = new JPanel(new BorderLayout(0, 0));
    leftPanel.setPreferredSize(new Dimension(400, 300));
    splitPane1 = new JSplitPane(JSplitPane.VERTICAL_SPLIT, true, topPanel, bottomPanel);
    splitPane1.setBorder(null);
    JPanel progressPanel = new JPanel(new BorderLayout(0, 0));
    progressLabel = new JLabel("");
    progressBar = new JProgressBar();
    progressPanel.add(progressLabel, BorderLayout.NORTH);
    progressPanel.add(progressBar, BorderLayout.CENTER);
    progressPanel.setBorder(new BorderUIResource.EmptyBorderUIResource(new java.awt.Insets(6, 0, 0, 0)));
    leftPanel.add(splitPane1, BorderLayout.CENTER);
    leftPanel.add(progressPanel, BorderLayout.SOUTH);
    leftPanel.setBorder(new BorderUIResource.EmptyBorderUIResource(new java.awt.Insets(12, 12, 12, 6)));
    JSplitPane splitPane2 = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, true, leftPanel, mapperPanel);
    splitPane2.setBorder(null);
    splitPane2.setDividerLocation(350);
    Color focusColor = UIManager.getColor("Focus.color");
    Border focusBorder = BorderFactory.createMatteBorder(2, 2, 2, 2, focusColor);
    splitPane1.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2));
    new FileDrop(null, splitPane1, focusBorder, new FileDrop.Listener() {

        public void filesDropped(java.io.File[] files) {
            importFiles(files);
        }
    });
    // end FileDrop.Listener
    getContentPane().setLayout(new java.awt.BorderLayout(0, 0));
    getContentPane().add(splitPane2, BorderLayout.CENTER);
    splitPane1.setDividerLocation(2000);
}
Also used : BorderUIResource(javax.swing.plaf.BorderUIResource) ListSelectionEvent(javax.swing.event.ListSelectionEvent) JTableHeader(javax.swing.table.JTableHeader) FileDrop(dr.app.gui.FileDrop) TableRenderer(jam.table.TableRenderer) MapperPanel(dr.app.mapper.application.mapper.MapperPanel) ListSelectionListener(javax.swing.event.ListSelectionListener) ActionPanel(jam.panels.ActionPanel) Border(javax.swing.border.Border) java.awt(java.awt)

Example 57 with JTableHeader

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

the class ColumnHeaderRenderer method getTableCellRendererComponent.

/**
 * {@inheritDoc}
 */
@Override
public Component getTableCellRendererComponent(final JTable table, final Object value, final boolean isSelected, final boolean hasFocus, final int row, final int column) {
    // set look and feel of a header
    if (table != null) {
        JTableHeader header = table.getTableHeader();
        if (header != null) {
            setForeground(header.getForeground());
            setBackground(header.getBackground());
            setFont(header.getFont());
        }
        if (table.isColumnSelected(column)) {
            Color bg = table.getSelectionBackground();
            setBackground(bg);
            setOpaque(true);
        } else {
            setOpaque(false);
        }
    }
    setBorder(UIManager.getBorder("TableHeader.cellBorder"));
    Icon typeIcon = null;
    Icon sortIcon = null;
    Object newValue = value;
    if (value instanceof DataColumnSpec) {
        DataColumnSpec colSpec = (DataColumnSpec) value;
        newValue = colSpec.getName();
        if (isShowIcon()) {
            typeIcon = colSpec.getType().getIcon();
        }
    }
    sortIcon = getSortIcon(table, column);
    if (typeIcon == null && sortIcon == null) {
        setIcon(null);
    } else {
        setIcon(new CompoundIcon(typeIcon, sortIcon));
    }
    setToolTipText(newValue != null ? newValue.toString() : null);
    setValue(newValue);
    return this;
}
Also used : DataColumnSpec(org.knime.core.data.DataColumnSpec) Color(java.awt.Color) JTableHeader(javax.swing.table.JTableHeader) Icon(javax.swing.Icon)

Example 58 with JTableHeader

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

the class TableContentView method onMouseClickInHeader.

/**
 * Invoked when a mouse event in the header occurs. This implementation
 * will create a popup menu when there is more than one renderer for that
 * column available and will also list all possible values in the column
 * where the mouse was clicked (as it is provided in the column spec).
 * The event's source is the table header
 *
 * @param e the mouse event in the table header
 */
protected void onMouseClickInHeader(final MouseEvent e) {
    JTableHeader header = getTableHeader();
    // get column in which event occurred
    int columnInView = header.columnAtPoint(e.getPoint());
    if (columnInView < 0) {
        // outside columns
        return;
    }
    Rectangle recOfColumn = header.getHeaderRect(columnInView);
    int horizPos = e.getX() - recOfColumn.x;
    assert (horizPos >= 0);
    if (SwingUtilities.isRightMouseButton(e)) {
        // right click in header.
        final JPopupMenu popup = getPopUpMenu(columnInView);
        if (popup.getSubElements().length > 0) {
            // only if it has content
            popup.show(header, e.getX(), e.getY());
        }
    } else if (e.isControlDown() && getContentModel().isSortingAllowed()) {
        // control pressed.
        onSortRequest(convertColumnIndexToModel(columnInView), null);
    } else if (SwingUtilities.isLeftMouseButton(e) && getContentModel().isSortingAllowed()) {
        // left click in header.
        TableSortOrder sortOrder = null;
        int colIndexInModel = -1;
        TableModel model = getModel();
        if (model instanceof TableContentModel) {
            TableContentModel cntModel = (TableContentModel) model;
            sortOrder = cntModel.getTableSortOrder();
            colIndexInModel = convertColumnIndexToModel(columnInView);
        } else if (model instanceof TableRowHeaderModel) {
            TableRowHeaderModel rowHeaderModel = (TableRowHeaderModel) model;
            TableContentInterface cntIface = rowHeaderModel.getTableContent();
            if (cntIface instanceof TableContentModel) {
                TableContentModel cntModel = (TableContentModel) cntIface;
                sortOrder = cntModel.getTableSortOrder();
                colIndexInModel = -1;
            }
        }
        TableSortKey sortKey;
        if (sortOrder == null) {
            sortKey = TableSortKey.NONE;
        } else {
            sortKey = sortOrder.getSortKeyForColumn(colIndexInModel);
        }
        final JPopupMenu popup = createSortPopupMenu(columnInView, sortKey);
        popup.show(header, e.getX(), e.getY());
    }
}
Also used : TableSortKey(org.knime.core.node.tableview.TableSortOrder.TableSortKey) Rectangle(java.awt.Rectangle) JTableHeader(javax.swing.table.JTableHeader) JPopupMenu(javax.swing.JPopupMenu) TableModel(javax.swing.table.TableModel)

Example 59 with JTableHeader

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

the class TableContentView method tableChanged.

/**
 * {@inheritDoc}
 */
@Override
public void tableChanged(final TableModelEvent e) {
    super.tableChanged(e);
    if (e == null || e.getFirstRow() == TableModelEvent.HEADER_ROW) {
        int bestRowHeight = fitCellSizeToRenderer();
        if (bestRowHeight != getRowHeight()) {
            firePropertyChange("requestRowHeight", getRowHeight(), bestRowHeight);
        }
    }
    final JTableHeader header = getTableHeader();
    if (header != null) {
        // update sort icons
        header.repaint();
    }
}
Also used : JTableHeader(javax.swing.table.JTableHeader)

Example 60 with JTableHeader

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

the class AbstractCorrelationComputeNodeView method changeRenderer.

/**
 * @param renderer the table's new renderer
 */
protected 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());
            }
            m_tableView.setColumnHeaderViewHeight(-1);
        } 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)

Aggregations

JTableHeader (javax.swing.table.JTableHeader)61 TableCellRenderer (javax.swing.table.TableCellRenderer)18 JTable (javax.swing.JTable)15 Component (java.awt.Component)13 TableColumn (javax.swing.table.TableColumn)12 TableColumnModel (javax.swing.table.TableColumnModel)12 JLabel (javax.swing.JLabel)11 DefaultTableCellRenderer (javax.swing.table.DefaultTableCellRenderer)8 JComponent (javax.swing.JComponent)7 JScrollPane (javax.swing.JScrollPane)7 BorderLayout (java.awt.BorderLayout)6 MouseEvent (java.awt.event.MouseEvent)6 JPopupMenu (javax.swing.JPopupMenu)6 MouseAdapter (java.awt.event.MouseAdapter)5 JButton (javax.swing.JButton)5 JPanel (javax.swing.JPanel)5 JCheckBoxMenuItem (javax.swing.JCheckBoxMenuItem)4 DefaultTableColumnModel (javax.swing.table.DefaultTableColumnModel)4 FormLayout (com.jgoodies.forms.layout.FormLayout)3 WindowAdapter (java.awt.event.WindowAdapter)3