Implemented {,SHIFT-} PAGE {UP,DOWN} key action in BasicListUI.  Also
had to make a small correction to JViewport's scrollRectToVisible that
PAGE DOWN revealed where we were off by 1 pixel.

Patch attached.


2005-07-28  Anthony Balkissoon  <[EMAIL PROTECTED]>

* javax/swing/JViewport.java:
(scrollRectToVisible): Consider the x and y position of the viewport
itself when scrolling down.  This fixes an off-by-1-pixel problem.
* javax/swing/plaf/basic/BasicListUI.java:
(KeyHandler.keyPressed): Implemented PAGEUP, SHIFT-PAGEUP, PAGEDOWN, 
and SHIFT-PAGEDOWN key actions.

- Tony
Index: javax/swing/JViewport.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/JViewport.java,v
retrieving revision 1.23
diff -u -r1.23 JViewport.java
--- javax/swing/JViewport.java	28 Jul 2005 13:27:59 -0000	1.23
+++ javax/swing/JViewport.java	28 Jul 2005 19:36:31 -0000
@@ -517,7 +517,8 @@
     else if (contentRect.y + viewBounds.y + contentRect.height > 
              (portBounds.y+portBounds.height))
       setViewPosition (new Point(pos.x, contentRect.y - 
-                                 (portBounds.height - contentRect.height)));
+                                 (portBounds.height - contentRect.height) -
+                                 portBounds.y));
 
     // X-DIRECTION
     pos = getViewPosition();
@@ -526,6 +527,7 @@
     else if (contentRect.x + viewBounds.x + contentRect.width > 
              (portBounds.x + portBounds.height))
       setViewPosition (new Point(contentRect.x - 
-                                 (portBounds.width - contentRect.width), pos.y));
+                                 (portBounds.width - contentRect.width)
+                                 - portBounds.x, pos.y));
   }
 }
Index: javax/swing/plaf/basic/BasicListUI.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/plaf/basic/BasicListUI.java,v
retrieving revision 1.29
diff -u -r1.29 BasicListUI.java
--- javax/swing/plaf/basic/BasicListUI.java	28 Jul 2005 15:34:33 -0000	1.29
+++ javax/swing/plaf/basic/BasicListUI.java	28 Jul 2005 19:36:31 -0000
@@ -236,11 +236,41 @@
         }
       else if (evt.getKeyCode() == KeyEvent.VK_PAGE_UP)
         {
-          // FIXME: implement, need JList.ensureIndexIsVisible to work
+          int target;
+          if (lead == BasicListUI.this.list.getFirstVisibleIndex())
+            {
+              target = Math.max 
+                (0, lead - (BasicListUI.this.list.getLastVisibleIndex() - 
+                             BasicListUI.this.list.getFirstVisibleIndex() + 1));
+            }
+          else
+            {
+              target = BasicListUI.this.list.getFirstVisibleIndex();
+            }
+          if (evt.getModifiers() == 0)
+            BasicListUI.this.list.setSelectedIndex(target);
+          else if (evt.getModifiers() == InputEvent.SHIFT_MASK)
+            BasicListUI.this.list.getSelectionModel().
+              setLeadSelectionIndex(target);
         }
       else if (evt.getKeyCode() == KeyEvent.VK_PAGE_DOWN)
         {
-          // FIXME: implement, need JList.ensureIndexIsVisible to work
+          int target;
+          if (lead == BasicListUI.this.list.getLastVisibleIndex())
+            {
+              target = Math.min
+                (max, lead + (BasicListUI.this.list.getLastVisibleIndex() -
+                              BasicListUI.this.list.getFirstVisibleIndex() + 1));
+            }
+          else
+            {
+              target = BasicListUI.this.list.getLastVisibleIndex();
+            }
+          if (evt.getModifiers() == 0)
+            BasicListUI.this.list.setSelectedIndex(target);
+          else if (evt.getModifiers() == InputEvent.SHIFT_MASK)
+            BasicListUI.this.list.getSelectionModel().
+              setLeadSelectionIndex(target);
         }
       else if (evt.getKeyCode() == KeyEvent.VK_BACK_SLASH
                && (evt.getModifiers() == InputEvent.CTRL_MASK))
_______________________________________________
Classpath-patches mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/classpath-patches

Reply via email to