Search in sources :

Example 1 with TreeCellRenderer

use of javax.swing.tree.TreeCellRenderer in project checkstyle by checkstyle.

the class TreeTableCellRenderer method updateUI.

/**
     * UpdateUI is overridden to set the colors of the Tree's renderer
     * to match that of the table.
     */
@Override
public void updateUI() {
    super.updateUI();
    // Make the tree's cell renderer use the table's cell selection
    // colors.
    final TreeCellRenderer tcr = getCellRenderer();
    if (tcr instanceof DefaultTreeCellRenderer) {
        final DefaultTreeCellRenderer renderer = (DefaultTreeCellRenderer) tcr;
        // For 1.1 uncomment this, 1.2 has a bug that will cause an
        // exception to be thrown if the border selection color is
        // null.
        // renderer.setBorderSelectionColor(null);
        renderer.setTextSelectionColor(UIManager.getColor("Table.selectionForeground"));
        renderer.setBackgroundSelectionColor(UIManager.getColor("Table.selectionBackground"));
    }
}
Also used : TreeCellRenderer(javax.swing.tree.TreeCellRenderer) DefaultTreeCellRenderer(javax.swing.tree.DefaultTreeCellRenderer) DefaultTreeCellRenderer(javax.swing.tree.DefaultTreeCellRenderer)

Example 2 with TreeCellRenderer

use of javax.swing.tree.TreeCellRenderer in project groovy-core by groovy.

the class ClosureRenderer method render.

private Component render() {
    if (children.isEmpty() || defaultRenderer) {
        defaultRenderer = true;
        children.clear();
        if (table != null) {
            TableCellRenderer tcr;
            if (tableHeader) {
                tcr = table.getTableHeader().getDefaultRenderer();
            } else {
                tcr = table.getDefaultRenderer(table.getColumnClass(column));
            }
            children.add(tcr.getTableCellRendererComponent(table, value, selected, focused, row, column));
        } else if (tree != null) {
            TreeCellRenderer tcr;
            tcr = new DefaultTreeCellRenderer();
            children.add(tcr.getTreeCellRendererComponent(tree, value, selected, expanded, leaf, row, focused));
        } else if (list != null) {
            ListCellRenderer lcr = (ListCellRenderer) UIManager.get("List.cellRenderer");
            if (lcr == null) {
                lcr = new DefaultListCellRenderer();
            }
            children.add(lcr.getListCellRendererComponent(list, value, row, selected, focused));
        }
    }
    Object o = update.call();
    if (o instanceof Component) {
        return (Component) o;
    } else {
        return (Component) children.get(0);
    }
}
Also used : TreeCellRenderer(javax.swing.tree.TreeCellRenderer) DefaultTreeCellRenderer(javax.swing.tree.DefaultTreeCellRenderer) TableCellRenderer(javax.swing.table.TableCellRenderer) DefaultTreeCellRenderer(javax.swing.tree.DefaultTreeCellRenderer)

Example 3 with TreeCellRenderer

use of javax.swing.tree.TreeCellRenderer in project intellij-community by JetBrains.

the class MavenUIUtil method installCheckboxRenderer.

public static void installCheckboxRenderer(final SimpleTree tree, final CheckboxHandler handler) {
    final JCheckBox checkbox = new JCheckBox();
    final JPanel panel = new JPanel(new BorderLayout());
    panel.add(checkbox, BorderLayout.WEST);
    final TreeCellRenderer baseRenderer = tree.getCellRenderer();
    tree.setCellRenderer(new TreeCellRenderer() {

        public Component getTreeCellRendererComponent(final JTree tree, final Object value, final boolean selected, final boolean expanded, final boolean leaf, final int row, final boolean hasFocus) {
            final Component baseComponent = baseRenderer.getTreeCellRendererComponent(tree, value, selected, expanded, leaf, row, hasFocus);
            final Object userObject = ((DefaultMutableTreeNode) value).getUserObject();
            if (!handler.isVisible(userObject)) {
                return baseComponent;
            }
            final Color foreground = selected ? UIUtil.getTreeSelectionForeground() : UIUtil.getTreeTextForeground();
            Color background = selected ? UIUtil.getTreeSelectionBackground(hasFocus) : UIUtil.getTreeTextBackground();
            panel.add(baseComponent, BorderLayout.CENTER);
            panel.setBackground(background);
            panel.setForeground(foreground);
            CheckBoxState state = handler.getState(userObject);
            checkbox.setSelected(state != CheckBoxState.UNCHECKED);
            checkbox.setEnabled(state != CheckBoxState.PARTIAL);
            checkbox.setBackground(background);
            checkbox.setForeground(foreground);
            return panel;
        }
    });
    tree.addMouseListener(new MouseAdapter() {

        public void mousePressed(MouseEvent e) {
            int row = tree.getRowForLocation(e.getX(), e.getY());
            if (row >= 0) {
                TreePath path = tree.getPathForRow(row);
                if (!isCheckboxEnabledFor(path, handler))
                    return;
                Rectangle checkBounds = checkbox.getBounds();
                checkBounds.setLocation(tree.getRowBounds(row).getLocation());
                if (checkBounds.contains(e.getPoint())) {
                    handler.toggle(path, e);
                    e.consume();
                    tree.setSelectionRow(row);
                }
            }
        }
    });
    tree.addKeyListener(new KeyAdapter() {

        public void keyPressed(KeyEvent e) {
            if (e.getKeyCode() == KeyEvent.VK_SPACE) {
                TreePath[] treePaths = tree.getSelectionPaths();
                if (treePaths != null) {
                    for (TreePath treePath : treePaths) {
                        if (!isCheckboxEnabledFor(treePath, handler))
                            continue;
                        handler.toggle(treePath, e);
                    }
                    e.consume();
                }
            }
        }
    });
}
Also used : TreeCellRenderer(javax.swing.tree.TreeCellRenderer) TreePath(javax.swing.tree.TreePath)

