modules/controls/src/main/java/javafx/scene/control/skin/VirtualContainerBase.java

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

@@ -1,7 +1,7 @@
 /*
- * Copyright (c) 2010, 2014, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2010, 2015, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
  * under the terms of the GNU General Public License version 2 only, as
  * published by the Free Software Foundation.  Oracle designates this

@@ -21,76 +21,118 @@
  * 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 javafx.scene.control.skin;
 
+import javafx.beans.property.ObjectProperty;
+import javafx.beans.property.SimpleObjectProperty;
+import javafx.scene.control.Cell;
 import javafx.scene.control.Control;
 import javafx.scene.control.IndexedCell;
 import javafx.scene.control.ScrollToEvent;
-
-import com.sun.javafx.scene.control.behavior.BehaviorBase;
+import javafx.scene.control.SkinBase;
+import javafx.util.Callback;
 
 /**
  * Parent class to control skins whose contents are virtualized and scrollable.
  * This class handles the interaction with the VirtualFlow class, which is the
  * main class handling the virtualization of the contents of this container.
- *
- * @profile common
  */
-public abstract class VirtualContainerBase<C extends Control, B extends BehaviorBase<C>, I extends IndexedCell> extends BehaviorSkinBase<C, B> {
+public abstract class VirtualContainerBase<C extends Control, I extends IndexedCell> extends SkinBase<C> {
+
+    /***************************************************************************
+     *                                                                         *
+     * Private fields                                                          *
+     *                                                                         *
+     **************************************************************************/
+    
+    boolean rowCountDirty;
+
+    /**
+     * The virtualized container which handles the layout and scrolling of
+     * all the cells.
+     */
+    private final VirtualFlow<I> flow;
+
+
     
-    protected boolean rowCountDirty;
+    /***************************************************************************
+     *                                                                         *
+     * Constructors                                                            *
+     *                                                                         *
+     **************************************************************************/
 
-    public VirtualContainerBase(final C control, B behavior) {
-        super(control, behavior);
+    /**
+     *
+     * @param control
+     */
+    public VirtualContainerBase(final C control) {
+        super(control);
         flow = createVirtualFlow();
         
         control.addEventHandler(ScrollToEvent.scrollToTopIndex(), event -> {
             // Fix for RT-24630: The row count in VirtualFlow was incorrect
             // (normally zero), so the scrollTo call was misbehaving.
             if (rowCountDirty) {
                 // update row count before we do a scroll
                 updateRowCount();
                 rowCountDirty = false;
             }
-            flow.scrollTo(event.getScrollTarget());
+            flow.scrollToTop(event.getScrollTarget());
         });
     }
 
-    /**
-     * The virtualized container which handles the layout and scrolling of
-     * all the cells.
-     */
-    protected final VirtualFlow<I> flow;
+
+
+    /***************************************************************************
+     *                                                                         *
+     * Abstract API                                                            *
+     *                                                                         *
+     **************************************************************************/
 
     /**
-     * Returns a Cell available to be used in the virtual flow. This means you
-     * may return either a previously used, but now unrequired cell, or alternatively
-     * create a new Cell instance.
-     *
-     * Preference is obviously given to reusing cells whenever possible, to keep
-     * performance costs down.
+     * Returns the total number of items in this container, including those
+     * that are currently hidden because they are out of view.
      */
-    public abstract I createCell();
+    abstract int getItemCount();
+    
+    abstract void updateRowCount();
+
+
+
+    /***************************************************************************
+     *                                                                         *
+     * Public API                                                              *
+     *                                                                         *
+     **************************************************************************/
+
+    /** {@inheritDoc} */
+    @Override protected void layoutChildren(double x, double y, double w, double h) {
+        checkState();
+    }
+
+
+
+    /***************************************************************************
+     *                                                                         *
+     * Private methods                                                         *
+     *                                                                         *
+     **************************************************************************/
 
     /**
      * This enables skin subclasses to provide a custom VirtualFlow implementation,
      * rather than have VirtualContainerBase instantiate the default instance.
      */
-    protected VirtualFlow<I> createVirtualFlow() {
-        return new VirtualFlow<I>();
+    VirtualFlow<I> createVirtualFlow() {
+        return new VirtualFlow<>();
     }
 
-    /**
-     * Returns the total number of items in this container, including those
-     * that are currently hidden because they are out of view.
-     */
-    public abstract int getItemCount();
-    
-    protected abstract void updateRowCount();
+    final VirtualFlow<I> getVirtualFlow() {
+        return flow;
+    }
 
     double getMaxCellWidth(int rowsToCount) {
         return snappedLeftInset() + flow.getMaxCellWidth(rowsToCount) + snappedRightInset();
     }
     

@@ -102,15 +144,11 @@
         }
 
         return height + snappedTopInset() + snappedBottomInset();
     }
 
-    @Override protected void layoutChildren(double x, double y, double w, double h) {
-        checkState();
-    }
-
-    protected void checkState() {
+    void checkState() {
         if (rowCountDirty) {
             updateRowCount();
             rowCountDirty = false;
         }
     }