changeset 1118:f6481c10db9e

RT-21655: Touch: PAgination touching the index buttons doesn't always work.
author Kinsley Wong
date Tue, 22 May 2012 13:48:46 -0700
parents 3c607527d01a
children e8b3ea91cdd6
files javafx-ui-controls/src/com/sun/javafx/scene/control/skin/PaginationSkin.java
diffstat 1 files changed, 96 insertions(+), 90 deletions(-) [+]
line wrap: on
line diff
--- a/javafx-ui-controls/src/com/sun/javafx/scene/control/skin/PaginationSkin.java	Tue May 22 13:03:15 2012 -0700
+++ b/javafx-ui-controls/src/com/sun/javafx/scene/control/skin/PaginationSkin.java	Tue May 22 13:48:46 2012 -0700
@@ -88,6 +88,7 @@
     private static final double THRESHOLD = 0.30;
 
     private Pagination pagination;
+    private StackPane stackPane;
     private ScrollPane currentScrollPane;
     private ScrollPane nextScrollPane;
     private Timeline timeline;
@@ -111,6 +112,9 @@
         setClip(clipRect);
 
         this.pagination = pagination;
+
+        this.stackPane = new StackPane();
+
         this.currentScrollPane = new ScrollPane();
         currentScrollPane.getStyleClass().add("page");
         currentScrollPane.setFitToWidth(true);
@@ -128,7 +132,8 @@
 
         this.navigation = new NavigationControl();
 
