changeset 840:20b49d777360

Pagination: cleanup page transistions.
author Kinsley Wong
date Wed, 18 Apr 2012 12:07:31 -0700
parents 3d6637fc8259
children 01ecdaeb7a86
files javafx-ui-controls/src/com/sun/javafx/scene/control/skin/PaginationSkin.java
diffstat 1 files changed, 39 insertions(+), 24 deletions(-) [+]
line wrap: on
line diff
--- a/javafx-ui-controls/src/com/sun/javafx/scene/control/skin/PaginationSkin.java	Tue Apr 17 18:44:06 2012 -0700
+++ b/javafx-ui-controls/src/com/sun/javafx/scene/control/skin/PaginationSkin.java	Wed Apr 18 12:07:31 2012 -0700
@@ -170,7 +170,16 @@
         currentIndex = usePageIndex ? getSkinnable().getPageIndex() : 0;
         toIndex = fromIndex + (numberOfPages - 1);
 
+        boolean isAnimate = animate;
+        if (isAnimate) {
+            animate = false;
+        }
+
         pagination.setPageIndex(currentIndex);
+
+        if (isAnimate) {
+            animate = true;
+        }
     }
 
     private void createPage(ScrollPane pane, int index) {
@@ -192,18 +201,19 @@
     private int currentAnimatedIndex;
     private int previousAnimatedIndex;
 
-    private void animateSwitchPage() {         
+    private void animateSwitchPage() {
         if (timeline != null) {
             // The current animation has not finished
             return;
         }
-        
-        previousAnimatedIndex = currentAnimatedIndex;
-        if (currentIndex > previousIndex) {            
-            currentAnimatedIndex++;
-        } else {
-            currentAnimatedIndex--;
-        }
+          // Uncomment this code is we want to see the page index
+          // selections as we cycle from previous to the current index.
+//        previousAnimatedIndex = currentAnimatedIndex;
+//        if (currentIndex > previousIndex) {
+//            currentAnimatedIndex++;
+//        } else {
+//            currentAnimatedIndex--;
+//        }
 
         createPage(nextScrollPane, currentAnimatedIndex);
         nextScrollPane.setCache(true);
@@ -257,7 +267,7 @@
             ScrollPane temp = currentScrollPane;
             currentScrollPane = nextScrollPane;
             nextScrollPane = temp;
-                        
+
             timeline = null;
             currentScrollPane.setTranslateX(0);
             nextScrollPane.setCache(false);
@@ -265,20 +275,22 @@
             nextScrollPane.setVisible(false);
             nextScrollPane.setContent(null);
 
-            int savedCurrentIndex = currentIndex;
-            int savedPreviousIndex = previousIndex;
-            
-            // We swap out the current and previous index so we can select
-            // and unselect them.
-            previousIndex = previousAnimatedIndex;
-            currentIndex = currentAnimatedIndex;            
-            navigation.updatePageIndex();            
-            currentIndex = savedCurrentIndex;
-            previousIndex = savedPreviousIndex;
-            
-            if (currentAnimatedIndex != currentIndex) {
-                animateSwitchPage();
-            }
+            // Uncomment this code is we want to see the page index
+            // selections as we cycle from previous to the current index.
+//            int savedCurrentIndex = currentIndex;
+//            int savedPreviousIndex = previousIndex;
+//
+//            // We swap out the current and previous index so we can select
+//            // and unselect them.
+//            previousIndex = previousAnimatedIndex;
+//            currentIndex = currentAnimatedIndex;
+            navigation.updatePageIndex();
+//            currentIndex = savedCurrentIndex;
+//            previousIndex = savedPreviousIndex;
+//
+//            if (currentAnimatedIndex != currentIndex) {
+//                animateSwitchPage();
+//            }
         }
     };
 
@@ -394,8 +406,11 @@
                 public void changed(ObservableValue<? extends Number> arg0, Number arg1, Number arg2) {
                     previousIndex = arg1.intValue();
                     currentIndex = arg2.intValue();
-                    if (animate) {                        
+                    if (animate) {
+                        // Uncomment this code is we want to see the page index
+                        // selections as we cycle from previous to the current index.
                         currentAnimatedIndex = previousIndex;
+                        currentAnimatedIndex = currentIndex;
                         animateSwitchPage();
                     } else {
                         updatePageIndex();