Search in sources :

Example 6 with BasicTreeUI

use of javax.swing.plaf.basic.BasicTreeUI in project intellij-community by JetBrains.

the class XDebuggerTreeRenderer method customizeCellRenderer.

public void customizeCellRenderer(@NotNull final JTree tree, final Object value, final boolean selected, final boolean expanded, final boolean leaf, final int row, final boolean hasFocus) {
    myHaveLink = false;
    myLink.getTreeCellRendererComponent(tree, value, selected, expanded, leaf, row, hasFocus);
    XDebuggerTreeNode node = (XDebuggerTreeNode) value;
    node.appendToComponent(this);
    setIcon(node.getIcon());
    Rectangle treeVisibleRect = tree.getParent() instanceof JViewport ? ((JViewport) tree.getParent()).getViewRect() : tree.getVisibleRect();
    TreePath path = tree.getPathForRow(row);
    int rowX = path != null ? getRowX((BasicTreeUI) tree.getUI(), row, path.getPathCount() - 1) : 0;
    if (myHaveLink) {
        setupLinkDimensions(treeVisibleRect, rowX);
    } else {
        int visibleRectRightX = treeVisibleRect.x + treeVisibleRect.width;
        int notFittingWidth = rowX + super.getPreferredSize().width - visibleRectRightX;
        if (node instanceof XValueNodeImpl && notFittingWidth > 0) {
            // text does not fit visible area - show link
            String rawValue = DebuggerUIUtil.getNodeRawValue((XValueNodeImpl) node);
            if (!StringUtil.isEmpty(rawValue) && tree.isShowing()) {
                Point treeRightSideOnScreen = new Point(visibleRectRightX, 0);
                SwingUtilities.convertPointToScreen(treeRightSideOnScreen, tree);
                Rectangle screen = ScreenUtil.getScreenRectangle(treeRightSideOnScreen);
                // text may fit the screen in ExpandableItemsHandler
                if (screen.x + screen.width < treeRightSideOnScreen.x + notFittingWidth) {
                    myLongTextLink.setupComponent(rawValue, ((XDebuggerTree) tree).getProject());
                    append(myLongTextLink.getLinkText(), myLongTextLink.getTextAttributes(), myLongTextLink);
                    setupLinkDimensions(treeVisibleRect, rowX);
                    myLinkWidth = 0;
                }
            }
        }
    }
    putClientProperty(ExpandableItemsHandler.RENDERER_DISABLED, myHaveLink);
}
Also used : TreePath(javax.swing.tree.TreePath) XValueNodeImpl(com.intellij.xdebugger.impl.ui.tree.nodes.XValueNodeImpl) BasicTreeUI(javax.swing.plaf.basic.BasicTreeUI) XDebuggerTreeNode(com.intellij.xdebugger.impl.ui.tree.nodes.XDebuggerTreeNode)

Example 7 with BasicTreeUI

use of javax.swing.plaf.basic.BasicTreeUI in project intellij-community by JetBrains.

the class TreeUtil method getExpandControlRange.

@Nullable
public static Range<Integer> getExpandControlRange(@NotNull final JTree aTree, @Nullable final TreePath path) {
    TreeModel treeModel = aTree.getModel();
    final BasicTreeUI basicTreeUI = (BasicTreeUI) aTree.getUI();
    Icon expandedIcon = basicTreeUI.getExpandedIcon();
    Range<Integer> box = null;
    if (path != null && !treeModel.isLeaf(path.getLastPathComponent())) {
        int boxWidth;
        Insets i = aTree.getInsets();
        if (expandedIcon != null) {
            boxWidth = expandedIcon.getIconWidth();
        } else {
            boxWidth = 8;
        }
        int boxLeftX = i != null ? i.left : 0;
        boolean leftToRight = aTree.getComponentOrientation().isLeftToRight();
        int depthOffset = getDepthOffset(aTree);
        int totalChildIndent = basicTreeUI.getLeftChildIndent() + basicTreeUI.getRightChildIndent();
        if (leftToRight) {
            boxLeftX += (path.getPathCount() + depthOffset - 2) * totalChildIndent + basicTreeUI.getLeftChildIndent() - boxWidth / 2;
        }
        int boxRightX = boxLeftX + boxWidth;
        box = new Range<>(boxLeftX, boxRightX);
    }
    return box;
}
Also used : BasicTreeUI(javax.swing.plaf.basic.BasicTreeUI) RelativePoint(com.intellij.ui.awt.RelativePoint) Nullable(org.jetbrains.annotations.Nullable)

