commit-classpath
[Top][All Lists]
Advanced

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

[commit-cp] classpath ChangeLog javax/swing/plaf/basic/Basi...


From: David Gilbert
Subject: [commit-cp] classpath ChangeLog javax/swing/plaf/basic/Basi...
Date: Thu, 08 Jun 2006 10:52:51 +0000

CVSROOT:        /sources/classpath
Module name:    classpath
Changes by:     David Gilbert <trebligd>        06/06/08 10:52:51

Modified files:
        .              : ChangeLog 
        javax/swing/plaf/basic: BasicScrollPaneUI.java 

Log message:
        2006-06-08  David Gilbert  <address@hidden>
        
                * javax/swing/plaf/basic/BasicScrollPaneUI.java
                (getInputMap): New method,
                (getActionMap): New method,
                (createActionMap): New method,
                (installKeyboardActions): Implemented,
                (uninstallKeyboardActions): Implemented.

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/classpath/ChangeLog?cvsroot=classpath&r1=1.7712&r2=1.7713
http://cvs.savannah.gnu.org/viewcvs/classpath/javax/swing/plaf/basic/BasicScrollPaneUI.java?cvsroot=classpath&r1=1.25&r2=1.26

Patches:
Index: ChangeLog
===================================================================
RCS file: /sources/classpath/classpath/ChangeLog,v
retrieving revision 1.7712
retrieving revision 1.7713
diff -u -b -r1.7712 -r1.7713
--- ChangeLog   8 Jun 2006 10:48:00 -0000       1.7712
+++ ChangeLog   8 Jun 2006 10:52:51 -0000       1.7713
@@ -1,3 +1,12 @@
+2006-06-08  David Gilbert  <address@hidden>
+
+       * javax/swing/plaf/basic/BasicScrollPaneUI.java
+       (getInputMap): New method,
+       (getActionMap): New method,
+       (createActionMap): New method,
+       (installKeyboardActions): Implemented,
+       (uninstallKeyboardActions): Implemented.
+
 2006-06-08  Robert Schuster  <address@hidden>
 
        * javax/swing/border/MatteBorder.java:

Index: javax/swing/plaf/basic/BasicScrollPaneUI.java
===================================================================
RCS file: 
/sources/classpath/classpath/javax/swing/plaf/basic/BasicScrollPaneUI.java,v
retrieving revision 1.25
retrieving revision 1.26
diff -u -b -r1.25 -r1.26
--- javax/swing/plaf/basic/BasicScrollPaneUI.java       1 Jun 2006 05:17:02 
-0000       1.25
+++ javax/swing/plaf/basic/BasicScrollPaneUI.java       8 Jun 2006 10:52:51 
-0000       1.26
@@ -1,5 +1,5 @@
 /* BasicScrollPaneUI.java
-   Copyright (C) 2002, 2004, 2005 Free Software Foundation, Inc.
+   Copyright (C) 2002, 2004, 2005, 2006, Free Software Foundation, Inc.
 
 This file is part of GNU Classpath.
 
@@ -45,6 +45,7 @@
 import java.awt.Graphics;
 import java.awt.Point;
 import java.awt.Rectangle;
+import java.awt.event.ActionEvent;
 import java.awt.event.ContainerEvent;
 import java.awt.event.ContainerListener;
 import java.awt.event.MouseWheelEvent;
@@ -52,20 +53,31 @@
 import java.beans.PropertyChangeEvent;
 import java.beans.PropertyChangeListener;
 
+import javax.swing.AbstractAction;
+import javax.swing.Action;
+import javax.swing.ActionMap;
+import javax.swing.InputMap;
 import javax.swing.JComponent;
 import javax.swing.JScrollBar;
 import javax.swing.JScrollPane;
+import javax.swing.JSlider;
 import javax.swing.JViewport;
 import javax.swing.LookAndFeel;
 import javax.swing.ScrollPaneConstants;
 import javax.swing.ScrollPaneLayout;
 import javax.swing.Scrollable;
 import javax.swing.SwingConstants;
+import javax.swing.SwingUtilities;
+import javax.swing.UIManager;
 import javax.swing.event.ChangeEvent;
 import javax.swing.event.ChangeListener;
+import javax.swing.plaf.ActionMapUIResource;
 import javax.swing.plaf.ComponentUI;
 import javax.swing.plaf.ScrollPaneUI;
 
+/**
+ * A UI delegate for the address@hidden JScrollPane} component.
+ */
 public class BasicScrollPaneUI extends ScrollPaneUI
   implements ScrollPaneConstants
 {
@@ -236,7 +248,7 @@
     final Rectangle rect = new Rectangle();
 
     /**
-     * Scroll with the mouse whell.
+     * Scroll with the mouse wheel.
      * 
      * @author Audrius Meskauskas (address@hidden)
      */
@@ -311,7 +323,11 @@
     }
     
     /**
-     * Get the scroll bar value or null if there is no such scroll bar.
+     * Get the scroll bar value or 0 if there is no such scroll bar.
+     * 
+     * @param bar  the scroll bar (<code>null</code> permitted).
+     * 
+     * @return The scroll bar value, or 0.
      */
     final int getValue(JScrollBar bar)
     {
@@ -478,6 +494,197 @@
       v.getComponent(i).addMouseWheelListener(mouseWheelListener);
   }
 
