[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Need help with BasicTreeUI
From: |
Lillian Angel |
Subject: |
Re: Need help with BasicTreeUI |
Date: |
Fri, 14 Oct 2005 09:24:52 -0400 |
I can help you with this. I will look into it today.
Lillian
On Thu, 2005-10-13 at 23:40 +0200, Jan Röhrich wrote:
> 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;
> }
>
> /**
>
> _______________________________________________
> Classpath mailing list
> address@hidden
> http://lists.gnu.org/mailman/listinfo/classpath