Example 8 with BasicTreeUI

use of javax.swing.plaf.basic.BasicTreeUI in project intellij-community by JetBrains.

the class SimpleTree method getBoxWidth.

private static int getBoxWidth(JTree tree) {
    BasicTreeUI basicTreeUI = (BasicTreeUI) tree.getUI();
    int boxWidth;
    if (basicTreeUI.getExpandedIcon() != null) {
        boxWidth = basicTreeUI.getExpandedIcon().getIconWidth();
    } else {
        boxWidth = 8;
    }
    return boxWidth;
}
Also used : BasicTreeUI(javax.swing.plaf.basic.BasicTreeUI)

Example 9 with BasicTreeUI

use of javax.swing.plaf.basic.BasicTreeUI in project intellij-community by JetBrains.

the class Tree method paintNodeContent.

private void paintNodeContent(Graphics g) {
    if (!(getUI() instanceof BasicTreeUI))
        return;
    final AbstractTreeBuilder builder = AbstractTreeBuilder.getBuilderFor(this);
    if (builder == null || builder.isDisposed())
        return;
    GraphicsConfig config = new GraphicsConfig(g);
    config.setAntialiasing(true);
    final AbstractTreeStructure structure = builder.getTreeStructure();
    for (int eachRow = 0; eachRow < getRowCount(); eachRow++) {
        final TreePath path = getPathForRow(eachRow);
        PresentableNodeDescriptor node = toPresentableNode(path.getLastPathComponent());
        if (node == null)
            continue;
        if (!node.isContentHighlighted())
            continue;
        if (highlightSingleNode()) {
            if (node.isContentHighlighted()) {
                final TreePath nodePath = getPath(node);
                Rectangle rect;
                final Rectangle parentRect = getPathBounds(nodePath);
                if (isExpanded(nodePath)) {
                    final int[] max = getMax(node, structure);
                    rect = new Rectangle(parentRect.x, parentRect.y, Math.max((int) parentRect.getMaxX(), max[1]) - parentRect.x - 1, Math.max((int) parentRect.getMaxY(), max[0]) - parentRect.y - 1);
                } else {
                    rect = parentRect;
                }
                if (rect != null) {
                    final Color highlightColor = node.getHighlightColor();
                    g.setColor(highlightColor);
                    g.fillRoundRect(rect.x, rect.y, rect.width, rect.height, 4, 4);
                    g.setColor(highlightColor.darker());
                    g.drawRoundRect(rect.x, rect.y, rect.width, rect.height, 4, 4);
                }
            }
        } else {
            //todo: to investigate why it might happen under 1.6: http://www.productiveme.net:8080/browse/PM-217
            if (node.getParentDescriptor() == null)
                continue;
            final Object[] kids = structure.getChildElements(node);
            if (kids.length == 0)
                continue;
            PresentableNodeDescriptor first = null;
            PresentableNodeDescriptor last = null;
            int lastIndex = -1;
            for (int i = 0; i < kids.length; i++) {
                final Object kid = kids[i];
                if (kid instanceof PresentableNodeDescriptor) {
                    PresentableNodeDescriptor eachKid = (PresentableNodeDescriptor) kid;
                    if (!node.isHighlightableContentNode(eachKid))
                        continue;
                    if (first == null) {
                        first = eachKid;
                    }
                    last = eachKid;
                    lastIndex = i;
                }
            }
            if (first == null || last == null)
                continue;
            Rectangle firstBounds = getPathBounds(getPath(first));
            if (isExpanded(getPath(last))) {
                if (lastIndex + 1 < kids.length) {
                    final Object child = kids[lastIndex + 1];
                    if (child instanceof PresentableNodeDescriptor) {
                        PresentableNodeDescriptor nextKid = (PresentableNodeDescriptor) child;
                        int nextRow = getRowForPath(getPath(nextKid));
                        last = toPresentableNode(getPathForRow(nextRow - 1).getLastPathComponent());
                    }
                } else {
                    NodeDescriptor parentNode = node.getParentDescriptor();
                    if (parentNode instanceof PresentableNodeDescriptor) {
                        final PresentableNodeDescriptor ppd = (PresentableNodeDescriptor) parentNode;
                        int nodeIndex = node.getIndex();
                        if (nodeIndex + 1 < structure.getChildElements(ppd).length) {
                            PresentableNodeDescriptor nextChild = ppd.getChildToHighlightAt(nodeIndex + 1);
                            int nextRow = getRowForPath(getPath(nextChild));
                            TreePath prevPath = getPathForRow(nextRow - 1);
                            if (prevPath != null) {
                                last = toPresentableNode(prevPath.getLastPathComponent());
                            }
                        } else {
                            int lastRow = getRowForPath(getPath(last));
                            PresentableNodeDescriptor lastParent = last;
                            boolean lastWasFound = false;
                            for (int i = lastRow + 1; i < getRowCount(); i++) {
                                PresentableNodeDescriptor eachNode = toPresentableNode(getPathForRow(i).getLastPathComponent());
                                if (!node.isParentOf(eachNode)) {
                                    last = lastParent;
                                    lastWasFound = true;
                                    break;
                                }
                                lastParent = eachNode;
                            }
                            if (!lastWasFound) {
                                last = toPresentableNode(getPathForRow(getRowCount() - 1).getLastPathComponent());
                            }
                        }
                    }
                }
            }
            if (last == null)
                continue;
            Rectangle lastBounds = getPathBounds(getPath(last));
            if (firstBounds == null || lastBounds == null)
                continue;
            Rectangle toPaint = new Rectangle(firstBounds.x, firstBounds.y, 0, (int) lastBounds.getMaxY() - firstBounds.y - 1);
            toPaint.width = getWidth() - toPaint.x - 4;
            final Color highlightColor = first.getHighlightColor();
            g.setColor(highlightColor);
            g.fillRoundRect(toPaint.x, toPaint.y, toPaint.width, toPaint.height, 4, 4);
            g.setColor(highlightColor.darker());
            g.drawRoundRect(toPaint.x, toPaint.y, toPaint.width, toPaint.height, 4, 4);
        }
    }
    config.restore();
}
Also used : GraphicsConfig(com.intellij.openapi.ui.GraphicsConfig) BasicTreeUI(javax.swing.plaf.basic.BasicTreeUI)

