150 } 151 152 /*************************************************************************** 153 * * 154 * Properties * 155 * * 156 **************************************************************************/ 157 158 private int oldMaxPageIndicatorCount = DEFAULT_MAX_PAGE_INDICATOR_COUNT; 159 private IntegerProperty maxPageIndicatorCount; 160 161 /** 162 * Sets the maximum number of page indicators. 163 * 164 * @param value the number of page indicators. The default is 10. 165 */ 166 public final void setMaxPageIndicatorCount(int value) { maxPageIndicatorCountProperty().set(value); } 167 168 /** 169 * Returns the maximum number of page indicators. 170 */ 171 public final int getMaxPageIndicatorCount() { 172 return maxPageIndicatorCount == null ? DEFAULT_MAX_PAGE_INDICATOR_COUNT : maxPageIndicatorCount.get(); 173 } 174 175 /** 176 * The maximum number of page indicators to use for this pagination control. 177 * The maximum number of pages indicators will remain unchanged if the value is less than 1 178 * or greater than the {@link #pageCount}. The number of page indicators will be 179 * reduced to fit the control if the {@code maxPageIndicatorCount} cannot fit. 180 * 181 * The default is 10 page indicators. 182 */ 183 public final IntegerProperty maxPageIndicatorCountProperty() { 184 if (maxPageIndicatorCount == null) { 185 maxPageIndicatorCount = new StyleableIntegerProperty(DEFAULT_MAX_PAGE_INDICATOR_COUNT) { 186 187 @Override protected void invalidated() { 188 if (!maxPageIndicatorCount.isBound()) { 189 if (getMaxPageIndicatorCount() < 1 || getMaxPageIndicatorCount() > getPageCount()) { 190 setMaxPageIndicatorCount(oldMaxPageIndicatorCount); 191 } 192 oldMaxPageIndicatorCount = getMaxPageIndicatorCount(); 193 } 194 } 195 196 @Override 197 public CssMetaData<Pagination,Number> getCssMetaData() { 198 return StyleableProperties.MAX_PAGE_INDICATOR_COUNT; 199 } 200 201 @Override 216 private IntegerProperty pageCount = new SimpleIntegerProperty(this, "pageCount", INDETERMINATE) { 217 @Override protected void invalidated() { 218 if (!pageCount.isBound()) { 219 if (getPageCount() < 1) { 220 setPageCount(oldPageCount); 221 } 222 oldPageCount = getPageCount(); 223 } 224 } 225 }; 226 227 /** 228 * Sets the number of pages. 229 * 230 * @param value the number of pages 231 */ 232 public final void setPageCount(int value) { pageCount.set(value); } 233 234 /** 235 * Returns the number of pages. 236 */ 237 public final int getPageCount() { return pageCount.get(); } 238 239 /** 240 * The number of pages for this pagination control. This 241 * value must be greater than or equal to 1. {@link #INDETERMINATE} 242 * should be used as the page count if the total number of pages is unknown. 243 * 244 * The default is an {@link #INDETERMINATE} number of pages. 245 */ 246 public final IntegerProperty pageCountProperty() { return pageCount; } 247 248 private final IntegerProperty currentPageIndex = new SimpleIntegerProperty(this, "currentPageIndex", 0) { 249 @Override protected void invalidated() { 250 if (!currentPageIndex.isBound()) { 251 if (getCurrentPageIndex() < 0) { 252 setCurrentPageIndex(0); 253 } else if (getCurrentPageIndex() > getPageCount() - 1) { 254 setCurrentPageIndex(getPageCount() - 1); 255 } 256 } 257 } 258 259 @Override 260 public void bind(ObservableValue<? extends Number> rawObservable) { 261 throw new UnsupportedOperationException("currentPageIndex supports only bidirectional binding"); 262 } 263 }; 264 265 /** 266 * Sets the current page index. 267 * @param value the current page index. 268 */ 269 public final void setCurrentPageIndex(int value) { currentPageIndex.set(value); } 270 271 /** 272 * Returns the current page index. 273 */ 274 public final int getCurrentPageIndex() { return currentPageIndex.get(); } 275 276 /** 277 * The current page index to display for this pagination control. The first page will be 278 * the current page if the value is less than 0. Similarly the last page 279 * will be the current page if the value is greater than the {@link #pageCount} 280 * 281 * The default is 0 for the first page. 282 * <p> 283 * Because the page indicators set the current page index, the currentPageIndex property permits only 284 * bidirectional binding. 285 * The {@link javafx.beans.property.IntegerProperty#bind(javafx.beans.value.ObservableValue) bind} method 286 * throws an UnsupportedOperationException. 287 * </p> 288 */ 289 public final IntegerProperty currentPageIndexProperty() { return currentPageIndex; } 290 291 private ObjectProperty<Callback<Integer, Node>> pageFactory = 292 new SimpleObjectProperty<Callback<Integer, Node>>(this, "pageFactory"); 293 294 /** 295 * Sets the page factory callback function. 296 */ 297 public final void setPageFactory(Callback<Integer, Node> value) { pageFactory.set(value); } 298 299 /** 300 * Returns the page factory callback function. 301 */ 302 public final Callback<Integer, Node> getPageFactory() {return pageFactory.get(); } 303 304 /** 305 * The pageFactory callback function that is called when a page has been 306 * selected by the application or the user. 307 * 308 * This function is required for the functionality of the pagination 309 * control. The callback function should load and return the contents the page index. 310 * Null should be returned if the page index does not exist. The currentPageIndex 311 * will not change when null is returned. 312 * 313 * The default is null if there is no page factory set. 314 */ 315 public final ObjectProperty<Callback<Integer, Node>> pageFactoryProperty() { return pageFactory; } 316 317 318 /*************************************************************************** 319 * * 320 * Methods * 321 * * 322 **************************************************************************/ 323 324 /** {@inheritDoc} */ 325 @Override protected Skin<?> createDefaultSkin() { 326 return new PaginationSkin(this); 327 } 328 329 /*************************************************************************** 330 * * 331 * Stylesheet Handling * 332 * * 333 **************************************************************************/ | 150 } 151 152 /*************************************************************************** 153 * * 154 * Properties * 155 * * 156 **************************************************************************/ 157 158 private int oldMaxPageIndicatorCount = DEFAULT_MAX_PAGE_INDICATOR_COUNT; 159 private IntegerProperty maxPageIndicatorCount; 160 161 /** 162 * Sets the maximum number of page indicators. 163 * 164 * @param value the number of page indicators. The default is 10. 165 */ 166 public final void setMaxPageIndicatorCount(int value) { maxPageIndicatorCountProperty().set(value); } 167 168 /** 169 * Returns the maximum number of page indicators. 170 * @return the maximum number of page indicators 171 */ 172 public final int getMaxPageIndicatorCount() { 173 return maxPageIndicatorCount == null ? DEFAULT_MAX_PAGE_INDICATOR_COUNT : maxPageIndicatorCount.get(); 174 } 175 176 /** 177 * The maximum number of page indicators to use for this pagination control. 178 * The maximum number of pages indicators will remain unchanged if the value is less than 1 179 * or greater than the {@link #pageCount}. The number of page indicators will be 180 * reduced to fit the control if the {@code maxPageIndicatorCount} cannot fit. 181 * 182 * The default is 10 page indicators. 183 * @return the maximum number of page indicators to use for this pagination control 184 */ 185 public final IntegerProperty maxPageIndicatorCountProperty() { 186 if (maxPageIndicatorCount == null) { 187 maxPageIndicatorCount = new StyleableIntegerProperty(DEFAULT_MAX_PAGE_INDICATOR_COUNT) { 188 189 @Override protected void invalidated() { 190 if (!maxPageIndicatorCount.isBound()) { 191 if (getMaxPageIndicatorCount() < 1 || getMaxPageIndicatorCount() > getPageCount()) { 192 setMaxPageIndicatorCount(oldMaxPageIndicatorCount); 193 } 194 oldMaxPageIndicatorCount = getMaxPageIndicatorCount(); 195 } 196 } 197 198 @Override 199 public CssMetaData<Pagination,Number> getCssMetaData() { 200 return StyleableProperties.MAX_PAGE_INDICATOR_COUNT; 201 } 202 203 @Override 218 private IntegerProperty pageCount = new SimpleIntegerProperty(this, "pageCount", INDETERMINATE) { 219 @Override protected void invalidated() { 220 if (!pageCount.isBound()) { 221 if (getPageCount() < 1) { 222 setPageCount(oldPageCount); 223 } 224 oldPageCount = getPageCount(); 225 } 226 } 227 }; 228 229 /** 230 * Sets the number of pages. 231 * 232 * @param value the number of pages 233 */ 234 public final void setPageCount(int value) { pageCount.set(value); } 235 236 /** 237 * Returns the number of pages. 238 * @return the number of pages 239 */ 240 public final int getPageCount() { return pageCount.get(); } 241 242 /** 243 * The number of pages for this pagination control. This 244 * value must be greater than or equal to 1. {@link #INDETERMINATE} 245 * should be used as the page count if the total number of pages is unknown. 246 * 247 * The default is an {@link #INDETERMINATE} number of pages. 248 * @return the number of pages for this pagination control 249 */ 250 public final IntegerProperty pageCountProperty() { return pageCount; } 251 252 private final IntegerProperty currentPageIndex = new SimpleIntegerProperty(this, "currentPageIndex", 0) { 253 @Override protected void invalidated() { 254 if (!currentPageIndex.isBound()) { 255 if (getCurrentPageIndex() < 0) { 256 setCurrentPageIndex(0); 257 } else if (getCurrentPageIndex() > getPageCount() - 1) { 258 setCurrentPageIndex(getPageCount() - 1); 259 } 260 } 261 } 262 263 @Override 264 public void bind(ObservableValue<? extends Number> rawObservable) { 265 throw new UnsupportedOperationException("currentPageIndex supports only bidirectional binding"); 266 } 267 }; 268 269 /** 270 * Sets the current page index. 271 * @param value the current page index. 272 */ 273 public final void setCurrentPageIndex(int value) { currentPageIndex.set(value); } 274 275 /** 276 * Returns the current page index. 277 * @return the current page index 278 */ 279 public final int getCurrentPageIndex() { return currentPageIndex.get(); } 280 281 /** 282 * The current page index to display for this pagination control. The first page will be 283 * the current page if the value is less than 0. Similarly the last page 284 * will be the current page if the value is greater than the {@link #pageCount} 285 * 286 * The default is 0 for the first page. 287 * <p> 288 * Because the page indicators set the current page index, the currentPageIndex property permits only 289 * bidirectional binding. 290 * The {@link javafx.beans.property.IntegerProperty#bind(javafx.beans.value.ObservableValue) bind} method 291 * throws an UnsupportedOperationException. 292 * </p> 293 * @return the current page index property 294 */ 295 public final IntegerProperty currentPageIndexProperty() { return currentPageIndex; } 296 297 private ObjectProperty<Callback<Integer, Node>> pageFactory = 298 new SimpleObjectProperty<Callback<Integer, Node>>(this, "pageFactory"); 299 300 /** 301 * Sets the page factory callback function. 302 * @param value the page factory callback function 303 */ 304 public final void setPageFactory(Callback<Integer, Node> value) { pageFactory.set(value); } 305 306 /** 307 * Returns the page factory callback function. 308 * @return the page factory callback function 309 */ 310 public final Callback<Integer, Node> getPageFactory() {return pageFactory.get(); } 311 312 /** 313 * The pageFactory callback function that is called when a page has been 314 * selected by the application or the user. 315 * 316 * This function is required for the functionality of the pagination 317 * control. The callback function should load and return the contents the page index. 318 * Null should be returned if the page index does not exist. The currentPageIndex 319 * will not change when null is returned. 320 * 321 * The default is null if there is no page factory set. 322 * @return the page factory property 323 */ 324 public final ObjectProperty<Callback<Integer, Node>> pageFactoryProperty() { return pageFactory; } 325 326 327 /*************************************************************************** 328 * * 329 * Methods * 330 * * 331 **************************************************************************/ 332 333 /** {@inheritDoc} */ 334 @Override protected Skin<?> createDefaultSkin() { 335 return new PaginationSkin(this); 336 } 337 338 /*************************************************************************** 339 * * 340 * Stylesheet Handling * 341 * * 342 **************************************************************************/ |