+  InputMap getInputMap(int condition) 
+  {
+    if (condition == JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT)
+      return (InputMap) UIManager.get("ScrollPane.ancestorInputMap");
+    return null;
+  }
+
+  /**
+   * Returns the action map for the address@hidden JScrollPane}.  All scroll 
panes 
+   * share a single action map which is created the first time this method is 
+   * called, then stored in the UIDefaults table for subsequent access.
+   * 
+   * @return The shared action map.
+   */
+  ActionMap getActionMap() 
+  {
+    ActionMap map = (ActionMap) UIManager.get("ScrollPane.actionMap");
+
+    if (map == null) // first time here
+      {
+        map = createActionMap();
+        if (map != null)
+          UIManager.put("Slider.actionMap", map);
+      }
+    return map;
+  }
+
+  /**
+   * Creates the action map shared by all address@hidden JSlider} instances.
+   * This method is called once by address@hidden #getActionMap()} when it 
+   * finds no action map in the UIDefaults table...after the map is 
+   * created, it gets added to the defaults table so that subsequent 
+   * calls to address@hidden #getActionMap()} will return the same shared 
+   * instance.
+   * 
+   * @return The action map.
+   */
+  ActionMap createActionMap()
+  {
+    ActionMap map = new ActionMapUIResource();
+    map.put("scrollLeft", 
+            new AbstractAction("scrollLeft") {
+              public void actionPerformed(ActionEvent event)
+              {
+                JScrollPane sp = (JScrollPane) event.getSource();
+                JScrollBar sb = sp.getHorizontalScrollBar();
+                if (sb.isVisible()) 
+                  {
+                    int delta = sb.getBlockIncrement(-1);
+                    sb.setValue(sb.getValue() + delta);
+                  }
+              }
+            }
+    );
+    map.put("scrollEnd", 
+            new AbstractAction("scrollEnd") {
+              public void actionPerformed(ActionEvent event)
+              {
+                JScrollPane sp = (JScrollPane) event.getSource();
+                JScrollBar sb1 = sp.getHorizontalScrollBar();
+                if (sb1.isVisible()) 
+                  {
+                    sb1.setValue(sb1.getMaximum());
+                  }
+                JScrollBar sb2 = sp.getVerticalScrollBar();
+                if (sb2.isVisible()) 
+                  {
+                    sb2.setValue(sb2.getMaximum());
+                  }
+              }
+            }
+    );
+    map.put("unitScrollUp", 
+            new AbstractAction("unitScrollUp") {
+              public void actionPerformed(ActionEvent event)
+              {
+                JScrollPane sp = (JScrollPane) event.getSource();
+                JScrollBar sb = sp.getVerticalScrollBar();
+                if (sb.isVisible()) 
+                  {
+                    int delta = sb.getUnitIncrement(-1);
+                    sb.setValue(sb.getValue() + delta);
+                  }
+              }
+            }
+    );
+    map.put("unitScrollLeft", 
+            new AbstractAction("unitScrollLeft") {
+              public void actionPerformed(ActionEvent event)
+              {
+                JScrollPane sp = (JScrollPane) event.getSource();
+                JScrollBar sb = sp.getHorizontalScrollBar();
+                if (sb.isVisible()) 
+                  {
+                    int delta = sb.getUnitIncrement(-1);
+                    sb.setValue(sb.getValue() + delta);
+                  }
+              }
+            }
+    );
+    map.put("scrollUp", 
+            new AbstractAction("scrollUp") {
+              public void actionPerformed(ActionEvent event)
+              {
+                JScrollPane sp = (JScrollPane) event.getSource();
+                JScrollBar sb = sp.getVerticalScrollBar();
+                if (sb.isVisible()) 
+                  {
+                    int delta = sb.getBlockIncrement(-1);
+                    sb.setValue(sb.getValue() + delta);
+                  }
+              }
+            }
+    );
+    map.put("scrollRight", 
+            new AbstractAction("scrollRight") {
+              public void actionPerformed(ActionEvent event)
+              {
+                JScrollPane sp = (JScrollPane) event.getSource();
+                JScrollBar sb = sp.getHorizontalScrollBar();
+                if (sb.isVisible()) 
+                  {
+                    int delta = sb.getBlockIncrement(1);
+                    sb.setValue(sb.getValue() + delta);
+                  }
+              }
+            }
+    );
+    map.put("scrollHome", 
+            new AbstractAction("scrollHome") {
+              public void actionPerformed(ActionEvent event)
+              {
+                JScrollPane sp = (JScrollPane) event.getSource();
+                JScrollBar sb1 = sp.getHorizontalScrollBar();
+                if (sb1.isVisible()) 
+                  {
+                    sb1.setValue(sb1.getMinimum());
+                  }
+                JScrollBar sb2 = sp.getVerticalScrollBar();
+                if (sb2.isVisible()) 
+                  {
+                    sb2.setValue(sb2.getMinimum());
+                  }
+              }
+            }
+    );
+    map.put("scrollDown", 
+            new AbstractAction("scrollDown") {
+              public void actionPerformed(ActionEvent event)
+              {
+                JScrollPane sp = (JScrollPane) event.getSource();
+                JScrollBar sb = sp.getVerticalScrollBar();
+                if (sb.isVisible()) 
+                  {
+                    int delta = sb.getBlockIncrement(1);
+                    sb.setValue(sb.getValue() + delta);
+                  }
+              }
+            }
+    );
+    map.put("unitScrollDown", 
+            new AbstractAction("unitScrollDown") {
+              public void actionPerformed(ActionEvent event)
+              {
+                JScrollPane sp = (JScrollPane) event.getSource();
+                JScrollBar sb = sp.getVerticalScrollBar();
+                if (sb.isVisible()) 
+                  {
+                    int delta = sb.getUnitIncrement(1);
+                    sb.setValue(sb.getValue() + delta);
+                  }
+              }
+            }
+    );
+    map.put("unitScrollRight", 
+            new AbstractAction("unitScrollRight") {
+              public void actionPerformed(ActionEvent event)
+              {
+                JScrollPane sp = (JScrollPane) event.getSource();
+                JScrollBar sb = sp.getHorizontalScrollBar();
+                if (sb.isVisible()) 
+                  {
+                    int delta = sb.getUnitIncrement(1);
+                    sb.setValue(sb.getValue() + delta);
+                  }
+              }
+            }
+    );
+    return map;
+  }
+  
   /**
    * Installs additional keyboard actions on the scrollpane. This is a hook
    * method provided to subclasses in order to install their own keyboard
@@ -486,10 +693,27 @@
    * @param sp the scrollpane to install keyboard actions on
    */
   protected void installKeyboardActions(JScrollPane sp)
