1 29 30 package nextapp.echo2.webcontainer.test; 31 32 import nextapp.echo2.app.Extent; 33 import nextapp.echo2.app.Grid; 34 import nextapp.echo2.app.Label; 35 import nextapp.echo2.app.layout.GridLayoutData; 36 import nextapp.echo2.webcontainer.syncpeer.GridProcessor; 37 import junit.framework.TestCase; 38 39 42 public class GridProcessorTest extends TestCase { 43 44 47 public void testBasicColumnWidthAndRowHeight() { 48 Grid grid = new Grid(3); 49 for (int i = 0; i < 12; ++i) { 50 grid.add(new Label()); 51 } 52 for (int i = 0; i < 4; ++i) { 53 grid.setColumnWidth(i, new Extent(i + 1)); 54 grid.setRowHeight(i, new Extent((i + 1)* 10)); 55 } 56 57 GridProcessor gridProcessor = new GridProcessor(grid); 58 assertEquals(3, gridProcessor.getColumnCount()); 59 assertEquals(4, gridProcessor.getRowCount()); 60 assertEquals(new Extent(1), gridProcessor.getColumnWidth(0)); 61 assertEquals(new Extent(2), gridProcessor.getColumnWidth(1)); 62 assertEquals(new Extent(3), gridProcessor.getColumnWidth(2)); 63 assertEquals(new Extent(10), gridProcessor.getRowHeight(0)); 64 assertEquals(new Extent(20), gridProcessor.getRowHeight(1)); 65 assertEquals(new Extent(30), gridProcessor.getRowHeight(2)); 66 assertEquals(new Extent(40), gridProcessor.getRowHeight(3)); 67 68 grid.setOrientation(Grid.ORIENTATION_VERTICAL); 69 gridProcessor = new GridProcessor(grid); 70 assertEquals(4, gridProcessor.getColumnCount()); 71 assertEquals(3, gridProcessor.getRowCount()); 72 assertEquals(new Extent(1), gridProcessor.getColumnWidth(0)); 73 assertEquals(new Extent(2), gridProcessor.getColumnWidth(1)); 74 assertEquals(new Extent(3), gridProcessor.getColumnWidth(2)); 75 assertEquals(new Extent(4), gridProcessor.getColumnWidth(3)); 76 assertEquals(new Extent(10), gridProcessor.getRowHeight(0)); 77 assertEquals(new Extent(20), gridProcessor.getRowHeight(1)); 78 assertEquals(new Extent(30), gridProcessor.getRowHeight(2)); 79 } 80 81 84 public void testEmptyGrid() { 85 Grid grid = new Grid(); 86 GridProcessor gridProcessor = new GridProcessor(grid); 87 assertEquals(0, gridProcessor.getColumnCount()); 88 assertEquals(0, gridProcessor.getRowCount()); 89 } 90 91 98 99 public void testLessThanSize() { 100 Grid grid = new Grid(); 101 grid.setSize(4); 102 103 grid.add(new Label()); 104 105 GridProcessor gridProcessor = new GridProcessor(grid); 106 assertEquals(1, gridProcessor.getColumnCount()); 107 assertEquals(1, gridProcessor.getRowCount()); 108 } 109 110 122 123 public void testLessThanSizeWithRowSpan() { 124 Grid grid = new Grid(); 125 grid.setSize(4); 126 127 Label label = new Label(); 128 GridLayoutData gridLayoutData = new GridLayoutData(); 129 gridLayoutData.setRowSpan(3); 130 label.setLayoutData(gridLayoutData); 131 grid.add(label); 132 133 GridProcessor gridProcessor = new GridProcessor(grid); 134 assertEquals(1, gridProcessor.getColumnCount()); 135 assertEquals(1, gridProcessor.getRowCount()); 136 } 137 138 150 public void testInvalidAttemptCollision() { 151 GridLayoutData layoutData; 152 Grid grid = new Grid(3); 153 grid.add(new Label("0")); 154 Label verticalCollider = new Label("VC"); 155 layoutData = new GridLayoutData(); 156 layoutData.setRowSpan(3); 157 verticalCollider.setLayoutData(layoutData); 158 grid.add(verticalCollider); 159 grid.add(new Label("1")); 160 Label horizontalCollider = new Label("HC"); 161 layoutData = new GridLayoutData(); 162 layoutData.setColumnSpan(3); 163 horizontalCollider.setLayoutData(layoutData); 164 grid.add(horizontalCollider); 165 grid.add(new Label("2")); 166 grid.add(new Label("3")); 167 GridProcessor gridProcessor = new GridProcessor(grid); 168 assertEquals("0", ((Label) gridProcessor.getContent(0, 0)).getText()); 169 assertEquals("VC", ((Label) gridProcessor.getContent(1, 0)).getText()); 170 assertEquals("1", ((Label) gridProcessor.getContent(2, 0)).getText()); 171 assertEquals("HC", ((Label) gridProcessor.getContent(0, 1)).getText()); 172 assertEquals("VC", ((Label) gridProcessor.getContent(1, 1)).getText()); 173 assertEquals("2", ((Label) gridProcessor.getContent(2, 1)).getText()); 174 assertEquals("3", ((Label) gridProcessor.getContent(0, 2)).getText()); 175 assertEquals("VC", ((Label) gridProcessor.getContent(1, 2)).getText()); 176 } 177 178 192 public void testOutOfBoundsRowSpan() { 193 Grid grid = new Grid(); 194 grid.add(new Label()); 195 196 Label label = new Label(); 197 GridLayoutData layoutData = new GridLayoutData(); 198 layoutData.setRowSpan(4); 199 label.setLayoutData(layoutData); 200 grid.add(label); 201 202 GridProcessor gridProcessor = new GridProcessor(grid); 203 204 assertEquals(2, gridProcessor.getColumnCount()); 206 assertEquals(2, gridProcessor.getRowCount()); 207 208 assertEquals(0, gridProcessor.getComponentIndex(0, 0)); 210 assertEquals(1, gridProcessor.getComponentIndex(1, 0)); 211 assertEquals(-1, gridProcessor.getComponentIndex(0, 1)); 212 assertEquals(1, gridProcessor.getComponentIndex(1, 1)); 213 214 assertEquals(1, gridProcessor.getColumnSpan(0, 0)); 216 assertEquals(1, gridProcessor.getColumnSpan(1, 0)); 217 assertEquals(-1, gridProcessor.getColumnSpan(0, 1)); 218 assertEquals(1, gridProcessor.getColumnSpan(1, 1)); 219 220 assertEquals(1, gridProcessor.getRowSpan(0, 0)); 222 assertEquals(2, gridProcessor.getRowSpan(1, 0)); 223 assertEquals(-1, gridProcessor.getRowSpan(0, 1)); 224 assertEquals(2, gridProcessor.getRowSpan(1, 1)); 225 } 226 227 241 public void testReduceColumnComplex() { 242 Grid grid = new Grid(); 243 244 grid.setSize(7); 246 for (int i = 0; i < 12; ++i) { 247 Label label = new Label(Integer.toString(i)); 248 if (i == 1 || i == 2 || i == 3 || i == 5 || i == 8 || i == 10 || i == 11) { 249 GridLayoutData layoutData = new GridLayoutData(); 250 layoutData.setColumnSpan(2); 251 if (i == 8) { 252 layoutData.setRowSpan(2); 253 } 254 label.setLayoutData(layoutData); 255 } 256 grid.add(label); 257 } 258 259 grid.setColumnWidth(0, new Extent(1)); 261 grid.setColumnWidth(1, new Extent(2)); 262 grid.setColumnWidth(2, new Extent(4)); 263 grid.setColumnWidth(3, new Extent(8)); 264 grid.setColumnWidth(4, new Extent(16)); 265 grid.setColumnWidth(5, new Extent(32)); 266 grid.setColumnWidth(6, new Extent(64)); 267 268 GridProcessor gridProcessor = new GridProcessor(grid); 269 270 assertEquals(5, gridProcessor.getColumnCount()); 272 assertEquals(3, gridProcessor.getRowCount()); 273 274 assertEquals(0, gridProcessor.getComponentIndex(0, 0)); 276 assertEquals(1, gridProcessor.getComponentIndex(1, 0)); 277 assertEquals(2, gridProcessor.getComponentIndex(2, 0)); 278 assertEquals(2, gridProcessor.getComponentIndex(3, 0)); 279 assertEquals(3, gridProcessor.getComponentIndex(4, 0)); 280 assertEquals(4, gridProcessor.getComponentIndex(0, 1)); 281 assertEquals(5, gridProcessor.getComponentIndex(1, 1)); 282 assertEquals(6, gridProcessor.getComponentIndex(2, 1)); 283 assertEquals(7, gridProcessor.getComponentIndex(3, 1)); 284 assertEquals(8, gridProcessor.getComponentIndex(4, 1)); 285 assertEquals(9, gridProcessor.getComponentIndex(0, 2)); 286 assertEquals(10, gridProcessor.getComponentIndex(1, 2)); 287 assertEquals(11, gridProcessor.getComponentIndex(2, 2)); 288 assertEquals(11, gridProcessor.getComponentIndex(3, 2)); 289 assertEquals(8, gridProcessor.getComponentIndex(4, 2)); 290 291 assertEquals(1, gridProcessor.getColumnSpan(0, 0)); 293 assertEquals(1, gridProcessor.getColumnSpan(1, 0)); 294 assertEquals(2, gridProcessor.getColumnSpan(2, 0)); 295 assertEquals(2, gridProcessor.getColumnSpan(3, 0)); 296 assertEquals(1, gridProcessor.getColumnSpan(4, 0)); 297 assertEquals(1, gridProcessor.getColumnSpan(0, 1)); 298 assertEquals(1, gridProcessor.getColumnSpan(1, 1)); 299 assertEquals(1, gridProcessor.getColumnSpan(2, 1)); 300 assertEquals(1, gridProcessor.getColumnSpan(3, 1)); 301 assertEquals(1, gridProcessor.getColumnSpan(4, 1)); 302 assertEquals(1, gridProcessor.getColumnSpan(0, 2)); 303 assertEquals(1, gridProcessor.getColumnSpan(1, 2)); 304 assertEquals(2, gridProcessor.getColumnSpan(2, 2)); 305 assertEquals(2, gridProcessor.getColumnSpan(3, 2)); 306 assertEquals(1, gridProcessor.getColumnSpan(4, 2)); 307 308 assertEquals(1, gridProcessor.getRowSpan(0, 0)); 310 assertEquals(1, gridProcessor.getRowSpan(1, 0)); 311 assertEquals(1, gridProcessor.getRowSpan(2, 0)); 312 assertEquals(1, gridProcessor.getRowSpan(3, 0)); 313 assertEquals(1, gridProcessor.getRowSpan(4, 0)); 314 assertEquals(1, gridProcessor.getRowSpan(0, 1)); 315 assertEquals(1, gridProcessor.getRowSpan(1, 1)); 316 assertEquals(1, gridProcessor.getRowSpan(3, 1)); 317 assertEquals(2, gridProcessor.getRowSpan(4, 1)); 318 assertEquals(1, gridProcessor.getRowSpan(0, 2)); 319 assertEquals(1, gridProcessor.getRowSpan(1, 2)); 320 assertEquals(1, gridProcessor.getRowSpan(2, 2)); 321 assertEquals(1, gridProcessor.getRowSpan(3, 2)); 322 assertEquals(2, gridProcessor.getRowSpan(4, 2)); 323 324 assertEquals(new Extent(1), gridProcessor.getColumnWidth(0)); 326 assertEquals(new Extent(6), gridProcessor.getColumnWidth(1)); 327 assertEquals(new Extent(8), gridProcessor.getColumnWidth(2)); 328 assertEquals(new Extent(16), gridProcessor.getColumnWidth(3)); 329 assertEquals(new Extent(96), gridProcessor.getColumnWidth(4)); 330 } 331 332 344 public void testReduceColumnSimple() { 345 Grid grid = new Grid(); 346 grid.setSize(4); 347 for (int i = 0; i < 6; ++i) { 348 Label label = new Label(Integer.toString(i)); 349 if (i == 1 || i == 4) { 350 GridLayoutData layoutData = new GridLayoutData(); 351 layoutData.setColumnSpan(2); 352 label.setLayoutData(layoutData); 353 } 354 grid.add(label); 355 } 356 GridProcessor gridProcessor = new GridProcessor(grid); 357 assertEquals(3, gridProcessor.getColumnCount()); 358 assertEquals(2, gridProcessor.getRowCount()); 359 assertEquals(0, gridProcessor.getComponentIndex(0, 0)); 360 assertEquals(1, gridProcessor.getComponentIndex(1, 0)); 361 assertEquals(2, gridProcessor.getComponentIndex(2, 0)); 362 assertEquals(3, gridProcessor.getComponentIndex(0, 1)); 363 assertEquals(4, gridProcessor.getComponentIndex(1, 1)); 364 assertEquals(5, gridProcessor.getComponentIndex(2, 1)); 365 } 366 367 386 public void testReduceRowComplex() { 387 Grid grid = new Grid(); 388 389 grid.setSize(3); 391 for (int i = 0; i < 12; ++i) { 392 Label label = new Label(Integer.toString(i)); 393 if (i == 3 || i == 4 || i == 5 || i == 6 || i == 8 || i == 10 || i == 11) { 394 GridLayoutData layoutData = new GridLayoutData(); 395 layoutData.setRowSpan(2); 396 if (i == 11) { 397 layoutData.setColumnSpan(2); 398 } 399 label.setLayoutData(layoutData); 400 } 401 grid.add(label); 402 } 403 404 grid.setRowHeight(0, new Extent(1)); 406 grid.setRowHeight(1, new Extent(2)); 407 grid.setRowHeight(2, new Extent(4)); 408 grid.setRowHeight(3, new Extent(8)); 409 grid.setRowHeight(4, new Extent(16)); 410 grid.setRowHeight(5, new Extent(32)); 411 grid.setRowHeight(6, new Extent(64)); 412 413 GridProcessor gridProcessor = new GridProcessor(grid); 414 415 assertEquals(3, gridProcessor.getColumnCount()); 417 assertEquals(5, gridProcessor.getRowCount()); 418 419 assertEquals(0, gridProcessor.getComponentIndex(0, 0)); 421 assertEquals(1, gridProcessor.getComponentIndex(1, 0)); 422 assertEquals(2, gridProcessor.getComponentIndex(2, 0)); 423 assertEquals(3, gridProcessor.getComponentIndex(0, 1)); 424 assertEquals(4, gridProcessor.getComponentIndex(1, 1)); 425 assertEquals(5, gridProcessor.getComponentIndex(2, 1)); 426 assertEquals(6, gridProcessor.getComponentIndex(0, 2)); 427 assertEquals(7, gridProcessor.getComponentIndex(1, 2)); 428 assertEquals(8, gridProcessor.getComponentIndex(2, 2)); 429 assertEquals(6, gridProcessor.getComponentIndex(0, 3)); 430 assertEquals(9, gridProcessor.getComponentIndex(1, 3)); 431 assertEquals(8, gridProcessor.getComponentIndex(2, 3)); 432 assertEquals(10, gridProcessor.getComponentIndex(0, 4)); 433 assertEquals(11, gridProcessor.getComponentIndex(1, 4)); 434 assertEquals(11, gridProcessor.getComponentIndex(2, 4)); 435 436 assertEquals(1, gridProcessor.getColumnSpan(0, 0)); 438 assertEquals(1, gridProcessor.getColumnSpan(1, 0)); 439 assertEquals(1, gridProcessor.getColumnSpan(2, 0)); 440 assertEquals(1, gridProcessor.getColumnSpan(0, 1)); 441 assertEquals(1, gridProcessor.getColumnSpan(1, 1)); 442 assertEquals(1, gridProcessor.getColumnSpan(2, 1)); 443 assertEquals(1, gridProcessor.getColumnSpan(0, 2)); 444 assertEquals(1, gridProcessor.getColumnSpan(1, 2)); 445 assertEquals(1, gridProcessor.getColumnSpan(2, 2)); 446 assertEquals(1, gridProcessor.getColumnSpan(0, 3)); 447 assertEquals(1, gridProcessor.getColumnSpan(1, 3)); 448 assertEquals(1, gridProcessor.getColumnSpan(2, 3)); 449 assertEquals(1, gridProcessor.getColumnSpan(0, 4)); 450 assertEquals(2, gridProcessor.getColumnSpan(1, 4)); 451 assertEquals(2, gridProcessor.getColumnSpan(2, 4)); 452 453 assertEquals(1, gridProcessor.getRowSpan(0, 0)); 455 assertEquals(1, gridProcessor.getRowSpan(1, 0)); 456 assertEquals(1, gridProcessor.getRowSpan(2, 0)); 457 assertEquals(1, gridProcessor.getRowSpan(0, 1)); 458 assertEquals(1, gridProcessor.getRowSpan(1, 1)); 459 assertEquals(1, gridProcessor.getRowSpan(2, 1)); 460 assertEquals(2, gridProcessor.getRowSpan(0, 2)); 461 assertEquals(1, gridProcessor.getRowSpan(1, 2)); 462 assertEquals(2, gridProcessor.getRowSpan(2, 2)); 463 assertEquals(2, gridProcessor.getRowSpan(0, 3)); 464 assertEquals(1, gridProcessor.getRowSpan(1, 3)); 465 assertEquals(2, gridProcessor.getRowSpan(2, 3)); 466 assertEquals(1, gridProcessor.getRowSpan(0, 4)); 467 assertEquals(1, gridProcessor.getRowSpan(1, 4)); 468 assertEquals(1, gridProcessor.getRowSpan(2, 4)); 469 470 assertEquals(new Extent(1), gridProcessor.getRowHeight(0)); 472 assertEquals(new Extent(6), gridProcessor.getRowHeight(1)); 473 assertEquals(new Extent(8), gridProcessor.getRowHeight(2)); 474 assertEquals(new Extent(16), gridProcessor.getRowHeight(3)); 475 assertEquals(new Extent(96), gridProcessor.getRowHeight(4)); 476 } 477 478 491 public void testReduceRowSimple() { 492 Grid grid = new Grid(); 493 grid.setSize(2); 494 for (int i = 0; i < 6; ++i) { 495 Label label = new Label(Integer.toString(i)); 496 if (i == 2 || i == 3) { 497 GridLayoutData layoutData = new GridLayoutData(); 498 layoutData.setRowSpan(2); 499 label.setLayoutData(layoutData); 500 } 501 grid.add(label); 502 } 503 GridProcessor gridProcessor = new GridProcessor(grid); 504 assertEquals(2, gridProcessor.getColumnCount()); 505 assertEquals(3, gridProcessor.getRowCount()); 506 assertEquals(0, gridProcessor.getComponentIndex(0, 0)); 507 assertEquals(1, gridProcessor.getComponentIndex(1, 0)); 508 assertEquals(2, gridProcessor.getComponentIndex(0, 1)); 509 assertEquals(3, gridProcessor.getComponentIndex(1, 1)); 510 assertEquals(4, gridProcessor.getComponentIndex(0, 2)); 511 assertEquals(5, gridProcessor.getComponentIndex(1, 2)); 512 } 513 514 530 public void testReduceColumnAndRowSimple() { 531 Grid grid = new Grid(); 532 grid.setSize(3); 533 for (int i = 0; i < 4; ++i) { 534 Label label = new Label(Integer.toString(i)); 535 if (i > 0) { 536 GridLayoutData layoutData = new GridLayoutData(); 537 if (i == 1 || i == 3) { 538 layoutData.setColumnSpan(2); 539 } 540 if (i == 2 || i == 3) { 541 layoutData.setRowSpan(2); 542 } 543 label.setLayoutData(layoutData); 544 } 545 grid.add(label); 546 } 547 548 GridProcessor gridProcessor = new GridProcessor(grid); 549 550 assertEquals(2, gridProcessor.getColumnCount()); 552 assertEquals(2, gridProcessor.getRowCount()); 553 554 assertEquals(0, gridProcessor.getComponentIndex(0, 0)); 556 assertEquals(1, gridProcessor.getComponentIndex(1, 0)); 557 assertEquals(2, gridProcessor.getComponentIndex(0, 1)); 558 assertEquals(3, gridProcessor.getComponentIndex(1, 1)); 559 560 assertEquals(1, gridProcessor.getColumnSpan(0, 0)); 562 assertEquals(1, gridProcessor.getColumnSpan(1, 0)); 563 assertEquals(1, gridProcessor.getColumnSpan(0, 1)); 564 assertEquals(1, gridProcessor.getColumnSpan(1, 1)); 565 566 assertEquals(1, gridProcessor.getRowSpan(0, 0)); 568 assertEquals(1, gridProcessor.getRowSpan(1, 0)); 569 assertEquals(1, gridProcessor.getRowSpan(0, 1)); 570 assertEquals(1, gridProcessor.getRowSpan(1, 1)); 571 } 572 573 574 588 public void testReduceColumnLong() { 589 Grid grid = new Grid(); 590 grid.setSize(4); 591 592 for (int i = 0; i < 6; ++i) { 593 Label label = new Label(Integer.toString(i)); 594 if (i % 2 == 0) { 595 GridLayoutData layoutData = new GridLayoutData(); 596 layoutData.setColumnSpan(3); 597 label.setLayoutData(layoutData); 598 } 599 grid.add(label); 600 } 601 602 GridProcessor gridProcessor = new GridProcessor(grid); 603 604 assertEquals(2, gridProcessor.getColumnCount()); 606 assertEquals(3, gridProcessor.getRowCount()); 607 608 assertEquals(0, gridProcessor.getComponentIndex(0, 0)); 610 assertEquals(1, gridProcessor.getComponentIndex(1, 0)); 611 assertEquals(2, gridProcessor.getComponentIndex(0, 1)); 612 assertEquals(3, gridProcessor.getComponentIndex(1, 1)); 613 assertEquals(4, gridProcessor.getComponentIndex(0, 2)); 614 assertEquals(5, gridProcessor.getComponentIndex(1, 2)); 615 616 assertEquals(1, gridProcessor.getColumnSpan(0, 0)); 618 assertEquals(1, gridProcessor.getColumnSpan(1, 0)); 619 assertEquals(1, gridProcessor.getColumnSpan(0, 1)); 620 assertEquals(1, gridProcessor.getColumnSpan(1, 1)); 621 assertEquals(1, gridProcessor.getColumnSpan(0, 2)); 622 assertEquals(1, gridProcessor.getColumnSpan(1, 2)); 623 624 assertEquals(1, gridProcessor.getRowSpan(0, 0)); 626 assertEquals(1, gridProcessor.getRowSpan(1, 0)); 627 assertEquals(1, gridProcessor.getRowSpan(0, 1)); 628 assertEquals(1, gridProcessor.getRowSpan(1, 1)); 629 assertEquals(1, gridProcessor.getRowSpan(0, 2)); 630 assertEquals(1, gridProcessor.getRowSpan(1, 2)); 631 } 632 633 646 public void testReduceRowLong() { 647 Grid grid = new Grid(); 648 grid.setSize(3); 649 650 for (int i = 0; i < 6; ++i) { 651 Label label = new Label(Integer.toString(i)); 652 if (i < 3) { 653 GridLayoutData layoutData = new GridLayoutData(); 654 layoutData.setRowSpan(3); 655 label.setLayoutData(layoutData); 656 } 657 grid.add(label); 658 } 659 660 GridProcessor gridProcessor = new GridProcessor(grid); 661 662 assertEquals(3, gridProcessor.getColumnCount()); 664 assertEquals(2, gridProcessor.getRowCount()); 665 666 assertEquals(0, gridProcessor.getComponentIndex(0, 0)); 668 assertEquals(1, gridProcessor.getComponentIndex(1, 0)); 669 assertEquals(2, gridProcessor.getComponentIndex(2, 0)); 670 assertEquals(3, gridProcessor.getComponentIndex(0, 1)); 671 assertEquals(4, gridProcessor.getComponentIndex(1, 1)); 672 assertEquals(5, gridProcessor.getComponentIndex(2, 1)); 673 674 assertEquals(1, gridProcessor.getColumnSpan(0, 0)); 676 assertEquals(1, gridProcessor.getColumnSpan(1, 0)); 677 assertEquals(1, gridProcessor.getColumnSpan(2, 0)); 678 assertEquals(1, gridProcessor.getColumnSpan(0, 1)); 679 assertEquals(1, gridProcessor.getColumnSpan(1, 1)); 680 assertEquals(1, gridProcessor.getColumnSpan(2, 1)); 681 682 assertEquals(1, gridProcessor.getRowSpan(0, 0)); 684 assertEquals(1, gridProcessor.getRowSpan(1, 0)); 685 assertEquals(1, gridProcessor.getRowSpan(2, 0)); 686 assertEquals(1, gridProcessor.getRowSpan(0, 1)); 687 assertEquals(1, gridProcessor.getRowSpan(1, 1)); 688 assertEquals(1, gridProcessor.getRowSpan(2, 1)); 689 } 690 691 707 public void testReduceColumnAndRowOneBigCell() { 708 Grid grid = new Grid(); 709 grid.setSize(3); 710 Label label = new Label("0"); 711 GridLayoutData layoutData = new GridLayoutData(); 712 layoutData.setColumnSpan(3); 713 layoutData.setRowSpan(5); 714 label.setLayoutData(layoutData); 715 grid.add(label); 716 717 GridProcessor gridProcessor = new GridProcessor(grid); 718 719 assertEquals(1, gridProcessor.getColumnCount()); 721 assertEquals(1, gridProcessor.getRowCount()); 722 723 assertEquals(0, gridProcessor.getComponentIndex(0, 0)); 725 726 assertEquals(1, gridProcessor.getColumnSpan(0, 0)); 728 assertEquals(1, gridProcessor.getRowSpan(0, 0)); 729 } 730 731 743 public void testRowSpanSimple() { 744 Grid grid = new Grid(); 745 for (int i = 0; i < 7; ++i) { 746 Label label = new Label(Integer.toString(i)); 747 if (i == 2) { 748 GridLayoutData layoutData = new GridLayoutData(); 749 layoutData.setRowSpan(2); 750 label.setLayoutData(layoutData); 751 } 752 grid.add(label); 753 } 754 755 GridProcessor gridProcessor = new GridProcessor(grid); 756 757 assertEquals(2, gridProcessor.getColumnCount()); 759 assertEquals(4, gridProcessor.getRowCount()); 760 761 assertEquals("0", ((Label) gridProcessor.getContent(0, 0)).getText()); 763 assertEquals("1", ((Label) gridProcessor.getContent(1, 0)).getText()); 764 assertEquals("2", ((Label) gridProcessor.getContent(0, 1)).getText()); 765 assertEquals("3", ((Label) gridProcessor.getContent(1, 1)).getText()); 766 assertEquals("2", ((Label) gridProcessor.getContent(0, 2)).getText()); 767 assertEquals("4", ((Label) gridProcessor.getContent(1, 2)).getText()); 768 assertEquals("5", ((Label) gridProcessor.getContent(0, 3)).getText()); 769 assertEquals("6", ((Label) gridProcessor.getContent(1, 3)).getText()); 770 } 771 772 786 public void testSimple() { 787 Grid grid = new Grid(); 788 for (int i = 0; i < 10; ++i) { 789 grid.add(new Label("test")); 790 } 791 792 GridProcessor gridProcessor = new GridProcessor(grid); 793 794 assertEquals(2, gridProcessor.getColumnCount()); 796 assertEquals(5, gridProcessor.getRowCount()); 797 } 798 799 816 public void testSimpleWithColumnSpan() { 817 Grid grid = new Grid(); 818 for (int i = 0; i < 10; ++i) { 819 Label label = new Label(); 820 if (i == 4) { 821 GridLayoutData layoutData = new GridLayoutData(); 822 layoutData.setColumnSpan(2); 823 label.setLayoutData(layoutData); 824 } 825 grid.add(label); 826 } 827 828 GridProcessor gridProcessor = new GridProcessor(grid); 829 830 assertEquals(2, gridProcessor.getColumnCount()); 832 assertEquals(6, gridProcessor.getRowCount()); 833 834 assertEquals(0, gridProcessor.getComponentIndex(0, 0)); 836 assertEquals(1, gridProcessor.getComponentIndex(1, 0)); 837 assertEquals(2, gridProcessor.getComponentIndex(0, 1)); 838 assertEquals(3, gridProcessor.getComponentIndex(1, 1)); 839 assertEquals(4, gridProcessor.getComponentIndex(0, 2)); 840 assertEquals(4, gridProcessor.getComponentIndex(1, 2)); 841 assertEquals(5, gridProcessor.getComponentIndex(0, 3)); 842 assertEquals(6, gridProcessor.getComponentIndex(1, 3)); 843 assertEquals(7, gridProcessor.getComponentIndex(0, 4)); 844 assertEquals(8, gridProcessor.getComponentIndex(1, 4)); 845 assertEquals(9, gridProcessor.getComponentIndex(0, 5)); 846 assertEquals(-1, gridProcessor.getComponentIndex(1, 5)); 847 848 assertEquals(1, gridProcessor.getColumnSpan(0, 0)); 850 assertEquals(1, gridProcessor.getColumnSpan(1, 0)); 851 assertEquals(1, gridProcessor.getColumnSpan(0, 1)); 852 assertEquals(1, gridProcessor.getColumnSpan(1, 1)); 853 assertEquals(2, gridProcessor.getColumnSpan(0, 2)); 854 assertEquals(2, gridProcessor.getColumnSpan(1, 2)); 855 assertEquals(1, gridProcessor.getColumnSpan(0, 3)); 856 assertEquals(1, gridProcessor.getColumnSpan(1, 3)); 857 assertEquals(1, gridProcessor.getColumnSpan(0, 4)); 858 assertEquals(1, gridProcessor.getColumnSpan(1, 4)); 859 assertEquals(1, gridProcessor.getColumnSpan(0, 5)); 860 assertEquals(-1, gridProcessor.getColumnSpan(1, 5)); 861 862 assertEquals(1, gridProcessor.getRowSpan(0, 0)); 864 assertEquals(1, gridProcessor.getRowSpan(1, 0)); 865 assertEquals(1, gridProcessor.getRowSpan(0, 1)); 866 assertEquals(1, gridProcessor.getRowSpan(1, 1)); 867 assertEquals(1, gridProcessor.getRowSpan(0, 2)); 868 assertEquals(1, gridProcessor.getRowSpan(1, 2)); 869 assertEquals(1, gridProcessor.getRowSpan(0, 3)); 870 assertEquals(1, gridProcessor.getRowSpan(1, 3)); 871 assertEquals(1, gridProcessor.getRowSpan(0, 4)); 872 assertEquals(1, gridProcessor.getRowSpan(1, 4)); 873 assertEquals(1, gridProcessor.getRowSpan(0, 5)); 874 assertEquals(-1, gridProcessor.getRowSpan(1, 5)); 875 } 876 877 894 public void testSimpleWithOversidedColumnSpan() { 895 Grid grid = new Grid(); 896 for (int i = 0; i < 10; ++i) { 897 Label label = new Label(); 898 if (i == 4) { 899 GridLayoutData layoutData = new GridLayoutData(); 900 layoutData.setColumnSpan(3); 901 label.setLayoutData(layoutData); 902 } 903 grid.add(label); 904 } 905 906 GridProcessor gridProcessor = new GridProcessor(grid); 907 908 assertEquals(2, gridProcessor.getColumnCount()); 910 assertEquals(6, gridProcessor.getRowCount()); 911 912 assertEquals(0, gridProcessor.getComponentIndex(0, 0)); 914 assertEquals(1, gridProcessor.getComponentIndex(1, 0)); 915 assertEquals(2, gridProcessor.getComponentIndex(0, 1)); 916 assertEquals(3, gridProcessor.getComponentIndex(1, 1)); 917 assertEquals(4, gridProcessor.getComponentIndex(0, 2)); 918 assertEquals(4, gridProcessor.getComponentIndex(1, 2)); 919 assertEquals(5, gridProcessor.getComponentIndex(0, 3)); 920 assertEquals(6, gridProcessor.getComponentIndex(1, 3)); 921 assertEquals(7, gridProcessor.getComponentIndex(0, 4)); 922 assertEquals(8, gridProcessor.getComponentIndex(1, 4)); 923 assertEquals(9, gridProcessor.getComponentIndex(0, 5)); 924 assertEquals(-1, gridProcessor.getComponentIndex(1, 5)); 925 926 assertEquals(1, gridProcessor.getColumnSpan(0, 0)); 929 assertEquals(1, gridProcessor.getColumnSpan(1, 0)); 930 assertEquals(1, gridProcessor.getColumnSpan(0, 1)); 931 assertEquals(1, gridProcessor.getColumnSpan(1, 1)); 932 assertEquals(2, gridProcessor.getColumnSpan(0, 2)); 933 assertEquals(2, gridProcessor.getColumnSpan(1, 2)); 934 assertEquals(1, gridProcessor.getColumnSpan(0, 3)); 935 assertEquals(1, gridProcessor.getColumnSpan(1, 3)); 936 assertEquals(1, gridProcessor.getColumnSpan(0, 4)); 937 assertEquals(1, gridProcessor.getColumnSpan(1, 4)); 938 assertEquals(1, gridProcessor.getColumnSpan(0, 5)); 939 assertEquals(-1, gridProcessor.getColumnSpan(1, 5)); 940 941 assertEquals(1, gridProcessor.getRowSpan(0, 0)); 943 assertEquals(1, gridProcessor.getRowSpan(1, 0)); 944 assertEquals(1, gridProcessor.getRowSpan(0, 1)); 945 assertEquals(1, gridProcessor.getRowSpan(1, 1)); 946 assertEquals(1, gridProcessor.getRowSpan(0, 2)); 947 assertEquals(1, gridProcessor.getRowSpan(1, 2)); 948 assertEquals(1, gridProcessor.getRowSpan(0, 3)); 949 assertEquals(1, gridProcessor.getRowSpan(1, 3)); 950 assertEquals(1, gridProcessor.getRowSpan(0, 4)); 951 assertEquals(1, gridProcessor.getRowSpan(1, 4)); 952 assertEquals(1, gridProcessor.getRowSpan(0, 5)); 953 assertEquals(-1, gridProcessor.getRowSpan(1, 5)); 954 } 955 956 966 public void testStaggeredSpans() { 967 Grid grid = new Grid(); 968 for (int i = 0; i < 4; ++i) { 969 Label label = new Label(); 970 if (i % 2 == 0) { 971 GridLayoutData gridLayoutData = new GridLayoutData(); 972 gridLayoutData.setRowSpan(2); 973 label.setLayoutData(gridLayoutData); 974 } 975 grid.add(label); 976 } 977 978 GridProcessor gridProcessor = new GridProcessor(grid); 979 980 assertEquals(2, gridProcessor.getColumnCount()); 982 assertEquals(3, gridProcessor.getRowCount()); 983 984 assertEquals(0, gridProcessor.getComponentIndex(0, 0)); 986 assertEquals(1, gridProcessor.getComponentIndex(1, 0)); 987 assertEquals(0, gridProcessor.getComponentIndex(0, 1)); 988 assertEquals(2, gridProcessor.getComponentIndex(1, 1)); 989 assertEquals(3, gridProcessor.getComponentIndex(0, 2)); 990 assertEquals(2, gridProcessor.getComponentIndex(1, 2)); 991 992 assertEquals(1, gridProcessor.getColumnSpan(0, 0)); 994 assertEquals(1, gridProcessor.getColumnSpan(1, 0)); 995 assertEquals(1, gridProcessor.getColumnSpan(0, 1)); 996 assertEquals(1, gridProcessor.getColumnSpan(1, 1)); 997 assertEquals(1, gridProcessor.getColumnSpan(0, 2)); 998 assertEquals(1, gridProcessor.getColumnSpan(1, 2)); 999 1000 assertEquals(2, gridProcessor.getRowSpan(0, 0)); 1002 assertEquals(1, gridProcessor.getRowSpan(1, 0)); 1003 assertEquals(2, gridProcessor.getRowSpan(0, 1)); 1004 assertEquals(2, gridProcessor.getRowSpan(1, 1)); 1005 assertEquals(1, gridProcessor.getRowSpan(0, 2)); 1006 assertEquals(2, gridProcessor.getRowSpan(1, 2)); 1007 } 1008} 1009 | Popular Tags |