Search in sources :

Example 81 with TableCellRenderer

use of javax.swing.table.TableCellRenderer in project jgnash by ccavanaugh.

the class ExpandingTable method prepareRenderer.

/**
     * Override prepareRenderer instead of using a custom renderer so the look and feel is preserved
     *
     * @see javax.swing.JTable#prepareRenderer(javax.swing.table.TableCellRenderer, int, int)
     */
@SuppressWarnings("MagicConstant")
@Override
public Component prepareRenderer(final TableCellRenderer renderer, final int row, final int column) {
    Component c = super.prepareRenderer(renderer, row, column);
    if (c instanceof JLabel) {
        if (!defaultSaved.get()) {
            // save the defaults so they can be restored
            defaultForeground = c.getForeground();
            defaultAlignment = ((JLabel) c).getHorizontalAlignment();
            defaultSaved.set(true);
        }
        E object = model.get(row);
        if (column == 0) {
            c.setForeground(defaultForeground);
            ((JLabel) c).setHorizontalAlignment(SwingConstants.LEFT);
            if (object != null) {
                Icon cachedIcon;
                int indent = iconIndent * (model.getVisibleDepth(object) - 1);
                if (model.isParent(object)) {
                    if (model.isExpanded(object)) {
                        String key = "eo" + indent;
                        cachedIcon = iconCache.computeIfAbsent(key, k -> IconUtils.createImageIcon(new IndentedIcon(new Icon[] { expandedIcon, openIcon }, indent, iconSpacing)));
                    } else {
                        String key = "co" + indent;
                        cachedIcon = iconCache.computeIfAbsent(key, k -> IconUtils.createImageIcon(new IndentedIcon(new Icon[] { collapsedIcon, closedIcon }, indent, iconSpacing)));
                    }
                } else {
                    // child without children
                    String key = "el" + indent;
                    cachedIcon = iconCache.computeIfAbsent(key, k -> IconUtils.createImageIcon(new IndentedIcon(new Icon[] { new EmptyIndentedIcon(new Icon[] { expandedIcon }, 0), leafIcon }, indent, iconSpacing)));
                }
                ((JLabel) c).setIcon(cachedIcon);
            }
        } else {
            c.setForeground(defaultForeground);
            ((JLabel) c).setHorizontalAlignment(defaultAlignment);
            ((JLabel) c).setIcon(null);
        }
    }
    return c;
}
Also used : Color(java.awt.Color) EventQueue(java.awt.EventQueue) UIManager(javax.swing.UIManager) ThemeManager(jgnash.ui.ThemeManager) IconUtils(jgnash.ui.util.IconUtils) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Point(java.awt.Point) HashMap(java.util.HashMap) Icon(javax.swing.Icon) KeyAdapter(java.awt.event.KeyAdapter) KeyEvent(java.awt.event.KeyEvent) JTree(javax.swing.JTree) TableCellRenderer(javax.swing.table.TableCellRenderer) Component(java.awt.Component) SwingConstants(javax.swing.SwingConstants) MouseEvent(java.awt.event.MouseEvent) JLabel(javax.swing.JLabel) Map(java.util.Map) Graphics(java.awt.Graphics) MouseAdapter(java.awt.event.MouseAdapter) JTable(javax.swing.JTable) Toolkit(java.awt.Toolkit) JLabel(javax.swing.JLabel) Icon(javax.swing.Icon) Component(java.awt.Component) Point(java.awt.Point)

Example 82 with TableCellRenderer

use of javax.swing.table.TableCellRenderer in project cytoscape-api by cytoscape.

the class JTreeTable method getToolTipText.

/**
	 * The code in this method is copy and pasted from source code to the same
	 * method in javax.swing.JTable, except for one value change on one line. If
	 * you'd like to see the change, please read the source code below.
	 * @param event the mouse event we're reacting to
	 */
@Override
public String getToolTipText(MouseEvent event) {
    String tip = null;
    Point p = event.getPoint();
    // Locate the renderer under the event location
    int hitColumnIndex = columnAtPoint(p);
    int hitRowIndex = rowAtPoint(p);
    if ((hitColumnIndex != -1) && (hitRowIndex != -1)) {
        TableCellRenderer renderer = getCellRenderer(hitRowIndex, hitColumnIndex);
        Component component = prepareRenderer(renderer, hitRowIndex, hitColumnIndex);
        // getting the tip
        if (component instanceof JComponent) {
            // Convert the event to the renderer's coordinate system
            Rectangle cellRect = getCellRect(hitRowIndex, hitColumnIndex, false);
            // HERE IS THE MODIFICATION FROM javax.swing.JTable:
            // p.translate(-cellRect.x, -cellRect.y);
            p.translate(-cellRect.x, 0);
            // END OF MODIFICATION
            MouseEvent newEvent = new MouseEvent(component, event.getID(), event.getWhen(), event.getModifiers(), p.x, p.y, event.getClickCount(), event.isPopupTrigger());
            tip = ((JComponent) component).getToolTipText(newEvent);
        }
    }
    // No tip from the renderer get our own tip
    if (tip == null)
        tip = getToolTipText();
    return tip;
}
Also used : TableCellRenderer(javax.swing.table.TableCellRenderer) MouseEvent(java.awt.event.MouseEvent)