-    throws NotImplementedException
   {
-    // TODO: Is this only a hook method or should we actually do something
-    // here? If the latter, than figure out what and implement this.
+    InputMap keyMap = getInputMap(
+        JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
+    SwingUtilities.replaceUIInputMap(sp, 
+        JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, keyMap);
+    ActionMap map = getActionMap();
+    SwingUtilities.replaceUIActionMap(sp, map);
+  }
+
+  /**
+   * Uninstalls all keyboard actions from the JScrollPane that have been
+   * installed by address@hidden #installKeyboardActions}. This is a hook 
method
+   * provided to subclasses to add their own keyboard actions.
+   *
+   * @param sp the scrollpane to uninstall keyboard actions from
+   */
+  protected void uninstallKeyboardActions(JScrollPane sp)
+  {
+    SwingUtilities.replaceUIActionMap(sp, null);
+    SwingUtilities.replaceUIInputMap(sp, 
+        JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, null);
   }
 
   /**
@@ -536,6 +760,8 @@
    * Creates and returns the mouse wheel listener for the scrollpane.
    *
    * @return the mouse wheel listener for the scrollpane
+   * 
+   * @since 1.4
    */
   protected MouseWheelListener createMouseWheelListener()
   {
@@ -574,20 +800,6 @@
 
   }
 
-  /**
-   * Uninstalls all keyboard actions from the JScrollPane that have been
-   * installed by address@hidden #installKeyboardActions}. This is a hook 
method
-   * provided to subclasses to add their own keyboard actions.
-   *
-   * @param sp the scrollpane to uninstall keyboard actions from
-   */
-  protected void uninstallKeyboardActions(JScrollPane sp)
-    throws NotImplementedException
-  {
-    // TODO: Is this only a hook method or should we actually do something
-    // here? If the latter, than figure out what and implement this.
-  }
-
   public Dimension getMinimumSize(JComponent c) 
   {
     JScrollPane p = (JScrollPane) c;




reply via email to

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