-        getChildren().addAll(currentScrollPane, nextScrollPane, navigation);
+        stackPane.getChildren().addAll(currentScrollPane, nextScrollPane);
+        getChildren().addAll(stackPane, navigation);
 
         pagination.maxPageIndicatorCountProperty().addListener(new InvalidationListener() {
             @Override
@@ -160,103 +165,105 @@
     private double pressPos;
     private boolean touchMoved = false;
     private void initializeSwipeAndTouchHandlers() {
-        setOnSwipeLeft(new EventHandler<SwipeEvent>() {
-            @Override public void handle(SwipeEvent t) {
-                touchMoved = false;
-                selectNext();
-                t.consume();
-            }
-        });
+        if (PlatformUtil.isEmbedded()) {
+            stackPane.setOnSwipeLeft(new EventHandler<SwipeEvent>() {
+                @Override public void handle(SwipeEvent t) {
+                    touchMoved = false;
+                    selectNext();
+                    t.consume();
+                }
+            });
 
-        setOnSwipeRight(new EventHandler<SwipeEvent>() {
-            @Override public void handle(SwipeEvent t) {
-                touchMoved = false;
-                selectPrevious();
-                t.consume();
-            }
-        });
+            stackPane.setOnSwipeRight(new EventHandler<SwipeEvent>() {
+                @Override public void handle(SwipeEvent t) {
+                    touchMoved = false;
+                    selectPrevious();
+                    t.consume();
+                }
+            });
 
-        setOnScrollStarted(new EventHandler<ScrollEvent>() {
-            @Override public void handle(ScrollEvent e) {
-                pressPos = e.getSceneX();
-                touchMoved = true;
-                e.consume();
-            }
-        });
+            stackPane.setOnScrollStarted(new EventHandler<ScrollEvent>() {
+                @Override public void handle(ScrollEvent e) {
+                    pressPos = e.getSceneX();
+                    touchMoved = true;
+                    e.consume();
+                }
+            });
 
-        setOnScroll(new EventHandler<ScrollEvent>() {
-            @Override public void handle(ScrollEvent e) {
-                if (!touchMoved) {
-                    // Ignore any scroll events after the scrolling has finished.
-                    return;
-                }
+            stackPane.setOnScroll(new EventHandler<ScrollEvent>() {
+                @Override public void handle(ScrollEvent e) {
+                    if (!touchMoved) {
+                        // Ignore any scroll events after the scrolling has finished.
+                        return;
+                    }
 
-                touchMoved = true;
-                double delta = e.getSceneX() - pressPos;
-                double width = getWidth() - (getInsets().getLeft() + getInsets().getRight());
-                double currentScrollPaneX;
-                double nextScrollPaneX;
+                    touchMoved = true;
+                    double delta = e.getSceneX() - pressPos;
+                    double width = getWidth() - (getInsets().getLeft() + getInsets().getRight());
+                    double currentScrollPaneX;
+                    double nextScrollPaneX;
 
-                if (delta < 0) {
-                    // right to left
-                    if (Math.abs(delta) <= width) {
-                        currentScrollPaneX = delta;
-                        nextScrollPaneX = width + delta;
-                    } else {
-                        currentScrollPaneX = -width;
-                        nextScrollPaneX = 0;
-                    }
-                    currentScrollPane.setTranslateX(currentScrollPaneX);
-                    if (pagination.getCurrentPageIndex() < getPageCount() - 1) {
-                        createPage(nextScrollPane, currentIndex + 1);
-                        nextScrollPane.setVisible(true);
-                        nextScrollPane.setTranslateX(nextScrollPaneX);
-                    } else {
-                        currentScrollPane.setTranslateX(0);
-                    }
-                } else {
-                    // left to right
-                    if (Math.abs(delta) <= width) {
-                        currentScrollPaneX = delta;
-                        nextScrollPaneX = -width + delta;
-                    } else {
-                        currentScrollPaneX = width;
-                        nextScrollPaneX = 0;
-                    }
-                    currentScrollPane.setTranslateX(currentScrollPaneX);
-                    if (pagination.getCurrentPageIndex() != 0) {
-                        createPage(nextScrollPane, currentIndex - 1);
-                        nextScrollPane.setVisible(true);
-                        nextScrollPane.setTranslateX(nextScrollPaneX);
-                    } else {
-                        currentScrollPane.setTranslateX(0);
-                    }
-                }
-                e.consume();
-            }
-        });
-
-        setOnScrollFinished(new EventHandler<ScrollEvent>() {
-            @Override
-            public void handle(ScrollEvent e) {
-                double delta = Math.abs(e.getSceneX() - pressPos);
-                double width = getWidth() - (getInsets().getLeft() + getInsets().getRight());
-                double threshold = delta/width;
-                if (touchMoved) {
-                    if (threshold > THRESHOLD) {
-                        if (pressPos > e.getSceneX()) {
-                            selectNext();
+                    if (delta < 0) {
+                        // right to left
+                        if (Math.abs(delta) <= width) {
+                            currentScrollPaneX = delta;
+                            nextScrollPaneX = width + delta;
                         } else {
-                            selectPrevious();
+                            currentScrollPaneX = -width;
+                            nextScrollPaneX = 0;
+                        }
+                        currentScrollPane.setTranslateX(currentScrollPaneX);
+                        if (pagination.getCurrentPageIndex() < getPageCount() - 1) {
+                            createPage(nextScrollPane, currentIndex + 1);
+                            nextScrollPane.setVisible(true);
+                            nextScrollPane.setTranslateX(nextScrollPaneX);
+                        } else {
+                            currentScrollPane.setTranslateX(0);
                         }
                     } else {
-                        animateClamping(pressPos > e.getSceneX());
+                        // left to right
+                        if (Math.abs(delta) <= width) {
+                            currentScrollPaneX = delta;
+                            nextScrollPaneX = -width + delta;
+                        } else {
+                            currentScrollPaneX = width;
+                            nextScrollPaneX = 0;
+                        }
+                        currentScrollPane.setTranslateX(currentScrollPaneX);
+                        if (pagination.getCurrentPageIndex() != 0) {
+                            createPage(nextScrollPane, currentIndex - 1);
+                            nextScrollPane.setVisible(true);
+                            nextScrollPane.setTranslateX(nextScrollPaneX);
+                        } else {
+                            currentScrollPane.setTranslateX(0);
+                        }
                     }
+                    e.consume();
                 }
-                touchMoved = false;
-                e.consume();
-            }
-        });
+            });
+
+            stackPane.setOnScrollFinished(new EventHandler<ScrollEvent>() {
+                @Override
+                public void handle(ScrollEvent e) {
+                    double delta = Math.abs(e.getSceneX() - pressPos);
+                    double width = getWidth() - (getInsets().getLeft() + getInsets().getRight());
+                    double threshold = delta/width;
+                    if (touchMoved) {
+                        if (threshold > THRESHOLD) {
+                            if (pressPos > e.getSceneX()) {
+                                selectNext();
+                            } else {
+                                selectPrevious();
+                            }
+                        } else {
+                            animateClamping(pressPos > e.getSceneX());
+                        }
+                    }
+                    touchMoved = false;
+                    e.consume();
+                }
+            });
+        }
     }
 
     private void resetIndexes(boolean usePageIndex) {
@@ -645,8 +652,7 @@
         double navigationHeight = snapSize(navigation.prefHeight(-1));
         double scrollPaneHeight = snapSize(height - navigationHeight);
 
-        layoutInArea(currentScrollPane, left, top, width, scrollPaneHeight, 0, HPos.CENTER, VPos.CENTER);
-        layoutInArea(nextScrollPane, left, top, width, scrollPaneHeight, 0, HPos.CENTER, VPos.CENTER);
+        layoutInArea(stackPane, left, top, width, scrollPaneHeight, 0, HPos.CENTER, VPos.CENTER);
         layoutInArea(navigation, left, scrollPaneHeight, width, navigationHeight, 0, HPos.CENTER, VPos.CENTER);
     }