changeset 1233:b855ec5afa28

RT-22026: [Pagination] need strict specification of behavior on max page indicators count.
author Kinsley Wong
date Tue, 05 Jun 2012 16:49:56 -0700
parents 46dadf1d60fc
children bbf040d2b20e
files javafx-ui-controls/src/javafx/scene/control/Pagination.java javafx-ui-controls/test/javafx/scene/control/PaginationTest.java
diffstat 2 files changed, 46 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/javafx-ui-controls/src/javafx/scene/control/Pagination.java	Tue Jun 05 14:44:47 2012 -0700
+++ b/javafx-ui-controls/src/javafx/scene/control/Pagination.java	Tue Jun 05 16:49:56 2012 -0700
@@ -69,7 +69,7 @@
  * The control can be customized to display numeric page indicators or bullet style indicators by
  * setting the style class {@link STYLE_CLASS_BULLET}.  The 
  * {@link #maxPageIndicatorCountProperty() maxPageIndicatorCountProperty} can be used to change 
- * the number of page indicators.  The property value can also be changed 
+ * the maximum number of page indicators.  The property value can also be changed 
  * via CSS using -fx-max-page-indicator-count.
  *</p> 
  * 
@@ -185,11 +185,10 @@
     }
     
     /**
-     * The maximum number of page indicators to use for this pagination control.  This
-     * value must be greater than or equal to 1.  The page indicators will 
-     * be unselected when the {@link #currentPageIndexProperty currentPageIndex} 
-     * is greater than the maxPageIndicatorCount.  The number of page indicators will be
-     * reduced if maxPageIndicatorCount cannot fit within this control. 
+     * The maximum number of page indicators to use for this pagination control.  
+     * The maximum number of pages indicators will remain unchanged if the value is less than 1 
+     * or greater than the {@link #pageCount}.  The number of page indicators will be
+     * reduced to fit the control if the {@code maxPageIndicatorCount} cannot fit.
      * 
      * The default is 10 page indicators.
      */    
@@ -198,7 +197,7 @@
             maxPageIndicatorCount = new StyleableIntegerProperty(DEFAULT_MAX_PAGE_INDICATOR_COUNT) {
 
                 @Override protected void invalidated() {
-                    if (getMaxPageIndicatorCount() < 1) {
+                    if (getMaxPageIndicatorCount() < 1 || getMaxPageIndicatorCount() > getPageCount()) {
                         setMaxPageIndicatorCount(oldMaxPageIndicatorCount);
                     }
                     oldMaxPageIndicatorCount = getMaxPageIndicatorCount();
@@ -253,14 +252,14 @@
      * The default is an {@link INDETERMINATE} number of pages.
      */    
     public final IntegerProperty pageCountProperty() { return pageCount; }
-
-    private int oldPageIndex;
+    
     private final IntegerProperty currentPageIndex = new SimpleIntegerProperty(this, "currentPageIndex", 0) {
         @Override protected void invalidated() {
             if (getCurrentPageIndex() < 0) {
-                setCurrentPageIndex(oldPageIndex);
+                setCurrentPageIndex(0);
+            } else if (getCurrentPageIndex() > getPageCount() - 1) {
+                setCurrentPageIndex(getPageCount() - 1);
             }
-            oldPageIndex = getCurrentPageIndex();
         }
     };
     
@@ -276,9 +275,9 @@
     public final int getCurrentPageIndex() { return currentPageIndex.get(); }
     
     /**
-     * The current page index to display for this pagination control.  This value
-     * must be greater than or equal to 0.  The page indicators will be unselected when
-     * the currentPageIndex is greater than the {@link #maxPageIndicatorCountProperty maxPageIndicatorCount}.
+     * The current page index to display for this pagination control.  The first page will be 
+     * the current page if the value is less than 0.  Similarly the last page 
+     * will be the current page if the value is greater than the {@link #pageCount}
      * 
      * The default is 0 for the first page.
      */    
--- a/javafx-ui-controls/test/javafx/scene/control/PaginationTest.java	Tue Jun 05 14:44:47 2012 -0700
+++ b/javafx-ui-controls/test/javafx/scene/control/PaginationTest.java	Tue Jun 05 16:49:56 2012 -0700
@@ -208,7 +208,7 @@
         pagination.setCurrentPageIndex(4);
     }
 
-    @Test public void setMaxPageIndicatorCountToZero() {
+    @Test public void setCountToZero() {
         pagination.setPageCount(0);
 
         root.setPrefSize(400, 400);
@@ -226,9 +226,40 @@
 
         pagination.setCurrentPageIndex(5);
         pagination.setCurrentPageIndex(-1);
-        assertEquals(5, pagination.getCurrentPageIndex());
+        assertEquals(0, pagination.getCurrentPageIndex());
     }
 
+    @Test public void setCurrentPageIndexGreaterThanPageCount() {
+        pagination.setPageCount(100);
+        root.setPrefSize(400, 400);
+        root.getChildren().add(pagination);
+        show();
+
+        pagination.setCurrentPageIndex(5);
+        pagination.setCurrentPageIndex(100);
+        assertEquals(99, pagination.getCurrentPageIndex());
+    }
+    
+    @Test public void setMaxPageIndicatorCountLessThanZero() {
+        pagination.setPageCount(100);
+        root.setPrefSize(400, 400);
+        root.getChildren().add(pagination);
+        show();
+
+        pagination.setMaxPageIndicatorCount(-1);
+        assertEquals(10, pagination.getMaxPageIndicatorCount());
+    }
+
+    @Test public void setMaxPageIndicatorCountGreaterThanPageCount() {
+        pagination.setPageCount(100);
+        root.setPrefSize(400, 400);
+        root.getChildren().add(pagination);
+        show();
+        
+        pagination.setMaxPageIndicatorCount(101);
+        assertEquals(10, pagination.getMaxPageIndicatorCount());
+    }
+    
     @Test public void pageCountIsLessThanMaxPageIndicatorCount_RT21660() {
         pagination.setPageCount(5);
         root.setPrefSize(400, 400);