Example 83 with TableCellRenderer

use of javax.swing.table.TableCellRenderer in project processdash by dtuma.

the class TeamMemberListTable method setupTableColumnHeader.

/** Create and configure the column header for the table */
private void setupTableColumnHeader() {
    // do not allow columns to be reordered. (That wouldn't make sense for
    // our weekly data columns, which appear in chronological order.
    getTableHeader().setReorderingAllowed(false);
    // set the first few "fixed" columns to use a default header renderer,
    // and set their size to our predefined column widths.
    TableCellRenderer plainRenderer = getTableHeader().getDefaultRenderer();
    for (int i = 0; i < COL_WIDTHS.length; i++) {
        getColumnModel().getColumn(i).setHeaderRenderer(plainRenderer);
        fixWidth(getColumnModel().getColumn(i), COL_WIDTHS[i]);
    }
    getColumnModel().getColumn(0).setMinWidth(10);
    getColumnModel().getColumn(0).setMaxWidth(Integer.MAX_VALUE);
    // install a DateHeaderRenderer for all remaining columns, and
    // configure the height of the regular renderer to match.
    DateHeaderRenderer dateHeaderRenderer = new DateHeaderRenderer(this);
    getTableHeader().setDefaultRenderer(dateHeaderRenderer);
    if (plainRenderer instanceof JComponent) {
        JComponent jc = (JComponent) plainRenderer;
        jc.setPreferredSize(dateHeaderRenderer.getPreferredSize());
    }
}
Also used : TableCellRenderer(javax.swing.table.TableCellRenderer) DefaultTableCellRenderer(javax.swing.table.DefaultTableCellRenderer) JComponent(javax.swing.JComponent) Point(java.awt.Point)

Example 84 with TableCellRenderer

use of javax.swing.table.TableCellRenderer in project processdash by dtuma.

the class BlameValueTable method getPreferredCellWidth.

private int getPreferredCellWidth(int row, int column) {
    TableCellRenderer cellRenderer = getCellRenderer(row, column);
    Component c = prepareRenderer(cellRenderer, row, column);
    int width = c.getPreferredSize().width + getIntercellSpacing().width;
    return width;
}
Also used : TableCellRenderer(javax.swing.table.TableCellRenderer) Component(java.awt.Component)

Example 85 with TableCellRenderer

use of javax.swing.table.TableCellRenderer in project processdash by dtuma.

the class WBSExcelWriter method writeCellsForNodeData.

private void writeCellsForNodeData(HSSFRow row, WBSNode node, TableColumnModel columns) {
    for (int c = 0; c < columns.getColumnCount(); c++) {
        TableColumn col = columns.getColumn(c);
        int columnIndex = col.getModelIndex();
        Object value = data.getValueAt(node, columnIndex);
        TableCellRenderer rend = col.getCellRenderer();
        if (rend == null)
            rend = table.getDefaultRenderer(data.getColumnClass(columnIndex));
        Component comp = rend.getTableCellRendererComponent(table, value, false, false, 99, 99);
        HSSFCell cell = row.createCell(s(c + 1));
        copyCellData(cell, rend, comp, value);
    }
}
Also used : TableCellRenderer(javax.swing.table.TableCellRenderer) HSSFCell(org.apache.poi.hssf.usermodel.HSSFCell) Component(java.awt.Component) TableColumn(javax.swing.table.TableColumn)

Aggregations

TableCellRenderer (javax.swing.table.TableCellRenderer)85 Component (java.awt.Component)30 TableColumn (javax.swing.table.TableColumn)30 DefaultTableCellRenderer (javax.swing.table.DefaultTableCellRenderer)20 JComponent (javax.swing.JComponent)12 JTable (javax.swing.JTable)12 JTableHeader (javax.swing.table.JTableHeader)12 TableColumnModel (javax.swing.table.TableColumnModel)12 MouseEvent (java.awt.event.MouseEvent)10 ColumnInfo (com.intellij.util.ui.ColumnInfo)8 JLabel (javax.swing.JLabel)8 DefaultTableColumnModel (javax.swing.table.DefaultTableColumnModel)8 JButton (javax.swing.JButton)7 TableCellEditor (javax.swing.table.TableCellEditor)7 ActionEvent (java.awt.event.ActionEvent)6 MouseAdapter (java.awt.event.MouseAdapter)6 List (java.util.List)6 TableModel (javax.swing.table.TableModel)6 JTextField (javax.swing.JTextField)5 ActionListener (java.awt.event.ActionListener)4