From 588fe51bf5369aea1170950bbb0bf26ef4c21ea8 Mon Sep 17 00:00:00 2001 From: Alexey Pegov Date: Mon, 10 Aug 2009 17:38:07 +0400 Subject: [PATCH] DeferredIcon fix: now should relayout the tree if evaluated icon's width differs from the initial one (classes has a visibility marker) --- lang-impl/src/com/intellij/ui/DeferredIconImpl.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/lang-impl/src/com/intellij/ui/DeferredIconImpl.java b/lang-impl/src/com/intellij/ui/DeferredIconImpl.java index 0f2648b53d..569532ebd8 100644 --- a/lang-impl/src/com/intellij/ui/DeferredIconImpl.java +++ b/lang-impl/src/com/intellij/ui/DeferredIconImpl.java @@ -11,6 +11,8 @@ import com.intellij.util.Function; import com.intellij.util.ui.EmptyIcon; import javax.swing.*; +import javax.swing.plaf.TreeUI; +import javax.swing.plaf.basic.BasicTreeUI; import java.awt.*; import java.lang.ref.WeakReference; @@ -71,11 +73,25 @@ public class DeferredIconImpl implements DeferredIcon { final Job job = JobScheduler.getInstance().createJob("Evaluating deferred icon", Job.DEFAULT_PRIORITY); job.addTask(new Runnable() { public void run() { + int oldWidth = myDelegateIcon.getIconWidth(); myDelegateIcon = evaluate(); + final boolean shouldRevalidate = myDelegateIcon.getIconWidth() != oldWidth; + //noinspection SSBasedInspection SwingUtilities.invokeLater(new Runnable() { public void run() { + if (shouldRevalidate) { + // revalidate will not work: jtree caches size of nodes + if (target instanceof JTree) { + final TreeUI ui = ((JTree)target).getUI(); + if (ui instanceof BasicTreeUI) { + // yep, reset size cache + ((BasicTreeUI)ui).setLeftChildIndent(((Integer)UIManager.get("Tree.leftChildIndent")).intValue()); + } + } + } + if (c == target) { c.repaint(x, y, getIconWidth(), getIconHeight()); } -- 2.11.4.GIT