Search in sources :

Example 1 with BasicTreeUI

use of javax.swing.plaf.basic.BasicTreeUI in project jdk8u_jdk by JetBrains.

the class bug8003830 method testNPEAtActionsPage.

public void testNPEAtActionsPage() {
    JTree tree = new JTree();
    BasicTreeUI ui = new NullReturningTreeUI();
    tree.setUI(ui);
    BasicTreeUI.TreePageAction tpa = ui.new TreePageAction(0, "down");
    tpa.actionPerformed(new ActionEvent(tree, 0, ""));
}
Also used : JTree(javax.swing.JTree) ActionEvent(java.awt.event.ActionEvent) BasicTreeUI(javax.swing.plaf.basic.BasicTreeUI)

Example 2 with BasicTreeUI

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

the class DeferredIconImpl method paintIcon.

@Override
public void paintIcon(final Component c, @NotNull final Graphics g, final int x, final int y) {
    if (!(myScaledDelegateIcon instanceof DeferredIconImpl && ((DeferredIconImpl) myScaledDelegateIcon).myScaledDelegateIcon instanceof DeferredIconImpl)) {
        //SOE protection
        myScaledDelegateIcon.paintIcon(c, g, x, y);
    }
    if (isDone() || myIsScheduled || PowerSaveMode.isEnabled()) {
        return;
    }
    myIsScheduled = true;
    final Component target = getTarget(c);
    final Component paintingParent = SwingUtilities.getAncestorOfClass(PaintingParent.class, c);
    final Rectangle paintingParentRec = paintingParent == null ? null : ((PaintingParent) paintingParent).getChildRec(c);
    ourIconsCalculatingExecutor.execute(() -> {
        int oldWidth = myScaledDelegateIcon.getIconWidth();
        final Icon[] evaluated = new Icon[1];
        final long startTime = System.currentTimeMillis();
        if (myNeedReadAction) {
            boolean result = ProgressIndicatorUtils.runInReadActionWithWriteActionPriority(() -> {
                IconDeferrerImpl.evaluateDeferred(() -> evaluated[0] = evaluate());
                if (myAutoUpdatable) {
                    myLastCalcTime = System.currentTimeMillis();
                    myLastTimeSpent = myLastCalcTime - startTime;
                }
            });
            if (!result) {
                myIsScheduled = false;
                return;
            }
        } else {
            IconDeferrerImpl.evaluateDeferred(() -> evaluated[0] = evaluate());
            if (myAutoUpdatable) {
                myLastCalcTime = System.currentTimeMillis();
                myLastTimeSpent = myLastCalcTime - startTime;
            }
        }
        final Icon result = evaluated[0];
        myScaledDelegateIcon = result;
        checkDelegationDepth();
        final boolean shouldRevalidate = Registry.is("ide.tree.deferred.icon.invalidates.cache") && myScaledDelegateIcon.getIconWidth() != oldWidth;
        ourLaterInvocator.offer(() -> {
            setDone(result);
            Component actualTarget = target;
            if (actualTarget != null && SwingUtilities.getWindowAncestor(actualTarget) == null) {
                actualTarget = paintingParent;
                if (actualTarget == null || SwingUtilities.getWindowAncestor(actualTarget) == null) {
                    actualTarget = null;
                }
            }
            if (actualTarget == null)
                return;
            if (shouldRevalidate) {
                // revalidate will not work: JTree caches size of nodes
                if (actualTarget instanceof JTree) {
                    final TreeUI ui = ((JTree) actualTarget).getUI();
                    if (ui instanceof BasicTreeUI) {
                        // this call is "fake" and only need to reset tree layout cache
                        ((BasicTreeUI) ui).setLeftChildIndent(UIUtil.getTreeLeftChildIndent());
                    }
                }
            }
            if (c == actualTarget) {
                c.repaint(x, y, getIconWidth(), getIconHeight());
            } else {
                ourRepaintScheduler.pushDirtyComponent(actualTarget, paintingParentRec);
            }
        });
    });
}
Also used : BasicTreeUI(javax.swing.plaf.basic.BasicTreeUI) ScalableIcon(com.intellij.openapi.util.ScalableIcon) EmptyIcon(com.intellij.util.ui.EmptyIcon) BasicTreeUI(javax.swing.plaf.basic.BasicTreeUI) TreeUI(javax.swing.plaf.TreeUI)

Example 3 with BasicTreeUI

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

the class CommittedChangeListRenderer method getRowX.

public static int getRowX(JTree tree, int depth) {
    if (tree == null)
        return 0;
    final TreeUI ui = tree.getUI();
    if (ui instanceof BasicTreeUI) {
        final BasicTreeUI treeUI = ((BasicTreeUI) ui);
        return (treeUI.getLeftChildIndent() + treeUI.getRightChildIndent()) * depth;
    }
    final int leftIndent = UIUtil.getTreeLeftChildIndent();
    final int rightIndent = UIUtil.getTreeRightChildIndent();
    return (leftIndent + rightIndent) * depth;
}
Also used : BasicTreeUI(javax.swing.plaf.basic.BasicTreeUI) BasicTreeUI(javax.swing.plaf.basic.BasicTreeUI) TreeUI(javax.swing.plaf.TreeUI)

Example 4 with BasicTreeUI

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

the class UsageViewImpl method clearRendererCache.

private void clearRendererCache() {
    ApplicationManager.getApplication().assertIsDispatchThread();
    // to avoid quadratic row enumeration
    if (expandingAll)
        return;
    // clear renderer cache of node preferred size
    TreeUI ui = myTree.getUI();
    if (ui instanceof BasicTreeUI) {
        AbstractLayoutCache treeState = ReflectionUtil.getField(BasicTreeUI.class, ui, AbstractLayoutCache.class, "treeState");
        Rectangle visibleRect = myTree.getVisibleRect();
        int rowForLocation = myTree.getClosestRowForLocation(0, visibleRect.y);
        int visibleRowCount = getVisibleRowCount();
        for (int i = rowForLocation + visibleRowCount + 1; i >= rowForLocation; i--) {
            final TreePath eachPath = myTree.getPathForRow(i);
            if (eachPath == null)
                continue;
            treeState.invalidatePathBounds(eachPath);
        }
        myTree.repaint(visibleRect);
    } else {
        myTree.setCellRenderer(myUsageViewTreeCellRenderer);
    }
}
Also used : BasicTreeUI(javax.swing.plaf.basic.BasicTreeUI) BasicTreeUI(javax.swing.plaf.basic.BasicTreeUI) TreeUI(javax.swing.plaf.TreeUI)

Example 5 with BasicTreeUI

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

the class ChangesTreeList method setChildIndent.

private void setChildIndent(boolean isFlat) {
    BasicTreeUI treeUI = (BasicTreeUI) getUI();
    treeUI.setLeftChildIndent(!isFlat ? UIUtil.getTreeLeftChildIndent() : 0);
    treeUI.setRightChildIndent(!isFlat ? UIUtil.getTreeRightChildIndent() : 0);
}
Also used : BasicTreeUI(javax.swing.plaf.basic.BasicTreeUI)

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