Example 10 with BasicTreeUI

use of javax.swing.plaf.basic.BasicTreeUI in project intellij-community by JetBrains.

the class Tree method isLocationInExpandControl.

private boolean isLocationInExpandControl(final TreePath path, final int x, final int y) {
    final TreeUI ui = getUI();
    if (!(ui instanceof BasicTreeUI))
        return false;
    try {
        Class aClass = ui.getClass();
        while (BasicTreeUI.class.isAssignableFrom(aClass) && !BasicTreeUI.class.equals(aClass)) {
            aClass = aClass.getSuperclass();
        }
        final Method method = ReflectionUtil.getDeclaredMethod(aClass, "isLocationInExpandControl", TreePath.class, int.class, int.class);
        if (method != null) {
            return (Boolean) method.invoke(ui, path, x, y);
        }
    } catch (Throwable ignore) {
    }
    return false;
}
Also used : BasicTreeUI(javax.swing.plaf.basic.BasicTreeUI) Method(java.lang.reflect.Method) BasicTreeUI(javax.swing.plaf.basic.BasicTreeUI) WideSelectionTreeUI(com.intellij.util.ui.tree.WideSelectionTreeUI) TreeUI(javax.swing.plaf.TreeUI)

Aggregations

BasicTreeUI (javax.swing.plaf.basic.BasicTreeUI)11 TreeUI (javax.swing.plaf.TreeUI)4 GraphicsConfig (com.intellij.openapi.ui.GraphicsConfig)1 ScalableIcon (com.intellij.openapi.util.ScalableIcon)1 RelativePoint (com.intellij.ui.awt.RelativePoint)1 EmptyIcon (com.intellij.util.ui.EmptyIcon)1 WideSelectionTreeUI (com.intellij.util.ui.tree.WideSelectionTreeUI)1 XDebuggerTreeNode (com.intellij.xdebugger.impl.ui.tree.nodes.XDebuggerTreeNode)1 XValueNodeImpl (com.intellij.xdebugger.impl.ui.tree.nodes.XValueNodeImpl)1 ActionEvent (java.awt.event.ActionEvent)1 Method (java.lang.reflect.Method)1 JTree (javax.swing.JTree)1 TreePath (javax.swing.tree.TreePath)1 Nullable (org.jetbrains.annotations.Nullable)1