modules/controls/src/main/java/com/sun/javafx/scene/control/skin/ScrollPaneSkin.java

Print this page




   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 com.sun.javafx.scene.control.skin;
  27 




  28 import javafx.animation.Animation.Status;
  29 import javafx.animation.KeyFrame;
  30 import javafx.animation.KeyValue;
  31 import javafx.animation.Timeline;
  32 import javafx.beans.InvalidationListener;
  33 import javafx.beans.Observable;
  34 import javafx.beans.property.DoubleProperty;
  35 import javafx.beans.property.DoublePropertyBase;
  36 import javafx.beans.value.ChangeListener;
  37 import javafx.beans.value.ObservableValue;
  38 import javafx.event.ActionEvent;
  39 import javafx.event.Event;
  40 import javafx.event.EventDispatchChain;
  41 import javafx.event.EventDispatcher;
  42 import javafx.event.EventHandler;
  43 import javafx.geometry.BoundingBox;
  44 import javafx.geometry.Bounds;

  45 import javafx.geometry.Orientation;
  46 import javafx.scene.Cursor;
  47 import javafx.scene.Node;
  48 import javafx.scene.control.ScrollBar;
  49 import javafx.scene.control.ScrollPane;
  50 import javafx.scene.control.ScrollPane.ScrollBarPolicy;
  51 import javafx.scene.input.MouseEvent;
  52 import javafx.scene.input.ScrollEvent;
  53 import javafx.scene.input.TouchEvent;
  54 import javafx.scene.layout.Region;
  55 import javafx.scene.layout.StackPane;
  56 import javafx.scene.shape.Rectangle;
  57 import javafx.util.Duration;
  58 import com.sun.javafx.Utils;
  59 import com.sun.javafx.application.PlatformImpl;
  60 import com.sun.javafx.scene.control.behavior.ScrollPaneBehavior;
  61 import com.sun.javafx.scene.traversal.TraversalEngine;
  62 import com.sun.javafx.scene.traversal.TraverseListener;
  63 import static com.sun.javafx.Utils.*;
  64 import static com.sun.javafx.scene.control.skin.Utils.*;
  65 import javafx.geometry.Insets;
  66 
  67 public class ScrollPaneSkin extends BehaviorSkinBase<ScrollPane, ScrollPaneBehavior> implements TraverseListener {
  68     /***************************************************************************
  69      *                                                                         *
  70      * UI Subcomponents                                                        *
  71      *                                                                         *
  72      **************************************************************************/
  73 
  74     private static final double DEFAULT_PREF_SIZE = 100.0;
  75 
  76     private static final double DEFAULT_MIN_SIZE = 36.0;
  77 
  78     private static final double DEFAULT_SB_BREADTH = 12.0;
  79     private static final double DEFAULT_EMBEDDED_SB_BREADTH = 8.0;
  80 
  81     private static final double PAN_THRESHOLD = 0.5;
  82 
  83     // state from the control
  84 
  85     private Node scrollNode;


1062             if (nodeHeight > contentHeight) {
1063                 updatePosY();
1064             } else {
1065                 viewContent.setLayoutY(0);
1066             }
1067         }
1068     }
1069 
1070     private double updatePosX() {
1071         final ScrollPane sp = getSkinnable();
1072         double x = isReverseNodeOrientation() ? (hsb.getMax() - (posX - hsb.getMin())) : posX;
1073         double minX = Math.min((- x / (hsb.getMax() - hsb.getMin()) * (nodeWidth - contentWidth)), 0);
1074         viewContent.setLayoutX(snapPosition(minX));
1075         if (!sp.hvalueProperty().isBound()) sp.setHvalue(Utils.clamp(sp.getHmin(), posX, sp.getHmax()));
1076         return posX;
1077     }
1078 
1079     private double updatePosY() {
1080         final ScrollPane sp = getSkinnable();
1081         double minY = Math.min((- posY / (vsb.getMax() - vsb.getMin()) * (nodeHeight - contentHeight)), 0);
1082         viewContent.setLayoutY(minY);
1083         if (!sp.vvalueProperty().isBound()) sp.setVvalue(Utils.clamp(sp.getVmin(), posY, sp.getVmax()));
1084         return posY;
1085     }
1086 
1087     private void resetClip() {
1088         clipRect.setWidth(snapSize(contentWidth));
1089         clipRect.setHeight(snapSize(contentHeight));
1090     }
1091 
1092     Timeline sbTouchTimeline;
1093     KeyFrame sbTouchKF1;
1094     KeyFrame sbTouchKF2;
1095     Timeline contentsToViewTimeline;
1096     KeyFrame contentsToViewKF1;
1097     KeyFrame contentsToViewKF2;
1098     KeyFrame contentsToViewKF3;
1099 
1100     private boolean tempVisibility;
1101 
1102 




   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 com.sun.javafx.scene.control.skin;
  27 
  28 import com.sun.javafx.Utils;
  29 import com.sun.javafx.scene.control.behavior.ScrollPaneBehavior;
  30 import com.sun.javafx.scene.traversal.TraversalEngine;
  31 import com.sun.javafx.scene.traversal.TraverseListener;
  32 import javafx.animation.Animation.Status;
  33 import javafx.animation.KeyFrame;
  34 import javafx.animation.KeyValue;
  35 import javafx.animation.Timeline;
  36 import javafx.beans.InvalidationListener;
  37 import javafx.beans.Observable;
  38 import javafx.beans.property.DoubleProperty;
  39 import javafx.beans.property.DoublePropertyBase;
  40 import javafx.beans.value.ChangeListener;
  41 import javafx.beans.value.ObservableValue;
  42 import javafx.event.ActionEvent;
  43 import javafx.event.Event;
  44 import javafx.event.EventDispatchChain;
  45 import javafx.event.EventDispatcher;
  46 import javafx.event.EventHandler;
  47 import javafx.geometry.BoundingBox;
  48 import javafx.geometry.Bounds;
  49 import javafx.geometry.Insets;
  50 import javafx.geometry.Orientation;
  51 import javafx.scene.Cursor;
  52 import javafx.scene.Node;
  53 import javafx.scene.control.ScrollBar;
  54 import javafx.scene.control.ScrollPane;
  55 import javafx.scene.control.ScrollPane.ScrollBarPolicy;
  56 import javafx.scene.input.MouseEvent;
  57 import javafx.scene.input.ScrollEvent;
  58 import javafx.scene.input.TouchEvent;

  59 import javafx.scene.layout.StackPane;
  60 import javafx.scene.shape.Rectangle;
  61 import javafx.util.Duration;
  62 
  63 import static com.sun.javafx.Utils.clamp;
  64 import static com.sun.javafx.scene.control.skin.Utils.boundedSize;





  65 
  66 public class ScrollPaneSkin extends BehaviorSkinBase<ScrollPane, ScrollPaneBehavior> implements TraverseListener {
  67     /***************************************************************************
  68      *                                                                         *
  69      * UI Subcomponents                                                        *
  70      *                                                                         *
  71      **************************************************************************/
  72 
  73     private static final double DEFAULT_PREF_SIZE = 100.0;
  74 
  75     private static final double DEFAULT_MIN_SIZE = 36.0;
  76 
  77     private static final double DEFAULT_SB_BREADTH = 12.0;
  78     private static final double DEFAULT_EMBEDDED_SB_BREADTH = 8.0;
  79 
  80     private static final double PAN_THRESHOLD = 0.5;
  81 
  82     // state from the control
  83 
  84     private Node scrollNode;


1061             if (nodeHeight > contentHeight) {
1062                 updatePosY();
1063             } else {
1064                 viewContent.setLayoutY(0);
1065             }
1066         }
1067     }
1068 
1069     private double updatePosX() {
1070         final ScrollPane sp = getSkinnable();
1071         double x = isReverseNodeOrientation() ? (hsb.getMax() - (posX - hsb.getMin())) : posX;
1072         double minX = Math.min((- x / (hsb.getMax() - hsb.getMin()) * (nodeWidth - contentWidth)), 0);
1073         viewContent.setLayoutX(snapPosition(minX));
1074         if (!sp.hvalueProperty().isBound()) sp.setHvalue(Utils.clamp(sp.getHmin(), posX, sp.getHmax()));
1075         return posX;
1076     }
1077 
1078     private double updatePosY() {
1079         final ScrollPane sp = getSkinnable();
1080         double minY = Math.min((- posY / (vsb.getMax() - vsb.getMin()) * (nodeHeight - contentHeight)), 0);
1081         viewContent.setLayoutY(snapPosition(minY));
1082         if (!sp.vvalueProperty().isBound()) sp.setVvalue(Utils.clamp(sp.getVmin(), posY, sp.getVmax()));
1083         return posY;
1084     }
1085 
1086     private void resetClip() {
1087         clipRect.setWidth(snapSize(contentWidth));
1088         clipRect.setHeight(snapSize(contentHeight));
1089     }
1090 
1091     Timeline sbTouchTimeline;
1092     KeyFrame sbTouchKF1;
1093     KeyFrame sbTouchKF2;
1094     Timeline contentsToViewTimeline;
1095     KeyFrame contentsToViewKF1;
1096     KeyFrame contentsToViewKF2;
1097     KeyFrame contentsToViewKF3;
1098 
1099     private boolean tempVisibility;
1100 
1101