StructureView: avoid flickering fix
authorKirill Kalishev <kirill.kalishev@jetbrains.com>
Thu, 4 Mar 2010 11:44:32 +0000 (14:44 +0300)
committerKirill Kalishev <kirill.kalishev@jetbrains.com>
Thu, 4 Mar 2010 11:44:32 +0000 (14:44 +0300)
platform/lang-impl/src/com/intellij/ide/impl/StructureViewWrapperImpl.java
platform/lang-impl/src/com/intellij/ide/structureView/newStructureView/StructureViewComponent.java
platform/platform-api/src/com/intellij/ide/structureView/StructureView.java

index 52c6bc49fb2c9f5a53216402dcfd7c9b28ffcba2..083e0f0110f6f6a4d14400309584b979b4879af7 100644 (file)
@@ -186,7 +186,12 @@ public class StructureViewWrapperImpl implements StructureViewWrapper, Disposabl
 
     boolean hadFocus = ToolWindowId.STRUCTURE_VIEW.equals(ToolWindowManager.getInstance(myProject).getActiveToolWindowId());
 
+    Dimension referenceSize = null;
     if (myStructureView != null) {
+      if (myStructureView instanceof StructureView.Scrollable) {
+        referenceSize = ((StructureView.Scrollable)myStructureView).getCurrentSize();
+      }
+
       myStructureView.storeState();
       Disposer.dispose(myStructureView);
       myStructureView = null;
@@ -238,6 +243,9 @@ public class StructureViewWrapperImpl implements StructureViewWrapper, Disposabl
           final StructureViewBuilder structureViewBuilder = editor.getStructureViewBuilder();
           if (structureViewBuilder != null) {
             myStructureView = structureViewBuilder.createStructureView(editor, myProject);
+            if (myStructureView instanceof StructureView.Scrollable) {
+              ((StructureView.Scrollable)myStructureView).setReferenceSizeWhileInitializing(referenceSize);
+            }
             myPanel.add(myStructureView.getComponent(), BorderLayout.CENTER);
             if (hadFocus) {
               JComponent focusedComponent = IdeFocusTraversalPolicy.getPreferredFocusedComponent(myStructureView.getComponent());
index 3bf98933699384ecc839e1cb52b0c0c4dd83fb63..9a73e95bba400fc98cbb9226590be22d1ab6de89 100644 (file)
@@ -65,7 +65,7 @@ import java.util.ArrayList;
 import java.util.Collection;
 import java.util.List;
 
-public class StructureViewComponent extends SimpleToolWindowPanel implements TreeActionsOwner, DataProvider, StructureView {
+public class StructureViewComponent extends SimpleToolWindowPanel implements TreeActionsOwner, DataProvider, StructureView.Scrollable {
   private static final Logger LOG = Logger.getInstance("#com.intellij.ide.structureView.newStructureView.StructureViewComponent");
   @NonNls private static final String ourHelpID = "viewingStructure.fileStructureView";
 
@@ -87,6 +87,7 @@ public class StructureViewComponent extends SimpleToolWindowPanel implements Tre
   private final Project myProject;
   private final StructureViewModel myTreeModel;
   private static int ourSettingsModificationCount;
+  private JTree myTree;
 
   public StructureViewComponent(FileEditor editor, StructureViewModel structureViewModel, Project project) {
     this(editor, structureViewModel, project, true);
@@ -120,12 +121,12 @@ public class StructureViewComponent extends SimpleToolWindowPanel implements Tre
     };
 
     final DefaultTreeModel model = new DefaultTreeModel(new DefaultMutableTreeNode(treeStructure.getRootElement()));
-    JTree tree = new Tree(model);
-    tree.setRootVisible(showRootNode);
-    tree.setShowsRootHandles(true);
+    myTree = new Tree(model);
+    myTree.setRootVisible(showRootNode);
+    myTree.setShowsRootHandles(true);
 
-    myAbstractTreeBuilder = new StructureTreeBuilder(project, tree,
-                                                     (DefaultTreeModel)tree.getModel(),treeStructure,myTreeModelWrapper) {
+    myAbstractTreeBuilder = new StructureTreeBuilder(project, myTree,
+                                                     (DefaultTreeModel)myTree.getModel(),treeStructure,myTreeModelWrapper) {
       @Override
       protected boolean validateNode(Object child) {
         return isValid(child);
@@ -805,4 +806,28 @@ public class StructureViewComponent extends SimpleToolWindowPanel implements Tre
     return ourHelpID;
   }
 
+  public Dimension getCurrentSize() {
+    return myTree.getSize();
+  }
+
+  public void setReferenceSizeWhileInitializing(Dimension size) {
+    _setRefSize(size);
+
+    if (size != null) {
+      myAbstractTreeBuilder.getReady(this).doWhenDone(new Runnable() {
+        public void run() {
+          _setRefSize(null);
+        }
+      });
+    }
+  }
+
+  private void _setRefSize(Dimension size) {
+    myTree.setPreferredSize(size);
+    myTree.setMinimumSize(size);
+    myTree.setMaximumSize(size);
+
+    myTree.revalidate();
+    myTree.repaint();
+  }
 }
index 647dfc0691facecefe46360fa21fdf45e34013ee..e1b3d7d3a79a3815cd8d689adeeedd7f337ee2c8 100644 (file)
@@ -20,6 +20,7 @@ import com.intellij.openapi.fileEditor.FileEditor;
 import com.intellij.openapi.util.ActionCallback;
 
 import javax.swing.*;
+import java.awt.*;
 
 /**
  * Defines the implementation of a custom structure view or file structure popup component.
@@ -74,4 +75,9 @@ public interface StructureView extends Disposable {
   void storeState();
 
   StructureViewModel getTreeModel();
+
+  interface Scrollable extends StructureView {
+    Dimension getCurrentSize();
+    void setReferenceSizeWhileInitializing(Dimension size);
+  }
 }