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

Print this page
rev 9240 : 8076423: JEP 253: Prepare JavaFX UI Controls & CSS APIs for Modularization

@@ -21,29 +21,47 @@
  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  * or visit www.oracle.com if you need additional information or have any
  * questions.
  */
 
-package com.sun.javafx.scene.control.skin;
+package com.sun.javafx.scene.control;
 
+import com.sun.javafx.util.Utils;
+import javafx.beans.property.BooleanProperty;
+import javafx.beans.property.SimpleBooleanProperty;
 import javafx.scene.control.IndexedCell;
 import javafx.scene.control.ScrollBar;
-
-import com.sun.javafx.util.Utils;
+import javafx.scene.control.skin.VirtualFlow;
 
 /**
  * This custom ScrollBar is used to map the increment & decrement features
  * to pixel based scrolling rather than thumb/track based scrolling, if the
  * "virtual" attribute is true.
  */
 public class VirtualScrollBar extends ScrollBar {
-    private final VirtualFlow flow;
 
-    private boolean virtual;
+    /**************************************************************************
+     *
+     * Private fields
+     *
+     **************************************************************************/
+
+    private final VirtualFlow flow;
     
     private boolean adjusting;
 
+
+
+    /**************************************************************************
+     *
+     * Constructors
+     *
+     **************************************************************************/
+
+    /**
+     * Creates a new VirtualScrollBar, for use by the VirtualFlow control.
+     */
     public VirtualScrollBar(final VirtualFlow flow) {
         this.flow = flow;
         
         super.valueProperty().addListener(valueModel -> {
             if (isVirtual()/* && oldValue != newValue*/) {

@@ -54,59 +72,76 @@
                 }
             }
         });
     }
 
-    public void setVirtual(boolean virtual) {
-        this.virtual = virtual;
+
+
+    /**************************************************************************
+     *
+     * Properties
+     *
+     **************************************************************************/
+
+    // --- virtual
+    private BooleanProperty virtual = new SimpleBooleanProperty(this, "virtual");
+    public final void setVirtual(boolean value) {
+        virtual.set(value);
+    }
+
+    public final boolean isVirtual() {
+        return virtual.get();
     }
 
-    public boolean isVirtual() {
-        return this.virtual;
+    public final BooleanProperty virtualProperty() {
+        return virtual;
     }
 
+
+    /**************************************************************************
+     *
+     * Public API
+     *
+     **************************************************************************/
+
+    /** {@inheritDoc} */
     @Override public void decrement() {
         if (isVirtual()) {
-            flow.adjustPixels(-10);
+            flow.scrollPixels(-10);
         } else {
             super.decrement();
         }
     }
 
+    /** {@inheritDoc} */
     @Override public void increment() {
         if (isVirtual()) {
-            flow.adjustPixels(10);
+            flow.scrollPixels(10);
         } else {
             super.increment();
         }
     }
     
-//    private double lastAdjustValue = 0.0;
-
     // this method is called when the user clicks in the scrollbar track, so
     // we special-case it to allow for page-up and page-down clicking to work
     // as expected.
+    /** {@inheritDoc} */
     @Override public void adjustValue(double pos) {
         if (isVirtual()) {
-//            if (pos == lastAdjustValue) {
-//                return;
-//            }
-
             adjusting = true;
             double oldValue = flow.getPosition();
             
             double newValue = ((getMax() - getMin()) * Utils.clamp(0, pos, 1))+getMin();
             if (newValue < oldValue) {
                 IndexedCell cell = flow.getFirstVisibleCell();
                 if (cell == null) return;
-                flow.showAsLast(cell);
+                flow.scrollToBottom(cell);
             } else if (newValue > oldValue) {
                 IndexedCell cell = flow.getLastVisibleCell();
                 if (cell == null) return;
-                flow.showAsFirst(cell);
+                flow.scrollToTop(cell);
             }
-//            lastAdjustValue = pos;
             
             adjusting = false;
         } else {
             super.adjustValue(pos);
         }