0N/A/*
3261N/A * Copyright (c) 1996, 2010, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/Apackage java.awt;
0N/A
0N/Aimport java.awt.peer.LightweightPeer;
0N/Aimport java.awt.peer.ScrollPanePeer;
0N/Aimport java.awt.event.*;
0N/Aimport javax.accessibility.*;
0N/Aimport sun.awt.ScrollPaneWheelScroller;
0N/Aimport sun.awt.SunToolkit;
0N/A
0N/Aimport java.beans.ConstructorProperties;
243N/Aimport java.beans.Transient;
0N/Aimport java.io.ObjectInputStream;
0N/Aimport java.io.ObjectOutputStream;
0N/Aimport java.io.IOException;
0N/A
0N/A/**
0N/A * A container class which implements automatic horizontal and/or
0N/A * vertical scrolling for a single child component. The display
0N/A * policy for the scrollbars can be set to:
0N/A * <OL>
0N/A * <LI>as needed: scrollbars created and shown only when needed by scrollpane
0N/A * <LI>always: scrollbars created and always shown by the scrollpane
0N/A * <LI>never: scrollbars never created or shown by the scrollpane
0N/A * </OL>
0N/A * <P>
0N/A * The state of the horizontal and vertical scrollbars is represented
0N/A * by two <code>ScrollPaneAdjustable</code> objects (one for each
0N/A * dimension) which implement the <code>Adjustable</code> interface.
0N/A * The API provides methods to access those objects such that the
0N/A * attributes on the Adjustable object (such as unitIncrement, value,
0N/A * etc.) can be manipulated.
0N/A * <P>
0N/A * Certain adjustable properties (minimum, maximum, blockIncrement,
0N/A * and visibleAmount) are set internally by the scrollpane in accordance
0N/A * with the geometry of the scrollpane and its child and these should
0N/A * not be set by programs using the scrollpane.
0N/A * <P>
0N/A * If the scrollbar display policy is defined as "never", then the
0N/A * scrollpane can still be programmatically scrolled using the
0N/A * setScrollPosition() method and the scrollpane will move and clip
0N/A * the child's contents appropriately. This policy is useful if the
0N/A * program needs to create and manage its own adjustable controls.
0N/A * <P>
0N/A * The placement of the scrollbars is controlled by platform-specific
0N/A * properties set by the user outside of the program.
0N/A * <P>
0N/A * The initial size of this container is set to 100x100, but can
0N/A * be reset using setSize().
0N/A * <P>
0N/A * Scrolling with the wheel on a wheel-equipped mouse is enabled by default.
0N/A * This can be disabled using <code>setWheelScrollingEnabled</code>.
0N/A * Wheel scrolling can be customized by setting the block and
0N/A * unit increment of the horizontal and vertical Adjustables.
0N/A * For information on how mouse wheel events are dispatched, see
0N/A * the class description for {@link MouseWheelEvent}.
0N/A * <P>
0N/A * Insets are used to define any space used by scrollbars and any
0N/A * borders created by the scroll pane. getInsets() can be used
0N/A * to get the current value for the insets. If the value of
0N/A * scrollbarsAlwaysVisible is false, then the value of the insets
0N/A * will change dynamically depending on whether the scrollbars are
0N/A * currently visible or not.
0N/A *
0N/A * @author Tom Ball
0N/A * @author Amy Fowler
0N/A * @author Tim Prinzing
0N/A */
0N/Apublic class ScrollPane extends Container implements Accessible {
0N/A
0N/A
0N/A /**
0N/A * Initialize JNI field and method IDs
0N/A */
0N/A private static native void initIDs();
0N/A
0N/A static {
0N/A /* ensure that the necessary native libraries are loaded */
0N/A Toolkit.loadLibraries();
0N/A if (!GraphicsEnvironment.isHeadless()) {
0N/A initIDs();
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Specifies that horizontal/vertical scrollbar should be shown
0N/A * only when the size of the child exceeds the size of the scrollpane
0N/A * in the horizontal/vertical dimension.
0N/A */
0N/A public static final int SCROLLBARS_AS_NEEDED = 0;
0N/A
0N/A /**
0N/A * Specifies that horizontal/vertical scrollbars should always be
0N/A * shown regardless of the respective sizes of the scrollpane and child.
0N/A */
0N/A public static final int SCROLLBARS_ALWAYS = 1;
0N/A
0N/A /**
0N/A * Specifies that horizontal/vertical scrollbars should never be shown
0N/A * regardless of the respective sizes of the scrollpane and child.
0N/A */
0N/A public static final int SCROLLBARS_NEVER = 2;
0N/A
0N/A /**
0N/A * There are 3 ways in which a scroll bar can be displayed.
0N/A * This integer will represent one of these 3 displays -
0N/A * (SCROLLBARS_ALWAYS, SCROLLBARS_AS_NEEDED, SCROLLBARS_NEVER)
0N/A *
0N/A * @serial
0N/A * @see #getScrollbarDisplayPolicy
0N/A */
0N/A private int scrollbarDisplayPolicy;
0N/A
0N/A /**
0N/A * An adjustable vertical scrollbar.
0N/A * It is important to note that you must <em>NOT</em> call 3
0N/A * <code>Adjustable</code> methods, namely:
0N/A * <code>setMinimum()</code>, <code>setMaximum()</code>,
0N/A * <code>setVisibleAmount()</code>.
0N/A *
0N/A * @serial
0N/A * @see #getVAdjustable
0N/A */
0N/A private ScrollPaneAdjustable vAdjustable;
0N/A
0N/A /**
0N/A * An adjustable horizontal scrollbar.
0N/A * It is important to note that you must <em>NOT</em> call 3
0N/A * <code>Adjustable</code> methods, namely:
0N/A * <code>setMinimum()</code>, <code>setMaximum()</code>,
0N/A * <code>setVisibleAmount()</code>.
0N/A *
0N/A * @serial
0N/A * @see #getHAdjustable
0N/A */
0N/A private ScrollPaneAdjustable hAdjustable;
0N/A
0N/A private static final String base = "scrollpane";
0N/A private static int nameCounter = 0;
0N/A
0N/A private static final boolean defaultWheelScroll = true;
0N/A
0N/A /**
0N/A * Indicates whether or not scrolling should take place when a
0N/A * MouseWheelEvent is received.
0N/A *
0N/A * @serial
0N/A * @since 1.4
0N/A */
0N/A private boolean wheelScrollingEnabled = defaultWheelScroll;
0N/A
0N/A /*
0N/A * JDK 1.1 serialVersionUID
0N/A */
0N/A private static final long serialVersionUID = 7956609840827222915L;
0N/A
0N/A /**
0N/A * Create a new scrollpane container with a scrollbar display
0N/A * policy of "as needed".
0N/A * @throws HeadlessException if GraphicsEnvironment.isHeadless()
0N/A * returns true
0N/A * @see java.awt.GraphicsEnvironment#isHeadless
0N/A */
0N/A public ScrollPane() throws HeadlessException {
0N/A this(SCROLLBARS_AS_NEEDED);
0N/A }
0N/A
0N/A /**
0N/A * Create a new scrollpane container.
0N/A * @param scrollbarDisplayPolicy policy for when scrollbars should be shown
0N/A * @throws IllegalArgumentException if the specified scrollbar
0N/A * display policy is invalid
0N/A * @throws HeadlessException if GraphicsEnvironment.isHeadless()
0N/A * returns true
0N/A * @see java.awt.GraphicsEnvironment#isHeadless
0N/A */
0N/A @ConstructorProperties({"scrollbarDisplayPolicy"})
0N/A public ScrollPane(int scrollbarDisplayPolicy) throws HeadlessException {
0N/A GraphicsEnvironment.checkHeadless();
0N/A this.layoutMgr = null;
0N/A this.width = 100;
0N/A this.height = 100;
0N/A switch (scrollbarDisplayPolicy) {
0N/A case SCROLLBARS_NEVER:
0N/A case SCROLLBARS_AS_NEEDED:
0N/A case SCROLLBARS_ALWAYS:
0N/A this.scrollbarDisplayPolicy = scrollbarDisplayPolicy;
0N/A break;
0N/A default:
0N/A throw new IllegalArgumentException("illegal scrollbar display policy");
0N/A }
0N/A
0N/A vAdjustable = new ScrollPaneAdjustable(this, new PeerFixer(this),
0N/A Adjustable.VERTICAL);
0N/A hAdjustable = new ScrollPaneAdjustable(this, new PeerFixer(this),
0N/A Adjustable.HORIZONTAL);
0N/A setWheelScrollingEnabled(defaultWheelScroll);
0N/A }
0N/A
0N/A /**
0N/A * Construct a name for this component. Called by getName() when the
0N/A * name is null.
0N/A */
0N/A String constructComponentName() {
0N/A synchronized (ScrollPane.class) {
0N/A return base + nameCounter++;
0N/A }
0N/A }
0N/A
0N/A // The scrollpane won't work with a windowless child... it assumes
0N/A // it is moving a child window around so the windowless child is
0N/A // wrapped with a window.
0N/A private void addToPanel(Component comp, Object constraints, int index) {
0N/A Panel child = new Panel();
0N/A child.setLayout(new BorderLayout());
0N/A child.add(comp);
0N/A super.addImpl(child, constraints, index);
0N/A validate();
0N/A }
0N/A
0N/A /**
0N/A * Adds the specified component to this scroll pane container.
0N/A * If the scroll pane has an existing child component, that
0N/A * component is removed and the new one is added.
0N/A * @param comp the component to be added
0N/A * @param constraints not applicable
0N/A * @param index position of child component (must be <= 0)
0N/A */
0N/A protected final void addImpl(Component comp, Object constraints, int index) {
0N/A synchronized (getTreeLock()) {
0N/A if (getComponentCount() > 0) {
0N/A remove(0);
0N/A }
0N/A if (index > 0) {
0N/A throw new IllegalArgumentException("position greater than 0");
0N/A }
0N/A
0N/A if (!SunToolkit.isLightweightOrUnknown(comp)) {
0N/A super.addImpl(comp, constraints, index);
0N/A } else {
0N/A addToPanel(comp, constraints, index);
0N/A }
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Returns the display policy for the scrollbars.
0N/A * @return the display policy for the scrollbars
0N/A */
0N/A public int getScrollbarDisplayPolicy() {
0N/A return scrollbarDisplayPolicy;
0N/A }
0N/A
0N/A /**
0N/A * Returns the current size of the scroll pane's view port.
0N/A * @return the size of the view port in pixels
0N/A */
0N/A public Dimension getViewportSize() {
0N/A Insets i = getInsets();
0N/A return new Dimension(width - i.right - i.left,
0N/A height - i.top - i.bottom);
0N/A }
0N/A
0N/A /**
0N/A * Returns the height that would be occupied by a horizontal
0N/A * scrollbar, which is independent of whether it is currently
0N/A * displayed by the scroll pane or not.
0N/A * @return the height of a horizontal scrollbar in pixels
0N/A */
0N/A public int getHScrollbarHeight() {
0N/A int h = 0;
0N/A if (scrollbarDisplayPolicy != SCROLLBARS_NEVER) {
0N/A ScrollPanePeer peer = (ScrollPanePeer)this.peer;
0N/A if (peer != null) {
0N/A h = peer.getHScrollbarHeight();
0N/A }
0N/A }
0N/A return h;
0N/A }
0N/A
0N/A /**
0N/A * Returns the width that would be occupied by a vertical
0N/A * scrollbar, which is independent of whether it is currently
0N/A * displayed by the scroll pane or not.
0N/A * @return the width of a vertical scrollbar in pixels
0N/A */
0N/A public int getVScrollbarWidth() {
0N/A int w = 0;
0N/A if (scrollbarDisplayPolicy != SCROLLBARS_NEVER) {
0N/A ScrollPanePeer peer = (ScrollPanePeer)this.peer;
0N/A if (peer != null) {
0N/A w = peer.getVScrollbarWidth();
0N/A }
0N/A }
0N/A return w;
0N/A }
0N/A
0N/A /**
0N/A * Returns the <code>ScrollPaneAdjustable</code> object which
0N/A * represents the state of the vertical scrollbar.
0N/A * The declared return type of this method is
0N/A * <code>Adjustable</code> to maintain backward compatibility.
0N/A * @see java.awt.ScrollPaneAdjustable
0N/A */
0N/A public Adjustable getVAdjustable() {
0N/A return vAdjustable;
0N/A }
0N/A
0N/A /**
0N/A * Returns the <code>ScrollPaneAdjustable</code> object which
0N/A * represents the state of the horizontal scrollbar.
0N/A * The declared return type of this method is
0N/A * <code>Adjustable</code> to maintain backward compatibility.
0N/A * @see java.awt.ScrollPaneAdjustable
0N/A */
0N/A public Adjustable getHAdjustable() {
0N/A return hAdjustable;
0N/A }
0N/A
0N/A /**
0N/A * Scrolls to the specified position within the child component.
0N/A * A call to this method is only valid if the scroll pane contains
0N/A * a child. Specifying a position outside of the legal scrolling bounds
0N/A * of the child will scroll to the closest legal position.
0N/A * Legal bounds are defined to be the rectangle:
0N/A * x = 0, y = 0, width = (child width - view port width),
0N/A * height = (child height - view port height).
0N/A * This is a convenience method which interfaces with the Adjustable
0N/A * objects which represent the state of the scrollbars.
0N/A * @param x the x position to scroll to
0N/A * @param y the y position to scroll to
0N/A * @throws NullPointerException if the scrollpane does not contain
0N/A * a child
0N/A */
0N/A public void setScrollPosition(int x, int y) {
0N/A synchronized (getTreeLock()) {
544N/A if (getComponentCount()==0) {
0N/A throw new NullPointerException("child is null");
0N/A }
0N/A hAdjustable.setValue(x);
0N/A vAdjustable.setValue(y);
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Scrolls to the specified position within the child component.
0N/A * A call to this method is only valid if the scroll pane contains
0N/A * a child and the specified position is within legal scrolling bounds
0N/A * of the child. Specifying a position outside of the legal scrolling
0N/A * bounds of the child will scroll to the closest legal position.
0N/A * Legal bounds are defined to be the rectangle:
0N/A * x = 0, y = 0, width = (child width - view port width),
0N/A * height = (child height - view port height).
0N/A * This is a convenience method which interfaces with the Adjustable
0N/A * objects which represent the state of the scrollbars.
0N/A * @param p the Point representing the position to scroll to
3025N/A * @throws NullPointerException if {@code p} is {@code null}
0N/A */
0N/A public void setScrollPosition(Point p) {
0N/A setScrollPosition(p.x, p.y);
0N/A }
0N/A
0N/A /**
0N/A * Returns the current x,y position within the child which is displayed
0N/A * at the 0,0 location of the scrolled panel's view port.
0N/A * This is a convenience method which interfaces with the adjustable
0N/A * objects which represent the state of the scrollbars.
0N/A * @return the coordinate position for the current scroll position
0N/A * @throws NullPointerException if the scrollpane does not contain
0N/A * a child
0N/A */
243N/A @Transient
0N/A public Point getScrollPosition() {
544N/A synchronized (getTreeLock()) {
544N/A if (getComponentCount()==0) {
544N/A throw new NullPointerException("child is null");
544N/A }
544N/A return new Point(hAdjustable.getValue(), vAdjustable.getValue());
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Sets the layout manager for this container. This method is
0N/A * overridden to prevent the layout mgr from being set.
0N/A * @param mgr the specified layout manager
0N/A */
0N/A public final void setLayout(LayoutManager mgr) {
0N/A throw new AWTError("ScrollPane controls layout");
0N/A }
0N/A
0N/A /**
0N/A * Lays out this container by resizing its child to its preferred size.
0N/A * If the new preferred size of the child causes the current scroll
0N/A * position to be invalid, the scroll position is set to the closest
0N/A * valid position.
0N/A *
0N/A * @see Component#validate
0N/A */
0N/A public void doLayout() {
0N/A layout();
0N/A }
0N/A
0N/A /**
0N/A * Determine the size to allocate the child component.
0N/A * If the viewport area is bigger than the childs
0N/A * preferred size then the child is allocated enough
0N/A * to fill the viewport, otherwise the child is given
0N/A * it's preferred size.
0N/A */
0N/A Dimension calculateChildSize() {
0N/A //
0N/A // calculate the view size, accounting for border but not scrollbars
0N/A // - don't use right/bottom insets since they vary depending
0N/A // on whether or not scrollbars were displayed on last resize
0N/A //
0N/A Dimension size = getSize();
0N/A Insets insets = getInsets();
0N/A int viewWidth = size.width - insets.left*2;
0N/A int viewHeight = size.height - insets.top*2;
0N/A
0N/A //
0N/A // determine whether or not horz or vert scrollbars will be displayed
0N/A //
0N/A boolean vbarOn;
0N/A boolean hbarOn;
0N/A Component child = getComponent(0);
0N/A Dimension childSize = new Dimension(child.getPreferredSize());
0N/A
0N/A if (scrollbarDisplayPolicy == SCROLLBARS_AS_NEEDED) {
0N/A vbarOn = childSize.height > viewHeight;
0N/A hbarOn = childSize.width > viewWidth;
0N/A } else if (scrollbarDisplayPolicy == SCROLLBARS_ALWAYS) {
0N/A vbarOn = hbarOn = true;
0N/A } else { // SCROLLBARS_NEVER
0N/A vbarOn = hbarOn = false;
0N/A }
0N/A
0N/A //
0N/A // adjust predicted view size to account for scrollbars
0N/A //
0N/A int vbarWidth = getVScrollbarWidth();
0N/A int hbarHeight = getHScrollbarHeight();
0N/A if (vbarOn) {
0N/A viewWidth -= vbarWidth;
0N/A }
0N/A if(hbarOn) {
0N/A viewHeight -= hbarHeight;
0N/A }
0N/A
0N/A //
0N/A // if child is smaller than view, size it up
0N/A //
0N/A if (childSize.width < viewWidth) {
0N/A childSize.width = viewWidth;
0N/A }
0N/A if (childSize.height < viewHeight) {
0N/A childSize.height = viewHeight;
0N/A }
0N/A
0N/A return childSize;
0N/A }
0N/A
0N/A /**
0N/A * @deprecated As of JDK version 1.1,
0N/A * replaced by <code>doLayout()</code>.
0N/A */
0N/A @Deprecated
0N/A public void layout() {
544N/A if (getComponentCount()==0) {
544N/A return;
544N/A }
544N/A Component c = getComponent(0);
544N/A Point p = getScrollPosition();
544N/A Dimension cs = calculateChildSize();
544N/A Dimension vs = getViewportSize();
544N/A Insets i = getInsets();
0N/A
544N/A c.reshape(i.left - p.x, i.top - p.y, cs.width, cs.height);
544N/A ScrollPanePeer peer = (ScrollPanePeer)this.peer;
544N/A if (peer != null) {
544N/A peer.childResized(cs.width, cs.height);
544N/A }
0N/A
544N/A // update adjustables... the viewport size may have changed
544N/A // with the scrollbars coming or going so the viewport size
544N/A // is updated before the adjustables.
544N/A vs = getViewportSize();
544N/A hAdjustable.setSpan(0, cs.width, vs.width);
544N/A vAdjustable.setSpan(0, cs.height, vs.height);
0N/A }
0N/A
0N/A /**
0N/A * Prints the component in this scroll pane.
0N/A * @param g the specified Graphics window
0N/A * @see Component#print
0N/A * @see Component#printAll
0N/A */
0N/A public void printComponents(Graphics g) {
544N/A if (getComponentCount()==0) {
544N/A return;
544N/A }
544N/A Component c = getComponent(0);
544N/A Point p = c.getLocation();
544N/A Dimension vs = getViewportSize();
544N/A Insets i = getInsets();
0N/A
544N/A Graphics cg = g.create();
544N/A try {
544N/A cg.clipRect(i.left, i.top, vs.width, vs.height);
544N/A cg.translate(p.x, p.y);
544N/A c.printAll(cg);
544N/A } finally {
544N/A cg.dispose();
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Creates the scroll pane's peer.
0N/A */
0N/A public void addNotify() {
0N/A synchronized (getTreeLock()) {
0N/A
0N/A int vAdjustableValue = 0;
0N/A int hAdjustableValue = 0;
0N/A
0N/A // Bug 4124460. Save the current adjustable values,
0N/A // so they can be restored after addnotify. Set the
0N/A // adjustables to 0, to prevent crashes for possible
0N/A // negative values.
0N/A if (getComponentCount() > 0) {
0N/A vAdjustableValue = vAdjustable.getValue();
0N/A hAdjustableValue = hAdjustable.getValue();
0N/A vAdjustable.setValue(0);
0N/A hAdjustable.setValue(0);
0N/A }
0N/A
0N/A if (peer == null)
0N/A peer = getToolkit().createScrollPane(this);
0N/A super.addNotify();
0N/A
0N/A // Bug 4124460. Restore the adjustable values.
0N/A if (getComponentCount() > 0) {
0N/A vAdjustable.setValue(vAdjustableValue);
0N/A hAdjustable.setValue(hAdjustableValue);
0N/A }
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Returns a string representing the state of this
0N/A * <code>ScrollPane</code>. This
0N/A * method is intended to be used only for debugging purposes, and the
0N/A * content and format of the returned string may vary between
0N/A * implementations. The returned string may be empty but may not be
0N/A * <code>null</code>.
0N/A *
0N/A * @return the parameter string of this scroll pane
0N/A */
0N/A public String paramString() {
0N/A String sdpStr;
0N/A switch (scrollbarDisplayPolicy) {
0N/A case SCROLLBARS_AS_NEEDED:
0N/A sdpStr = "as-needed";
0N/A break;
0N/A case SCROLLBARS_ALWAYS:
0N/A sdpStr = "always";
0N/A break;
0N/A case SCROLLBARS_NEVER:
0N/A sdpStr = "never";
0N/A break;
0N/A default:
0N/A sdpStr = "invalid display policy";
0N/A }
544N/A Point p = (getComponentCount()>0)? getScrollPosition() : new Point(0,0);
0N/A Insets i = getInsets();
0N/A return super.paramString()+",ScrollPosition=("+p.x+","+p.y+")"+
0N/A ",Insets=("+i.top+","+i.left+","+i.bottom+","+i.right+")"+
0N/A ",ScrollbarDisplayPolicy="+sdpStr+
0N/A ",wheelScrollingEnabled="+isWheelScrollingEnabled();
0N/A }
0N/A
0N/A void autoProcessMouseWheel(MouseWheelEvent e) {
0N/A processMouseWheelEvent(e);
0N/A }
0N/A
0N/A /**
0N/A * Process mouse wheel events that are delivered to this
0N/A * <code>ScrollPane</code> by scrolling an appropriate amount.
0N/A * <p>Note that if the event parameter is <code>null</code>
0N/A * the behavior is unspecified and may result in an
0N/A * exception.
0N/A *
0N/A * @param e the mouse wheel event
0N/A * @since 1.4
0N/A */
0N/A protected void processMouseWheelEvent(MouseWheelEvent e) {
0N/A if (isWheelScrollingEnabled()) {
0N/A ScrollPaneWheelScroller.handleWheelScrolling(this, e);
0N/A e.consume();
0N/A }
0N/A super.processMouseWheelEvent(e);
0N/A }
0N/A
0N/A /**
0N/A * If wheel scrolling is enabled, we return true for MouseWheelEvents
0N/A * @since 1.4
0N/A */
0N/A protected boolean eventTypeEnabled(int type) {
0N/A if (type == MouseEvent.MOUSE_WHEEL && isWheelScrollingEnabled()) {
0N/A return true;
0N/A }
0N/A else {
0N/A return super.eventTypeEnabled(type);
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Enables/disables scrolling in response to movement of the mouse wheel.
0N/A * Wheel scrolling is enabled by default.
0N/A *
0N/A * @param handleWheel <code>true</code> if scrolling should be done
0N/A * automatically for a MouseWheelEvent,
0N/A * <code>false</code> otherwise.
0N/A * @see #isWheelScrollingEnabled
0N/A * @see java.awt.event.MouseWheelEvent
0N/A * @see java.awt.event.MouseWheelListener
0N/A * @since 1.4
0N/A */
0N/A public void setWheelScrollingEnabled(boolean handleWheel) {
0N/A wheelScrollingEnabled = handleWheel;
0N/A }
0N/A
0N/A /**
0N/A * Indicates whether or not scrolling will take place in response to
0N/A * the mouse wheel. Wheel scrolling is enabled by default.
0N/A *
0N/A * @see #setWheelScrollingEnabled(boolean)
0N/A * @since 1.4
0N/A */
0N/A public boolean isWheelScrollingEnabled() {
0N/A return wheelScrollingEnabled;
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Writes default serializable fields to stream.
0N/A */
0N/A private void writeObject(ObjectOutputStream s) throws IOException {
0N/A // 4352819: We only need this degenerate writeObject to make
0N/A // it safe for future versions of this class to write optional
0N/A // data to the stream.
0N/A s.defaultWriteObject();
0N/A }
0N/A
0N/A /**
0N/A * Reads default serializable fields to stream.
0N/A * @exception HeadlessException if
0N/A * <code>GraphicsEnvironment.isHeadless()</code> returns
0N/A * <code>true</code>
0N/A * @see java.awt.GraphicsEnvironment#isHeadless
0N/A */
0N/A private void readObject(ObjectInputStream s)
0N/A throws ClassNotFoundException, IOException, HeadlessException
0N/A {
0N/A GraphicsEnvironment.checkHeadless();
0N/A // 4352819: Gotcha! Cannot use s.defaultReadObject here and
0N/A // then continue with reading optional data. Use GetField instead.
0N/A ObjectInputStream.GetField f = s.readFields();
0N/A
0N/A // Old fields
0N/A scrollbarDisplayPolicy = f.get("scrollbarDisplayPolicy",
0N/A SCROLLBARS_AS_NEEDED);
0N/A hAdjustable = (ScrollPaneAdjustable)f.get("hAdjustable", null);
0N/A vAdjustable = (ScrollPaneAdjustable)f.get("vAdjustable", null);
0N/A
0N/A // Since 1.4
0N/A wheelScrollingEnabled = f.get("wheelScrollingEnabled",
0N/A defaultWheelScroll);
0N/A
0N/A// // Note to future maintainers
0N/A// if (f.defaulted("wheelScrollingEnabled")) {
0N/A// // We are reading pre-1.4 stream that doesn't have
0N/A// // optional data, not even the TC_ENDBLOCKDATA marker.
0N/A// // Reading anything after this point is unsafe as we will
0N/A// // read unrelated objects further down the stream (4352819).
0N/A// }
0N/A// else {
0N/A// // Reading data from 1.4 or later, it's ok to try to read
0N/A// // optional data as OptionalDataException with eof == true
0N/A// // will be correctly reported
0N/A// }
0N/A }
0N/A
0N/A class PeerFixer implements AdjustmentListener, java.io.Serializable
0N/A {
0N/A private static final long serialVersionUID = 1043664721353696630L;
0N/A
0N/A PeerFixer(ScrollPane scroller) {
0N/A this.scroller = scroller;
0N/A }
0N/A
0N/A /**
0N/A * Invoked when the value of the adjustable has changed.
0N/A */
0N/A public void adjustmentValueChanged(AdjustmentEvent e) {
0N/A Adjustable adj = e.getAdjustable();
0N/A int value = e.getValue();
0N/A ScrollPanePeer peer = (ScrollPanePeer) scroller.peer;
0N/A if (peer != null) {
0N/A peer.setValue(adj, value);
0N/A }
0N/A
0N/A Component c = scroller.getComponent(0);
0N/A switch(adj.getOrientation()) {
0N/A case Adjustable.VERTICAL:
0N/A c.move(c.getLocation().x, -(value));
0N/A break;
0N/A case Adjustable.HORIZONTAL:
0N/A c.move(-(value), c.getLocation().y);
0N/A break;
0N/A default:
0N/A throw new IllegalArgumentException("Illegal adjustable orientation");
0N/A }
0N/A }
0N/A
0N/A private ScrollPane scroller;
0N/A }
0N/A
0N/A
0N/A/////////////////
0N/A// Accessibility support
0N/A////////////////
0N/A
0N/A /**
0N/A * Gets the AccessibleContext associated with this ScrollPane.
0N/A * For scroll panes, the AccessibleContext takes the form of an
0N/A * AccessibleAWTScrollPane.
0N/A * A new AccessibleAWTScrollPane instance is created if necessary.
0N/A *
0N/A * @return an AccessibleAWTScrollPane that serves as the
0N/A * AccessibleContext of this ScrollPane
0N/A * @since 1.3
0N/A */
0N/A public AccessibleContext getAccessibleContext() {
0N/A if (accessibleContext == null) {
0N/A accessibleContext = new AccessibleAWTScrollPane();
0N/A }
0N/A return accessibleContext;
0N/A }
0N/A
0N/A /**
0N/A * This class implements accessibility support for the
0N/A * <code>ScrollPane</code> class. It provides an implementation of the
0N/A * Java Accessibility API appropriate to scroll pane user-interface
0N/A * elements.
0N/A * @since 1.3
0N/A */
0N/A protected class AccessibleAWTScrollPane extends AccessibleAWTContainer
0N/A {
0N/A /*
0N/A * JDK 1.3 serialVersionUID
0N/A */
0N/A private static final long serialVersionUID = 6100703663886637L;
0N/A
0N/A /**
0N/A * Get the role of this object.
0N/A *
0N/A * @return an instance of AccessibleRole describing the role of the
0N/A * object
0N/A * @see AccessibleRole
0N/A */
0N/A public AccessibleRole getAccessibleRole() {
0N/A return AccessibleRole.SCROLL_PANE;
0N/A }
0N/A
0N/A } // class AccessibleAWTScrollPane
0N/A
0N/A}
0N/A
0N/A/*
0N/A * In JDK 1.1.1, the pkg private class java.awt.PeerFixer was moved to
0N/A * become an inner class of ScrollPane, which broke serialization
0N/A * for ScrollPane objects using JDK 1.1.
0N/A * Instead of moving it back out here, which would break all JDK 1.1.x
0N/A * releases, we keep PeerFixer in both places. Because of the scoping rules,
0N/A * the PeerFixer that is used in ScrollPane will be the one that is the
0N/A * inner class. This pkg private PeerFixer class below will only be used
0N/A * if the Java 2 platform is used to deserialize ScrollPane objects that were serialized
0N/A * using JDK1.1
0N/A */
0N/Aclass PeerFixer implements AdjustmentListener, java.io.Serializable {
0N/A /*
0N/A * serialVersionUID
0N/A */
0N/A private static final long serialVersionUID = 7051237413532574756L;
0N/A
0N/A PeerFixer(ScrollPane scroller) {
0N/A this.scroller = scroller;
0N/A }
0N/A
0N/A /**
0N/A * Invoked when the value of the adjustable has changed.
0N/A */
0N/A public void adjustmentValueChanged(AdjustmentEvent e) {
0N/A Adjustable adj = e.getAdjustable();
0N/A int value = e.getValue();
0N/A ScrollPanePeer peer = (ScrollPanePeer) scroller.peer;
0N/A if (peer != null) {
0N/A peer.setValue(adj, value);
0N/A }
0N/A
0N/A Component c = scroller.getComponent(0);
0N/A switch(adj.getOrientation()) {
0N/A case Adjustable.VERTICAL:
0N/A c.move(c.getLocation().x, -(value));
0N/A break;
0N/A case Adjustable.HORIZONTAL:
0N/A c.move(-(value), c.getLocation().y);
0N/A break;
0N/A default:
0N/A throw new IllegalArgumentException("Illegal adjustable orientation");
0N/A }
0N/A }
0N/A
0N/A private ScrollPane scroller;
0N/A}