Sorry about that. I fixed this. Also, it seemed that the width was not being calculated properly, so the labels were cut off. I fixed this too.
2005-10-13 Lillian Angel <[EMAIL PROTECTED]> * javax/swing/plaf/basic/BasicTreeUI.java (getPathForRow): Added check to prevent NPE. (getRowCount): Likewise. (getRowForPath): Likewise. (getPreferredSize): Adjusted width depending on x location and icon. (paintRecursive): Likewise. (getPreviousNode): Added check to prevent NPE. (getNextVisibleNode): Likewise. On Wed, 2005-10-12 at 23:10 +0200, Mark Wielaard wrote: > Hi Lillian, > > On Wed, 2005-10-05 at 17:28 -0400, Lillian Angel wrote: > > Fixed up BasicTreeUI because it was not efficent when painting. > > > > 2005-10-05 Lillian Angel <[EMAIL PROTECTED]> > > > > * javax/swing/plaf/metal/MetalTreeUI.java > > (installUI): Fixed to call toggleExpandState instead. > > * javax/swing/plaf/basic/BasicTreeUI.java > > (getPathForRow): Used currentVisiblePath to get Path. > > (getRowForPath): Used currentVisiblePath to get row. > > (getRowCount): Returned currentVisiblePath length. > > (updateLayoutCacheExpandedNodes): Took out unneeded code. > > (installUI): Fixed to call toggleExpandState instead. > > (getPreferredSize): Made more efficent by using > > currentVisiblePath. > > (toggleExpandState): Called updateCurrentVisiblePath. > > (getCellLocation): Made more efficent. > > (paintNode): Removed. > > (paintRecursive): Made more efficent, changed paintNode calls to > > paintRow. > > (getNextVisibleNode): Reimplemented to use currentVisiblePath. > > (getPreviousVisibleNode): Likewise. > > (paintRow): Implemented. > > (updateCurrentVisiblePath): New helper used to cache the current > > visible path. > > This broke junit for me (see stack trace below). The problem is that > newly introduces currentVisiblePath field can be NULL, but is used in > various places without checking whether or not it is NUll. > > java.lang.NullPointerException > at javax.swing.plaf.basic.BasicTreeUI.getPreferredSize > (BasicTreeUI.java:1474) > at javax.swing.plaf.basic.BasicTreeUI.getPreferredSize > (BasicTreeUI.java:1457) > at javax.swing.JComponent.getPreferredSize (JComponent.java:1083) > at javax.swing.JViewport.getViewSize (JViewport.java:297) > at javax.swing.plaf.basic.BasicScrollPaneUI.syncScrollPaneWithViewport > (BasicScrollPaneUI.java:434) > at > javax.swing.plaf.basic.BasicScrollPaneUI$ViewportChangeHandler.stateChanged > (BasicScrollPaneUI.java:160) > at javax.swing.JViewport.fireStateChanged (JViewport.java:623) > at javax.swing.JViewport.revalidate (JViewport.java:422) > at javax.swing.JComponent$1.run (JComponent.java:2111) > at java.awt.event.InvocationEvent.dispatch (InvocationEvent.java:191) > at java.awt.EventQueue.dispatchEvent (EventQueue.java:465) > at java.awt.EventDispatchThread.run (EventDispatchThread.java:75) >
Index: javax/swing/plaf/basic/BasicTreeUI.java =================================================================== RCS file: /cvsroot/classpath/classpath/javax/swing/plaf/basic/BasicTreeUI.java,v retrieving revision 1.91 diff -u -r1.91 BasicTreeUI.java --- javax/swing/plaf/basic/BasicTreeUI.java 12 Oct 2005 17:17:59 -0000 1.91 +++ javax/swing/plaf/basic/BasicTreeUI.java 13 Oct 2005 14:13:38 -0000 @@ -650,7 +650,7 @@ */ public TreePath getPathForRow(JTree tree, int row) { - if (treeModel != null) + if (treeModel != null && currentVisiblePath != null) { Object[] nodes = currentVisiblePath.getPath(); if (row < nodes.length) @@ -676,14 +676,16 @@ int row = 0; Object dest = path.getLastPathComponent(); int rowCount = getRowCount(tree); - Object[] nodes = currentVisiblePath.getPath(); - while (row < rowCount) + if (currentVisiblePath != null) { - if (dest.equals(nodes[row])) - return row; - row++; + Object[] nodes = currentVisiblePath.getPath(); + while (row < rowCount) + { + if (dest.equals(nodes[row])) + return row; + row++; + } } - return -1; } @@ -696,7 +698,9 @@ */ public int getRowCount(JTree tree) { - return currentVisiblePath.getPathCount(); + if (currentVisiblePath != null) + return currentVisiblePath.getPathCount(); + return 0; } /** @@ -1471,11 +1475,20 @@ { // FIXME: checkConsistancy not implemented, c not used int maxWidth = 0; - Object[] path = currentVisiblePath.getPath(); - for (int i = 0; i < path.length; i++) - maxWidth = Math.max(maxWidth, - (int) (getCellBounds(0, 0, path[i]).getWidth())); - return new Dimension(maxWidth, (getRowHeight() * path.length)); + 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); + maxWidth = Math.max(maxWidth, bounds.x + bounds.width + + getCurrentControlIcon(curr).getIconWidth()); + } + return new Dimension(maxWidth, (getRowHeight() * path.length)); + } + return new Dimension(0, 0); } /** @@ -2969,7 +2982,7 @@ String s = cell.toString(); Font f = tree.getFont(); FontMetrics fm = tree.getToolkit().getFontMetrics(f); - + if (s != null) return new Rectangle(x, y, SwingUtilities.computeStringWidth(fm, s) + 4, @@ -3056,11 +3069,13 @@ if (isLeaf) { + bounds.width += bounds.x; paintRow(g, clip, null, bounds, path, row, true, false, true); descent += getRowHeight(); } else - { + { + bounds.width += bounds.x + getCurrentControlIcon(path).getIconWidth(); if (depth > 0 || isRootVisible) { paintRow(g, clip, null, bounds, path, row, isExpanded, false, false); @@ -3253,13 +3268,16 @@ */ Object getPreviousVisibleNode(Object node) { - Object[] nodes = currentVisiblePath.getPath(); - int i = 0; - while (i < nodes.length && !node.equals(nodes[i])) - i++; - // return the next node - if (i-1 > 0) - return nodes[i-1]; + if (currentVisiblePath != null) + { + Object[] nodes = currentVisiblePath.getPath(); + int i = 0; + while (i < nodes.length && !node.equals(nodes[i])) + i++; + // return the next node + if (i-1 > 0) + return nodes[i-1]; + } return null; } @@ -3722,13 +3740,16 @@ */ Object getNextVisibleNode(Object node) { - Object[] nodes = currentVisiblePath.getPath(); - int i = 0; - while (i < nodes.length && !node.equals(nodes[i])) - i++; - // return the next node - if (i+1 < nodes.length) - return nodes[i+1]; + if (currentVisiblePath != null) + { + Object[] nodes = currentVisiblePath.getPath(); + int i = 0; + while (i < nodes.length && !node.equals(nodes[i])) + i++; + // return the next node + if (i+1 < nodes.length) + return nodes[i+1]; + } return null; } } // BasicTreeUI
_______________________________________________ Classpath-patches mailing list Classpath-patches@gnu.org http://lists.gnu.org/mailman/listinfo/classpath-patches