< prev index next >

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

Print this page


   1 /*
   2  * Copyright (c) 1996, 2015, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */

  25 package java.awt;
  26 




  27 import java.awt.peer.ScrollPanePeer;
  28 import java.awt.event.*;
  29 import javax.accessibility.*;
  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


 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 
 708 //      // Note to future maintainers
 709 //      if (f.defaulted("wheelScrollingEnabled")) {
 710 //          // We are reading pre-1.4 stream that doesn't have
 711 //          // optional data, not even the TC_ENDBLOCKDATA marker.
 712 //          // Reading anything after this point is unsafe as we will
 713 //          // read unrelated objects further down the stream (4352819).
 714 //      }
 715 //      else {
 716 //          // Reading data from 1.4 or later, it's ok to try to read
 717 //          // optional data as OptionalDataException with eof == true
 718 //          // will be correctly reported
 719 //      }
 720     }
 721 



 722     class PeerFixer implements AdjustmentListener, java.io.Serializable
 723     {
 724         private static final long serialVersionUID = 1043664721353696630L;
 725 
 726         PeerFixer(ScrollPane scroller) {
 727             this.scroller = scroller;
 728         }
 729 
 730         /**
 731          * Invoked when the value of the adjustable has changed.
 732          */
 733         @SuppressWarnings("deprecation")
 734         public void adjustmentValueChanged(AdjustmentEvent e) {
 735             Adjustable adj = e.getAdjustable();
 736             int value = e.getValue();
 737             ScrollPanePeer peer = (ScrollPanePeer) scroller.peer;
 738             if (peer != null) {
 739                 peer.setValue(adj, value);
 740             }
 741 


 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;
 803         }
 804 
 805     } // class AccessibleAWTScrollPane
 806 
 807 }
 808 
 809 /*
 810  * In JDK 1.1.1, the pkg private class java.awt.PeerFixer was moved to
 811  * become an inner class of ScrollPane, which broke serialization
 812  * for ScrollPane objects using JDK 1.1.
 813  * Instead of moving it back out here, which would break all JDK 1.1.x
 814  * releases, we keep PeerFixer in both places. Because of the scoping rules,
 815  * the PeerFixer that is used in ScrollPane will be the one that is the
 816  * inner class. This pkg private PeerFixer class below will only be used
 817  * if the Java 2 platform is used to deserialize ScrollPane objects that were serialized
 818  * using JDK1.1
 819  */

 820 class PeerFixer implements AdjustmentListener, java.io.Serializable {
 821     /*
 822      * serialVersionUID
 823      */
 824     private static final long serialVersionUID = 7051237413532574756L;
 825 
 826     PeerFixer(ScrollPane scroller) {
 827         this.scroller = scroller;
 828     }
 829 
 830     /**
 831      * Invoked when the value of the adjustable has changed.
 832      */
 833     @SuppressWarnings("deprecation")
 834     public void adjustmentValueChanged(AdjustmentEvent e) {
 835         Adjustable adj = e.getAdjustable();
 836         int value = e.getValue();
 837         ScrollPanePeer peer = (ScrollPanePeer) scroller.peer;
 838         if (peer != null) {
 839             peer.setValue(adj, value);
   1 /*
   2  * Copyright (c) 1996, 2020, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package java.awt;
  27 
  28 import java.awt.event.AdjustmentEvent;
  29 import java.awt.event.AdjustmentListener;
  30 import java.awt.event.MouseEvent;
  31 import java.awt.event.MouseWheelEvent;
  32 import java.awt.peer.ScrollPanePeer;





  33 import java.beans.ConstructorProperties;
  34 import java.beans.Transient;
  35 import java.io.IOException;
  36 import java.io.ObjectInputStream;
  37 import java.io.ObjectOutputStream;
  38 
  39 import javax.accessibility.Accessible;
  40 import javax.accessibility.AccessibleContext;
  41 import javax.accessibility.AccessibleRole;
  42 
  43 import sun.awt.ScrollPaneWheelScroller;
  44 import sun.awt.SunToolkit;
  45 
  46 /**
  47  * A container class which implements automatic horizontal and/or
  48  * vertical scrolling for a single child component.  The display
  49  * policy for the scrollbars can be set to:
  50  * <OL>
  51  * <LI>as needed: scrollbars created and shown only when needed by scrollpane
  52  * <LI>always: scrollbars created and always shown by the scrollpane
  53  * <LI>never: scrollbars never created or shown by the scrollpane
  54  * </OL>
  55  * <P>
  56  * The state of the horizontal and vertical scrollbars is represented
  57  * by two {@code ScrollPaneAdjustable} objects (one for each
  58  * dimension) which implement the {@code Adjustable} interface.
  59  * The API provides methods to access those objects such that the
  60  * attributes on the Adjustable object (such as unitIncrement, value,
  61  * etc.) can be manipulated.
  62  * <P>
  63  * Certain adjustable properties (minimum, maximum, blockIncrement,
  64  * and visibleAmount) are set internally by the scrollpane in accordance


 662         wheelScrollingEnabled = handleWheel;
 663     }
 664 
 665     /**
 666      * Indicates whether or not scrolling will take place in response to
 667      * the mouse wheel.  Wheel scrolling is enabled by default.
 668      *
 669      * @return {@code true} if the wheel scrolling enabled;
 670      *         otherwise {@code false}
 671      *
 672      * @see #setWheelScrollingEnabled(boolean)
 673      * @since 1.4
 674      */
 675     public boolean isWheelScrollingEnabled() {
 676         return wheelScrollingEnabled;
 677     }
 678 
 679 
 680     /**
 681      * Writes default serializable fields to stream.
 682      *
 683      * @param  s the {@code ObjectOutputStream} to write
 684      * @throws IOException if an I/O error occurs
 685      */
 686     private void writeObject(ObjectOutputStream s) throws IOException {
 687         // 4352819: We only need this degenerate writeObject to make
 688         // it safe for future versions of this class to write optional
 689         // data to the stream.
 690         s.defaultWriteObject();
 691     }
 692 
 693     /**
 694      * Reads default serializable fields to stream.
 695      *
 696      * @param  s the {@code ObjectInputStream} to read
 697      * @throws ClassNotFoundException if the class of a serialized object could
 698      *         not be found
 699      * @throws IOException if an I/O error occurs
 700      * @throws HeadlessException if {@code GraphicsEnvironment.isHeadless()}
 701      *         returns {@code true}
 702      * @see java.awt.GraphicsEnvironment#isHeadless
 703      */
 704     private void readObject(ObjectInputStream s)
 705         throws ClassNotFoundException, IOException, HeadlessException
 706     {
 707         GraphicsEnvironment.checkHeadless();
 708         // 4352819: Gotcha!  Cannot use s.defaultReadObject here and
 709         // then continue with reading optional data.  Use GetField instead.
 710         ObjectInputStream.GetField f = s.readFields();
 711 
 712         // Old fields
 713         scrollbarDisplayPolicy = f.get("scrollbarDisplayPolicy",
 714                                        SCROLLBARS_AS_NEEDED);
 715         hAdjustable = (ScrollPaneAdjustable)f.get("hAdjustable", null);
 716         vAdjustable = (ScrollPaneAdjustable)f.get("vAdjustable", null);
 717 
 718         // Since 1.4
 719         wheelScrollingEnabled = f.get("wheelScrollingEnabled",
 720                                       defaultWheelScroll);
 721 
 722 //      // Note to future maintainers
 723 //      if (f.defaulted("wheelScrollingEnabled")) {
 724 //          // We are reading pre-1.4 stream that doesn't have
 725 //          // optional data, not even the TC_ENDBLOCKDATA marker.
 726 //          // Reading anything after this point is unsafe as we will
 727 //          // read unrelated objects further down the stream (4352819).
 728 //      }
 729 //      else {
 730 //          // Reading data from 1.4 or later, it's ok to try to read
 731 //          // optional data as OptionalDataException with eof == true
 732 //          // will be correctly reported
 733 //      }
 734     }
 735 
 736     /**
 737      * Invoked when the value of the adjustable has changed.
 738      */
 739     class PeerFixer implements AdjustmentListener, java.io.Serializable
 740     {
 741         private static final long serialVersionUID = 1043664721353696630L;
 742 
 743         PeerFixer(ScrollPane scroller) {
 744             this.scroller = scroller;
 745         }
 746 
 747         /**
 748          * Invoked when the value of the adjustable has changed.
 749          */
 750         @SuppressWarnings("deprecation")
 751         public void adjustmentValueChanged(AdjustmentEvent e) {
 752             Adjustable adj = e.getAdjustable();
 753             int value = e.getValue();
 754             ScrollPanePeer peer = (ScrollPanePeer) scroller.peer;
 755             if (peer != null) {
 756                 peer.setValue(adj, value);
 757             }
 758 


 806         /*
 807          * JDK 1.3 serialVersionUID
 808          */
 809         private static final long serialVersionUID = 6100703663886637L;
 810 
 811         /**
 812          * Get the role of this object.
 813          *
 814          * @return an instance of AccessibleRole describing the role of the
 815          * object
 816          * @see AccessibleRole
 817          */
 818         public AccessibleRole getAccessibleRole() {
 819             return AccessibleRole.SCROLL_PANE;
 820         }
 821 
 822     } // class AccessibleAWTScrollPane
 823 
 824 }
 825 
 826 /**
 827  * In JDK 1.1.1, the pkg private class java.awt.PeerFixer was moved to
 828  * become an inner class of ScrollPane, which broke serialization
 829  * for ScrollPane objects using JDK 1.1.
 830  * Instead of moving it back out here, which would break all JDK 1.1.x
 831  * releases, we keep PeerFixer in both places. Because of the scoping rules,
 832  * the PeerFixer that is used in ScrollPane will be the one that is the
 833  * inner class. This pkg private PeerFixer class below will only be used
 834  * if the Java 2 platform is used to deserialize ScrollPane objects that were serialized
 835  * using JDK1.1
 836  */
 837 @Deprecated(forRemoval = true)
 838 class PeerFixer implements AdjustmentListener, java.io.Serializable {
 839     /*
 840      * serialVersionUID
 841      */
 842     private static final long serialVersionUID = 7051237413532574756L;
 843 
 844     PeerFixer(ScrollPane scroller) {
 845         this.scroller = scroller;
 846     }
 847 
 848     /**
 849      * Invoked when the value of the adjustable has changed.
 850      */
 851     @SuppressWarnings("deprecation")
 852     public void adjustmentValueChanged(AdjustmentEvent e) {
 853         Adjustable adj = e.getAdjustable();
 854         int value = e.getValue();
 855         ScrollPanePeer peer = (ScrollPanePeer) scroller.peer;
 856         if (peer != null) {
 857             peer.setValue(adj, value);
< prev index next >