summaryrefslogtreecommitdiff
path: root/javax/swing/plaf/basic/BasicScrollBarUI.java
diff options
context:
space:
mode:
authorAndrew John Hughes <gnu_andrew@member.fsf.org>2006-06-11 18:23:15 +0000
committerAndrew John Hughes <gnu_andrew@member.fsf.org>2006-06-11 18:23:15 +0000
commit35d18ccf396a6cfdcbe5bbdf38df7d01852250bc (patch)
tree562e6d161a8957db8a46900b46f661c5e52e1a34 /javax/swing/plaf/basic/BasicScrollBarUI.java
parentc5877847749d21bdf84e33929ffa52a56e5c6ca0 (diff)
downloadclasspath-35d18ccf396a6cfdcbe5bbdf38df7d01852250bc.tar.gz
2006-06-11 Andrew John Hughes <gnu_andrew@member.fsf.org>
* Merge of HEAD-->generics between 2006/05/29 and 2006/06/11.
Diffstat (limited to 'javax/swing/plaf/basic/BasicScrollBarUI.java')
-rw-r--r--javax/swing/plaf/basic/BasicScrollBarUI.java179
1 files changed, 155 insertions, 24 deletions
diff --git a/javax/swing/plaf/basic/BasicScrollBarUI.java b/javax/swing/plaf/basic/BasicScrollBarUI.java
index f24485484..a81120abd 100644
--- a/javax/swing/plaf/basic/BasicScrollBarUI.java
+++ b/javax/swing/plaf/basic/BasicScrollBarUI.java
@@ -1,5 +1,5 @@
/* BasicScrollBarUI.java --
- Copyright (C) 2004, 2005 Free Software Foundation, Inc.
+ Copyright (C) 2004, 2005, 2006, Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -38,8 +38,6 @@ exception statement from your version. */
package javax.swing.plaf.basic;
-import gnu.classpath.NotImplementedException;
-
import java.awt.Color;
import java.awt.Component;
import java.awt.Container;
@@ -56,10 +54,14 @@ import java.awt.event.MouseMotionListener;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
+import javax.swing.AbstractAction;
+import javax.swing.ActionMap;
import javax.swing.BoundedRangeModel;
+import javax.swing.InputMap;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JScrollBar;
+import javax.swing.JSlider;
import javax.swing.LookAndFeel;
import javax.swing.SwingConstants;
import javax.swing.SwingUtilities;
@@ -67,6 +69,7 @@ import javax.swing.Timer;
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.ScrollBarUI;
@@ -762,15 +765,151 @@ public class BasicScrollBarUI extends ScrollBarUI implements LayoutManager,
}
/**
- * This method installs the keyboard actions for the scrollbar.
+ * Installs the input map from the look and feel defaults, and a
+ * corresponding action map. Note the the keyboard bindings will only
+ * work when the {@link JScrollBar} component has the focus, which is rare.
*/
protected void installKeyboardActions()
- throws NotImplementedException
{
- // FIXME: implement.
+ InputMap keyMap = getInputMap(
+ JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
+ SwingUtilities.replaceUIInputMap(scrollbar,
+ JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, keyMap);
+ ActionMap map = getActionMap();
+ SwingUtilities.replaceUIActionMap(scrollbar, map);
+ }
+
+ /**
+ * Uninstalls the input map and action map installed by
+ * {@link #installKeyboardActions()}.
+ */
+ protected void uninstallKeyboardActions()
+ {
+ SwingUtilities.replaceUIActionMap(scrollbar, null);
+ SwingUtilities.replaceUIInputMap(scrollbar,
+ JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, null);
+ }
+
+ InputMap getInputMap(int condition)
+ {
+ if (condition == JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT)
+ return (InputMap) UIManager.get("ScrollBar.focusInputMap");
+ return null;
+ }
+
+ /**
+ * Returns the action map for the {@link JScrollBar}. All scroll bars
+ * 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("ScrollBar.actionMap");
+
+ if (map == null) // first time here
+ {
+ map = createActionMap();
+ if (map != null)
+ UIManager.put("ScrollBar.actionMap", map);
+ }
+ return map;
}
/**
+ * Creates the action map shared by all {@link JSlider} instances.
+ * This method is called once by {@link #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 {@link #getActionMap()} will return the same shared
+ * instance.
+ *
+ * @return The action map.
+ */
+ ActionMap createActionMap()
+ {
+ ActionMap map = new ActionMapUIResource();
+ map.put("positiveUnitIncrement",
+ new AbstractAction("positiveUnitIncrement") {
+ public void actionPerformed(ActionEvent event)
+ {
+ JScrollBar sb = (JScrollBar) event.getSource();
+ if (sb.isVisible())
+ {
+ int delta = sb.getUnitIncrement(1);
+ sb.setValue(sb.getValue() + delta);
+ }
+ }
+ }
+ );
+ map.put("positiveBlockIncrement",
+ new AbstractAction("positiveBlockIncrement") {
+ public void actionPerformed(ActionEvent event)
+ {
+ JScrollBar sb = (JScrollBar) event.getSource();
+ if (sb.isVisible())
+ {
+ int delta = sb.getBlockIncrement(1);
+ sb.setValue(sb.getValue() + delta);
+ }
+ }
+ }
+ );
+ map.put("negativeUnitIncrement",
+ new AbstractAction("negativeUnitIncrement") {
+ public void actionPerformed(ActionEvent event)
+ {
+ JScrollBar sb = (JScrollBar) event.getSource();
+ if (sb.isVisible())
+ {
+ int delta = sb.getUnitIncrement(-1);
+ sb.setValue(sb.getValue() + delta);
+ }
+ }
+ }
+ );
+ map.put("negativeBlockIncrement",
+ new AbstractAction("negativeBlockIncrement") {
+ public void actionPerformed(ActionEvent event)
+ {
+ JScrollBar sb = (JScrollBar) event.getSource();
+ if (sb.isVisible())
+ {
+ int delta = sb.getBlockIncrement(-1);
+ sb.setValue(sb.getValue() + delta);
+ }
+ }
+ }
+ );
+ map.put("minScroll",
+ new AbstractAction("minScroll") {
+ public void actionPerformed(ActionEvent event)
+ {
+ JScrollBar sb = (JScrollBar) event.getSource();
+ if (sb.isVisible())
+ {
+ sb.setValue(sb.getMinimum());
+ }
+ }
+ }
+ );
+ map.put("maxScroll",
+ new AbstractAction("maxScroll") {
+ public void actionPerformed(ActionEvent event)
+ {
+ JScrollBar sb = (JScrollBar) event.getSource();
+ if (sb.isVisible())
+ {
+ sb.setValue(sb.getMaximum());
+ }
+ }
+ }
+ );
+ return map;
+ }
+
+ /**
* This method installs any listeners for the scrollbar. This method also
* installs listeners for things such as the JButtons and the timer.
*/
@@ -806,19 +945,20 @@ public class BasicScrollBarUI extends ScrollBarUI implements LayoutManager,
super.installUI(c);
if (c instanceof JScrollBar)
{
- scrollbar = (JScrollBar) c;
+ scrollbar = (JScrollBar) c;
- trackRect = new Rectangle();
- thumbRect = new Rectangle();
+ trackRect = new Rectangle();
+ thumbRect = new Rectangle();
- scrollTimer = new Timer(300, null);
+ scrollTimer = new Timer(300, null);
installDefaults();
- installComponents();
- configureScrollBarColors();
- installListeners();
+ installComponents();
+ configureScrollBarColors();
+ installListeners();
+ installKeyboardActions();
- calculatePreferredSize();
+ calculatePreferredSize();
}
}
@@ -1140,16 +1280,6 @@ public class BasicScrollBarUI extends ScrollBarUI implements LayoutManager,
}
/**
- * This method uninstalls any keyboard actions this scrollbar acquired
- * during install.
- */
- protected void uninstallKeyboardActions()
- throws NotImplementedException
- {
- // FIXME: implement.
- }
-
- /**
* This method uninstalls any listeners that were registered during install.
*/
protected void uninstallListeners()
@@ -1186,6 +1316,7 @@ public class BasicScrollBarUI extends ScrollBarUI implements LayoutManager,
*/
public void uninstallUI(JComponent c)
{
+ uninstallKeyboardActions();
uninstallListeners();
uninstallDefaults();
uninstallComponents();