classpath
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Need help with BasicTreeUI


From: Jan Röhrich
Subject: Need help with BasicTreeUI
Date: Thu, 13 Oct 2005 23:40:05 +0200

There are still some problems running my custom TreeUI which inherits
from BasicTreeUI.
(updateCachedPreferredSize) was not implemented so I decided to move
most of the code from (getPreferredSize) to (updateCachedPreferredSize)
which is imho the best place for computing the size (see the patch
attached). 
But now the TreeWorld in gnu.classpath.examples.swing.Demo doesn't work
anymore. The tree isn't even displayed because the preferred size is
0x0. But when I set preferredSize to at least 10x10 there are a lot of
bugs painting the tree.

Anybody out there who can help me to drag down this problem? I'm not
very familiar with painting in BasicTreeUI.

Jan

Index: BasicTreeUI.java
===================================================================
RCS
file: /cvsroot/classpath/classpath/javax/swing/plaf/basic/BasicTreeUI.java,v
retrieving revision 1.95
diff -u -r1.95 BasicTreeUI.java
--- BasicTreeUI.java    13 Oct 2005 19:34:08 -0000      1.95
+++ BasicTreeUI.java    13 Oct 2005 21:30:31 -0000
@@ -1160,7 +1160,7 @@
    */
   protected void updateSize()
   {
-    preferredSize = null;
+    validCachedPreferredSize = false;
     updateCachedPreferredSize();
     tree.treeDidChange();
   }
@@ -1174,7 +1174,26 @@
    */
   protected void updateCachedPreferredSize()
   {
-    // FIXME: not implemented
+    int maxWidth = 0;
+    boolean isLeaf = false;
+    if (currentVisiblePath != null)
+      {
+        Object[] path = currentVisiblePath.getPath();
+        for (int i = 0; i < path.length; i++)
+          {
+            TreePath curr = new TreePath(getPathToRoot(path[i], 0));
+            Rectangle bounds = getPathBounds(tree, 
+                        curr);  
+            if (treeModel != null)
+              isLeaf = treeModel.isLeaf(curr);
+            if (hasControlIcons())
+              bounds.width += getCurrentControlIcon(curr).getIconWidth
();
+            maxWidth = Math.max(maxWidth, bounds.x + bounds.width);
+          }
+        preferredSize = new Dimension(maxWidth, (getRowHeight() *
path.length));
+      }
+    preferredSize = new Dimension(0, 0);
+    validCachedPreferredSize = true;
   }
 
   /**
@@ -1478,25 +1497,11 @@
   public Dimension getPreferredSize(JComponent c, boolean
checkConsistancy)
   {
     // FIXME: checkConsistancy not implemented, c not used
-    int maxWidth = 0;
-    boolean isLeaf = false;
-    if (currentVisiblePath != null)
+    if(!validCachedPreferredSize) 
       {
-        Object[] path = currentVisiblePath.getPath();
-        for (int i = 0; i < path.length; i++)
-          {
-            TreePath curr = new TreePath(getPathToRoot(path[i], 0));
-            Rectangle bounds = getPathBounds(tree, 
-                        curr);  
-            if (treeModel != null)
-              isLeaf = treeModel.isLeaf(curr);
-            if (hasControlIcons())
-              bounds.width += getCurrentControlIcon(curr).getIconWidth
();
-            maxWidth = Math.max(maxWidth, bounds.x + bounds.width);
-          }
-        return new Dimension(maxWidth, (getRowHeight() * path.length));
+        updateCachedPreferredSize();
       }
-    return new Dimension(0, 0);
+    return preferredSize;
   }
 
   /**

Attachment: signature.asc
Description: Dies ist ein digital signierter Nachrichtenteil


reply via email to

[Prev in Thread] Current Thread [Next in Thread]