Example 4 with TreeCellRenderer

use of javax.swing.tree.TreeCellRenderer in project intellij-community by JetBrains.

the class TreeTableTree method updateUI.

public void updateUI() {
    super.updateUI();
    TreeCellRenderer tcr = super.getCellRenderer();
    if (tcr instanceof DefaultTreeCellRenderer) {
        DefaultTreeCellRenderer dtcr = (DefaultTreeCellRenderer) tcr;
        dtcr.setTextSelectionColor(UIUtil.getTableSelectionForeground());
        dtcr.setBackgroundSelectionColor(UIUtil.getTableSelectionBackground());
    }
}
Also used : TreeCellRenderer(javax.swing.tree.TreeCellRenderer) DefaultTreeCellRenderer(javax.swing.tree.DefaultTreeCellRenderer) DefaultTreeCellRenderer(javax.swing.tree.DefaultTreeCellRenderer)

Example 5 with TreeCellRenderer

use of javax.swing.tree.TreeCellRenderer in project intellij-community by JetBrains.

the class MultilineTreeCellRenderer method installRenderer.

public static JScrollPane installRenderer(final JTree tree, final MultilineTreeCellRenderer renderer) {
    final TreeCellRenderer defaultRenderer = tree.getCellRenderer();
    JScrollPane scrollpane = new JBScrollPane(tree) {

        private int myAddRemoveCounter = 0;

        private boolean myShouldResetCaches = false;

        public void setSize(Dimension d) {
            boolean isChanged = getWidth() != d.width || myShouldResetCaches;
            super.setSize(d);
            if (isChanged)
                resetCaches();
        }

        public void reshape(int x, int y, int w, int h) {
            boolean isChanged = w != getWidth() || myShouldResetCaches;
            super.reshape(x, y, w, h);
            if (isChanged)
                resetCaches();
        }

        private void resetCaches() {
            resetHeightCache(tree, defaultRenderer, renderer);
            myShouldResetCaches = false;
        }

        public void addNotify() {
            //To change body of overriden methods use Options | File Templates.
            super.addNotify();
            if (myAddRemoveCounter == 0)
                myShouldResetCaches = true;
            myAddRemoveCounter++;
        }

        public void removeNotify() {
            //To change body of overriden methods use Options | File Templates.
            super.removeNotify();
            myAddRemoveCounter--;
        }
    };
    scrollpane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
    scrollpane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
    tree.setCellRenderer(renderer);
    scrollpane.addComponentListener(new ComponentAdapter() {

        public void componentResized(ComponentEvent e) {
            resetHeightCache(tree, defaultRenderer, renderer);
        }

        public void componentShown(ComponentEvent e) {
            // componentResized not called when adding to opened tool window.
            // Seems to be BUG#4765299, however I failed to create same code to reproduce it.
            // To reproduce it with IDEA: 1. remove this method, 2. Start any Ant task, 3. Keep message window open 4. start Ant task again.
            resetHeightCache(tree, defaultRenderer, renderer);
        }
    });
    return scrollpane;
}
Also used : TreeCellRenderer(javax.swing.tree.TreeCellRenderer) ComponentEvent(java.awt.event.ComponentEvent) JBScrollPane(com.intellij.ui.components.JBScrollPane) ComponentAdapter(java.awt.event.ComponentAdapter)

Aggregations

TreeCellRenderer (javax.swing.tree.TreeCellRenderer)14 DefaultTreeCellRenderer (javax.swing.tree.DefaultTreeCellRenderer)7 TreePath (javax.swing.tree.TreePath)4 ComponentAdapter (java.awt.event.ComponentAdapter)2 ComponentEvent (java.awt.event.ComponentEvent)2 TableCellRenderer (javax.swing.table.TableCellRenderer)2 CompilerOptionInfo (com.intellij.flex.model.bc.CompilerOptionInfo)1 ValueSource (com.intellij.flex.model.bc.ValueSource)1 DetailsComponent (com.intellij.openapi.ui.DetailsComponent)1 JBScrollPane (com.intellij.ui.components.JBScrollPane)1 TreeTableView (com.intellij.ui.dualView.TreeTableView)1 TableView (com.intellij.ui.table.TableView)1 TableViewModel (com.intellij.util.ui.TableViewModel)1 Color (java.awt.Color)1 Insets (java.awt.Insets)1 Rectangle (java.awt.Rectangle)1 Enumeration (java.util.Enumeration)1 UIResource (javax.swing.plaf.UIResource)1 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)1 DefaultTreeCellEditor (javax.swing.tree.DefaultTreeCellEditor)1