1 44 45 package org.jfree.layout; 46 47 import java.awt.Component ; 48 import java.awt.Container ; 49 import java.awt.Dimension ; 50 import java.awt.Insets ; 51 import java.awt.LayoutManager ; 52 import java.io.Serializable ; 53 54 60 public class FormatLayout implements LayoutManager , Serializable { 61 62 63 private static final long serialVersionUID = 2866692886323930722L; 64 65 66 public static final int C = 1; 67 68 69 public static final int LC = 2; 70 71 72 public static final int LCB = 3; 73 74 75 public static final int LCLC = 4; 76 77 78 public static final int LCLCB = 5; 79 80 81 public static final int LCBLC = 6; 82 83 84 public static final int LCBLCB = 7; 85 86 87 private int[] rowFormats; 88 89 90 private int rowGap; 91 92 95 private int[] columnGaps; 96 97 98 private int[] rowHeights; 99 100 101 private int totalHeight; 102 103 104 private int[] columnWidths; 105 106 107 private int totalWidth; 108 109 110 private int columns1and2Width; 111 112 113 private int columns4and5Width; 114 115 116 private int columns1to4Width; 117 118 119 private int columns1to5Width; 120 121 122 private int columns0to5Width; 123 124 178 public FormatLayout(final int rowCount, final int[] rowFormats) { 179 180 this.rowFormats = rowFormats; 181 this.rowGap = 2; 182 this.columnGaps = new int[5]; 183 this.columnGaps[0] = 10; 184 this.columnGaps[1] = 5; 185 this.columnGaps[2] = 5; 186 this.columnGaps[3] = 10; 187 this.columnGaps[4] = 5; 188 189 this.rowHeights = new int[rowCount]; 191 this.columnWidths = new int[6]; 192 } 193 194 201 public Dimension preferredLayoutSize(final Container parent) { 202 203 Component c0, c1, c2, c3, c4, c5; 204 205 synchronized (parent.getTreeLock()) { 206 final Insets insets = parent.getInsets(); 207 int componentIndex = 0; 208 final int rowCount = this.rowHeights.length; 209 for (int i = 0; i < this.columnWidths.length; i++) { 210 this.columnWidths[i] = 0; 211 } 212 this.columns1and2Width = 0; 213 this.columns4and5Width = 0; 214 this.columns1to4Width = 0; 215 this.columns1to5Width = 0; 216 this.columns0to5Width = 0; 217 218 this.totalHeight = 0; 219 for (int rowIndex = 0; rowIndex < rowCount; rowIndex++) { 220 final int format 221 = this.rowFormats[rowIndex % this.rowFormats.length]; 222 switch (format) { 223 case FormatLayout.C: 224 c0 = parent.getComponent(componentIndex); 225 updateC(rowIndex, c0.getPreferredSize()); 226 componentIndex = componentIndex + 1; 227 break; 228 case FormatLayout.LC: 229 c0 = parent.getComponent(componentIndex); 230 c1 = parent.getComponent(componentIndex + 1); 231 updateLC(rowIndex, c0.getPreferredSize(), 232 c1.getPreferredSize()); 233 componentIndex = componentIndex + 2; 234 break; 235 case FormatLayout.LCB: 236 c0 = parent.getComponent(componentIndex); 237 c1 = parent.getComponent(componentIndex + 1); 238 c2 = parent.getComponent(componentIndex + 2); 239 updateLCB(rowIndex, 240 c0.getPreferredSize(), 241 c1.getPreferredSize(), 242 c2.getPreferredSize()); 243 componentIndex = componentIndex + 3; 244 break; 245 case FormatLayout.LCLC: 246 c0 = parent.getComponent(componentIndex); 247 c1 = parent.getComponent(componentIndex + 1); 248 c2 = parent.getComponent(componentIndex + 2); 249 c3 = parent.getComponent(componentIndex + 3); 250 updateLCLC(rowIndex, 251 c0.getPreferredSize(), 252 c1.getPreferredSize(), 253 c2.getPreferredSize(), 254 c3.getPreferredSize()); 255 componentIndex = componentIndex + 4; 256 break; 257 case FormatLayout.LCBLC: 258 c0 = parent.getComponent(componentIndex); 259 c1 = parent.getComponent(componentIndex + 1); 260 c2 = parent.getComponent(componentIndex + 2); 261 c3 = parent.getComponent(componentIndex + 3); 262 c4 = parent.getComponent(componentIndex + 4); 263 updateLCBLC(rowIndex, 264 c0.getPreferredSize(), 265 c1.getPreferredSize(), 266 c2.getPreferredSize(), 267 c3.getPreferredSize(), 268 c4.getPreferredSize()); 269 componentIndex = componentIndex + 5; 270 break; 271 case FormatLayout.LCLCB: 272 c0 = parent.getComponent(componentIndex); 273 c1 = parent.getComponent(componentIndex + 1); 274 c2 = parent.getComponent(componentIndex + 2); 275 c3 = parent.getComponent(componentIndex + 3); 276 c4 = parent.getComponent(componentIndex + 4); 277 updateLCLCB(rowIndex, 278 c0.getPreferredSize(), 279 c1.getPreferredSize(), 280 c2.getPreferredSize(), 281 c3.getPreferredSize(), 282 c4.getPreferredSize()); 283 componentIndex = componentIndex + 5; 284 break; 285 case FormatLayout.LCBLCB: 286 c0 = parent.getComponent(componentIndex); 287 c1 = parent.getComponent(componentIndex + 1); 288 c2 = parent.getComponent(componentIndex + 2); 289 c3 = parent.getComponent(componentIndex + 3); 290 c4 = parent.getComponent(componentIndex + 4); 291 c5 = parent.getComponent(componentIndex + 5); 292 updateLCBLCB(rowIndex, 293 c0.getPreferredSize(), 294 c1.getPreferredSize(), 295 c2.getPreferredSize(), 296 c3.getPreferredSize(), 297 c4.getPreferredSize(), 298 c5.getPreferredSize()); 299 componentIndex = componentIndex + 6; 300 break; 301 } 302 } 303 complete(); 304 return new Dimension (this.totalWidth + insets.left + insets.right, 305 this.totalHeight + (rowCount - 1) * this.rowGap 306 + insets.top + insets.bottom); 307 } 308 } 309 310 317 public Dimension minimumLayoutSize(final Container parent) { 318 319 Component c0, c1, c2, c3, c4, c5; 320 321 synchronized (parent.getTreeLock()) { 322 final Insets insets = parent.getInsets(); 323 int componentIndex = 0; 324 final int rowCount = this.rowHeights.length; 325 for (int i = 0; i < this.columnWidths.length; i++) { 326 this.columnWidths[i] = 0; 327 } 328 this.columns1and2Width = 0; 329 this.columns4and5Width = 0; 330 this.columns1to4Width = 0; 331 this.columns1to5Width = 0; 332 this.columns0to5Width = 0; 333 final int totalHeight = 0; 334 for (int rowIndex = 0; rowIndex < rowCount; rowIndex++) { 335 336 final int format 337 = this.rowFormats[rowIndex % this.rowFormats.length]; 338 339 switch (format) { 340 case FormatLayout.C: 341 c0 = parent.getComponent(componentIndex); 342 this.columns0to5Width = Math.max( 343 this.columns0to5Width, c0.getMinimumSize().width 344 ); 345 componentIndex = componentIndex + 1; 346 break; 347 case FormatLayout.LC: 348 c0 = parent.getComponent(componentIndex); 349 c1 = parent.getComponent(componentIndex + 1); 350 updateLC(rowIndex, 351 c0.getMinimumSize(), 352 c1.getMinimumSize()); 353 componentIndex = componentIndex + 2; 354 break; 355 case FormatLayout.LCB: 356 c0 = parent.getComponent(componentIndex); 357 c1 = parent.getComponent(componentIndex + 1); 358 c2 = parent.getComponent(componentIndex + 2); 359 updateLCB(rowIndex, 360 c0.getMinimumSize(), 361 c1.getMinimumSize(), 362 c2.getMinimumSize()); 363 componentIndex = componentIndex + 3; 364 break; 365 case FormatLayout.LCLC: 366 c0 = parent.getComponent(componentIndex); 367 c1 = parent.getComponent(componentIndex + 1); 368 c2 = parent.getComponent(componentIndex + 2); 369 c3 = parent.getComponent(componentIndex + 3); 370 updateLCLC(rowIndex, 371 c0.getMinimumSize(), 372 c1.getMinimumSize(), 373 c2.getMinimumSize(), 374 c3.getMinimumSize()); 375 componentIndex = componentIndex + 3; 376 break; 377 case FormatLayout.LCBLC: 378 c0 = parent.getComponent(componentIndex); 379 c1 = parent.getComponent(componentIndex + 1); 380 c2 = parent.getComponent(componentIndex + 2); 381 c3 = parent.getComponent(componentIndex + 3); 382 c4 = parent.getComponent(componentIndex + 4); 383 updateLCBLC(rowIndex, 384 c0.getMinimumSize(), 385 c1.getMinimumSize(), 386 c2.getMinimumSize(), 387 c3.getMinimumSize(), 388 c4.getMinimumSize()); 389 componentIndex = componentIndex + 4; 390 break; 391 case FormatLayout.LCLCB: 392 c0 = parent.getComponent(componentIndex); 393 c1 = parent.getComponent(componentIndex + 1); 394 c2 = parent.getComponent(componentIndex + 2); 395 c3 = parent.getComponent(componentIndex + 3); 396 c4 = parent.getComponent(componentIndex + 4); 397 updateLCLCB(rowIndex, 398 c0.getMinimumSize(), 399 c1.getMinimumSize(), 400 c2.getMinimumSize(), 401 c3.getMinimumSize(), 402 c4.getMinimumSize()); 403 componentIndex = componentIndex + 4; 404 break; 405 case FormatLayout.LCBLCB: 406 c0 = parent.getComponent(componentIndex); 407 c1 = parent.getComponent(componentIndex + 1); 408 c2 = parent.getComponent(componentIndex + 2); 409 c3 = parent.getComponent(componentIndex + 3); 410 c4 = parent.getComponent(componentIndex + 4); 411 c5 = parent.getComponent(componentIndex + 5); 412 updateLCBLCB(rowIndex, 413 c0.getMinimumSize(), 414 c1.getMinimumSize(), 415 c2.getMinimumSize(), 416 c3.getMinimumSize(), 417 c4.getMinimumSize(), 418 c5.getMinimumSize()); 419 componentIndex = componentIndex + 5; 420 break; 421 } 422 } 423 complete(); 424 return new Dimension (this.totalWidth + insets.left + insets.right, 425 totalHeight + (rowCount - 1) * this.rowGap 426 + insets.top + insets.bottom); 427 } 428 } 429 430 435 public void layoutContainer(final Container parent) { 436 Component c0, c1, c2, c3, c4, c5; 437 438 synchronized (parent.getTreeLock()) { 439 final Insets insets = parent.getInsets(); 440 int componentIndex = 0; 441 final int rowCount = this.rowHeights.length; 442 for (int i = 0; i < this.columnWidths.length; i++) { 443 this.columnWidths[i] = 0; 444 } 445 this.columns1and2Width = 0; 446 this.columns4and5Width = 0; 447 this.columns1to4Width = 0; 448 this.columns1to5Width = 0; 449 this.columns0to5Width 450 = parent.getBounds().width - insets.left - insets.right; 451 452 this.totalHeight = 0; 453 for (int rowIndex = 0; rowIndex < rowCount; rowIndex++) { 454 final int format 455 = this.rowFormats[rowIndex % this.rowFormats.length]; 456 switch (format) { 457 case FormatLayout.C: 458 c0 = parent.getComponent(componentIndex); 459 updateC(rowIndex, c0.getPreferredSize()); 460 componentIndex = componentIndex + 1; 461 break; 462 case FormatLayout.LC: 463 c0 = parent.getComponent(componentIndex); 464 c1 = parent.getComponent(componentIndex + 1); 465 updateLC(rowIndex, c0.getPreferredSize(), 466 c1.getPreferredSize()); 467 componentIndex = componentIndex + 2; 468 break; 469 case FormatLayout.LCB: 470 c0 = parent.getComponent(componentIndex); 471 c1 = parent.getComponent(componentIndex + 1); 472 c2 = parent.getComponent(componentIndex + 2); 473 updateLCB(rowIndex, 474 c0.getPreferredSize(), 475 c1.getPreferredSize(), 476 c2.getPreferredSize()); 477 componentIndex = componentIndex + 3; 478 break; 479 case FormatLayout.LCLC: 480 c0 = parent.getComponent(componentIndex); 481 c1 = parent.getComponent(componentIndex + 1); 482 c2 = parent.getComponent(componentIndex + 2); 483 c3 = parent.getComponent(componentIndex + 3); 484 updateLCLC(rowIndex, 485 c0.getPreferredSize(), 486 c1.getPreferredSize(), 487 c2.getPreferredSize(), 488 c3.getPreferredSize()); 489 componentIndex = componentIndex + 4; 490 break; 491 case FormatLayout.LCBLC: 492 c0 = parent.getComponent(componentIndex); 493 c1 = parent.getComponent(componentIndex + 1); 494 c2 = parent.getComponent(componentIndex + 2); 495 c3 = parent.getComponent(componentIndex + 3); 496 c4 = parent.getComponent(componentIndex + 4); 497 updateLCBLC(rowIndex, 498 c0.getPreferredSize(), 499 c1.getPreferredSize(), 500 c2.getPreferredSize(), 501 c3.getPreferredSize(), 502 c4.getPreferredSize()); 503 componentIndex = componentIndex + 5; 504 break; 505 case FormatLayout.LCLCB: 506 c0 = parent.getComponent(componentIndex); 507 c1 = parent.getComponent(componentIndex + 1); 508 c2 = parent.getComponent(componentIndex + 2); 509 c3 = parent.getComponent(componentIndex + 3); 510 c4 = parent.getComponent(componentIndex + 4); 511 updateLCLCB(rowIndex, 512 c0.getPreferredSize(), 513 c1.getPreferredSize(), 514 c2.getPreferredSize(), 515 c3.getPreferredSize(), 516 c4.getPreferredSize()); 517 componentIndex = componentIndex + 5; 518 break; 519 case FormatLayout.LCBLCB: 520 c0 = parent.getComponent(componentIndex); 521 c1 = parent.getComponent(componentIndex + 1); 522 c2 = parent.getComponent(componentIndex + 2); 523 c3 = parent.getComponent(componentIndex + 3); 524 c4 = parent.getComponent(componentIndex + 4); 525 c5 = parent.getComponent(componentIndex + 5); 526 updateLCBLCB(rowIndex, 527 c0.getPreferredSize(), 528 c1.getPreferredSize(), 529 c2.getPreferredSize(), 530 c3.getPreferredSize(), 531 c4.getPreferredSize(), 532 c5.getPreferredSize()); 533 componentIndex = componentIndex + 6; 534 break; 535 } 536 } 537 complete(); 538 539 componentIndex = 0; 540 int rowY = insets.top; 541 final int[] rowX = new int[6]; 542 rowX[0] = insets.left; 543 rowX[1] = rowX[0] + this.columnWidths[0] + this.columnGaps[0]; 544 rowX[2] = rowX[1] + this.columnWidths[1] + this.columnGaps[1]; 545 rowX[3] = rowX[2] + this.columnWidths[2] + this.columnGaps[2]; 546 rowX[4] = rowX[3] + this.columnWidths[3] + this.columnGaps[3]; 547 rowX[5] = rowX[4] + this.columnWidths[4] + this.columnGaps[4]; 548 final int w1to2 = this.columnWidths[1] + this.columnGaps[1] 549 + this.columnWidths[2]; 550 final int w4to5 = this.columnWidths[4] + this.columnGaps[4] 551 + this.columnWidths[5]; 552 final int w1to4 = w1to2 + this.columnGaps[2] + this.columnWidths[3] 553 + this.columnGaps[3] + this.columnWidths[4]; 554 final int w1to5 = w1to4 + this.columnGaps[4] + this.columnWidths[5]; 555 final int w0to5 = w1to5 + this.columnWidths[0] + this.columnGaps[0]; 556 for (int rowIndex = 0; rowIndex < rowCount; rowIndex++) { 557 final int format 558 = this.rowFormats[rowIndex % this.rowFormats.length]; 559 560 switch (format) { 561 case FormatLayout.C: 562 c0 = parent.getComponent(componentIndex); 563 c0.setBounds(rowX[0], rowY, w0to5, 564 c0.getPreferredSize().height); 565 componentIndex = componentIndex + 1; 566 break; 567 case FormatLayout.LC: 568 c0 = parent.getComponent(componentIndex); 569 c0.setBounds( 570 rowX[0], 571 rowY + (this.rowHeights[rowIndex] 572 - c0.getPreferredSize().height) / 2, 573 this.columnWidths[0], c0.getPreferredSize().height 574 ); 575 c1 = parent.getComponent(componentIndex + 1); 576 c1.setBounds( 577 rowX[1], 578 rowY + (this.rowHeights[rowIndex] 579 - c1.getPreferredSize().height) / 2, 580 w1to5, c1.getPreferredSize().height 581 ); 582 componentIndex = componentIndex + 2; 583 break; 584 case FormatLayout.LCB: 585 c0 = parent.getComponent(componentIndex); 586 c0.setBounds( 587 rowX[0], 588 rowY + (this.rowHeights[rowIndex] 589 - c0.getPreferredSize().height) / 2, 590 this.columnWidths[0], c0.getPreferredSize().height 591 ); 592 c1 = parent.getComponent(componentIndex + 1); 593 c1.setBounds( 594 rowX[1], 595 rowY + (this.rowHeights[rowIndex] 596 - c1.getPreferredSize().height) / 2, 597 w1to4, c1.getPreferredSize().height 598 ); 599 c2 = parent.getComponent(componentIndex + 2); 600 c2.setBounds( 601 rowX[5], 602 rowY + (this.rowHeights[rowIndex] 603 - c2.getPreferredSize().height) / 2, 604 this.columnWidths[5], c2.getPreferredSize().height 605 ); 606 componentIndex = componentIndex + 3; 607 break; 608 case FormatLayout.LCLC: 609 c0 = parent.getComponent(componentIndex); 610 c0.setBounds( 611 rowX[0], 612 rowY + (this.rowHeights[rowIndex] 613 - c0.getPreferredSize().height) / 2, 614 this.columnWidths[0], c0.getPreferredSize().height 615 ); 616 c1 = parent.getComponent(componentIndex + 1); 617 c1.setBounds( 618 rowX[1], 619 rowY + (this.rowHeights[rowIndex] 620 - c1.getPreferredSize().height) / 2, 621 w1to2, c1.getPreferredSize().height 622 ); 623 c2 = parent.getComponent(componentIndex + 2); 624 c2.setBounds( 625 rowX[3], 626 rowY + (this.rowHeights[rowIndex] 627 - c2.getPreferredSize().height) / 2, 628 this.columnWidths[3], c2.getPreferredSize().height 629 ); 630 c3 = parent.getComponent(componentIndex + 3); 631 c3.setBounds( 632 rowX[4], 633 rowY + (this.rowHeights[rowIndex] 634 - c3.getPreferredSize().height) / 2, 635 w4to5, c3.getPreferredSize().height 636 ); 637 componentIndex = componentIndex + 4; 638 break; 639 case FormatLayout.LCBLC: 640 c0 = parent.getComponent(componentIndex); 641 c0.setBounds( 642 rowX[0], 643 rowY + (this.rowHeights[rowIndex] 644 - c0.getPreferredSize().height) / 2, 645 this.columnWidths[0], c0.getPreferredSize().height 646 ); 647 c1 = parent.getComponent(componentIndex + 1); 648 c1.setBounds( 649 rowX[1], 650 rowY + (this.rowHeights[rowIndex] 651 - c1.getPreferredSize().height) / 2, 652 this.columnWidths[1], c1.getPreferredSize().height 653 ); 654 c2 = parent.getComponent(componentIndex + 2); 655 c2.setBounds( 656 rowX[2], 657 rowY + (this.rowHeights[rowIndex] 658 - c2.getPreferredSize().height) / 2, 659 this.columnWidths[2], c2.getPreferredSize().height 660 ); 661 c3 = parent.getComponent(componentIndex + 3); 662 c3.setBounds( 663 rowX[3], 664 rowY + (this.rowHeights[rowIndex] 665 - c3.getPreferredSize().height) / 2, 666 this.columnWidths[3], c3.getPreferredSize().height 667 ); 668 c4 = parent.getComponent(componentIndex + 4); 669 c4.setBounds( 670 rowX[4], 671 rowY + (this.rowHeights[rowIndex] 672 - c4.getPreferredSize().height) / 2, 673 w4to5, c4.getPreferredSize().height 674 ); 675 componentIndex = componentIndex + 5; 676 break; 677 case FormatLayout.LCLCB: 678 c0 = parent.getComponent(componentIndex); 679 c0.setBounds( 680 rowX[0], 681 rowY + (this.rowHeights[rowIndex] 682 - c0.getPreferredSize().height) / 2, 683 this.columnWidths[0], c0.getPreferredSize().height 684 ); 685 c1 = parent.getComponent(componentIndex + 1); 686 c1.setBounds( 687 rowX[1], 688 rowY + (this.rowHeights[rowIndex] 689 - c1.getPreferredSize().height) / 2, 690 w1to2, c1.getPreferredSize().height 691 ); 692 c2 = parent.getComponent(componentIndex + 2); 693 c2.setBounds( 694 rowX[3], 695 rowY + (this.rowHeights[rowIndex] 696 - c2.getPreferredSize().height) / 2, 697 this.columnWidths[3], c2.getPreferredSize().height 698 ); 699 c3 = parent.getComponent(componentIndex + 3); 700 c3.setBounds( 701 rowX[4], 702 rowY + (this.rowHeights[rowIndex] 703 - c3.getPreferredSize().height) / 2, 704 this.columnWidths[4], c3.getPreferredSize().height 705 ); 706 c4 = parent.getComponent(componentIndex + 4); 707 c4.setBounds( 708 rowX[5], 709 rowY + (this.rowHeights[rowIndex] 710 - c4.getPreferredSize().height) / 2, 711 this.columnWidths[5], c4.getPreferredSize().height 712 ); 713 componentIndex = componentIndex + 5; 714 break; 715 case FormatLayout.LCBLCB: 716 c0 = parent.getComponent(componentIndex); 717 c0.setBounds( 718 rowX[0], 719 rowY + (this.rowHeights[rowIndex] 720 - c0.getPreferredSize().height) / 2, 721 this.columnWidths[0], c0.getPreferredSize().height 722 ); 723 c1 = parent.getComponent(componentIndex + 1); 724 c1.setBounds( 725 rowX[1], 726 rowY + (this.rowHeights[rowIndex] 727 - c1.getPreferredSize().height) / 2, 728 this.columnWidths[1], c1.getPreferredSize().height 729 ); 730 c2 = parent.getComponent(componentIndex + 2); 731 c2.setBounds( 732 rowX[2], 733 rowY + (this.rowHeights[rowIndex] 734 - c2.getPreferredSize().height) / 2, 735 this.columnWidths[2], c2.getPreferredSize().height 736 ); 737 c3 = parent.getComponent(componentIndex + 3); 738 c3.setBounds( 739 rowX[3], 740 rowY + (this.rowHeights[rowIndex] 741 - c3.getPreferredSize().height) / 2, 742 this.columnWidths[3], c3.getPreferredSize().height 743 ); 744 c4 = parent.getComponent(componentIndex + 4); 745 c4.setBounds( 746 rowX[4], 747 rowY + (this.rowHeights[rowIndex] 748 - c4.getPreferredSize().height) / 2, 749 this.columnWidths[4], c4.getPreferredSize().height 750 ); 751 c5 = parent.getComponent(componentIndex + 5); 752 c5.setBounds( 753 rowX[5], 754 rowY + (this.rowHeights[rowIndex] 755 - c5.getPreferredSize().height) / 2, 756 this.columnWidths[5], c5.getPreferredSize().height 757 ); 758 componentIndex = componentIndex + 6; 759 break; 760 } 761 rowY = rowY + this.rowHeights[rowIndex] + this.rowGap; 762 } 763 } 764 } 765 766 772 protected void updateC(final int rowIndex, final Dimension d0) { 773 this.rowHeights[rowIndex] = d0.height; 774 this.totalHeight = this.totalHeight + this.rowHeights[rowIndex]; 775 this.columns0to5Width = Math.max(this.columns0to5Width, d0.width); 776 } 777 778 785 protected void updateLC(final int rowIndex, final Dimension d0, 786 final Dimension d1) { 787 788 this.rowHeights[rowIndex] = Math.max(d0.height, d1.height); 789 this.totalHeight = this.totalHeight + this.rowHeights[rowIndex]; 790 this.columnWidths[0] = Math.max(this.columnWidths[0], d0.width); 791 this.columns1to5Width = Math.max(this.columns1to5Width, d1.width); 792 793 } 794 795 803 protected void updateLCB(final int rowIndex, 804 final Dimension d0, final Dimension d1, 805 final Dimension d2) { 806 807 this.rowHeights[rowIndex] 808 = Math.max(d0.height, Math.max(d1.height, d2.height)); 809 this.totalHeight = this.totalHeight + this.rowHeights[rowIndex]; 810 this.columnWidths[0] = Math.max(this.columnWidths[0], d0.width); 811 this.columns1to4Width = Math.max(this.columns1to4Width, d1.width); 812 this.columnWidths[5] = Math.max(this.columnWidths[5], d2.width); 813 814 } 815 816 825 protected void updateLCLC(final int rowIndex, final Dimension d0, 826 final Dimension d1, final Dimension d2, 827 final Dimension d3) { 828 829 this.rowHeights[rowIndex] = Math.max(Math.max(d0.height, d1.height), 830 Math.max(d2.height, d3.height)); 831 this.totalHeight = this.totalHeight + this.rowHeights[rowIndex]; 832 this.columnWidths[0] = Math.max(this.columnWidths[0], d0.width); 833 this.columns1and2Width = Math.max(this.columns1and2Width, d1.width); 834 this.columnWidths[3] = Math.max(this.columnWidths[3], d2.width); 835 this.columns4and5Width = Math.max(this.columns4and5Width, d3.width); 836 } 837 838 848 protected void updateLCBLC(final int rowIndex, final Dimension d0, 849 final Dimension d1, final Dimension d2, 850 final Dimension d3, final Dimension d4) { 851 852 this.rowHeights[rowIndex] = (Math.max( 853 d0.height, 854 Math.max(Math.max(d1.height, d2.height), 855 Math.max(d3.height, d4.height))) 856 ); 857 this.totalHeight = this.totalHeight + this.rowHeights[rowIndex]; 858 this.columnWidths[0] = Math.max(this.columnWidths[0], d0.width); 859 this.columnWidths[1] = Math.max(this.columnWidths[1], d1.width); 860 this.columnWidths[2] = Math.max(this.columnWidths[2], d2.width); 861 this.columnWidths[3] = Math.max(this.columnWidths[3], d3.width); 862 this.columns4and5Width = Math.max(this.columns4and5Width, d4.width); 863 864 } 865 866 876 protected void updateLCLCB(final int rowIndex, final Dimension d0, 877 final Dimension d1, final Dimension d2, 878 final Dimension d3, final Dimension d4) { 879 880 this.rowHeights[rowIndex] = (Math.max(d0.height, 881 Math.max(Math.max(d1.height, d2.height), 882 Math.max(d3.height, d4.height)))); 883 this.totalHeight = this.totalHeight + this.rowHeights[rowIndex]; 884 this.columnWidths[0] = Math.max(this.columnWidths[0], d0.width); 885 this.columns1and2Width = Math.max(this.columns1and2Width, d1.width); 886 this.columnWidths[3] = Math.max(this.columnWidths[3], d2.width); 887 this.columnWidths[4] = Math.max(this.columnWidths[4], d3.width); 888 this.columnWidths[5] = Math.max(this.columnWidths[5], d4.width); 889 890 } 891 892 903 protected void updateLCBLCB(final int rowIndex, 904 final Dimension d0, final Dimension d1, 905 final Dimension d2, 906 final Dimension d3, final Dimension d4, 907 final Dimension d5) { 908 909 this.rowHeights[rowIndex] = Math.max( 910 Math.max(d0.height, d1.height), 911 Math.max(Math.max(d2.height, d3.height), 912 Math.max(d4.height, d5.height)) 913 ); 914 this.totalHeight = this.totalHeight + this.rowHeights[rowIndex]; 915 this.columnWidths[0] = Math.max(this.columnWidths[0], d0.width); 916 this.columnWidths[1] = Math.max(this.columnWidths[1], d1.width); 917 this.columnWidths[2] = Math.max(this.columnWidths[2], d2.width); 918 this.columnWidths[3] = Math.max(this.columnWidths[3], d3.width); 919 this.columnWidths[4] = Math.max(this.columnWidths[4], d4.width); 920 this.columnWidths[5] = Math.max(this.columnWidths[5], d5.width); 921 922 } 923 924 927 public void complete() { 928 929 this.columnWidths[1] = Math.max( 930 this.columnWidths[1], 931 this.columns1and2Width - this.columnGaps[1] - this.columnWidths[2] 932 ); 933 934 this.columnWidths[4] = Math.max( 935 this.columnWidths[4], 936 Math.max( 937 this.columns4and5Width - this.columnGaps[4] 938 - this.columnWidths[5], 939 Math.max( 940 this.columns1to4Width - this.columnGaps[1] 941 - this.columnGaps[2] - this.columnGaps[3] 942 - this.columnWidths[1] - this.columnWidths[2] 943 - this.columnWidths[3], 944 this.columns1to5Width - this.columnGaps[1] 945 - this.columnGaps[2] - this.columnGaps[3] 946 - this.columnWidths[1] - this.columnWidths[2] 947 - this.columnWidths[3] - this.columnGaps[4] 948 ) 949 ) 950 ); 951 952 int leftWidth = this.columnWidths[0] + this.columnGaps[0] 953 + this.columnWidths[1] + this.columnGaps[1] 954 + this.columnWidths[2]; 955 956 int rightWidth = this.columnWidths[3] + this.columnGaps[3] 957 + this.columnWidths[4] + this.columnGaps[4] 958 + this.columnWidths[5]; 959 960 if (splitLayout()) { 961 if (leftWidth > rightWidth) { 962 final int mismatch = leftWidth - rightWidth; 963 this.columnWidths[4] = this.columnWidths[4] + mismatch; 964 rightWidth = rightWidth + mismatch; 965 } 966 else { 967 final int mismatch = rightWidth - leftWidth; 968 this.columnWidths[1] = this.columnWidths[1] + mismatch; 969 leftWidth = leftWidth + mismatch; 970 } 971 } 972 973 this.totalWidth = leftWidth + this.columnGaps[2] + rightWidth; 974 975 if (this.columns0to5Width > this.totalWidth) { 976 final int spaceToAdd = (this.columns0to5Width - this.totalWidth); 977 if (splitLayout()) { 978 final int halfSpaceToAdd = spaceToAdd / 2; 979 this.columnWidths[1] = this.columnWidths[1] + halfSpaceToAdd; 980 this.columnWidths[4] = this.columnWidths[4] + spaceToAdd 981 - halfSpaceToAdd; 982 this.totalWidth = this.totalWidth + spaceToAdd; 983 } 984 else { 985 this.columnWidths[1] = this.columnWidths[1] + spaceToAdd; 986 this.totalWidth = this.totalWidth + spaceToAdd; 987 } 988 } 989 990 } 991 992 998 private boolean splitLayout() { 999 for (int i = 0; i < this.rowFormats.length; i++) { 1000 if (this.rowFormats[i] > FormatLayout.LCB) { 1001 return true; 1002 } 1003 } 1004 return false; 1005 } 1006 1007 1012 public void addLayoutComponent(final Component comp) { 1013 } 1015 1016 1021 public void removeLayoutComponent(final Component comp) { 1022 } 1024 1025 1031 public void addLayoutComponent(final String name, final Component comp) { 1032 } 1034 1035 1041 public void removeLayoutComponent(final String name, final Component comp) { 1042 } 1044 1045} 1046 | Popular Tags |