< prev index next >

src/java.desktop/share/classes/java/awt/ScrollPane.java

Print this page




  30 import sun.awt.ScrollPaneWheelScroller;
  31 import sun.awt.SunToolkit;
  32 
  33 import java.beans.ConstructorProperties;
  34 import java.beans.Transient;
  35 import java.io.ObjectInputStream;
  36 import java.io.ObjectOutputStream;
  37 import java.io.IOException;
  38 
  39 /**
  40  * A container class which implements automatic horizontal and/or
  41  * vertical scrolling for a single child component.  The display
  42  * policy for the scrollbars can be set to:
  43  * <OL>
  44  * <LI>as needed: scrollbars created and shown only when needed by scrollpane
  45  * <LI>always: scrollbars created and always shown by the scrollpane
  46  * <LI>never: scrollbars never created or shown by the scrollpane
  47  * </OL>
  48  * <P>
  49  * The state of the horizontal and vertical scrollbars is represented
  50  * by two <code>ScrollPaneAdjustable</code> objects (one for each
  51  * dimension) which implement the <code>Adjustable</code> interface.
  52  * The API provides methods to access those objects such that the
  53  * attributes on the Adjustable object (such as unitIncrement, value,
  54  * etc.) can be manipulated.
  55  * <P>
  56  * Certain adjustable properties (minimum, maximum, blockIncrement,
  57  * and visibleAmount) are set internally by the scrollpane in accordance
  58  * with the geometry of the scrollpane and its child and these should
  59  * not be set by programs using the scrollpane.
  60  * <P>
  61  * If the scrollbar display policy is defined as "never", then the
  62  * scrollpane can still be programmatically scrolled using the
  63  * setScrollPosition() method and the scrollpane will move and clip
  64  * the child's contents appropriately.  This policy is useful if the
  65  * program needs to create and manage its own adjustable controls.
  66  * <P>
  67  * The placement of the scrollbars is controlled by platform-specific
  68  * properties set by the user outside of the program.
  69  * <P>
  70  * The initial size of this container is set to 100x100, but can
  71  * be reset using setSize().
  72  * <P>
  73  * Scrolling with the wheel on a wheel-equipped mouse is enabled by default.
  74  * This can be disabled using <code>setWheelScrollingEnabled</code>.
  75  * Wheel scrolling can be customized by setting the block and
  76  * unit increment of the horizontal and vertical Adjustables.
  77  * For information on how mouse wheel events are dispatched, see
  78  * the class description for {@link MouseWheelEvent}.
  79  * <P>
  80  * Insets are used to define any space used by scrollbars and any
  81  * borders created by the scroll pane. getInsets() can be used
  82  * to get the current value for the insets.  If the value of
  83  * scrollbarsAlwaysVisible is false, then the value of the insets
  84  * will change dynamically depending on whether the scrollbars are
  85  * currently visible or not.
  86  *
  87  * @author      Tom Ball
  88  * @author      Amy Fowler
  89  * @author      Tim Prinzing
  90  */
  91 public class ScrollPane extends Container implements Accessible {
  92 
  93 
  94     /**


 119 
 120     /**
 121      * Specifies that horizontal/vertical scrollbars should never be shown
 122      * regardless of the respective sizes of the scrollpane and child.
 123      */
 124     public static final int SCROLLBARS_NEVER = 2;
 125 
 126     /**
 127      * There are 3 ways in which a scroll bar can be displayed.
 128      * This integer will represent one of these 3 displays -
 129      * (SCROLLBARS_ALWAYS, SCROLLBARS_AS_NEEDED, SCROLLBARS_NEVER)
 130      *
 131      * @serial
 132      * @see #getScrollbarDisplayPolicy
 133      */
 134     private int scrollbarDisplayPolicy;
 135 
 136     /**
 137      * An adjustable vertical scrollbar.
 138      * It is important to note that you must <em>NOT</em> call 3
 139      * <code>Adjustable</code> methods, namely:
 140      * <code>setMinimum()</code>, <code>setMaximum()</code>,
 141      * <code>setVisibleAmount()</code>.
 142      *
 143      * @serial
 144      * @see #getVAdjustable
 145      */
 146     private ScrollPaneAdjustable vAdjustable;
 147 
 148     /**
 149      * An adjustable horizontal scrollbar.
 150      * It is important to note that you must <em>NOT</em> call 3
 151      * <code>Adjustable</code> methods, namely:
 152      * <code>setMinimum()</code>, <code>setMaximum()</code>,
 153      * <code>setVisibleAmount()</code>.
 154      *
 155      * @serial
 156      * @see #getHAdjustable
 157      */
 158     private ScrollPaneAdjustable hAdjustable;
 159 
 160     private static final String base = "scrollpane";
 161     private static int nameCounter = 0;
 162 
 163     private static final boolean defaultWheelScroll = true;
 164 
 165     /**
 166      * Indicates whether or not scrolling should take place when a
 167      * MouseWheelEvent is received.
 168      *
 169      * @serial
 170      * @since 1.4
 171      */
 172     private boolean wheelScrollingEnabled = defaultWheelScroll;
 173 


 301     }
 302 
 303     /**
 304      * Returns the width that would be occupied by a vertical
 305      * scrollbar, which is independent of whether it is currently
 306      * displayed by the scroll pane or not.
 307      * @return the width of a vertical scrollbar in pixels
 308      */
 309     public int getVScrollbarWidth() {
 310         int w = 0;
 311         if (scrollbarDisplayPolicy != SCROLLBARS_NEVER) {
 312             ScrollPanePeer peer = (ScrollPanePeer)this.peer;
 313             if (peer != null) {
 314                 w = peer.getVScrollbarWidth();
 315             }
 316         }
 317         return w;
 318     }
 319 
 320     /**
 321      * Returns the <code>ScrollPaneAdjustable</code> object which
 322      * represents the state of the vertical scrollbar.
 323      * The declared return type of this method is
 324      * <code>Adjustable</code> to maintain backward compatibility.
 325      *
 326      * @see java.awt.ScrollPaneAdjustable
 327      * @return the vertical scrollbar state
 328      */
 329     public Adjustable getVAdjustable() {
 330         return vAdjustable;
 331     }
 332 
 333     /**
 334      * Returns the <code>ScrollPaneAdjustable</code> object which
 335      * represents the state of the horizontal scrollbar.
 336      * The declared return type of this method is
 337      * <code>Adjustable</code> to maintain backward compatibility.
 338      *
 339      * @see java.awt.ScrollPaneAdjustable
 340      * @return the horizontal scrollbar state
 341      */
 342     public Adjustable getHAdjustable() {
 343         return hAdjustable;
 344     }
 345 
 346     /**
 347      * Scrolls to the specified position within the child component.
 348      * A call to this method is only valid if the scroll pane contains
 349      * a child.  Specifying a position outside of the legal scrolling bounds
 350      * of the child will scroll to the closest legal position.
 351      * Legal bounds are defined to be the rectangle:
 352      * x = 0, y = 0, width = (child width - view port width),
 353      * height = (child height - view port height).
 354      * This is a convenience method which interfaces with the Adjustable
 355      * objects which represent the state of the scrollbars.
 356      * @param x the x position to scroll to
 357      * @param y the y position to scroll to


 471         }
 472         if(hbarOn) {
 473             viewHeight -= hbarHeight;
 474         }
 475 
 476         //
 477         // if child is smaller than view, size it up
 478         //
 479         if (childSize.width < viewWidth) {
 480             childSize.width = viewWidth;
 481         }
 482         if (childSize.height < viewHeight) {
 483             childSize.height = viewHeight;
 484         }
 485 
 486         return childSize;
 487     }
 488 
 489     /**
 490      * @deprecated As of JDK version 1.1,
 491      * replaced by <code>doLayout()</code>.
 492      */
 493     @Deprecated
 494     public void layout() {
 495         if (getComponentCount()==0) {
 496             return;
 497         }
 498         Component c = getComponent(0);
 499         Point p = getScrollPosition();
 500         Dimension cs = calculateChildSize();
 501         Dimension vs = getViewportSize();
 502 
 503         c.reshape(- p.x, - p.y, cs.width, cs.height);
 504         ScrollPanePeer peer = (ScrollPanePeer)this.peer;
 505         if (peer != null) {
 506             peer.childResized(cs.width, cs.height);
 507         }
 508 
 509         // update adjustables... the viewport size may have changed
 510         // with the scrollbars coming or going so the viewport size
 511         // is updated before the adjustables.


 556                 vAdjustableValue = vAdjustable.getValue();
 557                 hAdjustableValue = hAdjustable.getValue();
 558                 vAdjustable.setValue(0);
 559                 hAdjustable.setValue(0);
 560             }
 561 
 562             if (peer == null)
 563                 peer = getComponentFactory().createScrollPane(this);
 564             super.addNotify();
 565 
 566             // Bug 4124460. Restore the adjustable values.
 567             if (getComponentCount() > 0) {
 568                 vAdjustable.setValue(vAdjustableValue);
 569                 hAdjustable.setValue(hAdjustableValue);
 570             }
 571         }
 572     }
 573 
 574     /**
 575      * Returns a string representing the state of this
 576      * <code>ScrollPane</code>. This
 577      * method is intended to be used only for debugging purposes, and the
 578      * content and format of the returned string may vary between
 579      * implementations. The returned string may be empty but may not be
 580      * <code>null</code>.
 581      *
 582      * @return the parameter string of this scroll pane
 583      */
 584     public String paramString() {
 585         String sdpStr;
 586         switch (scrollbarDisplayPolicy) {
 587             case SCROLLBARS_AS_NEEDED:
 588                 sdpStr = "as-needed";
 589                 break;
 590             case SCROLLBARS_ALWAYS:
 591                 sdpStr = "always";
 592                 break;
 593             case SCROLLBARS_NEVER:
 594                 sdpStr = "never";
 595                 break;
 596             default:
 597                 sdpStr = "invalid display policy";
 598         }
 599         Point p = (getComponentCount()>0)? getScrollPosition() : new Point(0,0);
 600         Insets i = getInsets();
 601         return super.paramString()+",ScrollPosition=("+p.x+","+p.y+")"+
 602             ",Insets=("+i.top+","+i.left+","+i.bottom+","+i.right+")"+
 603             ",ScrollbarDisplayPolicy="+sdpStr+
 604         ",wheelScrollingEnabled="+isWheelScrollingEnabled();
 605     }
 606 
 607     void autoProcessMouseWheel(MouseWheelEvent e) {
 608         processMouseWheelEvent(e);
 609     }
 610 
 611     /**
 612      * Process mouse wheel events that are delivered to this
 613      * <code>ScrollPane</code> by scrolling an appropriate amount.
 614      * <p>Note that if the event parameter is <code>null</code>
 615      * the behavior is unspecified and may result in an
 616      * exception.
 617      *
 618      * @param e  the mouse wheel event
 619      * @since 1.4
 620      */
 621     protected void processMouseWheelEvent(MouseWheelEvent e) {
 622         if (isWheelScrollingEnabled()) {
 623             ScrollPaneWheelScroller.handleWheelScrolling(this, e);
 624             e.consume();
 625         }
 626         super.processMouseWheelEvent(e);
 627     }
 628 
 629     /**
 630      * If wheel scrolling is enabled, we return true for MouseWheelEvents
 631      * @since 1.4
 632      */
 633     protected boolean eventTypeEnabled(int type) {
 634         if (type == MouseEvent.MOUSE_WHEEL && isWheelScrollingEnabled()) {
 635             return true;
 636         }
 637         else {
 638             return super.eventTypeEnabled(type);
 639         }
 640     }
 641 
 642     /**
 643      * Enables/disables scrolling in response to movement of the mouse wheel.
 644      * Wheel scrolling is enabled by default.
 645      *
 646      * @param handleWheel   <code>true</code> if scrolling should be done
 647      *                      automatically for a MouseWheelEvent,
 648      *                      <code>false</code> otherwise.
 649      * @see #isWheelScrollingEnabled
 650      * @see java.awt.event.MouseWheelEvent
 651      * @see java.awt.event.MouseWheelListener
 652      * @since 1.4
 653      */
 654     public void setWheelScrollingEnabled(boolean handleWheel) {
 655         wheelScrollingEnabled = handleWheel;
 656     }
 657 
 658     /**
 659      * Indicates whether or not scrolling will take place in response to
 660      * the mouse wheel.  Wheel scrolling is enabled by default.
 661      *
 662      * @return {@code true} if the wheel scrolling enabled;
 663      *         otherwise {@code false}
 664      *
 665      * @see #setWheelScrollingEnabled(boolean)
 666      * @since 1.4
 667      */
 668     public boolean isWheelScrollingEnabled() {
 669         return wheelScrollingEnabled;
 670     }
 671 
 672 
 673     /**
 674      * Writes default serializable fields to stream.
 675      */
 676     private void writeObject(ObjectOutputStream s) throws IOException {
 677         // 4352819: We only need this degenerate writeObject to make
 678         // it safe for future versions of this class to write optional
 679         // data to the stream.
 680         s.defaultWriteObject();
 681     }
 682 
 683     /**
 684      * Reads default serializable fields to stream.
 685      * @exception HeadlessException if
 686      * <code>GraphicsEnvironment.isHeadless()</code> returns
 687      * <code>true</code>
 688      * @see java.awt.GraphicsEnvironment#isHeadless
 689      */
 690     private void readObject(ObjectInputStream s)
 691         throws ClassNotFoundException, IOException, HeadlessException
 692     {
 693         GraphicsEnvironment.checkHeadless();
 694         // 4352819: Gotcha!  Cannot use s.defaultReadObject here and
 695         // then continue with reading optional data.  Use GetField instead.
 696         ObjectInputStream.GetField f = s.readFields();
 697 
 698         // Old fields
 699         scrollbarDisplayPolicy = f.get("scrollbarDisplayPolicy",
 700                                        SCROLLBARS_AS_NEEDED);
 701         hAdjustable = (ScrollPaneAdjustable)f.get("hAdjustable", null);
 702         vAdjustable = (ScrollPaneAdjustable)f.get("vAdjustable", null);
 703 
 704         // Since 1.4
 705         wheelScrollingEnabled = f.get("wheelScrollingEnabled",
 706                                       defaultWheelScroll);
 707 


 762 
 763     /**
 764      * Gets the AccessibleContext associated with this ScrollPane.
 765      * For scroll panes, the AccessibleContext takes the form of an
 766      * AccessibleAWTScrollPane.
 767      * A new AccessibleAWTScrollPane instance is created if necessary.
 768      *
 769      * @return an AccessibleAWTScrollPane that serves as the
 770      *         AccessibleContext of this ScrollPane
 771      * @since 1.3
 772      */
 773     public AccessibleContext getAccessibleContext() {
 774         if (accessibleContext == null) {
 775             accessibleContext = new AccessibleAWTScrollPane();
 776         }
 777         return accessibleContext;
 778     }
 779 
 780     /**
 781      * This class implements accessibility support for the
 782      * <code>ScrollPane</code> class.  It provides an implementation of the
 783      * Java Accessibility API appropriate to scroll pane user-interface
 784      * elements.
 785      * @since 1.3
 786      */
 787     protected class AccessibleAWTScrollPane extends AccessibleAWTContainer
 788     {
 789         /*
 790          * JDK 1.3 serialVersionUID
 791          */
 792         private static final long serialVersionUID = 6100703663886637L;
 793 
 794         /**
 795          * Get the role of this object.
 796          *
 797          * @return an instance of AccessibleRole describing the role of the
 798          * object
 799          * @see AccessibleRole
 800          */
 801         public AccessibleRole getAccessibleRole() {
 802             return AccessibleRole.SCROLL_PANE;




  30 import sun.awt.ScrollPaneWheelScroller;
  31 import sun.awt.SunToolkit;
  32 
  33 import java.beans.ConstructorProperties;
  34 import java.beans.Transient;
  35 import java.io.ObjectInputStream;
  36 import java.io.ObjectOutputStream;
  37 import java.io.IOException;
  38 
  39 /**
  40  * A container class which implements automatic horizontal and/or
  41  * vertical scrolling for a single child component.  The display
  42  * policy for the scrollbars can be set to:
  43  * <OL>
  44  * <LI>as needed: scrollbars created and shown only when needed by scrollpane
  45  * <LI>always: scrollbars created and always shown by the scrollpane
  46  * <LI>never: scrollbars never created or shown by the scrollpane
  47  * </OL>
  48  * <P>
  49  * The state of the horizontal and vertical scrollbars is represented
  50  * by two {@code ScrollPaneAdjustable} objects (one for each
  51  * dimension) which implement the {@code Adjustable} interface.
  52  * The API provides methods to access those objects such that the
  53  * attributes on the Adjustable object (such as unitIncrement, value,
  54  * etc.) can be manipulated.
  55  * <P>
  56  * Certain adjustable properties (minimum, maximum, blockIncrement,
  57  * and visibleAmount) are set internally by the scrollpane in accordance
  58  * with the geometry of the scrollpane and its child and these should
  59  * not be set by programs using the scrollpane.
  60  * <P>
  61  * If the scrollbar display policy is defined as "never", then the
  62  * scrollpane can still be programmatically scrolled using the
  63  * setScrollPosition() method and the scrollpane will move and clip
  64  * the child's contents appropriately.  This policy is useful if the
  65  * program needs to create and manage its own adjustable controls.
  66  * <P>
  67  * The placement of the scrollbars is controlled by platform-specific
  68  * properties set by the user outside of the program.
  69  * <P>
  70  * The initial size of this container is set to 100x100, but can
  71  * be reset using setSize().
  72  * <P>
  73  * Scrolling with the wheel on a wheel-equipped mouse is enabled by default.
  74  * This can be disabled using {@code setWheelScrollingEnabled}.
  75  * Wheel scrolling can be customized by setting the block and
  76  * unit increment of the horizontal and vertical Adjustables.
  77  * For information on how mouse wheel events are dispatched, see
  78  * the class description for {@link MouseWheelEvent}.
  79  * <P>
  80  * Insets are used to define any space used by scrollbars and any
  81  * borders created by the scroll pane. getInsets() can be used
  82  * to get the current value for the insets.  If the value of
  83  * scrollbarsAlwaysVisible is false, then the value of the insets
  84  * will change dynamically depending on whether the scrollbars are
  85  * currently visible or not.
  86  *
  87  * @author      Tom Ball
  88  * @author      Amy Fowler
  89  * @author      Tim Prinzing
  90  */
  91 public class ScrollPane extends Container implements Accessible {
  92 
  93 
  94     /**


 119 
 120     /**
 121      * Specifies that horizontal/vertical scrollbars should never be shown
 122      * regardless of the respective sizes of the scrollpane and child.
 123      */
 124     public static final int SCROLLBARS_NEVER = 2;
 125 
 126     /**
 127      * There are 3 ways in which a scroll bar can be displayed.
 128      * This integer will represent one of these 3 displays -
 129      * (SCROLLBARS_ALWAYS, SCROLLBARS_AS_NEEDED, SCROLLBARS_NEVER)
 130      *
 131      * @serial
 132      * @see #getScrollbarDisplayPolicy
 133      */
 134     private int scrollbarDisplayPolicy;
 135 
 136     /**
 137      * An adjustable vertical scrollbar.
 138      * It is important to note that you must <em>NOT</em> call 3
 139      * {@code Adjustable} methods, namely:
 140      * {@code setMinimum()}, {@code setMaximum()},
 141      * {@code setVisibleAmount()}.
 142      *
 143      * @serial
 144      * @see #getVAdjustable
 145      */
 146     private ScrollPaneAdjustable vAdjustable;
 147 
 148     /**
 149      * An adjustable horizontal scrollbar.
 150      * It is important to note that you must <em>NOT</em> call 3
 151      * {@code Adjustable} methods, namely:
 152      * {@code setMinimum()}, {@code setMaximum()},
 153      * {@code setVisibleAmount()}.
 154      *
 155      * @serial
 156      * @see #getHAdjustable
 157      */
 158     private ScrollPaneAdjustable hAdjustable;
 159 
 160     private static final String base = "scrollpane";
 161     private static int nameCounter = 0;
 162 
 163     private static final boolean defaultWheelScroll = true;
 164 
 165     /**
 166      * Indicates whether or not scrolling should take place when a
 167      * MouseWheelEvent is received.
 168      *
 169      * @serial
 170      * @since 1.4
 171      */
 172     private boolean wheelScrollingEnabled = defaultWheelScroll;
 173 


 301     }
 302 
 303     /**
 304      * Returns the width that would be occupied by a vertical
 305      * scrollbar, which is independent of whether it is currently
 306      * displayed by the scroll pane or not.
 307      * @return the width of a vertical scrollbar in pixels
 308      */
 309     public int getVScrollbarWidth() {
 310         int w = 0;
 311         if (scrollbarDisplayPolicy != SCROLLBARS_NEVER) {
 312             ScrollPanePeer peer = (ScrollPanePeer)this.peer;
 313             if (peer != null) {
 314                 w = peer.getVScrollbarWidth();
 315             }
 316         }
 317         return w;
 318     }
 319 
 320     /**
 321      * Returns the {@code ScrollPaneAdjustable} object which
 322      * represents the state of the vertical scrollbar.
 323      * The declared return type of this method is
 324      * {@code Adjustable} to maintain backward compatibility.
 325      *
 326      * @see java.awt.ScrollPaneAdjustable
 327      * @return the vertical scrollbar state
 328      */
 329     public Adjustable getVAdjustable() {
 330         return vAdjustable;
 331     }
 332 
 333     /**
 334      * Returns the {@code ScrollPaneAdjustable} object which
 335      * represents the state of the horizontal scrollbar.
 336      * The declared return type of this method is
 337      * {@code Adjustable} to maintain backward compatibility.
 338      *
 339      * @see java.awt.ScrollPaneAdjustable
 340      * @return the horizontal scrollbar state
 341      */
 342     public Adjustable getHAdjustable() {
 343         return hAdjustable;
 344     }
 345 
 346     /**
 347      * Scrolls to the specified position within the child component.
 348      * A call to this method is only valid if the scroll pane contains
 349      * a child.  Specifying a position outside of the legal scrolling bounds
 350      * of the child will scroll to the closest legal position.
 351      * Legal bounds are defined to be the rectangle:
 352      * x = 0, y = 0, width = (child width - view port width),
 353      * height = (child height - view port height).
 354      * This is a convenience method which interfaces with the Adjustable
 355      * objects which represent the state of the scrollbars.
 356      * @param x the x position to scroll to
 357      * @param y the y position to scroll to


 471         }
 472         if(hbarOn) {
 473             viewHeight -= hbarHeight;
 474         }
 475 
 476         //
 477         // if child is smaller than view, size it up
 478         //
 479         if (childSize.width < viewWidth) {
 480             childSize.width = viewWidth;
 481         }
 482         if (childSize.height < viewHeight) {
 483             childSize.height = viewHeight;
 484         }
 485 
 486         return childSize;
 487     }
 488 
 489     /**
 490      * @deprecated As of JDK version 1.1,
 491      * replaced by {@code doLayout()}.
 492      */
 493     @Deprecated
 494     public void layout() {
 495         if (getComponentCount()==0) {
 496             return;
 497         }
 498         Component c = getComponent(0);
 499         Point p = getScrollPosition();
 500         Dimension cs = calculateChildSize();
 501         Dimension vs = getViewportSize();
 502 
 503         c.reshape(- p.x, - p.y, cs.width, cs.height);
 504         ScrollPanePeer peer = (ScrollPanePeer)this.peer;
 505         if (peer != null) {
 506             peer.childResized(cs.width, cs.height);
 507         }
 508 
 509         // update adjustables... the viewport size may have changed
 510         // with the scrollbars coming or going so the viewport size
 511         // is updated before the adjustables.


 556                 vAdjustableValue = vAdjustable.getValue();
 557                 hAdjustableValue = hAdjustable.getValue();
 558                 vAdjustable.setValue(0);
 559                 hAdjustable.setValue(0);
 560             }
 561 
 562             if (peer == null)
 563                 peer = getComponentFactory().createScrollPane(this);
 564             super.addNotify();
 565 
 566             // Bug 4124460. Restore the adjustable values.
 567             if (getComponentCount() > 0) {
 568                 vAdjustable.setValue(vAdjustableValue);
 569                 hAdjustable.setValue(hAdjustableValue);
 570             }
 571         }
 572     }
 573 
 574     /**
 575      * Returns a string representing the state of this
 576      * {@code ScrollPane}. This
 577      * method is intended to be used only for debugging purposes, and the
 578      * content and format of the returned string may vary between
 579      * implementations. The returned string may be empty but may not be
 580      * {@code null}.
 581      *
 582      * @return the parameter string of this scroll pane
 583      */
 584     public String paramString() {
 585         String sdpStr;
 586         switch (scrollbarDisplayPolicy) {
 587             case SCROLLBARS_AS_NEEDED:
 588                 sdpStr = "as-needed";
 589                 break;
 590             case SCROLLBARS_ALWAYS:
 591                 sdpStr = "always";
 592                 break;
 593             case SCROLLBARS_NEVER:
 594                 sdpStr = "never";
 595                 break;
 596             default:
 597                 sdpStr = "invalid display policy";
 598         }
 599         Point p = (getComponentCount()>0)? getScrollPosition() : new Point(0,0);
 600         Insets i = getInsets();
 601         return super.paramString()+",ScrollPosition=("+p.x+","+p.y+")"+
 602             ",Insets=("+i.top+","+i.left+","+i.bottom+","+i.right+")"+
 603             ",ScrollbarDisplayPolicy="+sdpStr+
 604         ",wheelScrollingEnabled="+isWheelScrollingEnabled();
 605     }
 606 
 607     void autoProcessMouseWheel(MouseWheelEvent e) {
 608         processMouseWheelEvent(e);
 609     }
 610 
 611     /**
 612      * Process mouse wheel events that are delivered to this
 613      * {@code ScrollPane} by scrolling an appropriate amount.
 614      * <p>Note that if the event parameter is {@code null}
 615      * the behavior is unspecified and may result in an
 616      * exception.
 617      *
 618      * @param e  the mouse wheel event
 619      * @since 1.4
 620      */
 621     protected void processMouseWheelEvent(MouseWheelEvent e) {
 622         if (isWheelScrollingEnabled()) {
 623             ScrollPaneWheelScroller.handleWheelScrolling(this, e);
 624             e.consume();
 625         }
 626         super.processMouseWheelEvent(e);
 627     }
 628 
 629     /**
 630      * If wheel scrolling is enabled, we return true for MouseWheelEvents
 631      * @since 1.4
 632      */
 633     protected boolean eventTypeEnabled(int type) {
 634         if (type == MouseEvent.MOUSE_WHEEL && isWheelScrollingEnabled()) {
 635             return true;
 636         }
 637         else {
 638             return super.eventTypeEnabled(type);
 639         }
 640     }
 641 
 642     /**
 643      * Enables/disables scrolling in response to movement of the mouse wheel.
 644      * Wheel scrolling is enabled by default.
 645      *
 646      * @param handleWheel   {@code true} if scrolling should be done
 647      *                      automatically for a MouseWheelEvent,
 648      *                      {@code false} otherwise.
 649      * @see #isWheelScrollingEnabled
 650      * @see java.awt.event.MouseWheelEvent
 651      * @see java.awt.event.MouseWheelListener
 652      * @since 1.4
 653      */
 654     public void setWheelScrollingEnabled(boolean handleWheel) {
 655         wheelScrollingEnabled = handleWheel;
 656     }
 657 
 658     /**
 659      * Indicates whether or not scrolling will take place in response to
 660      * the mouse wheel.  Wheel scrolling is enabled by default.
 661      *
 662      * @return {@code true} if the wheel scrolling enabled;
 663      *         otherwise {@code false}
 664      *
 665      * @see #setWheelScrollingEnabled(boolean)
 666      * @since 1.4
 667      */
 668     public boolean isWheelScrollingEnabled() {
 669         return wheelScrollingEnabled;
 670     }
 671 
 672 
 673     /**
 674      * Writes default serializable fields to stream.
 675      */
 676     private void writeObject(ObjectOutputStream s) throws IOException {
 677         // 4352819: We only need this degenerate writeObject to make
 678         // it safe for future versions of this class to write optional
 679         // data to the stream.
 680         s.defaultWriteObject();
 681     }
 682 
 683     /**
 684      * Reads default serializable fields to stream.
 685      * @exception HeadlessException if
 686      * {@code GraphicsEnvironment.isHeadless()} returns
 687      * {@code true}
 688      * @see java.awt.GraphicsEnvironment#isHeadless
 689      */
 690     private void readObject(ObjectInputStream s)
 691         throws ClassNotFoundException, IOException, HeadlessException
 692     {
 693         GraphicsEnvironment.checkHeadless();
 694         // 4352819: Gotcha!  Cannot use s.defaultReadObject here and
 695         // then continue with reading optional data.  Use GetField instead.
 696         ObjectInputStream.GetField f = s.readFields();
 697 
 698         // Old fields
 699         scrollbarDisplayPolicy = f.get("scrollbarDisplayPolicy",
 700                                        SCROLLBARS_AS_NEEDED);
 701         hAdjustable = (ScrollPaneAdjustable)f.get("hAdjustable", null);
 702         vAdjustable = (ScrollPaneAdjustable)f.get("vAdjustable", null);
 703 
 704         // Since 1.4
 705         wheelScrollingEnabled = f.get("wheelScrollingEnabled",
 706                                       defaultWheelScroll);
 707 


 762 
 763     /**
 764      * Gets the AccessibleContext associated with this ScrollPane.
 765      * For scroll panes, the AccessibleContext takes the form of an
 766      * AccessibleAWTScrollPane.
 767      * A new AccessibleAWTScrollPane instance is created if necessary.
 768      *
 769      * @return an AccessibleAWTScrollPane that serves as the
 770      *         AccessibleContext of this ScrollPane
 771      * @since 1.3
 772      */
 773     public AccessibleContext getAccessibleContext() {
 774         if (accessibleContext == null) {
 775             accessibleContext = new AccessibleAWTScrollPane();
 776         }
 777         return accessibleContext;
 778     }
 779 
 780     /**
 781      * This class implements accessibility support for the
 782      * {@code ScrollPane} class.  It provides an implementation of the
 783      * Java Accessibility API appropriate to scroll pane user-interface
 784      * elements.
 785      * @since 1.3
 786      */
 787     protected class AccessibleAWTScrollPane extends AccessibleAWTContainer
 788     {
 789         /*
 790          * JDK 1.3 serialVersionUID
 791          */
 792         private static final long serialVersionUID = 6100703663886637L;
 793 
 794         /**
 795          * Get the role of this object.
 796          *
 797          * @return an instance of AccessibleRole describing the role of the
 798          * object
 799          * @see AccessibleRole
 800          */
 801         public AccessibleRole getAccessibleRole() {
 802             return AccessibleRole.SCROLL_PANE;


< prev index next >