249 /*************************************************************************** 250 * * 251 * Public API * 252 * * 253 **************************************************************************/ 254 255 /** {@inheritDoc} */ 256 @Override public void dispose() { 257 super.dispose(); 258 259 if (behavior != null) { 260 behavior.dispose(); 261 } 262 } 263 264 /** {@inheritDoc} */ 265 @Override protected void layoutChildren(final double x, final double y, 266 final double w, final double h) { 267 268 final double incrementArrowButtonWidth = incrementArrowButton.snappedLeftInset() + 269 snapSize(incrementArrow.prefWidth(-1)) + incrementArrowButton.snappedRightInset(); 270 271 final double decrementArrowButtonWidth = decrementArrowButton.snappedLeftInset() + 272 snapSize(decrementArrow.prefWidth(-1)) + decrementArrowButton.snappedRightInset(); 273 274 final double widestArrowButton = Math.max(incrementArrowButtonWidth, decrementArrowButtonWidth); 275 276 // we need to decide on our layout approach, and this depends on 277 // the presence of style classes in the Spinner styleClass list. 278 // To be a bit more efficient, we observe the list for changes, so 279 // here in layoutChildren we can just react to a few booleans. 280 if (layoutMode == ARROWS_ON_RIGHT_VERTICAL || layoutMode == ARROWS_ON_LEFT_VERTICAL) { 281 final double textFieldStartX = layoutMode == ARROWS_ON_RIGHT_VERTICAL ? x : x + widestArrowButton; 282 final double buttonStartX = layoutMode == ARROWS_ON_RIGHT_VERTICAL ? x + w - widestArrowButton : x; 283 final double halfHeight = Math.floor(h / 2.0); 284 285 textField.resizeRelocate(textFieldStartX, y, w - widestArrowButton, h); 286 287 incrementArrowButton.resize(widestArrowButton, halfHeight); 288 positionInArea(incrementArrowButton, buttonStartX, y, 289 widestArrowButton, halfHeight, 0, HPos.CENTER, VPos.CENTER); 290 291 decrementArrowButton.resize(widestArrowButton, halfHeight); 292 positionInArea(decrementArrowButton, buttonStartX, y + halfHeight, 293 widestArrowButton, h - halfHeight, 0, HPos.CENTER, VPos.BOTTOM); 294 } else if (layoutMode == ARROWS_ON_RIGHT_HORIZONTAL || layoutMode == ARROWS_ON_LEFT_HORIZONTAL) { 295 final double totalButtonWidth = incrementArrowButtonWidth + decrementArrowButtonWidth; 296 final double textFieldStartX = layoutMode == ARROWS_ON_RIGHT_HORIZONTAL ? x : x + totalButtonWidth; 297 final double buttonStartX = layoutMode == ARROWS_ON_RIGHT_HORIZONTAL ? x + w - totalButtonWidth : x; 298 299 textField.resizeRelocate(textFieldStartX, y, w - totalButtonWidth, h); 300 301 // decrement is always on the left 302 decrementArrowButton.resize(decrementArrowButtonWidth, h); 303 positionInArea(decrementArrowButton, buttonStartX, y, 304 decrementArrowButtonWidth, h, 0, HPos.CENTER, VPos.CENTER); 305 306 // ... and increment is always on the right 307 incrementArrowButton.resize(incrementArrowButtonWidth, h); 308 positionInArea(incrementArrowButton, buttonStartX + decrementArrowButtonWidth, y, 309 incrementArrowButtonWidth, h, 0, HPos.CENTER, VPos.CENTER); 310 } else if (layoutMode == SPLIT_ARROWS_VERTICAL) { 311 final double incrementArrowButtonHeight = incrementArrowButton.snappedTopInset() + 312 snapSize(incrementArrow.prefHeight(-1)) + incrementArrowButton.snappedBottomInset(); 313 314 final double decrementArrowButtonHeight = decrementArrowButton.snappedTopInset() + 315 snapSize(decrementArrow.prefHeight(-1)) + decrementArrowButton.snappedBottomInset(); 316 317 final double tallestArrowButton = Math.max(incrementArrowButtonHeight, decrementArrowButtonHeight); 318 319 // increment is at the top 320 incrementArrowButton.resize(w, tallestArrowButton); 321 positionInArea(incrementArrowButton, x, y, 322 w, tallestArrowButton, 0, HPos.CENTER, VPos.CENTER); 323 324 // textfield in the middle 325 textField.resizeRelocate(x, y + tallestArrowButton, w, h - (2*tallestArrowButton)); 326 327 // decrement is at the bottom 328 decrementArrowButton.resize(w, tallestArrowButton); 329 positionInArea(decrementArrowButton, x, h - tallestArrowButton, 330 w, tallestArrowButton, 0, HPos.CENTER, VPos.CENTER); 331 } else if (layoutMode == SPLIT_ARROWS_HORIZONTAL) { 332 // decrement is on the left-hand side 333 decrementArrowButton.resize(widestArrowButton, h); 334 positionInArea(decrementArrowButton, x, y, 335 widestArrowButton, h, 0, HPos.CENTER, VPos.CENTER); | 249 /*************************************************************************** 250 * * 251 * Public API * 252 * * 253 **************************************************************************/ 254 255 /** {@inheritDoc} */ 256 @Override public void dispose() { 257 super.dispose(); 258 259 if (behavior != null) { 260 behavior.dispose(); 261 } 262 } 263 264 /** {@inheritDoc} */ 265 @Override protected void layoutChildren(final double x, final double y, 266 final double w, final double h) { 267 268 final double incrementArrowButtonWidth = incrementArrowButton.snappedLeftInset() + 269 snapSizeX(incrementArrow.prefWidth(-1)) + incrementArrowButton.snappedRightInset(); 270 271 final double decrementArrowButtonWidth = decrementArrowButton.snappedLeftInset() + 272 snapSizeX(decrementArrow.prefWidth(-1)) + decrementArrowButton.snappedRightInset(); 273 274 final double widestArrowButton = Math.max(incrementArrowButtonWidth, decrementArrowButtonWidth); 275 276 // we need to decide on our layout approach, and this depends on 277 // the presence of style classes in the Spinner styleClass list. 278 // To be a bit more efficient, we observe the list for changes, so 279 // here in layoutChildren we can just react to a few booleans. 280 if (layoutMode == ARROWS_ON_RIGHT_VERTICAL || layoutMode == ARROWS_ON_LEFT_VERTICAL) { 281 final double textFieldStartX = layoutMode == ARROWS_ON_RIGHT_VERTICAL ? x : x + widestArrowButton; 282 final double buttonStartX = layoutMode == ARROWS_ON_RIGHT_VERTICAL ? x + w - widestArrowButton : x; 283 final double halfHeight = Math.floor(h / 2.0); 284 285 textField.resizeRelocate(textFieldStartX, y, w - widestArrowButton, h); 286 287 incrementArrowButton.resize(widestArrowButton, halfHeight); 288 positionInArea(incrementArrowButton, buttonStartX, y, 289 widestArrowButton, halfHeight, 0, HPos.CENTER, VPos.CENTER); 290 291 decrementArrowButton.resize(widestArrowButton, halfHeight); 292 positionInArea(decrementArrowButton, buttonStartX, y + halfHeight, 293 widestArrowButton, h - halfHeight, 0, HPos.CENTER, VPos.BOTTOM); 294 } else if (layoutMode == ARROWS_ON_RIGHT_HORIZONTAL || layoutMode == ARROWS_ON_LEFT_HORIZONTAL) { 295 final double totalButtonWidth = incrementArrowButtonWidth + decrementArrowButtonWidth; 296 final double textFieldStartX = layoutMode == ARROWS_ON_RIGHT_HORIZONTAL ? x : x + totalButtonWidth; 297 final double buttonStartX = layoutMode == ARROWS_ON_RIGHT_HORIZONTAL ? x + w - totalButtonWidth : x; 298 299 textField.resizeRelocate(textFieldStartX, y, w - totalButtonWidth, h); 300 301 // decrement is always on the left 302 decrementArrowButton.resize(decrementArrowButtonWidth, h); 303 positionInArea(decrementArrowButton, buttonStartX, y, 304 decrementArrowButtonWidth, h, 0, HPos.CENTER, VPos.CENTER); 305 306 // ... and increment is always on the right 307 incrementArrowButton.resize(incrementArrowButtonWidth, h); 308 positionInArea(incrementArrowButton, buttonStartX + decrementArrowButtonWidth, y, 309 incrementArrowButtonWidth, h, 0, HPos.CENTER, VPos.CENTER); 310 } else if (layoutMode == SPLIT_ARROWS_VERTICAL) { 311 final double incrementArrowButtonHeight = incrementArrowButton.snappedTopInset() + 312 snapSizeY(incrementArrow.prefHeight(-1)) + incrementArrowButton.snappedBottomInset(); 313 314 final double decrementArrowButtonHeight = decrementArrowButton.snappedTopInset() + 315 snapSizeY(decrementArrow.prefHeight(-1)) + decrementArrowButton.snappedBottomInset(); 316 317 final double tallestArrowButton = Math.max(incrementArrowButtonHeight, decrementArrowButtonHeight); 318 319 // increment is at the top 320 incrementArrowButton.resize(w, tallestArrowButton); 321 positionInArea(incrementArrowButton, x, y, 322 w, tallestArrowButton, 0, HPos.CENTER, VPos.CENTER); 323 324 // textfield in the middle 325 textField.resizeRelocate(x, y + tallestArrowButton, w, h - (2*tallestArrowButton)); 326 327 // decrement is at the bottom 328 decrementArrowButton.resize(w, tallestArrowButton); 329 positionInArea(decrementArrowButton, x, h - tallestArrowButton, 330 w, tallestArrowButton, 0, HPos.CENTER, VPos.CENTER); 331 } else if (layoutMode == SPLIT_ARROWS_HORIZONTAL) { 332 // decrement is on the left-hand side 333 decrementArrowButton.resize(widestArrowButton, h); 334 positionInArea(decrementArrowButton, x, y, 335 widestArrowButton, h, 0, HPos.CENTER, VPos.CENTER); |