Surely, RI shows that the tree scrolls only in one direction, down.

Roman Kennke wrote:
This fixes unit-scrolling and implements block scrolling for JTree. It also fixes a minor glitch in VariableHeightLayoutCache.

2006-08-13  Roman Kennke  <[EMAIL PROTECTED]>

    * javax/swing/JTree.java
    (getScrollableUnitIncrement): Fixed direction.
    (getScrollableBlockIncrement): Implemented to scroll one
    page.
    * javax/swing/tree/VariableHeightLayoutCache.java
    (distance): Consider y + height already outside the node.

/Roman
------------------------------------------------------------------------

Index: javax/swing/JTree.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/JTree.java,v
retrieving revision 1.72
diff -u -1 -2 -r1.72 JTree.java
--- javax/swing/JTree.java      9 Aug 2006 16:22:49 -0000       1.72
+++ javax/swing/JTree.java      13 Aug 2006 20:33:17 -0000
@@ -1675,47 +1675,70 @@
* * @param visibleRect the currently visible part of the component.
    * @param orientation the scrolling orientation
    * @param direction the scrolling direction (negative - up, positive -down).
    *          The values greater than one means that more mouse wheel or 
similar
    *          events were generated, and hence it is better to scroll the 
longer
    *          distance.
    * @author Audrius Meskauskas ([EMAIL PROTECTED])
    */
   public int getScrollableUnitIncrement(Rectangle visibleRect, int orientation,
                                         int direction)
   {
-    int delta;
+    int delta = 0;
// Round so that the top would start from the row boundary
     if (orientation == SwingConstants.VERTICAL)
       {
-        // One pixel down, otherwise picks another row too high.
-        int row = getClosestRowForLocation(visibleRect.x, visibleRect.y + 1);
-        row = row + direction;
-        if (row < 0)
-          row = 0;
-
-        Rectangle newTop = getRowBounds(row);
-        delta = newTop.y - visibleRect.y;
+        int row = getClosestRowForLocation(0, visibleRect.y);
+        if (row != -1)
+          {
+            Rectangle b = getRowBounds(row);
+            if (b.y != visibleRect.y)
+              {
+                if (direction < 0)
+                  delta = Math.max(0, visibleRect.y - b.y);
+                else
+                  delta = b.y + b.height - visibleRect.height;
+              }
+            else
+              {
+                if (direction < 0)
+                  {
+                    if (row != 0)
+                      {
+                        b = getRowBounds(row - 1);
+                        delta = b.height;
+                      }
+                  }
+                else
+                  delta = b.height;
+              }
+          }
       }
     else
-      delta = direction * rowHeight == 0 ? 20 : rowHeight;
+      // The RI always  returns 4 for HORIZONTAL scrolling.
+      delta = 4;
     return delta;
   }
public int getScrollableBlockIncrement(Rectangle visibleRect,
                                          int orientation, int direction)
   {
-    return getScrollableUnitIncrement(visibleRect, orientation, direction);
+    int block;
+    if (orientation == SwingConstants.VERTICAL)
+      block = visibleRect.height;
+    else
+      block = visibleRect.width;
+    return block;
   }
public boolean getScrollableTracksViewportHeight()
   {
     if (getParent() instanceof JViewport)
       return ((JViewport) getParent()).getHeight() > getPreferredSize().height;
     return false;
   }
public boolean getScrollableTracksViewportWidth()
   {
     if (getParent() instanceof JViewport)
Index: javax/swing/tree/VariableHeightLayoutCache.java
===================================================================
RCS file: 
/cvsroot/classpath/classpath/javax/swing/tree/VariableHeightLayoutCache.java,v
retrieving revision 1.16
diff -u -1 -2 -r1.16 VariableHeightLayoutCache.java
--- javax/swing/tree/VariableHeightLayoutCache.java     7 Jun 2006 14:36:03 
-0000       1.16
+++ javax/swing/tree/VariableHeightLayoutCache.java     13 Aug 2006 20:33:17 
-0000
@@ -442,26 +442,26 @@
     else
       return best.getPath();
} /**
    * Get the closest distance from this point till the given rectangle. Only
    * vertical distance is taken into consideration.
    */
   int distance(Rectangle r, int x, int y)
   {
     if (y < r.y)
       return r.y - y;
-    else if (y > r.y + r.height)
-      return y - (r.y + r.height);
+    else if (y > r.y + r.height - 1)
+      return y - (r.y + r.height - 1);
     else
       return 0;
   }
/**
    * Get the number of the visible childs for the given tree path. If the node
    * is not expanded, 0 is returned. Otherwise, the number of children is
    * obtained from the model as the number of children for the last path
    * component.
* * @param path the tree path
    * @return int the number of the visible childs (for row).


Reply via email to