1 /* 2 * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 package javafx.scene.control.skin; 27 28 import static org.junit.Assert.assertEquals; 29 import static org.junit.Assert.assertFalse; 30 import static org.junit.Assert.assertTrue; 31 32 import com.sun.javafx.scene.control.skin.Utils; 33 import javafx.beans.value.ObservableValue; 34 import javafx.geometry.Insets; 35 import javafx.geometry.Pos; 36 import javafx.scene.control.ContentDisplay; 37 import javafx.scene.control.Label; 38 import javafx.scene.control.OverrunStyle; 39 import javafx.scene.control.SkinBaseAccessor; 40 import javafx.scene.effect.BlendMode; 41 import javafx.scene.paint.Color; 42 import javafx.scene.shape.Rectangle; 43 import javafx.scene.text.Font; 44 import javafx.scene.text.Text; 45 import javafx.scene.text.TextAlignment; 46 47 import org.junit.Before; 48 import org.junit.Test; 49 50 /** 51 * Need to test: 52 * - String truncation works correctly 53 * - min/max/pref width/height when multiline text is turned on 54 */ 55 public class LabelSkinTest { 56 private Label label; 57 private LabelSkinMock skin; 58 private Text text; 59 60 @Before public void setup() { 61 label = new Label(); 62 skin = new LabelSkinMock(label); 63 // Set some padding so that any places where padding was being 64 // computed but wasn't expected will be caught. 65 label.setPadding(new Insets(10, 10, 10, 10)); 66 label.setSkin(skin); 67 // It so happens that a brand new LabelSkin on a plain Label 68 // will have as its only child the Text node 69 text = (Text) SkinBaseAccessor.getChildren(skin).get(0); 70 } 71 72 /**************************************************************************** 73 * * 74 * Tests for change notification * 75 * * 76 ***************************************************************************/ 77 78 @Test public void sizeChangesOnLabelShouldInvoke_handleControlPropertyChanged() { 79 skin.addWatchedProperty(label.widthProperty()); 80 skin.addWatchedProperty(label.heightProperty()); 81 assertFalse(skin.propertyChanged); // sanity check 82 label.resize(500, label.getHeight()); 83 assertTrue(skin.propertyChanged); 84 assertEquals(1, skin.propertyChangeCount); // sanity check 85 label.resize(label.getWidth(), label.prefHeight(label.getWidth())); 86 assertEquals(2, skin.propertyChangeCount); // sanity check 87 } 88 89 @Test public void textFillChangesOnLabelShouldInvoke_handleControlPropertyChanged() { 90 skin.addWatchedProperty(label.textFillProperty()); 91 label.setTextFill(Color.PURPLE); 92 assertTrue(skin.propertyChanged); 93 } 94 95 @Test public void fontChangesOnLabelShouldInvoke_handleControlPropertyChanged() { 96 skin.addWatchedProperty(label.fontProperty()); 97 final Font f = Font.font("Arial", 64); 98 label.setFont(f); 99 assertTrue(skin.propertyChanged); 100 } 101 102 @Test public void graphicChangesOnLabelShouldInvoke_handleControlPropertyChanged() { 103 skin.addWatchedProperty(label.graphicProperty()); 104 label.setGraphic(new Rectangle()); 105 assertTrue(skin.propertyChanged); 106 } 107 108 @Test public void contentDisplayChangesOnLabelShouldInvoke_handleControlPropertyChanged() { 109 skin.addWatchedProperty(label.contentDisplayProperty()); 110 label.setContentDisplay(ContentDisplay.TEXT_ONLY); 111 assertTrue(skin.propertyChanged); 112 } 113 114 @Test public void graphicTextGapChangesOnLabelShouldInvoke_handleControlPropertyChanged() { 115 skin.addWatchedProperty(label.graphicTextGapProperty()); 116 label.setGraphicTextGap(60.34); 117 assertTrue(skin.propertyChanged); 118 } 119 120 @Test public void hposChangesOnLabelShouldInvoke_handleControlPropertyChanged() { 121 skin.addWatchedProperty(label.alignmentProperty()); 122 label.setAlignment(Pos.CENTER_RIGHT); 123 label.setAlignment(Pos.CENTER_RIGHT); 124 assertTrue(skin.propertyChanged); 125 } 126 127 @Test public void vposChangesOnLabelShouldInvoke_handleControlPropertyChanged() { 128 skin.addWatchedProperty(label.alignmentProperty()); 129 label.setAlignment(Pos.TOP_CENTER); 130 assertTrue(skin.propertyChanged); 131 } 132 133 @Test public void textChangesOnLabelShouldInvoke_handleControlPropertyChanged() { 134 skin.addWatchedProperty(label.textProperty()); 135 label.setText("Bust my buffers!"); 136 assertTrue(skin.propertyChanged); 137 } 138 139 @Test public void textAlignmentChangesOnLabelShouldInvoke_handleControlPropertyChanged() { 140 skin.addWatchedProperty(label.textAlignmentProperty()); 141 label.setTextAlignment(TextAlignment.JUSTIFY); 142 assertTrue(skin.propertyChanged); 143 } 144 145 @Test public void textOverrunChangesOnLabelShouldInvoke_handleControlPropertyChanged() { 146 skin.addWatchedProperty(label.textOverrunProperty()); 147 label.setTextOverrun(OverrunStyle.CENTER_WORD_ELLIPSIS); 148 assertTrue(skin.propertyChanged); 149 } 150 151 @Test public void wrapTextChangesOnLabelShouldInvoke_handleControlPropertyChanged() { 152 skin.addWatchedProperty(label.wrapTextProperty()); 153 label.setWrapText(true); 154 assertTrue(skin.propertyChanged); 155 } 156 157 @Test public void underlineChangesOnLabelShouldInvoke_handleControlPropertyChanged() { 158 skin.addWatchedProperty(label.underlineProperty()); 159 label.setUnderline(true); 160 assertTrue(skin.propertyChanged); 161 } 162 163 @Test public void uninterestingChangesOnLabelShouldNotInvoke_handleControlPropertyChanged() { 164 label.setBlendMode(BlendMode.BLUE); 165 assertFalse(skin.propertyChanged); 166 } 167 168 /**************************************************************************** 169 * * 170 * Tests for invalidation. When each of various properties change, we need * 171 * to invalidate some state, such as via requestLayout(). * 172 * * 173 ***************************************************************************/ 174 175 @Test public void graphicLayoutBoundsChangeShouldInvalidateLayoutAndDisplayText() { 176 final Rectangle r = new Rectangle(20, 20); 177 label.setGraphic(r); 178 label.layout(); 179 skin.updateDisplayedText(); 180 181 r.setWidth(30); 182 assertTrue(label.isNeedsLayout()); 183 assertTrue(skin.invalidText); 184 } 185 186 @Test public void widthChangesOnLabelShouldInvalidateLayoutAndDisplayText() { 187 label.layout(); 188 skin.updateDisplayedText(); 189 190 label.resize(500, label.getHeight()); 191 assertTrue(label.isNeedsLayout()); 192 assertTrue(skin.invalidText); 193 } 194 195 @Test public void widthChangesWhenWrapTextIsTrueUpdatesTheWrappingWidth() { 196 // Assert that the wrapping width changes with the label width if wrapText is true. 197 // However, this will only be required if the longest line in the text is itself 198 // wider than the label's available width. 199 label.setText("A long line which is wider than 100 pixels."); 200 label.setWrapText(true); 201 label.autosize(); 202 //label.layout(); 203 skin.updateDisplayedText(); 204 205 final double oldWrappingWidth = text.getWrappingWidth(); 206 label.resize(100, label.getHeight()); 207 skin.updateDisplayedText(); 208 assertFalse(oldWrappingWidth == text.getWrappingWidth()); 209 assertTrue(text.getWrappingWidth() > 0); 210 } 211 212 @Test public void widthChangesWhenWrapTextIsFalseKeepsWrappingWidthAtZero() { 213 label.layout(); 214 skin.updateDisplayedText(); 215 216 label.resize(500, label.getHeight()); 217 assertEquals(0, text.getWrappingWidth(), 0); 218 } 219 220 @Test public void fontChangesOnLabelShouldInvalidateLayoutAndDisplayTextAndEllipsesWidthAndTextWidth() { 221 label.layout(); 222 skin.updateDisplayedText(); 223 224 label.setFont(Font.font("Arial", 37)); 225 assertTrue(label.isNeedsLayout()); 226 assertTrue(skin.invalidText); 227 assertEquals(Double.NEGATIVE_INFINITY, skin.textWidth, 0); 228 assertEquals(Double.NEGATIVE_INFINITY, skin.ellipsisWidth, 0); 229 } 230 231 @Test public void graphicChangesOnLabelShouldInvalidateLayoutAndDisplayText() { 232 label.layout(); 233 skin.updateDisplayedText(); 234 235 label.setGraphic(new Rectangle(20, 20)); 236 assertTrue(label.isNeedsLayout()); 237 assertTrue(skin.invalidText); 238 } 239 240 @Test public void contentDisplayChangesOnLabelShouldInvalidateLayoutAndDisplayText() { 241 label.layout(); 242 skin.updateDisplayedText(); 243 244 label.setContentDisplay(ContentDisplay.GRAPHIC_ONLY); 245 assertTrue(label.isNeedsLayout()); 246 assertTrue(skin.invalidText); 247 } 248 249 @Test public void graphicTextGapChangesOnLabelShouldInvalidateLayoutAndDisplayText() { 250 label.layout(); 251 skin.updateDisplayedText(); 252 253 label.setGraphicTextGap(8.37); 254 assertTrue(label.isNeedsLayout()); 255 assertTrue(skin.invalidText); 256 } 257 258 @Test public void hposChangesOnLabelShouldInvalidateLayout() { 259 label.layout(); 260 skin.updateDisplayedText(); 261 262 label.setAlignment(Pos.CENTER_RIGHT); 263 assertTrue(label.isNeedsLayout()); 264 assertFalse(skin.invalidText); 265 } 266 267 @Test public void vposChangesOnLabelShouldInvalidateLayout() { 268 label.layout(); 269 skin.updateDisplayedText(); 270 271 label.setAlignment(Pos.TOP_CENTER); 272 assertTrue(label.isNeedsLayout()); 273 assertFalse(skin.invalidText); 274 } 275 276 @Test public void textChangesOnLabelShouldInvalidateLayoutAndDisplayTextAndTextWidth() { 277 label.layout(); 278 skin.updateDisplayedText(); 279 280 label.setText("Apples and Oranges"); 281 assertTrue(label.isNeedsLayout()); 282 assertTrue(skin.invalidText); 283 assertEquals(Double.NEGATIVE_INFINITY, skin.textWidth, 0); 284 } 285 // TODO(aim): changing textAlignment doesn't actually change Text layoutBounds 286 // 287 // @Test public void textAlignmentChangesOnLabelShouldInvalidateLayout() { 288 // label.layout(); 289 // skin.updateDisplayedText(); 290 // 291 // label.setTextAlignment(TextAlignment.JUSTIFY); 292 // assertTrue(label.isNeedsLayout()); 293 // assertFalse(skin.invalidText); 294 // } 295 296 @Test public void textOverrunChangesOnLabelShouldInvalidateLayoutAndDisplayText() { 297 label.layout(); 298 skin.updateDisplayedText(); 299 300 label.setTextOverrun(OverrunStyle.CENTER_WORD_ELLIPSIS); 301 assertTrue(label.isNeedsLayout()); 302 assertTrue(skin.invalidText); 303 } 304 305 @Test public void wrapTextChangesOnLabelShouldInvalidateLayoutAndDisplayTextAndWrappingWidth() { 306 label.setText("A long line which is wider than 100 pixels."); 307 label.resize(100, 30); 308 label.layout(); 309 skin.updateDisplayedText(); 310 311 final double oldWrappingWidth = text.getWrappingWidth(); 312 label.setWrapText(true); 313 assertTrue(label.isNeedsLayout()); 314 assertTrue(skin.invalidText); 315 assertFalse(oldWrappingWidth == text.getWrappingWidth()); 316 assertTrue(text.getWrappingWidth() > 0); 317 } 318 319 @Test public void underlineChangesOnLabelShouldInvalidateLayoutAndDisplayText() { 320 label.layout(); 321 skin.updateDisplayedText(); 322 323 label.setUnderline(true); 324 assertTrue(label.isNeedsLayout()); 325 assertTrue(skin.invalidText); 326 } 327 328 /**************************************************************************** 329 * * 330 * Tests for minWidth * 331 * * 332 ***************************************************************************/ 333 334 @Test public void whenTextIsNullAndNoGraphic_computeMinWidth_ReturnsZero() { 335 label.setPadding(new Insets(7, 7, 7, 7)); 336 label.setText(null); 337 assertEquals(0.0 + 14, label.minWidth(-1), 0); 338 } 339 340 @Test public void whenTextIsEmptyAndNoGraphic_computeMinWidth_ReturnsZero() { 341 label.setPadding(new Insets(7, 7, 7, 7)); 342 label.setText(""); 343 assertEquals(0.0 + 14, label.minWidth(-1), 0); 344 } 345 346 @Test public void whenTextIsShorterThanEllipsisAndNoGraphic_computeMinWidth_ReturnsTextWidth() { 347 label.setPadding(new Insets(7, 7, 7, 7)); 348 label.setText("."); 349 assertTrue(label.minWidth(-1) >= 0); 350 assertEquals(skin.textWidth + 14, label.minWidth(-1), 0); 351 } 352 353 @Test public void whenTextIsGreaterThanEllipsisAndNoGraphic_computeMinWidth_ReturnsEllipsisWidth() { 354 label.setPadding(new Insets(7, 7, 7, 7)); 355 label.setText("These are the times that try men's souls."); 356 assertTrue(label.minWidth(-1) >= 0); 357 assertEquals(skin.ellipsisWidth + 14, label.minWidth(-1), 0); 358 } 359 360 @Test public void whenTextIsNullAndGraphicIsUnmanaged_computeMinWidth_ReturnsZero() { 361 label.setPadding(new Insets(7, 7, 7, 7)); 362 Rectangle r = new Rectangle(23, 500); 363 r.setManaged(false); 364 label.setGraphic(r); 365 label.setText(null); 366 assertEquals(0.0 + 14, label.minWidth(-1), 0); 367 } 368 369 @Test public void whenTextIsEmptyAndGraphicIsUnmanaged_computeMinWidth_ReturnsZero() { 370 label.setPadding(new Insets(7, 7, 7, 7)); 371 Rectangle r = new Rectangle(23, 500); 372 r.setManaged(false); 373 label.setGraphic(r); 374 label.setText(""); 375 assertEquals(0.0 + 14, label.minWidth(-1), 0); 376 } 377 378 @Test public void whenTextIsShorterThanEllipsisAndGraphicIsUnmanaged_computeMinWidth_ReturnsTextWidth() { 379 label.setPadding(new Insets(7, 7, 7, 7)); 380 Rectangle r = new Rectangle(23, 500); 381 r.setManaged(false); 382 label.setGraphic(r); 383 label.setText("."); 384 assertTrue(label.minWidth(-1) >= 0); 385 assertEquals(skin.textWidth + 14, label.minWidth(-1), 0); 386 } 387 388 @Test public void whenTextIsGreaterThanEllipsisAndGraphicIsUnmanaged_computeMinWidth_ReturnsEllipsisWidth() { 389 label.setPadding(new Insets(7, 7, 7, 7)); 390 Rectangle r = new Rectangle(23, 500); 391 r.setManaged(false); 392 label.setGraphic(r); 393 label.setText("These are the times that try men's souls."); 394 assertTrue(label.minWidth(-1) >= 0); 395 assertEquals(skin.ellipsisWidth + 14, label.minWidth(-1), 0); 396 } 397 398 @Test public void whenTextIsNullAndGraphicIsSet_computeMinWidth_ReturnsGraphicWidth() { 399 label.setPadding(new Insets(7, 7, 7, 7)); 400 Rectangle r = new Rectangle(23, 23); 401 label.setGraphic(r); 402 label.setText(null); 403 assertTrue(label.minWidth(-1) >= 0); 404 assertEquals(23 + 14, label.minWidth(-1), 0); 405 } 406 407 @Test public void whenTextIsEmptyAndGraphicIsSet_computeMinWidth_ReturnsGraphicWidth() { 408 label.setPadding(new Insets(7, 7, 7, 7)); 409 Rectangle r = new Rectangle(23, 23); 410 label.setGraphic(r); 411 label.setText(""); 412 assertTrue(label.minWidth(-1) >= 0); 413 assertEquals(23 + 14, label.minWidth(-1), 0); 414 } 415 416 @Test public void whenTextIsShorterThanEllipsisAndGraphicIsSetAndContentDisplayIsLEFT_computeMinWidth_ReturnsGraphicWidthPlusGraphicTextGapPlusTextWidth() { 417 label.setPadding(new Insets(7, 7, 7, 7)); 418 Rectangle r = new Rectangle(23, 23); 419 label.setGraphicTextGap(2); 420 label.setGraphic(r); 421 label.setContentDisplay(ContentDisplay.LEFT); 422 label.setText("."); 423 assertTrue(label.minWidth(-1) >= 0); 424 assertEquals(23 + 2 + skin.textWidth + 14, label.minWidth(-1), 0); 425 } 426 427 @Test public void whenTextIsLongThanEllipsisAndGraphicIsSetAndContentDisplayIsLEFT_computeMinWidth_ReturnsGraphicWidthPlusGraphicTextGapPlusEllipsisWidth() { 428 label.setPadding(new Insets(7, 7, 7, 7)); 429 Rectangle r = new Rectangle(23, 23); 430 label.setGraphicTextGap(2); 431 label.setGraphic(r); 432 label.setContentDisplay(ContentDisplay.LEFT); 433 label.setText("Wherefore art thou Romeo?"); 434 assertTrue(label.minWidth(-1) >= 0); 435 assertEquals(23 + 2 + skin.ellipsisWidth + 14, label.minWidth(-1), 0); 436 } 437 438 @Test public void whenTextIsShorterThanEllipsisAndGraphicIsSetAndContentDisplayIsRIGHT_computeMinWidth_ReturnsGraphicWidthPlusGraphicTextGapPlusTextWidth() { 439 label.setPadding(new Insets(7, 7, 7, 7)); 440 Rectangle r = new Rectangle(23, 23); 441 label.setGraphicTextGap(2); 442 label.setGraphic(r); 443 label.setContentDisplay(ContentDisplay.RIGHT); 444 label.setText("."); 445 assertTrue(label.minWidth(-1) >= 0); 446 assertEquals(23 + 2 + skin.textWidth + 14, label.minWidth(-1), 0); 447 } 448 449 @Test public void whenTextIsLongThanEllipsisAndGraphicIsSetAndContentDisplayIsRIGHT_computeMinWidth_ReturnsGraphicWidthPlusGraphicTextGapPlusEllipsisWidth() { 450 label.setPadding(new Insets(7, 7, 7, 7)); 451 Rectangle r = new Rectangle(23, 23); 452 label.setGraphicTextGap(2); 453 label.setGraphic(r); 454 label.setContentDisplay(ContentDisplay.RIGHT); 455 label.setText("Wherefore art thou Romeo?"); 456 assertTrue(label.minWidth(-1) >= 0); 457 assertEquals(23 + 2 + skin.ellipsisWidth + 14, label.minWidth(-1), 0); 458 } 459 460 @Test public void whenTextIsShorterThanEllipsisAndGraphicIsSetAndContentDisplayIsCENTER_computeMinWidth_ReturnsRightAnswer() { 461 label.setPadding(new Insets(7, 7, 7, 7)); 462 Rectangle r = new Rectangle(23, 23); 463 label.setGraphicTextGap(2); 464 label.setGraphic(r); 465 label.setContentDisplay(ContentDisplay.CENTER); 466 label.setText("."); 467 assertTrue(label.minWidth(-1) >= 0); 468 assertEquals(Math.max(23, skin.textWidth) + 14, label.minWidth(-1), 0); 469 } 470 471 @Test public void whenTextIsLongThanEllipsisAndGraphicIsSetAndContentDisplayIsCENTER_computeMinWidth_ReturnsRightAnswer() { 472 label.setPadding(new Insets(7, 7, 7, 7)); 473 Rectangle r = new Rectangle(23, 23); 474 label.setGraphicTextGap(2); 475 label.setGraphic(r); 476 label.setContentDisplay(ContentDisplay.CENTER); 477 label.setText("Wherefore art thou Romeo?"); 478 assertTrue(label.minWidth(-1) >= 0); 479 assertEquals(Math.max(23, skin.ellipsisWidth) + 14, label.minWidth(-1), 0); 480 } 481 482 @Test public void whenTextIsShorterThanEllipsisAndGraphicIsSetAndContentDisplayIsTOP_computeMinWidth_ReturnsRightAnswer() { 483 label.setPadding(new Insets(7, 7, 7, 7)); 484 Rectangle r = new Rectangle(23, 23); 485 label.setGraphicTextGap(2); 486 label.setGraphic(r); 487 label.setContentDisplay(ContentDisplay.TOP); 488 label.setText("."); 489 assertTrue(label.minWidth(-1) >= 0); 490 assertEquals(Math.max(23, skin.textWidth) + 14, label.minWidth(-1), 0); 491 } 492 493 @Test public void whenTextIsLongThanEllipsisAndGraphicIsSetAndContentDisplayIsTOP_computeMinWidth_ReturnsRightAnswer() { 494 label.setPadding(new Insets(7, 7, 7, 7)); 495 Rectangle r = new Rectangle(23, 23); 496 label.setGraphicTextGap(2); 497 label.setGraphic(r); 498 label.setContentDisplay(ContentDisplay.TOP); 499 label.setText("Wherefore art thou Romeo?"); 500 assertTrue(label.minWidth(-1) >= 0); 501 assertEquals(Math.max(23, skin.ellipsisWidth) + 14, label.minWidth(-1), 0); 502 } 503 504 @Test public void whenTextIsShorterThanEllipsisAndGraphicIsSetAndContentDisplayIsBOTTOM_computeMinWidth_ReturnsRightAnswer() { 505 label.setPadding(new Insets(7, 7, 7, 7)); 506 Rectangle r = new Rectangle(23, 23); 507 label.setGraphicTextGap(2); 508 label.setGraphic(r); 509 label.setContentDisplay(ContentDisplay.BOTTOM); 510 label.setText("."); 511 assertTrue(label.minWidth(-1) >= 0); 512 assertEquals(Math.max(23, skin.textWidth) + 14, label.minWidth(-1), 0); 513 } 514 515 @Test public void whenTextIsLongThanEllipsisAndGraphicIsSetAndContentDisplayIsBOTTOM_computeMinWidth_ReturnsRightAnswer() { 516 label.setPadding(new Insets(7, 7, 7, 7)); 517 Rectangle r = new Rectangle(23, 23); 518 label.setGraphicTextGap(2); 519 label.setGraphic(r); 520 label.setContentDisplay(ContentDisplay.BOTTOM); 521 label.setText("Wherefore art thou Romeo?"); 522 assertTrue(label.minWidth(-1) >= 0); 523 assertEquals(Math.max(23, skin.ellipsisWidth) + 14, label.minWidth(-1), 0); 524 } 525 526 @Test public void whenTextIsShorterThanEllipsisAndGraphicIsSetAndContentDisplayIsGRAPHIC_ONLY_computeMinWidth_ReturnsRightAnswer() { 527 label.setPadding(new Insets(7, 7, 7, 7)); 528 Rectangle r = new Rectangle(3, 3); 529 label.setGraphicTextGap(2); 530 label.setGraphic(r); 531 label.setContentDisplay(ContentDisplay.GRAPHIC_ONLY); 532 label.setText("."); 533 assertTrue(label.minWidth(-1) >= 0); 534 assertEquals(3 + 14, label.minWidth(-1), 0); 535 } 536 537 @Test public void whenTextIsLongThanEllipsisAndGraphicIsSetAndContentDisplayIsGRAPHIC_ONLY_computeMinWidth_ReturnsRightAnswer() { 538 label.setPadding(new Insets(7, 7, 7, 7)); 539 Rectangle r = new Rectangle(3, 3); 540 label.setGraphicTextGap(2); 541 label.setGraphic(r); 542 label.setContentDisplay(ContentDisplay.GRAPHIC_ONLY); 543 label.setText("Wherefore art thou Romeo?"); 544 assertTrue(label.minWidth(-1) >= 0); 545 assertEquals(3 + 14, label.minWidth(-1), 0); 546 } 547 548 @Test public void whenTextIsShorterThanEllipsisAndGraphicIsSetAndContentDisplayIsTEXT_ONLY_computeMinWidth_ReturnsRightAnswer() { 549 label.setPadding(new Insets(7, 7, 7, 7)); 550 Rectangle r = new Rectangle(230, 230); 551 label.setGraphicTextGap(2); 552 label.setGraphic(r); 553 label.setContentDisplay(ContentDisplay.TEXT_ONLY); 554 label.setText("."); 555 assertTrue(label.minWidth(-1) >= 0); 556 assertEquals(skin.textWidth + 14, label.minWidth(-1), 0); 557 } 558 559 @Test public void whenTextIsLongThanEllipsisAndGraphicIsSetAndContentDisplayIsTEXT_ONLY_computeMinWidth_ReturnsRightAnswer() { 560 label.setPadding(new Insets(7, 7, 7, 7)); 561 Rectangle r = new Rectangle(230, 230); 562 label.setGraphicTextGap(2); 563 label.setGraphic(r); 564 label.setContentDisplay(ContentDisplay.TEXT_ONLY); 565 label.setText("Wherefore art thou Romeo?"); 566 assertTrue(label.minWidth(-1) >= 0); 567 assertEquals(skin.ellipsisWidth + 14, label.minWidth(-1), 0); 568 } 569 570 /**************************************************************************** 571 * * 572 * Tests for minHeight * 573 * * 574 ***************************************************************************/ 575 576 @Test public void whenTextIsNullAndNoGraphic_computeMinHeight_ReturnsSingleLineStringHeight() { 577 label.setText(null); 578 label.setPadding(new Insets(7, 7, 7, 7)); 579 final double lineHeight = Utils.computeTextHeight(label.getFont(), " ", 0, text.getBoundsType()); 580 assertEquals(lineHeight + 14, label.minHeight(-1), 0); 581 } 582 583 @Test public void whenTextIsEmptyAndNoGraphic_computeMinHeight_ReturnsSingleLineStringHeight() { 584 label.setText(""); 585 label.setPadding(new Insets(7, 7, 7, 7)); 586 final double lineHeight = Utils.computeTextHeight(label.getFont(), " ", 0, text.getBoundsType()); 587 assertEquals(lineHeight + 14, label.minHeight(-1), 0); 588 } 589 590 @Test public void whenTextIsSetAndNoGraphic_computeMinHeight_ReturnsSingleLineStringHeight() { 591 label.setText("Howdy Pardner"); 592 label.setPadding(new Insets(7, 7, 7, 7)); 593 assertTrue(label.minHeight(-1) >= 0); 594 final double lineHeight = Utils.computeTextHeight(label.getFont(), " ", 0, text.getBoundsType()); 595 assertEquals(lineHeight + 14, label.minHeight(-1), 0); 596 } 597 598 @Test public void whenTextIsNullAndUnmanagedGraphic_computeMinHeight_ReturnsSingleLineStringHeight() { 599 label.setText(null); 600 label.setPadding(new Insets(7, 7, 7, 7)); 601 Rectangle r = new Rectangle(23, 500); 602 r.setManaged(false); 603 label.setGraphic(r); 604 final double lineHeight = Utils.computeTextHeight(label.getFont(), " ", 0, text.getBoundsType()); 605 assertEquals(lineHeight + 14, label.minHeight(-1), 0); 606 } 607 608 @Test public void whenTextIsEmptyAndUnmanagedGraphic_computeMinHeight_ReturnsSingleLineStringHeight() { 609 label.setText(""); 610 label.setPadding(new Insets(7, 7, 7, 7)); 611 Rectangle r = new Rectangle(23, 500); 612 r.setManaged(false); 613 label.setGraphic(r); 614 final double lineHeight = Utils.computeTextHeight(label.getFont(), " ", 0, text.getBoundsType()); 615 assertEquals(lineHeight + 14, label.minHeight(-1), 0); 616 } 617 618 @Test public void whenTextIsSetAndUnmanagedGraphic_computeMinHeight_ReturnsSingleLineStringHeight() { 619 label.setText("Howdy Pardner"); 620 label.setPadding(new Insets(7, 7, 7, 7)); 621 Rectangle r = new Rectangle(23, 500); 622 r.setManaged(false); 623 label.setGraphic(r); 624 final double lineHeight = Utils.computeTextHeight(label.getFont(), " ", 0, text.getBoundsType()); 625 assertTrue(label.minHeight(-1) >= 0); 626 assertEquals(lineHeight + 14, label.minHeight(-1), 0); 627 } 628 629 @Test public void whenTextIsNullAndGraphicIsSetWithTOPContentDisplay_computeMinHeight_ReturnsRightAnswer() { 630 label.setText(null); 631 label.setPadding(new Insets(7, 7, 7, 7)); 632 Rectangle r = new Rectangle(23, 23); 633 label.setGraphicTextGap(2); 634 label.setGraphic(r); 635 label.setContentDisplay(ContentDisplay.TOP); 636 final double lineHeight = Utils.computeTextHeight(label.getFont(), " ", 0, text.getBoundsType()); 637 assertEquals(23 + lineHeight + 2 + 14, label.minHeight(-1), 0); 638 } 639 640 @Test public void whenTextIsEmptyAndGraphicIsSetWithTOPContentDisplay_computeMinHeight_ReturnsRightAnswer() { 641 label.setText(""); 642 label.setPadding(new Insets(7, 7, 7, 7)); 643 Rectangle r = new Rectangle(23, 23); 644 label.setGraphicTextGap(2); 645 label.setGraphic(r); 646 label.setContentDisplay(ContentDisplay.TOP); 647 final double lineHeight = Utils.computeTextHeight(label.getFont(), " ", 0, text.getBoundsType()); 648 assertEquals(23 + lineHeight + 2 + 14, label.minHeight(-1), 0); 649 } 650 651 @Test public void whenTextIsSetAndGraphicIsSetWithTOPContentDisplay_computeMinHeight_ReturnsRightAnswer() { 652 label.setText("For crying in the mud"); 653 label.setPadding(new Insets(7, 7, 7, 7)); 654 Rectangle r = new Rectangle(23, 23); 655 label.setGraphic(r); 656 label.setGraphicTextGap(2); 657 label.setContentDisplay(ContentDisplay.TOP); 658 final double lineHeight = Utils.computeTextHeight(label.getFont(), " ", 0, text.getBoundsType()); 659 assertEquals(23 + lineHeight + 2 + 14, label.minHeight(-1), 0); 660 } 661 662 @Test public void whenTextIsNullAndGraphicIsSetWithRIGHTContentDisplay_computeMinHeight_ReturnsRightAnswer() { 663 label.setText(null); 664 label.setPadding(new Insets(7, 7, 7, 7)); 665 Rectangle r = new Rectangle(23, 23); 666 label.setGraphic(r); 667 label.setContentDisplay(ContentDisplay.RIGHT); 668 final double lineHeight = Utils.computeTextHeight(label.getFont(), " ", 0, text.getBoundsType()); 669 assertEquals(Math.max(23, lineHeight) + 14, label.minHeight(-1), 0); 670 } 671 672 @Test public void whenTextIsEmptyAndGraphicIsSetWithRIGHTContentDisplay_computeMinHeight_ReturnsRightAnswer() { 673 label.setText(""); 674 label.setPadding(new Insets(7, 7, 7, 7)); 675 Rectangle r = new Rectangle(23, 23); 676 label.setGraphic(r); 677 label.setContentDisplay(ContentDisplay.RIGHT); 678 final double lineHeight = Utils.computeTextHeight(label.getFont(), " ", 0, text.getBoundsType()); 679 assertEquals(Math.max(23, lineHeight) + 14, label.minHeight(-1), 0); 680 } 681 682 @Test public void whenTextIsSetAndGraphicIsSetWithRIGHTContentDisplay_computeMinHeight_ReturnsRightAnswer() { 683 label.setText("For crying in the mud"); 684 label.setPadding(new Insets(7, 7, 7, 7)); 685 Rectangle r = new Rectangle(23, 23); 686 label.setGraphic(r); 687 label.setContentDisplay(ContentDisplay.RIGHT); 688 final double lineHeight = Utils.computeTextHeight(label.getFont(), " ", 0, text.getBoundsType()); 689 assertEquals(Math.max(23, lineHeight) + 14, label.minHeight(-1), 0); 690 } 691 692 @Test public void whenTextIsNullAndGraphicIsSetWithBOTTOMContentDisplay_computeMinHeight_ReturnsRightAnswer() { 693 label.setText(null); 694 label.setPadding(new Insets(7, 7, 7, 7)); 695 Rectangle r = new Rectangle(23, 23); 696 label.setGraphicTextGap(2); 697 label.setGraphic(r); 698 label.setContentDisplay(ContentDisplay.BOTTOM); 699 final double lineHeight = Utils.computeTextHeight(label.getFont(), " ", 0, text.getBoundsType()); 700 assertEquals(23 + lineHeight + 2 + 14, label.minHeight(-1), 0); 701 } 702 703 @Test public void whenTextIsEmptyAndGraphicIsSetWithBOTTOMContentDisplay_computeMinHeight_ReturnsRightAnswer() { 704 label.setText(""); 705 label.setPadding(new Insets(7, 7, 7, 7)); 706 Rectangle r = new Rectangle(23, 23); 707 label.setGraphicTextGap(2); 708 label.setGraphic(r); 709 label.setContentDisplay(ContentDisplay.BOTTOM); 710 final double lineHeight = Utils.computeTextHeight(label.getFont(), " ", 0, text.getBoundsType()); 711 assertEquals(23 + lineHeight + 2 + 14, label.minHeight(-1), 0); 712 } 713 714 @Test public void whenTextIsSetAndGraphicIsSetWithBOTTOMContentDisplay_computeMinHeight_ReturnsRightAnswer() { 715 label.setText("For crying in the mud"); 716 label.setPadding(new Insets(7, 7, 7, 7)); 717 Rectangle r = new Rectangle(23, 23); 718 label.setGraphic(r); 719 label.setGraphicTextGap(2); 720 label.setContentDisplay(ContentDisplay.BOTTOM); 721 final double lineHeight = Utils.computeTextHeight(label.getFont(), " ", 0, text.getBoundsType()); 722 assertEquals(23 + lineHeight + 2 + 14, label.minHeight(-1), 0); 723 } 724 725 @Test public void whenTextIsNullAndGraphicIsSetWithLEFTContentDisplay_computeMinHeight_ReturnsRightAnswer() { 726 label.setText(null); 727 label.setPadding(new Insets(7, 7, 7, 7)); 728 Rectangle r = new Rectangle(23, 23); 729 label.setGraphic(r); 730 label.setContentDisplay(ContentDisplay.LEFT); 731 final double lineHeight = Utils.computeTextHeight(label.getFont(), " ", 0, text.getBoundsType()); 732 assertEquals(Math.max(23, lineHeight) + 14, label.minHeight(-1), 0); 733 } 734 735 @Test public void whenTextIsEmptyAndGraphicIsSetWithLEFTContentDisplay_computeMinHeight_ReturnsRightAnswer() { 736 label.setText(""); 737 label.setPadding(new Insets(7, 7, 7, 7)); 738 Rectangle r = new Rectangle(23, 23); 739 label.setGraphic(r); 740 label.setContentDisplay(ContentDisplay.LEFT); 741 final double lineHeight = Utils.computeTextHeight(label.getFont(), " ", 0, text.getBoundsType()); 742 assertEquals(Math.max(23, lineHeight) + 14, label.minHeight(-1), 0); 743 } 744 745 @Test public void whenTextIsSetAndGraphicIsSetWithLEFTContentDisplay_computeMinHeight_ReturnsRightAnswer() { 746 label.setText("For crying in the mud"); 747 label.setPadding(new Insets(7, 7, 7, 7)); 748 Rectangle r = new Rectangle(23, 23); 749 label.setGraphic(r); 750 label.setContentDisplay(ContentDisplay.LEFT); 751 final double lineHeight = Utils.computeTextHeight(label.getFont(), " ", 0, text.getBoundsType()); 752 assertEquals(Math.max(23, lineHeight) + 14, label.minHeight(-1), 0); 753 } 754 755 @Test public void whenTextIsNullAndGraphicIsSetWithCENTERContentDisplay_computeMinHeight_ReturnsRightAnswer() { 756 label.setText(null); 757 label.setPadding(new Insets(7, 7, 7, 7)); 758 Rectangle r = new Rectangle(23, 23); 759 label.setGraphic(r); 760 label.setContentDisplay(ContentDisplay.CENTER); 761 final double lineHeight = Utils.computeTextHeight(label.getFont(), " ", 0, text.getBoundsType()); 762 assertEquals(Math.max(23, lineHeight) + 14, label.minHeight(-1), 0); 763 } 764 765 @Test public void whenTextIsEmptyAndGraphicIsSetWithCENTERContentDisplay_computeMinHeight_ReturnsRightAnswer() { 766 label.setText(""); 767 label.setPadding(new Insets(7, 7, 7, 7)); 768 Rectangle r = new Rectangle(23, 23); 769 label.setGraphic(r); 770 label.setContentDisplay(ContentDisplay.CENTER); 771 final double lineHeight = Utils.computeTextHeight(label.getFont(), " ", 0, text.getBoundsType()); 772 assertEquals(Math.max(23, lineHeight) + 14, label.minHeight(-1), 0); 773 } 774 775 @Test public void whenTextIsSetAndGraphicIsSetWithCENTERContentDisplay_computeMinHeight_ReturnsRightAnswer() { 776 label.setText("For crying in the mud"); 777 label.setPadding(new Insets(7, 7, 7, 7)); 778 Rectangle r = new Rectangle(23, 23); 779 label.setGraphic(r); 780 label.setContentDisplay(ContentDisplay.CENTER); 781 final double lineHeight = Utils.computeTextHeight(label.getFont(), " ", 0, text.getBoundsType()); 782 assertEquals(Math.max(23, lineHeight) + 14, label.minHeight(-1), 0); 783 } 784 785 @Test public void whenTextIsNullAndGraphicIsSetWithGRAPHIC_ONLYContentDisplay_computeMinHeight_ReturnsRightAnswer() { 786 label.setText(null); 787 label.setPadding(new Insets(7, 7, 7, 7)); 788 Rectangle r = new Rectangle(23, 23); 789 label.setGraphic(r); 790 label.setContentDisplay(ContentDisplay.GRAPHIC_ONLY); 791 assertEquals(23 + 14, label.minHeight(-1), 0); 792 } 793 794 @Test public void whenTextIsEmptyAndGraphicIsSetWithGRAPHIC_ONLYContentDisplay_computeMinHeight_ReturnsRightAnswer() { 795 label.setText(""); 796 label.setPadding(new Insets(7, 7, 7, 7)); 797 Rectangle r = new Rectangle(23, 23); 798 label.setGraphic(r); 799 label.setContentDisplay(ContentDisplay.GRAPHIC_ONLY); 800 assertEquals(23 + 14, label.minHeight(-1), 0); 801 } 802 803 @Test public void whenTextIsSetAndGraphicIsSetWithGRAPHIC_ONLYContentDisplay_computeMinHeight_ReturnsRightAnswer() { 804 label.setText("For crying in the mud"); 805 label.setPadding(new Insets(7, 7, 7, 7)); 806 Rectangle r = new Rectangle(23, 23); 807 label.setGraphic(r); 808 label.setContentDisplay(ContentDisplay.GRAPHIC_ONLY); 809 assertEquals(23 + 14, label.minHeight(-1), 0); 810 } 811 812 @Test public void whenTextIsNullAndGraphicIsSetWithTEXT_ONLYContentDisplay_computeMinHeight_ReturnsRightAnswer() { 813 label.setText(null); 814 label.setPadding(new Insets(7, 7, 7, 7)); 815 Rectangle r = new Rectangle(23, 23); 816 label.setGraphic(r); 817 label.setContentDisplay(ContentDisplay.TEXT_ONLY); 818 final double lineHeight = Utils.computeTextHeight(label.getFont(), " ", 0, text.getBoundsType()); 819 assertEquals(lineHeight + 14, label.minHeight(-1), 0); 820 } 821 822 @Test public void whenTextIsEmptyAndGraphicIsSetWithTEXT_ONLYContentDisplay_computeMinHeight_ReturnsRightAnswer() { 823 label.setText(""); 824 label.setPadding(new Insets(7, 7, 7, 7)); 825 Rectangle r = new Rectangle(23, 23); 826 label.setGraphic(r); 827 label.setContentDisplay(ContentDisplay.TEXT_ONLY); 828 final double lineHeight = Utils.computeTextHeight(label.getFont(), " ", 0, text.getBoundsType()); 829 assertEquals(lineHeight + 14, label.minHeight(-1), 0); 830 } 831 832 @Test public void whenTextIsSetAndGraphicIsSetWithTEXT_ONLYContentDisplay_computeMinHeight_ReturnsRightAnswer() { 833 label.setText("For crying in the mud"); 834 label.setPadding(new Insets(7, 7, 7, 7)); 835 Rectangle r = new Rectangle(23, 23); 836 label.setGraphic(r); 837 label.setContentDisplay(ContentDisplay.TEXT_ONLY); 838 final double lineHeight = Utils.computeTextHeight(label.getFont(), " ", 0, text.getBoundsType()); 839 assertEquals(lineHeight + 14, label.minHeight(-1), 0); 840 } 841 842 /**************************************************************************** 843 * * 844 * Tests for prefWidth * 845 * * 846 ***************************************************************************/ 847 848 @Test public void whenTextIsNullAndNoGraphic_computePrefWidth_ReturnsPadding() { 849 label.setText(null); 850 label.setPadding(new Insets(7, 7, 7, 7)); 851 assertEquals(14, label.prefWidth(-1), 0); 852 } 853 854 @Test public void whenTextIsEmptyAndNoGraphic_computePrefWidth_ReturnsPadding() { 855 label.setText(""); 856 label.setPadding(new Insets(7, 7, 7, 7)); 857 assertEquals(14, label.prefWidth(-1), 0); 858 } 859 860 @Test public void whenTextIsSetAndNoGraphic_computePrefWidth_ReturnsTextWidthPlusPadding() { 861 label.setText("Lollipop"); 862 label.setPadding(new Insets(7, 7, 7, 7)); 863 final double textWidth = Utils.computeTextWidth(label.getFont(), "Lollipop", 0); 864 assertEquals(14 + textWidth, label.prefWidth(-1), 0); 865 } 866 867 @Test public void whenTextIsNullAndUnmanagedGraphic_computePrefWidth_ReturnsPadding() { 868 label.setText(null); 869 Rectangle r = new Rectangle(0, 0, 50, 50); 870 r.setManaged(false); 871 label.setGraphic(r); 872 label.setPadding(new Insets(7, 7, 7, 7)); 873 assertEquals(14, label.prefWidth(-1), 0); 874 } 875 876 @Test public void whenTextIsEmptyAndUnmanagedGraphic_computePrefWidth_ReturnsPadding() { 877 label.setText(""); 878 Rectangle r = new Rectangle(0, 0, 50, 50); 879 r.setManaged(false); 880 label.setGraphic(r); 881 label.setPadding(new Insets(7, 7, 7, 7)); 882 assertEquals(14, label.prefWidth(-1), 0); 883 } 884 885 @Test public void whenTextIsSetAndUnmanagedGraphic_computePrefWidth_ReturnsTextWidthPlusPadding() { 886 label.setText("Lollipop"); 887 Rectangle r = new Rectangle(0, 0, 50, 50); 888 r.setManaged(false); 889 label.setGraphic(r); 890 label.setPadding(new Insets(7, 7, 7, 7)); 891 final double textWidth = Utils.computeTextWidth(label.getFont(), "Lollipop", 0); 892 assertEquals(14 + textWidth, label.prefWidth(-1), 0); 893 } 894 895 @Test public void whenTextIsNullAndGraphicIsSetWithTOPContentDisplay_computePrefWidth_ReturnsGraphicWidthPlusPadding() { 896 label.setText(null); 897 label.setGraphic(new Rectangle(0, 0, 20, 20)); 898 label.setGraphicTextGap(6.5); 899 label.setContentDisplay(ContentDisplay.TOP); 900 label.setPadding(new Insets(7, 7, 7, 7)); 901 assertEquals(14 + 20, label.prefWidth(-1), 0); 902 } 903 904 @Test public void whenTextIsEmptyAndGraphicIsSetWithTOPContentDisplay_computePrefWidth_ReturnsGraphicWidthPlusPadding() { 905 label.setText(""); 906 label.setGraphic(new Rectangle(0, 0, 20, 20)); 907 label.setGraphicTextGap(6.5); 908 label.setContentDisplay(ContentDisplay.TOP); 909 label.setPadding(new Insets(7, 7, 7, 7)); 910 assertEquals(14 + 20, label.prefWidth(-1), 0); 911 } 912 913 @Test public void whenTextIsSetAndGraphicIsSetWithTOPContentDisplayAndGraphicIsWider_computePrefWidth_ReturnsGraphicWidthPlusPadding() { 914 label.setText("Lollipop"); 915 label.setGraphic(new Rectangle(0, 0, 200, 20)); 916 label.setGraphicTextGap(6.5); 917 label.setContentDisplay(ContentDisplay.TOP); 918 label.setPadding(new Insets(7, 7, 7, 7)); 919 assertEquals(14 + 200, label.prefWidth(-1), 0); 920 } 921 922 @Test public void whenTextIsSetAndGraphicIsSetWithTOPContentDisplayAndTextIsWider_computePrefWidth_ReturnsTextWidthPlusPadding() { 923 label.setText("This is the right place"); 924 label.setGraphic(new Rectangle(0, 0, 20, 20)); 925 label.setGraphicTextGap(6.5); 926 label.setContentDisplay(ContentDisplay.TOP); 927 label.setPadding(new Insets(7, 7, 7, 7)); 928 final double textWidth = Utils.computeTextWidth(label.getFont(), "This is the right place", 0); 929 assertEquals(14 + textWidth, label.prefWidth(-1), 0); 930 } 931 932 @Test public void whenTextIsNullAndGraphicIsSetWithRIGHTContentDisplay_computePrefWidth_ReturnsGraphicPlusPaddingNotIncludingGap() { 933 label.setText(null); 934 label.setGraphic(new Rectangle(0, 0, 20, 20)); 935 label.setGraphicTextGap(6.5); 936 label.setContentDisplay(ContentDisplay.RIGHT); 937 label.setPadding(new Insets(7, 7, 7, 7)); 938 assertEquals(20 + 14, label.prefWidth(-1), 0); 939 } 940 941 @Test public void whenTextIsEmptyAndGraphicIsSetWithRIGHTContentDisplay_computePrefWidth_ReturnsGraphicPlusPaddingNotIncludingGap() { 942 label.setText(""); 943 label.setGraphic(new Rectangle(0, 0, 20, 20)); 944 label.setGraphicTextGap(6.5); 945 label.setContentDisplay(ContentDisplay.RIGHT); 946 label.setPadding(new Insets(7, 7, 7, 7)); 947 assertEquals(20 + 14, label.prefWidth(-1), 0); 948 } 949 950 @Test public void whenTextIsSetAndGraphicIsSetWithRIGHTContentDisplay_computePrefWidth_ReturnsTextWidthPlusGraphicWidthPlusGapPlusPadding() { 951 label.setText("Howdy"); 952 label.setGraphic(new Rectangle(0, 0, 20, 20)); 953 label.setGraphicTextGap(6.5); 954 label.setContentDisplay(ContentDisplay.RIGHT); 955 label.setPadding(new Insets(7, 7, 7, 7)); 956 final double textWidth = Utils.computeTextWidth(label.getFont(), "Howdy", 0); 957 assertEquals(14 + textWidth + 6.5 + 20, label.prefWidth(-1), 0); 958 } 959 960 @Test public void whenTextIsNullAndGraphicIsSetWithBOTTOMContentDisplay_computePrefWidth_ReturnsGraphicWidthPlusPadding() { 961 label.setText(null); 962 label.setGraphic(new Rectangle(0, 0, 20, 20)); 963 label.setGraphicTextGap(6.5); 964 label.setContentDisplay(ContentDisplay.BOTTOM); 965 label.setPadding(new Insets(7, 7, 7, 7)); 966 assertEquals(14 + 20, label.prefWidth(-1), 0); 967 } 968 969 @Test public void whenTextIsEmptyAndGraphicIsSetWithBOTTOMContentDisplay_computePrefWidth_ReturnsGraphicWidthPlusPadding() { 970 label.setText(null); 971 label.setGraphic(new Rectangle(0, 0, 20, 20)); 972 label.setGraphicTextGap(6.5); 973 label.setContentDisplay(ContentDisplay.BOTTOM); 974 label.setPadding(new Insets(7, 7, 7, 7)); 975 assertEquals(14 + 20, label.prefWidth(-1), 0); 976 } 977 978 @Test public void whenTextIsSetAndGraphicIsSetWithBOTTOMContentDisplayAndGraphicIsWider_computePrefWidth_ReturnsGraphicWidthPlusPadding() { 979 label.setText("Lollipop"); 980 label.setGraphic(new Rectangle(0, 0, 200, 20)); 981 label.setGraphicTextGap(6.5); 982 label.setContentDisplay(ContentDisplay.BOTTOM); 983 label.setPadding(new Insets(7, 7, 7, 7)); 984 assertEquals(14 + 200, label.prefWidth(-1), 0); 985 } 986 987 @Test public void whenTextIsSetAndGraphicIsSetWithBOTTOMContentDisplayAndTextIsWider_computePrefWidth_ReturnsTextWidthPlusPadding() { 988 label.setText("This is the right place"); 989 label.setGraphic(new Rectangle(0, 0, 20, 20)); 990 label.setGraphicTextGap(6.5); 991 label.setContentDisplay(ContentDisplay.BOTTOM); 992 label.setPadding(new Insets(7, 7, 7, 7)); 993 final double textWidth = Utils.computeTextWidth(label.getFont(), "This is the right place", 0); 994 assertEquals(14 + textWidth, label.prefWidth(-1), 0); 995 } 996 997 @Test public void whenTextIsNullAndGraphicIsSetWithLEFTContentDisplay_computePrefWidth_ReturnsGraphicPlusPaddingNotIncludingGap() { 998 label.setText(null); 999 label.setGraphic(new Rectangle(0, 0, 20, 20)); 1000 label.setGraphicTextGap(6.5); 1001 label.setContentDisplay(ContentDisplay.LEFT); 1002 label.setPadding(new Insets(7, 7, 7, 7)); 1003 assertEquals(20 + 14, label.prefWidth(-1), 0); 1004 } 1005 1006 @Test public void whenTextIsEmptyAndGraphicIsSetWithLEFTContentDisplay_computePrefWidth_ReturnsGraphicPlusPaddingNotIncludingGap() { 1007 label.setText(""); 1008 label.setGraphic(new Rectangle(0, 0, 20, 20)); 1009 label.setGraphicTextGap(6.5); 1010 label.setContentDisplay(ContentDisplay.LEFT); 1011 label.setPadding(new Insets(7, 7, 7, 7)); 1012 assertEquals(20 + 14, label.prefWidth(-1), 0); 1013 } 1014 1015 @Test public void whenTextIsSetAndGraphicIsSetWithLEFTContentDisplay_computePrefWidth_ReturnsTextWidthPlusGraphicWidthPlusGapPlusPadding() { 1016 label.setText("Howdy"); 1017 label.setGraphic(new Rectangle(0, 0, 20, 20)); 1018 label.setGraphicTextGap(6.5); 1019 label.setContentDisplay(ContentDisplay.LEFT); 1020 label.setPadding(new Insets(7, 7, 7, 7)); 1021 final double textWidth = Utils.computeTextWidth(label.getFont(), "Howdy", 0); 1022 assertEquals(14 + textWidth + 6.5 + 20, label.prefWidth(-1), 0); 1023 } 1024 1025 @Test public void whenTextIsNullAndGraphicIsSetWithCENTERContentDisplay_computePrefWidth_ReturnsGraphicWidthPlusPadding() { 1026 label.setText(null); 1027 label.setGraphic(new Rectangle(0, 0, 20, 20)); 1028 label.setGraphicTextGap(6.5); 1029 label.setContentDisplay(ContentDisplay.CENTER); 1030 label.setPadding(new Insets(7, 7, 7, 7)); 1031 assertEquals(14 + 20, label.prefWidth(-1), 0); 1032 } 1033 1034 @Test public void whenTextIsEmptyAndGraphicIsSetWithCENTERContentDisplay_computePrefWidth_ReturnsGraphicWidthPlusPadding() { 1035 label.setText(""); 1036 label.setGraphic(new Rectangle(0, 0, 20, 20)); 1037 label.setGraphicTextGap(6.5); 1038 label.setContentDisplay(ContentDisplay.CENTER); 1039 label.setPadding(new Insets(7, 7, 7, 7)); 1040 assertEquals(14 + 20, label.prefWidth(-1), 0); 1041 } 1042 1043 @Test public void whenTextIsSetAndGraphicIsSetWithCENTERContentDisplayAndGraphicIsWider_computePrefWidth_ReturnsGraphicWidthPlusPadding() { 1044 label.setText("Lollipop"); 1045 label.setGraphic(new Rectangle(0, 0, 200, 20)); 1046 label.setGraphicTextGap(6.5); 1047 label.setContentDisplay(ContentDisplay.CENTER); 1048 label.setPadding(new Insets(7, 7, 7, 7)); 1049 assertEquals(14 + 200, label.prefWidth(-1), 0); 1050 } 1051 1052 @Test public void whenTextIsSetAndGraphicIsSetWithCENTERContentDisplayAndTextIsWider_computePrefWidth_ReturnsTextWidthPlusPadding() { 1053 label.setText("This is the right place"); 1054 label.setGraphic(new Rectangle(0, 0, 20, 20)); 1055 label.setGraphicTextGap(6.5); 1056 label.setContentDisplay(ContentDisplay.CENTER); 1057 label.setPadding(new Insets(7, 7, 7, 7)); 1058 final double textWidth = Utils.computeTextWidth(label.getFont(), "This is the right place", 0); 1059 assertEquals(14 + textWidth, label.prefWidth(-1), 0); 1060 } 1061 1062 @Test public void whenTextIsNullAndGraphicIsSetWithGRAPHIC_ONLYContentDisplay_computePrefWidth_ReturnsGraphicWidthPlusPadding() { 1063 label.setText(null); 1064 label.setGraphic(new Rectangle(0, 0, 20, 20)); 1065 label.setGraphicTextGap(6.5); 1066 label.setContentDisplay(ContentDisplay.GRAPHIC_ONLY); 1067 label.setPadding(new Insets(7, 7, 7, 7)); 1068 assertEquals(14 + 20, label.prefWidth(-1), 0); 1069 } 1070 1071 @Test public void whenTextIsEmptyAndGraphicIsSetWithGRAPHIC_ONLYContentDisplay_computePrefWidth_ReturnsGraphicWidthPlusPadding() { 1072 label.setText(""); 1073 label.setGraphic(new Rectangle(0, 0, 20, 20)); 1074 label.setGraphicTextGap(6.5); 1075 label.setContentDisplay(ContentDisplay.GRAPHIC_ONLY); 1076 label.setPadding(new Insets(7, 7, 7, 7)); 1077 assertEquals(14 + 20, label.prefWidth(-1), 0); 1078 } 1079 1080 @Test public void whenTextIsSetAndGraphicIsSetWithGRAPHIC_ONLYContentDisplayAndGraphicIsWider_computePrefWidth_ReturnsGraphicWidthPlusPadding() { 1081 label.setText("Howdy"); 1082 label.setGraphic(new Rectangle(0, 0, 200, 20)); 1083 label.setGraphicTextGap(6.5); 1084 label.setContentDisplay(ContentDisplay.GRAPHIC_ONLY); 1085 label.setPadding(new Insets(7, 7, 7, 7)); 1086 assertEquals(14 + 200, label.prefWidth(-1), 0); 1087 } 1088 1089 @Test public void whenTextIsSetAndGraphicIsSetWithGRAPHIC_ONLYContentDisplayAndTextIsWider_computePrefWidth_ReturnsGraphicWidthPlusPadding() { 1090 label.setText("Tally ho, off to the races"); 1091 label.setGraphic(new Rectangle(0, 0, 20, 20)); 1092 label.setGraphicTextGap(6.5); 1093 label.setContentDisplay(ContentDisplay.GRAPHIC_ONLY); 1094 label.setPadding(new Insets(7, 7, 7, 7)); 1095 assertEquals(14 + 20, label.prefWidth(-1), 0); 1096 } 1097 1098 // TODO should this include the gap?? 1099 @Test public void whenTextIsNullAndGraphicIsSetWithTEXT_ONLYContentDisplay_computePrefWidth_ReturnsPadding() { 1100 label.setText(null); 1101 label.setGraphic(new Rectangle(0, 0, 20, 20)); 1102 label.setGraphicTextGap(6.5); 1103 label.setContentDisplay(ContentDisplay.TEXT_ONLY); 1104 label.setPadding(new Insets(7, 7, 7, 7)); 1105 assertEquals(14, label.prefWidth(-1), 0); 1106 } 1107 1108 @Test public void whenTextIsEmptyAndGraphicIsSetWithTEXT_ONLYContentDisplay_computePrefWidth_ReturnsPadding() { 1109 label.setText(""); 1110 label.setGraphic(new Rectangle(0, 0, 20, 20)); 1111 label.setGraphicTextGap(6.5); 1112 label.setContentDisplay(ContentDisplay.TEXT_ONLY); 1113 label.setPadding(new Insets(7, 7, 7, 7)); 1114 assertEquals(14, label.prefWidth(-1), 0); 1115 } 1116 1117 // TODO should this include the gap? I guess not, otherwise our gap would have to default to 0 1118 @Test public void whenTextIsSetAndGraphicIsSetWithTEXT_ONLYContentDisplay_computePrefWidth_ReturnsTextWidthPlusPadding() { 1119 label.setText("Yippee Skippee"); 1120 label.setGraphic(new Rectangle(0, 0, 20, 20)); 1121 label.setGraphicTextGap(6.5); 1122 label.setContentDisplay(ContentDisplay.TEXT_ONLY); 1123 label.setPadding(new Insets(7, 7, 7, 7)); 1124 final double textWidth = Utils.computeTextWidth(label.getFont(), "Yippee Skippee", 0); 1125 assertEquals(14 + textWidth, label.prefWidth(-1), 0); 1126 } 1127 1128 /**************************************************************************** 1129 * * 1130 * Tests for prefHeight * 1131 * * 1132 ***************************************************************************/ 1133 1134 @Test public void whenTextHasNewlines_computePrefHeight_IncludesTheMultipleLinesInThePrefHeight() { 1135 label.setText("This\nis a test\nof the emergency\nbroadcast system.\nThis is only a test"); 1136 label.setPadding(new Insets(0, 0, 0, 0)); 1137 final double singleLineHeight = Utils.computeTextHeight(label.getFont(), " ", 0, text.getBoundsType()); 1138 final double height = label.prefHeight(-1); 1139 assertTrue(height >= singleLineHeight * 5); 1140 } 1141 1142 @Test public void whenTextHasNewlinesAfterPreviousComputationOf_computePrefHeight_IncludesTheMultipleLinesInThePrefHeight() { 1143 label.setText("This is a test"); 1144 final double oldPrefHeight = label.prefHeight(-1); 1145 label.setText("This\nis a test\nof the emergency\nbroadcast system.\nThis is only a test"); 1146 final double newPrefHeight = label.prefHeight(-1); 1147 assertTrue(oldPrefHeight != newPrefHeight); 1148 } 1149 1150 @Test public void whenTextIsNullAndNoGraphic_computePrefHeight_ReturnsSingleLineStringHeightPlusPadding() { 1151 label.setText(null); 1152 label.setPadding(new Insets(7, 7, 7, 7)); 1153 final double lineHeight = Utils.computeTextHeight(label.getFont(), " ", 0, text.getBoundsType()); 1154 assertEquals(14 + lineHeight, label.prefHeight(-1), 0); 1155 } 1156 1157 @Test public void whenTextIsEmptyAndNoGraphic_computePrefHeight_ReturnsSingleLineStringHeightPlusPadding() { 1158 label.setText(""); 1159 label.setPadding(new Insets(7, 7, 7, 7)); 1160 final double lineHeight = Utils.computeTextHeight(label.getFont(), " ", 0, text.getBoundsType()); 1161 assertEquals(14 + lineHeight, label.prefHeight(-1), 0); 1162 } 1163 1164 @Test public void whenTextIsSetAndNoGraphic_computePrefHeight_ReturnsSingleLineStringHeightPlusPadding() { 1165 label.setText("Howdy Pardner"); 1166 label.setPadding(new Insets(7, 7, 7, 7)); 1167 assertTrue(label.prefHeight(-1) >= 0); 1168 final double lineHeight = Utils.computeTextHeight(label.getFont(), " ", 0, text.getBoundsType()); 1169 assertEquals(14 + lineHeight, label.prefHeight(-1), 0); 1170 } 1171 1172 @Test public void whenTextIsNullAndUnmanagedGraphic_computePrefHeight_ReturnsSingleLineStringHeightPlusPadding() { 1173 label.setText(null); 1174 label.setPadding(new Insets(7, 7, 7, 7)); 1175 Rectangle r = new Rectangle(23, 500); 1176 r.setManaged(false); 1177 label.setGraphic(r); 1178 final double lineHeight = Utils.computeTextHeight(label.getFont(), " ", 0, text.getBoundsType()); 1179 assertEquals(14 + lineHeight, label.prefHeight(-1), 0); 1180 } 1181 1182 @Test public void whenTextIsEmptyAndUnmanagedGraphic_computePrefHeight_ReturnsSingleLineStringHeightPlusPadding() { 1183 label.setText(""); 1184 label.setPadding(new Insets(7, 7, 7, 7)); 1185 Rectangle r = new Rectangle(23, 500); 1186 r.setManaged(false); 1187 label.setGraphic(r); 1188 final double lineHeight = Utils.computeTextHeight(label.getFont(), " ", 0, text.getBoundsType()); 1189 assertEquals(14 + lineHeight, label.prefHeight(-1), 0); 1190 } 1191 1192 @Test public void whenTextIsSetAndUnmanagedGraphic_computePrefHeight_ReturnsSingleLineStringHeightPlusPadding() { 1193 label.setText("Howdy Pardner"); 1194 label.setPadding(new Insets(7, 7, 7, 7)); 1195 Rectangle r = new Rectangle(23, 500); 1196 r.setManaged(false); 1197 label.setGraphic(r); 1198 final double lineHeight = Utils.computeTextHeight(label.getFont(), " ", 0, text.getBoundsType()); 1199 assertTrue(label.prefHeight(-1) >= 0); 1200 assertEquals(14 + lineHeight, label.prefHeight(-1), 0); 1201 } 1202 1203 @Test public void whenTextIsNullAndGraphicIsSetWithTOPContentDisplay_computePrefHeight_ReturnsRightAnswer() { 1204 label.setText(null); 1205 label.setPadding(new Insets(7, 7, 7, 7)); 1206 Rectangle r = new Rectangle(23, 23); 1207 label.setGraphicTextGap(2); 1208 label.setGraphic(r); 1209 label.setContentDisplay(ContentDisplay.TOP); 1210 final double lineHeight = Utils.computeTextHeight(label.getFont(), " ", 0, text.getBoundsType()); 1211 assertEquals(14 + 23 + lineHeight + 2, label.prefHeight(-1), 0); 1212 } 1213 1214 @Test public void whenTextIsEmptyAndGraphicIsSetWithTOPContentDisplay_computePrefHeight_ReturnsRightAnswer() { 1215 label.setText(""); 1216 label.setPadding(new Insets(7, 7, 7, 7)); 1217 Rectangle r = new Rectangle(23, 23); 1218 label.setGraphicTextGap(2); 1219 label.setGraphic(r); 1220 label.setContentDisplay(ContentDisplay.TOP); 1221 final double lineHeight = Utils.computeTextHeight(label.getFont(), " ", 0, text.getBoundsType()); 1222 assertEquals(14 + 23 + lineHeight + 2, label.prefHeight(-1), 0); 1223 } 1224 1225 @Test public void whenTextIsSetAndGraphicIsSetWithTOPContentDisplay_computePrefHeight_ReturnsRightAnswer() { 1226 label.setText("For crying in the mud"); 1227 label.setPadding(new Insets(7, 7, 7, 7)); 1228 Rectangle r = new Rectangle(23, 23); 1229 label.setGraphic(r); 1230 label.setGraphicTextGap(2); 1231 label.setContentDisplay(ContentDisplay.TOP); 1232 final double lineHeight = Utils.computeTextHeight(label.getFont(), " ", 0, text.getBoundsType()); 1233 assertEquals(14 + 23 + lineHeight + 2, label.prefHeight(-1), 0); 1234 } 1235 1236 @Test public void whenTextIsNullAndGraphicIsSetWithRIGHTContentDisplay_computePrefHeight_ReturnsRightAnswer() { 1237 label.setText(null); 1238 label.setPadding(new Insets(7, 7, 7, 7)); 1239 Rectangle r = new Rectangle(23, 23); 1240 label.setGraphic(r); 1241 label.setContentDisplay(ContentDisplay.RIGHT); 1242 final double lineHeight = Utils.computeTextHeight(label.getFont(), " ", 0, text.getBoundsType()); 1243 assertEquals(14 + Math.max(23, lineHeight), label.prefHeight(-1), 0); 1244 } 1245 1246 @Test public void whenTextIsEmptyAndGraphicIsSetWithRIGHTContentDisplay_computePrefHeight_ReturnsRightAnswer() { 1247 label.setText(""); 1248 label.setPadding(new Insets(7, 7, 7, 7)); 1249 Rectangle r = new Rectangle(23, 23); 1250 label.setGraphic(r); 1251 label.setContentDisplay(ContentDisplay.RIGHT); 1252 final double lineHeight = Utils.computeTextHeight(label.getFont(), " ", 0, text.getBoundsType()); 1253 assertEquals(14 + Math.max(23, lineHeight), label.prefHeight(-1), 0); 1254 } 1255 1256 @Test public void whenTextIsSetAndGraphicIsSetWithRIGHTContentDisplay_computePrefHeight_ReturnsRightAnswer() { 1257 label.setText("For crying in the mud"); 1258 label.setPadding(new Insets(7, 7, 7, 7)); 1259 Rectangle r = new Rectangle(23, 23); 1260 label.setGraphic(r); 1261 label.setContentDisplay(ContentDisplay.RIGHT); 1262 final double lineHeight = Utils.computeTextHeight(label.getFont(), " ", 0, text.getBoundsType()); 1263 assertEquals(14 + Math.max(23, lineHeight), label.prefHeight(-1), 0); 1264 } 1265 1266 @Test public void whenTextIsNullAndGraphicIsSetWithBOTTOMContentDisplay_computePrefHeight_ReturnsRightAnswer() { 1267 label.setText(null); 1268 label.setPadding(new Insets(7, 7, 7, 7)); 1269 Rectangle r = new Rectangle(23, 23); 1270 label.setGraphicTextGap(2); 1271 label.setGraphic(r); 1272 label.setContentDisplay(ContentDisplay.BOTTOM); 1273 final double lineHeight = Utils.computeTextHeight(label.getFont(), " ", 0, text.getBoundsType()); 1274 assertEquals(14 + 23 + lineHeight + 2, label.prefHeight(-1), 0); 1275 } 1276 1277 @Test public void whenTextIsEmptyAndGraphicIsSetWithBOTTOMContentDisplay_computePrefHeight_ReturnsRightAnswer() { 1278 label.setText(""); 1279 label.setPadding(new Insets(7, 7, 7, 7)); 1280 Rectangle r = new Rectangle(23, 23); 1281 label.setGraphicTextGap(2); 1282 label.setGraphic(r); 1283 label.setContentDisplay(ContentDisplay.BOTTOM); 1284 final double lineHeight = Utils.computeTextHeight(label.getFont(), " ", 0, text.getBoundsType()); 1285 assertEquals(14 + 23 + lineHeight + 2, label.prefHeight(-1), 0); 1286 } 1287 1288 @Test public void whenTextIsSetAndGraphicIsSetWithBOTTOMContentDisplay_computePrefHeight_ReturnsRightAnswer() { 1289 label.setText("For crying in the mud"); 1290 label.setPadding(new Insets(7, 7, 7, 7)); 1291 Rectangle r = new Rectangle(23, 23); 1292 label.setGraphic(r); 1293 label.setGraphicTextGap(2); 1294 label.setContentDisplay(ContentDisplay.BOTTOM); 1295 final double lineHeight = Utils.computeTextHeight(label.getFont(), " ", 0, text.getBoundsType()); 1296 assertEquals(14 + 23 + lineHeight + 2, label.prefHeight(-1), 0); 1297 } 1298 1299 @Test public void whenTextIsNullAndGraphicIsSetWithLEFTContentDisplay_computePrefHeight_ReturnsRightAnswer() { 1300 label.setText(null); 1301 label.setPadding(new Insets(7, 7, 7, 7)); 1302 Rectangle r = new Rectangle(23, 23); 1303 label.setGraphic(r); 1304 label.setContentDisplay(ContentDisplay.LEFT); 1305 final double lineHeight = Utils.computeTextHeight(label.getFont(), " ", 0, text.getBoundsType()); 1306 assertEquals(14 + Math.max(23, lineHeight), label.prefHeight(-1), 0); 1307 } 1308 1309 @Test public void whenTextIsEmptyAndGraphicIsSetWithLEFTContentDisplay_computePrefHeight_ReturnsRightAnswer() { 1310 label.setText(""); 1311 label.setPadding(new Insets(7, 7, 7, 7)); 1312 Rectangle r = new Rectangle(23, 23); 1313 label.setGraphic(r); 1314 label.setContentDisplay(ContentDisplay.LEFT); 1315 final double lineHeight = Utils.computeTextHeight(label.getFont(), " ", 0, text.getBoundsType()); 1316 assertEquals(14 + Math.max(23, lineHeight), label.prefHeight(-1), 0); 1317 } 1318 1319 @Test public void whenTextIsSetAndGraphicIsSetWithLEFTContentDisplay_computePrefHeight_ReturnsRightAnswer() { 1320 label.setText("For crying in the mud"); 1321 label.setPadding(new Insets(7, 7, 7, 7)); 1322 Rectangle r = new Rectangle(23, 23); 1323 label.setGraphic(r); 1324 label.setContentDisplay(ContentDisplay.LEFT); 1325 final double lineHeight = Utils.computeTextHeight(label.getFont(), " ", 0, text.getBoundsType()); 1326 assertEquals(14 + Math.max(23, lineHeight), label.prefHeight(-1), 0); 1327 } 1328 1329 @Test public void whenTextIsNullAndGraphicIsSetWithCENTERContentDisplay_computePrefHeight_ReturnsRightAnswer() { 1330 label.setText(null); 1331 label.setPadding(new Insets(7, 7, 7, 7)); 1332 Rectangle r = new Rectangle(23, 23); 1333 label.setGraphic(r); 1334 label.setContentDisplay(ContentDisplay.CENTER); 1335 final double lineHeight = Utils.computeTextHeight(label.getFont(), " ", 0, text.getBoundsType()); 1336 assertEquals(14 + Math.max(23, lineHeight), label.prefHeight(-1), 0); 1337 } 1338 1339 @Test public void whenTextIsEmptyAndGraphicIsSetWithCENTERContentDisplay_computePrefHeight_ReturnsRightAnswer() { 1340 label.setText(""); 1341 label.setPadding(new Insets(7, 7, 7, 7)); 1342 Rectangle r = new Rectangle(23, 23); 1343 label.setGraphic(r); 1344 label.setContentDisplay(ContentDisplay.CENTER); 1345 final double lineHeight = Utils.computeTextHeight(label.getFont(), " ", 0, text.getBoundsType()); 1346 assertEquals(14 + Math.max(23, lineHeight), label.prefHeight(-1), 0); 1347 } 1348 1349 @Test public void whenTextIsSetAndGraphicIsSetWithCENTERContentDisplay_computePrefHeight_ReturnsRightAnswer() { 1350 label.setText("For crying in the mud"); 1351 label.setPadding(new Insets(7, 7, 7, 7)); 1352 Rectangle r = new Rectangle(23, 23); 1353 label.setGraphic(r); 1354 label.setContentDisplay(ContentDisplay.CENTER); 1355 final double lineHeight = Utils.computeTextHeight(label.getFont(), " ", 0, text.getBoundsType()); 1356 assertEquals(14 + Math.max(23, lineHeight), label.prefHeight(-1), 0); 1357 } 1358 1359 @Test public void whenTextIsNullAndGraphicIsSetWithGRAPHIC_ONLYContentDisplay_computePrefHeight_ReturnsRightAnswer() { 1360 label.setText(null); 1361 label.setPadding(new Insets(7, 7, 7, 7)); 1362 Rectangle r = new Rectangle(23, 23); 1363 label.setGraphic(r); 1364 label.setContentDisplay(ContentDisplay.GRAPHIC_ONLY); 1365 assertEquals(14 + 23, label.prefHeight(-1), 0); 1366 } 1367 1368 @Test public void whenTextIsEmptyAndGraphicIsSetWithGRAPHIC_ONLYContentDisplay_computePrefHeight_ReturnsRightAnswer() { 1369 label.setText(""); 1370 label.setPadding(new Insets(7, 7, 7, 7)); 1371 Rectangle r = new Rectangle(23, 23); 1372 label.setGraphic(r); 1373 label.setContentDisplay(ContentDisplay.GRAPHIC_ONLY); 1374 assertEquals(14 + 23, label.prefHeight(-1), 0); 1375 } 1376 1377 @Test public void whenTextIsSetAndGraphicIsSetWithGRAPHIC_ONLYContentDisplay_computePrefHeight_ReturnsRightAnswer() { 1378 label.setText("For crying in the mud"); 1379 label.setPadding(new Insets(7, 7, 7, 7)); 1380 Rectangle r = new Rectangle(23, 23); 1381 label.setGraphic(r); 1382 label.setContentDisplay(ContentDisplay.GRAPHIC_ONLY); 1383 assertEquals(14 + 23, label.prefHeight(-1), 0); 1384 } 1385 1386 @Test public void whenTextIsNullAndGraphicIsSetWithTEXT_ONLYContentDisplay_computePrefHeight_ReturnsRightAnswer() { 1387 label.setText(null); 1388 label.setPadding(new Insets(7, 7, 7, 7)); 1389 Rectangle r = new Rectangle(23, 23); 1390 label.setGraphic(r); 1391 label.setContentDisplay(ContentDisplay.TEXT_ONLY); 1392 final double lineHeight = Utils.computeTextHeight(label.getFont(), " ", 0, text.getBoundsType()); 1393 assertEquals(14 + lineHeight, label.prefHeight(-1), 0); 1394 } 1395 1396 @Test public void whenTextIsEmptyAndGraphicIsSetWithTEXT_ONLYContentDisplay_computePrefHeight_ReturnsRightAnswer() { 1397 label.setText(""); 1398 label.setPadding(new Insets(7, 7, 7, 7)); 1399 Rectangle r = new Rectangle(23, 23); 1400 label.setGraphic(r); 1401 label.setContentDisplay(ContentDisplay.TEXT_ONLY); 1402 final double lineHeight = Utils.computeTextHeight(label.getFont(), " ", 0, text.getBoundsType()); 1403 assertEquals(14 + lineHeight, label.prefHeight(-1), 0); 1404 } 1405 1406 @Test public void whenTextIsSetAndGraphicIsSetWithTEXT_ONLYContentDisplay_computePrefHeight_ReturnsRightAnswer() { 1407 label.setText("For crying in the mud"); 1408 label.setPadding(new Insets(7, 7, 7, 7)); 1409 Rectangle r = new Rectangle(23, 23); 1410 label.setGraphic(r); 1411 label.setContentDisplay(ContentDisplay.TEXT_ONLY); 1412 final double lineHeight = Utils.computeTextHeight(label.getFont(), " ", 0, text.getBoundsType()); 1413 assertEquals(14 + lineHeight, label.prefHeight(-1), 0); 1414 } 1415 1416 /**************************************************************************** 1417 * * 1418 * Tests maxWidth * 1419 * * 1420 ***************************************************************************/ 1421 1422 @Test public void whenTextIsNullAndNoGraphic_computeMaxWidth_ReturnsPadding() { 1423 label.setText(null); 1424 label.setPadding(new Insets(7, 7, 7, 7)); 1425 assertEquals(14, label.maxWidth(-1), 0); 1426 } 1427 1428 @Test public void whenTextIsEmptyAndNoGraphic_computeMaxWidth_ReturnsPadding() { 1429 label.setText(""); 1430 label.setPadding(new Insets(7, 7, 7, 7)); 1431 assertEquals(14, label.maxWidth(-1), 0); 1432 } 1433 1434 @Test public void whenTextIsSetAndNoGraphic_computeMaxWidth_ReturnsTextWidthPlusPadding() { 1435 label.setText("Lollipop"); 1436 label.setPadding(new Insets(7, 7, 7, 7)); 1437 final double textWidth = Utils.computeTextWidth(label.getFont(), "Lollipop", 0); 1438 assertEquals(14 + textWidth, label.maxWidth(-1), 0); 1439 } 1440 1441 @Test public void whenTextIsNullAndUnmanagedGraphic_computeMaxWidth_ReturnsPadding() { 1442 label.setText(null); 1443 Rectangle r = new Rectangle(0, 0, 50, 50); 1444 r.setManaged(false); 1445 label.setGraphic(r); 1446 label.setPadding(new Insets(7, 7, 7, 7)); 1447 assertEquals(14, label.maxWidth(-1), 0); 1448 } 1449 1450 @Test public void whenTextIsEmptyAndUnmanagedGraphic_computeMaxWidth_ReturnsPadding() { 1451 label.setText(""); 1452 Rectangle r = new Rectangle(0, 0, 50, 50); 1453 r.setManaged(false); 1454 label.setGraphic(r); 1455 label.setPadding(new Insets(7, 7, 7, 7)); 1456 assertEquals(14, label.maxWidth(-1), 0); 1457 } 1458 1459 @Test public void whenTextIsSetAndUnmanagedGraphic_computeMaxWidth_ReturnsTextWidthPlusPadding() { 1460 label.setText("Lollipop"); 1461 Rectangle r = new Rectangle(0, 0, 50, 50); 1462 r.setManaged(false); 1463 label.setGraphic(r); 1464 label.setPadding(new Insets(7, 7, 7, 7)); 1465 final double textWidth = Utils.computeTextWidth(label.getFont(), "Lollipop", 0); 1466 assertEquals(14 + textWidth, label.maxWidth(-1), 0); 1467 } 1468 1469 @Test public void whenTextIsNullAndGraphicIsSetWithTOPContentDisplay_computeMaxWidth_ReturnsGraphicWidthPlusPadding() { 1470 label.setText(null); 1471 label.setGraphic(new Rectangle(0, 0, 20, 20)); 1472 label.setGraphicTextGap(6.5); 1473 label.setContentDisplay(ContentDisplay.TOP); 1474 label.setPadding(new Insets(7, 7, 7, 7)); 1475 assertEquals(14 + 20, label.maxWidth(-1), 0); 1476 } 1477 1478 @Test public void whenTextIsEmptyAndGraphicIsSetWithTOPContentDisplay_computeMaxWidth_ReturnsGraphicWidthPlusPadding() { 1479 label.setText(""); 1480 label.setGraphic(new Rectangle(0, 0, 20, 20)); 1481 label.setGraphicTextGap(6.5); 1482 label.setContentDisplay(ContentDisplay.TOP); 1483 label.setPadding(new Insets(7, 7, 7, 7)); 1484 assertEquals(14 + 20, label.maxWidth(-1), 0); 1485 } 1486 1487 @Test public void whenTextIsSetAndGraphicIsSetWithTOPContentDisplayAndGraphicIsWider_computeMaxWidth_ReturnsGraphicWidthPlusPadding() { 1488 label.setText("Lollipop"); 1489 label.setGraphic(new Rectangle(0, 0, 200, 20)); 1490 label.setGraphicTextGap(6.5); 1491 label.setContentDisplay(ContentDisplay.TOP); 1492 label.setPadding(new Insets(7, 7, 7, 7)); 1493 assertEquals(14 + 200, label.maxWidth(-1), 0); 1494 } 1495 1496 @Test public void whenTextIsSetAndGraphicIsSetWithTOPContentDisplayAndTextIsWider_computeMaxWidth_ReturnsTextWidthPlusPadding() { 1497 label.setText("This is the right place"); 1498 label.setGraphic(new Rectangle(0, 0, 20, 20)); 1499 label.setGraphicTextGap(6.5); 1500 label.setContentDisplay(ContentDisplay.TOP); 1501 label.setPadding(new Insets(7, 7, 7, 7)); 1502 final double textWidth = Utils.computeTextWidth(label.getFont(), "This is the right place", 0); 1503 assertEquals(14 + textWidth, label.maxWidth(-1), 0); 1504 } 1505 1506 @Test public void whenTextIsNullAndGraphicIsSetWithRIGHTContentDisplay_computeMaxWidth_ReturnsGraphicPlusPaddingNotIncludingGap() { 1507 label.setText(null); 1508 label.setGraphic(new Rectangle(0, 0, 20, 20)); 1509 label.setGraphicTextGap(6.5); 1510 label.setContentDisplay(ContentDisplay.RIGHT); 1511 label.setPadding(new Insets(7, 7, 7, 7)); 1512 assertEquals(20 + 14, label.maxWidth(-1), 0); 1513 } 1514 1515 @Test public void whenTextIsEmptyAndGraphicIsSetWithRIGHTContentDisplay_computeMaxWidth_ReturnsGraphicPlusPaddingNotIncludingGap() { 1516 label.setText(""); 1517 label.setGraphic(new Rectangle(0, 0, 20, 20)); 1518 label.setGraphicTextGap(6.5); 1519 label.setContentDisplay(ContentDisplay.RIGHT); 1520 label.setPadding(new Insets(7, 7, 7, 7)); 1521 assertEquals(20 + 14, label.maxWidth(-1), 0); 1522 } 1523 1524 @Test public void whenTextIsSetAndGraphicIsSetWithRIGHTContentDisplay_computeMaxWidth_ReturnsTextWidthPlusGraphicWidthPlusGapPlusPadding() { 1525 label.setText("Howdy"); 1526 label.setGraphic(new Rectangle(0, 0, 20, 20)); 1527 label.setGraphicTextGap(6.5); 1528 label.setContentDisplay(ContentDisplay.RIGHT); 1529 label.setPadding(new Insets(7, 7, 7, 7)); 1530 final double textWidth = Utils.computeTextWidth(label.getFont(), "Howdy", 0); 1531 assertEquals(14 + textWidth + 6.5 + 20, label.maxWidth(-1), 0); 1532 } 1533 1534 @Test public void whenTextIsNullAndGraphicIsSetWithBOTTOMContentDisplay_computeMaxWidth_ReturnsGraphicWidthPlusPadding() { 1535 label.setText(null); 1536 label.setGraphic(new Rectangle(0, 0, 20, 20)); 1537 label.setGraphicTextGap(6.5); 1538 label.setContentDisplay(ContentDisplay.BOTTOM); 1539 label.setPadding(new Insets(7, 7, 7, 7)); 1540 assertEquals(14 + 20, label.maxWidth(-1), 0); 1541 } 1542 1543 @Test public void whenTextIsEmptyAndGraphicIsSetWithBOTTOMContentDisplay_computeMaxWidth_ReturnsGraphicWidthPlusPadding() { 1544 label.setText(null); 1545 label.setGraphic(new Rectangle(0, 0, 20, 20)); 1546 label.setGraphicTextGap(6.5); 1547 label.setContentDisplay(ContentDisplay.BOTTOM); 1548 label.setPadding(new Insets(7, 7, 7, 7)); 1549 assertEquals(14 + 20, label.maxWidth(-1), 0); 1550 } 1551 1552 @Test public void whenTextIsSetAndGraphicIsSetWithBOTTOMContentDisplayAndGraphicIsWider_computeMaxWidth_ReturnsGraphicWidthPlusPadding() { 1553 label.setText("Lollipop"); 1554 label.setGraphic(new Rectangle(0, 0, 200, 20)); 1555 label.setGraphicTextGap(6.5); 1556 label.setContentDisplay(ContentDisplay.BOTTOM); 1557 label.setPadding(new Insets(7, 7, 7, 7)); 1558 assertEquals(14 + 200, label.maxWidth(-1), 0); 1559 } 1560 1561 @Test public void whenTextIsSetAndGraphicIsSetWithBOTTOMContentDisplayAndTextIsWider_computeMaxWidth_ReturnsTextWidthPlusPadding() { 1562 label.setText("This is the right place"); 1563 label.setGraphic(new Rectangle(0, 0, 20, 20)); 1564 label.setGraphicTextGap(6.5); 1565 label.setContentDisplay(ContentDisplay.BOTTOM); 1566 label.setPadding(new Insets(7, 7, 7, 7)); 1567 final double textWidth = Utils.computeTextWidth(label.getFont(), "This is the right place", 0); 1568 assertEquals(14 + textWidth, label.maxWidth(-1), 0); 1569 } 1570 1571 @Test public void whenTextIsNullAndGraphicIsSetWithLEFTContentDisplay_computeMaxWidth_ReturnsGraphicPlusPaddingNotIncludingGap() { 1572 label.setText(null); 1573 label.setGraphic(new Rectangle(0, 0, 20, 20)); 1574 label.setGraphicTextGap(6.5); 1575 label.setContentDisplay(ContentDisplay.LEFT); 1576 label.setPadding(new Insets(7, 7, 7, 7)); 1577 assertEquals(20 + 14, label.maxWidth(-1), 0); 1578 } 1579 1580 @Test public void whenTextIsEmptyAndGraphicIsSetWithLEFTContentDisplay_computeMaxWidth_ReturnsGraphicPlusPaddingNotIncludingGap() { 1581 label.setText(""); 1582 label.setGraphic(new Rectangle(0, 0, 20, 20)); 1583 label.setGraphicTextGap(6.5); 1584 label.setContentDisplay(ContentDisplay.LEFT); 1585 label.setPadding(new Insets(7, 7, 7, 7)); 1586 assertEquals(20 + 14, label.maxWidth(-1), 0); 1587 } 1588 1589 @Test public void whenTextIsSetAndGraphicIsSetWithLEFTContentDisplay_computeMaxWidth_ReturnsTextWidthPlusGraphicWidthPlusGapPlusPadding() { 1590 label.setText("Howdy"); 1591 label.setGraphic(new Rectangle(0, 0, 20, 20)); 1592 label.setGraphicTextGap(6.5); 1593 label.setContentDisplay(ContentDisplay.LEFT); 1594 label.setPadding(new Insets(7, 7, 7, 7)); 1595 final double textWidth = Utils.computeTextWidth(label.getFont(), "Howdy", 0); 1596 assertEquals(14 + textWidth + 6.5 + 20, label.maxWidth(-1), 0); 1597 } 1598 1599 @Test public void whenTextIsNullAndGraphicIsSetWithCENTERContentDisplay_computeMaxWidth_ReturnsGraphicWidthPlusPadding() { 1600 label.setText(null); 1601 label.setGraphic(new Rectangle(0, 0, 20, 20)); 1602 label.setGraphicTextGap(6.5); 1603 label.setContentDisplay(ContentDisplay.CENTER); 1604 label.setPadding(new Insets(7, 7, 7, 7)); 1605 assertEquals(14 + 20, label.maxWidth(-1), 0); 1606 } 1607 1608 @Test public void whenTextIsEmptyAndGraphicIsSetWithCENTERContentDisplay_computeMaxWidth_ReturnsGraphicWidthPlusPadding() { 1609 label.setText(""); 1610 label.setGraphic(new Rectangle(0, 0, 20, 20)); 1611 label.setGraphicTextGap(6.5); 1612 label.setContentDisplay(ContentDisplay.CENTER); 1613 label.setPadding(new Insets(7, 7, 7, 7)); 1614 assertEquals(14 + 20, label.maxWidth(-1), 0); 1615 } 1616 1617 @Test public void whenTextIsSetAndGraphicIsSetWithCENTERContentDisplayAndGraphicIsWider_computeMaxWidth_ReturnsGraphicWidthPlusPadding() { 1618 label.setText("Lollipop"); 1619 label.setGraphic(new Rectangle(0, 0, 200, 20)); 1620 label.setGraphicTextGap(6.5); 1621 label.setContentDisplay(ContentDisplay.CENTER); 1622 label.setPadding(new Insets(7, 7, 7, 7)); 1623 assertEquals(14 + 200, label.maxWidth(-1), 0); 1624 } 1625 1626 @Test public void whenTextIsSetAndGraphicIsSetWithCENTERContentDisplayAndTextIsWider_computeMaxWidth_ReturnsTextWidthPlusPadding() { 1627 label.setText("This is the right place"); 1628 label.setGraphic(new Rectangle(0, 0, 20, 20)); 1629 label.setGraphicTextGap(6.5); 1630 label.setContentDisplay(ContentDisplay.CENTER); 1631 label.setPadding(new Insets(7, 7, 7, 7)); 1632 final double textWidth = Utils.computeTextWidth(label.getFont(), "This is the right place", 0); 1633 assertEquals(14 + textWidth, label.maxWidth(-1), 0); 1634 } 1635 1636 @Test public void whenTextIsNullAndGraphicIsSetWithGRAPHIC_ONLYContentDisplay_computeMaxWidth_ReturnsGraphicWidthPlusPadding() { 1637 label.setText(null); 1638 label.setGraphic(new Rectangle(0, 0, 20, 20)); 1639 label.setGraphicTextGap(6.5); 1640 label.setContentDisplay(ContentDisplay.GRAPHIC_ONLY); 1641 label.setPadding(new Insets(7, 7, 7, 7)); 1642 assertEquals(14 + 20, label.maxWidth(-1), 0); 1643 } 1644 1645 @Test public void whenTextIsEmptyAndGraphicIsSetWithGRAPHIC_ONLYContentDisplay_computeMaxWidth_ReturnsGraphicWidthPlusPadding() { 1646 label.setText(""); 1647 label.setGraphic(new Rectangle(0, 0, 20, 20)); 1648 label.setGraphicTextGap(6.5); 1649 label.setContentDisplay(ContentDisplay.GRAPHIC_ONLY); 1650 label.setPadding(new Insets(7, 7, 7, 7)); 1651 assertEquals(14 + 20, label.maxWidth(-1), 0); 1652 } 1653 1654 @Test public void whenTextIsSetAndGraphicIsSetWithGRAPHIC_ONLYContentDisplayAndGraphicIsWider_computeMaxWidth_ReturnsGraphicWidthPlusPadding() { 1655 label.setText("Howdy"); 1656 label.setGraphic(new Rectangle(0, 0, 200, 20)); 1657 label.setGraphicTextGap(6.5); 1658 label.setContentDisplay(ContentDisplay.GRAPHIC_ONLY); 1659 label.setPadding(new Insets(7, 7, 7, 7)); 1660 assertEquals(14 + 200, label.maxWidth(-1), 0); 1661 } 1662 1663 @Test public void whenTextIsSetAndGraphicIsSetWithGRAPHIC_ONLYContentDisplayAndTextIsWider_computeMaxWidth_ReturnsGraphicWidthPlusPadding() { 1664 label.setText("Tally ho, off to the races"); 1665 label.setGraphic(new Rectangle(0, 0, 20, 20)); 1666 label.setGraphicTextGap(6.5); 1667 label.setContentDisplay(ContentDisplay.GRAPHIC_ONLY); 1668 label.setPadding(new Insets(7, 7, 7, 7)); 1669 assertEquals(14 + 20, label.maxWidth(-1), 0); 1670 } 1671 1672 // TODO should this include the gap?? 1673 @Test public void whenTextIsNullAndGraphicIsSetWithTEXT_ONLYContentDisplay_computeMaxWidth_ReturnsPadding() { 1674 label.setText(null); 1675 label.setGraphic(new Rectangle(0, 0, 20, 20)); 1676 label.setGraphicTextGap(6.5); 1677 label.setContentDisplay(ContentDisplay.TEXT_ONLY); 1678 label.setPadding(new Insets(7, 7, 7, 7)); 1679 assertEquals(14, label.maxWidth(-1), 0); 1680 } 1681 1682 @Test public void whenTextIsEmptyAndGraphicIsSetWithTEXT_ONLYContentDisplay_computeMaxWidth_ReturnsPadding() { 1683 label.setText(""); 1684 label.setGraphic(new Rectangle(0, 0, 20, 20)); 1685 label.setGraphicTextGap(6.5); 1686 label.setContentDisplay(ContentDisplay.TEXT_ONLY); 1687 label.setPadding(new Insets(7, 7, 7, 7)); 1688 assertEquals(14, label.maxWidth(-1), 0); 1689 } 1690 1691 // TODO should this include the gap? I guess not, otherwise our gap would have to default to 0 1692 @Test public void whenTextIsSetAndGraphicIsSetWithTEXT_ONLYContentDisplay_computeMaxWidth_ReturnsTextWidthPlusPadding() { 1693 label.setText("Yippee Skippee"); 1694 label.setGraphic(new Rectangle(0, 0, 20, 20)); 1695 label.setGraphicTextGap(6.5); 1696 label.setContentDisplay(ContentDisplay.TEXT_ONLY); 1697 label.setPadding(new Insets(7, 7, 7, 7)); 1698 final double textWidth = Utils.computeTextWidth(label.getFont(), "Yippee Skippee", 0); 1699 assertEquals(14 + textWidth, label.maxWidth(-1), 0); 1700 } 1701 1702 /**************************************************************************** 1703 * * 1704 * Tests for maxHeight. * 1705 * * 1706 ***************************************************************************/ 1707 1708 @Test public void whenTextIsNullAndNoGraphic_computeMaxHeight_ReturnsSingleLineStringHeightPlusPadding() { 1709 label.setText(null); 1710 label.setPadding(new Insets(7, 7, 7, 7)); 1711 final double lineHeight = Utils.computeTextHeight(label.getFont(), " ", 0, text.getBoundsType()); 1712 assertEquals(14 + lineHeight, label.maxHeight(-1), 0); 1713 } 1714 1715 @Test public void whenTextIsEmptyAndNoGraphic_computeMaxHeight_ReturnsSingleLineStringHeightPlusPadding() { 1716 label.setText(""); 1717 label.setPadding(new Insets(7, 7, 7, 7)); 1718 final double lineHeight = Utils.computeTextHeight(label.getFont(), " ", 0, text.getBoundsType()); 1719 assertEquals(14 + lineHeight, label.maxHeight(-1), 0); 1720 } 1721 1722 @Test public void whenTextIsSetAndNoGraphic_computeMaxHeight_ReturnsSingleLineStringHeightPlusPadding() { 1723 label.setText("Howdy Pardner"); 1724 label.setPadding(new Insets(7, 7, 7, 7)); 1725 assertTrue(label.maxHeight(-1) >= 0); 1726 final double lineHeight = Utils.computeTextHeight(label.getFont(), " ", 0, text.getBoundsType()); 1727 assertEquals(14 + lineHeight, label.maxHeight(-1), 0); 1728 } 1729 1730 @Test public void whenTextIsNullAndUnmanagedGraphic_computeMaxHeight_ReturnsSingleLineStringHeightPlusPadding() { 1731 label.setText(null); 1732 label.setPadding(new Insets(7, 7, 7, 7)); 1733 Rectangle r = new Rectangle(23, 500); 1734 r.setManaged(false); 1735 label.setGraphic(r); 1736 final double lineHeight = Utils.computeTextHeight(label.getFont(), " ", 0, text.getBoundsType()); 1737 assertEquals(14 + lineHeight, label.maxHeight(-1), 0); 1738 } 1739 1740 @Test public void whenTextIsEmptyAndUnmanagedGraphic_computeMaxHeight_ReturnsSingleLineStringHeightPlusPadding() { 1741 label.setText(""); 1742 label.setPadding(new Insets(7, 7, 7, 7)); 1743 Rectangle r = new Rectangle(23, 500); 1744 r.setManaged(false); 1745 label.setGraphic(r); 1746 final double lineHeight = Utils.computeTextHeight(label.getFont(), " ", 0, text.getBoundsType()); 1747 assertEquals(14 + lineHeight, label.maxHeight(-1), 0); 1748 } 1749 1750 @Test public void whenTextIsSetAndUnmanagedGraphic_computeMaxHeight_ReturnsSingleLineStringHeightPlusPadding() { 1751 label.setText("Howdy Pardner"); 1752 label.setPadding(new Insets(7, 7, 7, 7)); 1753 Rectangle r = new Rectangle(23, 500); 1754 r.setManaged(false); 1755 label.setGraphic(r); 1756 final double lineHeight = Utils.computeTextHeight(label.getFont(), " ", 0, text.getBoundsType()); 1757 assertTrue(label.maxHeight(-1) >= 0); 1758 assertEquals(14 + lineHeight, label.maxHeight(-1), 0); 1759 } 1760 1761 @Test public void whenTextIsNullAndGraphicIsSetWithTOPContentDisplay_computeMaxHeight_ReturnsRightAnswer() { 1762 label.setText(null); 1763 label.setPadding(new Insets(7, 7, 7, 7)); 1764 Rectangle r = new Rectangle(23, 23); 1765 label.setGraphicTextGap(2); 1766 label.setGraphic(r); 1767 label.setContentDisplay(ContentDisplay.TOP); 1768 final double lineHeight = Utils.computeTextHeight(label.getFont(), " ", 0, text.getBoundsType()); 1769 assertEquals(14 + 23 + lineHeight + 2, label.maxHeight(-1), 0); 1770 } 1771 1772 @Test public void whenTextIsEmptyAndGraphicIsSetWithTOPContentDisplay_computeMaxHeight_ReturnsRightAnswer() { 1773 label.setText(""); 1774 label.setPadding(new Insets(7, 7, 7, 7)); 1775 Rectangle r = new Rectangle(23, 23); 1776 label.setGraphicTextGap(2); 1777 label.setGraphic(r); 1778 label.setContentDisplay(ContentDisplay.TOP); 1779 final double lineHeight = Utils.computeTextHeight(label.getFont(), " ", 0, text.getBoundsType()); 1780 assertEquals(14 + 23 + lineHeight + 2, label.maxHeight(-1), 0); 1781 } 1782 1783 @Test public void whenTextIsSetAndGraphicIsSetWithTOPContentDisplay_computeMaxHeight_ReturnsRightAnswer() { 1784 label.setText("For crying in the mud"); 1785 label.setPadding(new Insets(7, 7, 7, 7)); 1786 Rectangle r = new Rectangle(23, 23); 1787 label.setGraphic(r); 1788 label.setGraphicTextGap(2); 1789 label.setContentDisplay(ContentDisplay.TOP); 1790 final double lineHeight = Utils.computeTextHeight(label.getFont(), " ", 0, text.getBoundsType()); 1791 assertEquals(14 + 23 + lineHeight + 2, label.maxHeight(-1), 0); 1792 } 1793 1794 @Test public void whenTextIsNullAndGraphicIsSetWithRIGHTContentDisplay_computeMaxHeight_ReturnsRightAnswer() { 1795 label.setText(null); 1796 label.setPadding(new Insets(7, 7, 7, 7)); 1797 Rectangle r = new Rectangle(23, 23); 1798 label.setGraphic(r); 1799 label.setContentDisplay(ContentDisplay.RIGHT); 1800 final double lineHeight = Utils.computeTextHeight(label.getFont(), " ", 0, text.getBoundsType()); 1801 assertEquals(14 + Math.max(23, lineHeight), label.maxHeight(-1), 0); 1802 } 1803 1804 @Test public void whenTextIsEmptyAndGraphicIsSetWithRIGHTContentDisplay_computeMaxHeight_ReturnsRightAnswer() { 1805 label.setText(""); 1806 label.setPadding(new Insets(7, 7, 7, 7)); 1807 Rectangle r = new Rectangle(23, 23); 1808 label.setGraphic(r); 1809 label.setContentDisplay(ContentDisplay.RIGHT); 1810 final double lineHeight = Utils.computeTextHeight(label.getFont(), " ", 0, text.getBoundsType()); 1811 assertEquals(14 + Math.max(23, lineHeight), label.maxHeight(-1), 0); 1812 } 1813 1814 @Test public void whenTextIsSetAndGraphicIsSetWithRIGHTContentDisplay_computeMaxHeight_ReturnsRightAnswer() { 1815 label.setText("For crying in the mud"); 1816 label.setPadding(new Insets(7, 7, 7, 7)); 1817 Rectangle r = new Rectangle(23, 23); 1818 label.setGraphic(r); 1819 label.setContentDisplay(ContentDisplay.RIGHT); 1820 final double lineHeight = Utils.computeTextHeight(label.getFont(), " ", 0, text.getBoundsType()); 1821 assertEquals(14 + Math.max(23, lineHeight), label.maxHeight(-1), 0); 1822 } 1823 1824 @Test public void whenTextIsNullAndGraphicIsSetWithBOTTOMContentDisplay_computeMaxHeight_ReturnsRightAnswer() { 1825 label.setText(null); 1826 label.setPadding(new Insets(7, 7, 7, 7)); 1827 Rectangle r = new Rectangle(23, 23); 1828 label.setGraphicTextGap(2); 1829 label.setGraphic(r); 1830 label.setContentDisplay(ContentDisplay.BOTTOM); 1831 final double lineHeight = Utils.computeTextHeight(label.getFont(), " ", 0, text.getBoundsType()); 1832 assertEquals(14 + 23 + lineHeight + 2, label.maxHeight(-1), 0); 1833 } 1834 1835 @Test public void whenTextIsEmptyAndGraphicIsSetWithBOTTOMContentDisplay_computeMaxHeight_ReturnsRightAnswer() { 1836 label.setText(""); 1837 label.setPadding(new Insets(7, 7, 7, 7)); 1838 Rectangle r = new Rectangle(23, 23); 1839 label.setGraphicTextGap(2); 1840 label.setGraphic(r); 1841 label.setContentDisplay(ContentDisplay.BOTTOM); 1842 final double lineHeight = Utils.computeTextHeight(label.getFont(), " ", 0, text.getBoundsType()); 1843 assertEquals(14 + 23 + lineHeight + 2, label.maxHeight(-1), 0); 1844 } 1845 1846 @Test public void whenTextIsSetAndGraphicIsSetWithBOTTOMContentDisplay_computeMaxHeight_ReturnsRightAnswer() { 1847 label.setText("For crying in the mud"); 1848 label.setPadding(new Insets(7, 7, 7, 7)); 1849 Rectangle r = new Rectangle(23, 23); 1850 label.setGraphic(r); 1851 label.setGraphicTextGap(2); 1852 label.setContentDisplay(ContentDisplay.BOTTOM); 1853 final double lineHeight = Utils.computeTextHeight(label.getFont(), " ", 0, text.getBoundsType()); 1854 assertEquals(14 + 23 + lineHeight + 2, label.maxHeight(-1), 0); 1855 } 1856 1857 @Test public void whenTextIsNullAndGraphicIsSetWithLEFTContentDisplay_computeMaxHeight_ReturnsRightAnswer() { 1858 label.setText(null); 1859 label.setPadding(new Insets(7, 7, 7, 7)); 1860 Rectangle r = new Rectangle(23, 23); 1861 label.setGraphic(r); 1862 label.setContentDisplay(ContentDisplay.LEFT); 1863 final double lineHeight = Utils.computeTextHeight(label.getFont(), " ", 0, text.getBoundsType()); 1864 assertEquals(14 + Math.max(23, lineHeight), label.maxHeight(-1), 0); 1865 } 1866 1867 @Test public void whenTextIsEmptyAndGraphicIsSetWithLEFTContentDisplay_computeMaxHeight_ReturnsRightAnswer() { 1868 label.setText(""); 1869 label.setPadding(new Insets(7, 7, 7, 7)); 1870 Rectangle r = new Rectangle(23, 23); 1871 label.setGraphic(r); 1872 label.setContentDisplay(ContentDisplay.LEFT); 1873 final double lineHeight = Utils.computeTextHeight(label.getFont(), " ", 0, text.getBoundsType()); 1874 assertEquals(14 + Math.max(23, lineHeight), label.maxHeight(-1), 0); 1875 } 1876 1877 @Test public void whenTextIsSetAndGraphicIsSetWithLEFTContentDisplay_computeMaxHeight_ReturnsRightAnswer() { 1878 label.setText("For crying in the mud"); 1879 label.setPadding(new Insets(7, 7, 7, 7)); 1880 Rectangle r = new Rectangle(23, 23); 1881 label.setGraphic(r); 1882 label.setContentDisplay(ContentDisplay.LEFT); 1883 final double lineHeight = Utils.computeTextHeight(label.getFont(), " ", 0, text.getBoundsType()); 1884 assertEquals(14 + Math.max(23, lineHeight), label.maxHeight(-1), 0); 1885 } 1886 1887 @Test public void whenTextIsNullAndGraphicIsSetWithCENTERContentDisplay_computeMaxHeight_ReturnsRightAnswer() { 1888 label.setText(null); 1889 label.setPadding(new Insets(7, 7, 7, 7)); 1890 Rectangle r = new Rectangle(23, 23); 1891 label.setGraphic(r); 1892 label.setContentDisplay(ContentDisplay.CENTER); 1893 final double lineHeight = Utils.computeTextHeight(label.getFont(), " ", 0, text.getBoundsType()); 1894 assertEquals(14 + Math.max(23, lineHeight), label.maxHeight(-1), 0); 1895 } 1896 1897 @Test public void whenTextIsEmptyAndGraphicIsSetWithCENTERContentDisplay_computeMaxHeight_ReturnsRightAnswer() { 1898 label.setText(""); 1899 label.setPadding(new Insets(7, 7, 7, 7)); 1900 Rectangle r = new Rectangle(23, 23); 1901 label.setGraphic(r); 1902 label.setContentDisplay(ContentDisplay.CENTER); 1903 final double lineHeight = Utils.computeTextHeight(label.getFont(), " ", 0, text.getBoundsType()); 1904 assertEquals(14 + Math.max(23, lineHeight), label.maxHeight(-1), 0); 1905 } 1906 1907 @Test public void whenTextIsSetAndGraphicIsSetWithCENTERContentDisplay_computeMaxHeight_ReturnsRightAnswer() { 1908 label.setText("For crying in the mud"); 1909 label.setPadding(new Insets(7, 7, 7, 7)); 1910 Rectangle r = new Rectangle(23, 23); 1911 label.setGraphic(r); 1912 label.setContentDisplay(ContentDisplay.CENTER); 1913 final double lineHeight = Utils.computeTextHeight(label.getFont(), " ", 0, text.getBoundsType()); 1914 assertEquals(14 + Math.max(23, lineHeight), label.maxHeight(-1), 0); 1915 } 1916 1917 @Test public void whenTextIsNullAndGraphicIsSetWithGRAPHIC_ONLYContentDisplay_computeMaxHeight_ReturnsRightAnswer() { 1918 label.setText(null); 1919 label.setPadding(new Insets(7, 7, 7, 7)); 1920 Rectangle r = new Rectangle(23, 23); 1921 label.setGraphic(r); 1922 label.setContentDisplay(ContentDisplay.GRAPHIC_ONLY); 1923 assertEquals(14 + 23, label.maxHeight(-1), 0); 1924 } 1925 1926 @Test public void whenTextIsEmptyAndGraphicIsSetWithGRAPHIC_ONLYContentDisplay_computeMaxHeight_ReturnsRightAnswer() { 1927 label.setText(""); 1928 label.setPadding(new Insets(7, 7, 7, 7)); 1929 Rectangle r = new Rectangle(23, 23); 1930 label.setGraphic(r); 1931 label.setContentDisplay(ContentDisplay.GRAPHIC_ONLY); 1932 assertEquals(14 + 23, label.maxHeight(-1), 0); 1933 } 1934 1935 @Test public void whenTextIsSetAndGraphicIsSetWithGRAPHIC_ONLYContentDisplay_computeMaxHeight_ReturnsRightAnswer() { 1936 label.setText("For crying in the mud"); 1937 label.setPadding(new Insets(7, 7, 7, 7)); 1938 Rectangle r = new Rectangle(23, 23); 1939 label.setGraphic(r); 1940 label.setContentDisplay(ContentDisplay.GRAPHIC_ONLY); 1941 assertEquals(14 + 23, label.maxHeight(-1), 0); 1942 } 1943 1944 @Test public void whenTextIsNullAndGraphicIsSetWithTEXT_ONLYContentDisplay_computeMaxHeight_ReturnsRightAnswer() { 1945 label.setText(null); 1946 label.setPadding(new Insets(7, 7, 7, 7)); 1947 Rectangle r = new Rectangle(23, 23); 1948 label.setGraphic(r); 1949 label.setContentDisplay(ContentDisplay.TEXT_ONLY); 1950 final double lineHeight = Utils.computeTextHeight(label.getFont(), " ", 0, text.getBoundsType()); 1951 assertEquals(14 + lineHeight, label.maxHeight(-1), 0); 1952 } 1953 1954 @Test public void whenTextIsEmptyAndGraphicIsSetWithTEXT_ONLYContentDisplay_computeMaxHeight_ReturnsRightAnswer() { 1955 label.setText(""); 1956 label.setPadding(new Insets(7, 7, 7, 7)); 1957 Rectangle r = new Rectangle(23, 23); 1958 label.setGraphic(r); 1959 label.setContentDisplay(ContentDisplay.TEXT_ONLY); 1960 final double lineHeight = Utils.computeTextHeight(label.getFont(), " ", 0, text.getBoundsType()); 1961 assertEquals(14 + lineHeight, label.maxHeight(-1), 0); 1962 } 1963 1964 @Test public void whenTextIsSetAndGraphicIsSetWithTEXT_ONLYContentDisplay_computeMaxHeight_ReturnsRightAnswer() { 1965 label.setText("For crying in the mud"); 1966 label.setPadding(new Insets(7, 7, 7, 7)); 1967 Rectangle r = new Rectangle(23, 23); 1968 label.setGraphic(r); 1969 label.setContentDisplay(ContentDisplay.TEXT_ONLY); 1970 final double lineHeight = Utils.computeTextHeight(label.getFont(), " ", 0, text.getBoundsType()); 1971 assertEquals(14 + lineHeight, label.maxHeight(-1), 0); 1972 } 1973 1974 @Test public void maxWidthTracksPreferred() { 1975 label.setPrefWidth(500); 1976 assertEquals(500, label.maxWidth(-1), 0); 1977 } 1978 1979 @Test public void maxHeightTracksPreferred() { 1980 label.setPrefHeight(500); 1981 assertEquals(500, label.maxHeight(-1), 0); 1982 } 1983 1984 /**************************************************************************** 1985 * * 1986 * Tests for updateDisplayedText * 1987 * * 1988 ***************************************************************************/ 1989 1990 // tests for updateDisplayedText (not even sure how to test it exactly yet) 1991 1992 1993 public static final class LabelSkinMock extends LabelSkin { 1994 boolean propertyChanged = false; 1995 int propertyChangeCount = 0; 1996 1997 public LabelSkinMock(Label label) { 1998 super(label); 1999 } 2000 2001 public void addWatchedProperty(ObservableValue<?> p) { 2002 p.addListener(o -> { 2003 propertyChanged = true; 2004 propertyChangeCount++; 2005 }); 2006 } 2007 } 2008 }