Search in sources :

Example 1 with TreeUI

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

the class Tree method setUI.

@Override
public void setUI(final TreeUI ui) {
    TreeUI actualUI = ui;
    if (!isCustomUI()) {
        if (!(ui instanceof WideSelectionTreeUI) && isWideSelection() && !UIUtil.isUnderGTKLookAndFeel()) {
            actualUI = new WideSelectionTreeUI(isWideSelection(), getWideSelectionBackgroundCondition());
        }
    }
    super.setUI(actualUI);
}
Also used : WideSelectionTreeUI(com.intellij.util.ui.tree.WideSelectionTreeUI) BasicTreeUI(javax.swing.plaf.basic.BasicTreeUI) WideSelectionTreeUI(com.intellij.util.ui.tree.WideSelectionTreeUI) TreeUI(javax.swing.plaf.TreeUI)

Example 2 with TreeUI

use of javax.swing.plaf.TreeUI 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 3 with TreeUI

use of javax.swing.plaf.TreeUI 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 TreeUI

use of javax.swing.plaf.TreeUI 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 5 with TreeUI

use of javax.swing.plaf.TreeUI in project com.revolsys.open by revolsys.

the class LayerRendererTreeNode method mouseClicked.

@Override
public void mouseClicked(final MouseEvent e) {
    final Object source = e.getSource();
    final JTree tree = getTree();
    if (source == tree) {
        final int clickCount = e.getClickCount();
        if (clickCount == 2 && SwingUtilities.isLeftMouseButton(e)) {
            final int x = e.getX();
            final int y = e.getY();
            final TreePath path = tree.getPathForLocation(x, y);
            final LayerRenderer<?> renderer = getRenderer();
            final TreeUI ui = tree.getUI();
            final Rectangle bounds = ui.getPathBounds(tree, path);
            final int cX = x - bounds.x;
            final int index = cX / 21;
            int offset = 0;
            if (index == offset) {
                renderer.setVisible(!renderer.isVisible());
            }
            offset++;
            e.consume();
        }
    }
}
Also used : JTree(javax.swing.JTree) TreePath(javax.swing.tree.TreePath) Rectangle(java.awt.Rectangle) TreeUI(javax.swing.plaf.TreeUI)

Aggregations

TreeUI (javax.swing.plaf.TreeUI)8 BasicTreeUI (javax.swing.plaf.basic.BasicTreeUI)5 Rectangle (java.awt.Rectangle)3 JTree (javax.swing.JTree)3 TreePath (javax.swing.tree.TreePath)3 WideSelectionTreeUI (com.intellij.util.ui.tree.WideSelectionTreeUI)2 AbstractLayer (com.revolsys.swing.map.layer.AbstractLayer)2 Layer (com.revolsys.swing.map.layer.Layer)2 ScalableIcon (com.intellij.openapi.util.ScalableIcon)1 EmptyIcon (com.intellij.util.ui.EmptyIcon)1 Method (java.lang.reflect.Method)1