modules/graphics/src/main/java/javafx/scene/layout/BorderPane.java

Print this page




 495             height = height < minHeight ? minHeight : height;
 496             final double minWidth = minWidth(height);
 497             width = width < minWidth ? minWidth : width;
 498         }
 499 
 500         final double insideX = insets.getLeft();
 501         final double insideY = insets.getTop();
 502         final double insideWidth = width - insideX - insets.getRight();
 503         final double insideHeight = height - insideY - insets.getBottom();
 504         final Node c = getCenter();
 505         final Node r = getRight();
 506         final Node b = getBottom();
 507         final Node l = getLeft();
 508         final Node t = getTop();
 509 
 510         double topHeight = 0;
 511         if (t != null && t.isManaged()) {
 512             Insets topMargin = getNodeMargin(t);
 513             double adjustedWidth = adjustWidthByMargin(insideWidth, topMargin);
 514             double adjustedHeight = adjustHeightByMargin(insideHeight, topMargin);
 515             topHeight = snapSize(t.prefHeight(adjustedWidth));
 516             topHeight = Math.min(topHeight, adjustedHeight);
 517             Vec2d result = boundedNodeSizeWithBias(t, adjustedWidth,
 518                    topHeight, true, true, TEMP_VEC2D);
 519             topHeight = snapSize(result.y);
 520             t.resize(snapSize(result.x), topHeight);
 521 
 522             topHeight = snapSpace(topMargin.getBottom()) + topHeight + snapSpace(topMargin.getTop());
 523             Pos alignment = getAlignment(t);
 524             positionInArea(t, insideX, insideY, insideWidth, topHeight, 0/*ignore baseline*/,
 525                     topMargin,
 526                     alignment != null? alignment.getHpos() : HPos.LEFT,
 527                     alignment != null? alignment.getVpos() : VPos.TOP, isSnapToPixel());
 528         }
 529 
 530         double bottomHeight = 0;
 531         if (b != null && b.isManaged()) {
 532             Insets bottomMargin = getNodeMargin(b);
 533             double adjustedWidth = adjustWidthByMargin(insideWidth, bottomMargin);
 534             double adjustedHeight = adjustHeightByMargin(insideHeight - topHeight, bottomMargin);
 535             bottomHeight = snapSize(b.prefHeight(adjustedWidth));
 536             bottomHeight = Math.min(bottomHeight, adjustedHeight);
 537             Vec2d result = boundedNodeSizeWithBias(b, adjustedWidth,
 538                     bottomHeight, true, true, TEMP_VEC2D);
 539             bottomHeight = snapSize(result.y);
 540             b.resize(snapSize(result.x), bottomHeight);
 541 
 542             bottomHeight = snapSpace(bottomMargin.getBottom()) + bottomHeight + snapSpace(bottomMargin.getTop());
 543             Pos alignment = getAlignment(b);
 544             positionInArea(b, insideX, insideY + insideHeight - bottomHeight,
 545                     insideWidth, bottomHeight, 0/*ignore baseline*/,
 546                     bottomMargin,
 547                     alignment != null? alignment.getHpos() : HPos.LEFT,
 548                     alignment != null? alignment.getVpos() : VPos.BOTTOM, isSnapToPixel());
 549         }
 550 
 551         double leftWidth = 0;
 552         if (l != null && l.isManaged()) {
 553             Insets leftMargin = getNodeMargin(l);
 554             double adjustedWidth = adjustWidthByMargin(insideWidth, leftMargin);
 555             double adjustedHeight = adjustHeightByMargin(insideHeight - topHeight - bottomHeight, leftMargin); // ????
 556             leftWidth = snapSize(l.prefWidth(adjustedHeight));
 557             leftWidth = Math.min(leftWidth, adjustedWidth);
 558             Vec2d result = boundedNodeSizeWithBias(l, leftWidth, adjustedHeight,
 559                     true, true, TEMP_VEC2D);
 560             leftWidth = snapSize(result.x);
 561             l.resize(leftWidth, snapSize(result.y));
 562 
 563             leftWidth = snapSpace(leftMargin.getLeft()) + leftWidth + snapSpace(leftMargin.getRight());
 564             Pos alignment = getAlignment(l);
 565             positionInArea(l, insideX, insideY + topHeight,
 566                     leftWidth, insideHeight - topHeight - bottomHeight, 0/*ignore baseline*/,
 567                     leftMargin,
 568                     alignment != null? alignment.getHpos() : HPos.LEFT,
 569                     alignment != null? alignment.getVpos() : VPos.TOP, isSnapToPixel());
 570         }
 571 
 572         double rightWidth = 0;
 573         if (r != null && r.isManaged()) {
 574             Insets rightMargin = getNodeMargin(r);
 575             double adjustedWidth = adjustWidthByMargin(insideWidth - leftWidth, rightMargin);
 576             double adjustedHeight = adjustHeightByMargin(insideHeight - topHeight - bottomHeight, rightMargin);
 577 
 578             rightWidth = snapSize(r.prefWidth(adjustedHeight));
 579             rightWidth = Math.min(rightWidth, adjustedWidth);
 580             Vec2d result = boundedNodeSizeWithBias(r, rightWidth, adjustedHeight,
 581                     true, true, TEMP_VEC2D);
 582             rightWidth = snapSize(result.x);
 583             r.resize(rightWidth, snapSize(result.y));
 584 
 585             rightWidth = snapSpace(rightMargin.getLeft()) + rightWidth + snapSpace(rightMargin.getRight());
 586             Pos alignment = getAlignment(r);
 587             positionInArea(r, insideX + insideWidth - rightWidth, insideY + topHeight,
 588                     rightWidth, insideHeight - topHeight - bottomHeight, 0/*ignore baseline*/,
 589                     rightMargin,
 590                     alignment != null? alignment.getHpos() : HPos.RIGHT,
 591                     alignment != null? alignment.getVpos() : VPos.TOP, isSnapToPixel());
 592         }
 593 
 594         if (c != null && c.isManaged()) {
 595             Pos alignment = getAlignment(c);
 596 
 597             layoutInArea(c, insideX + leftWidth, insideY + topHeight,
 598                     insideWidth - leftWidth - rightWidth,
 599                     insideHeight - topHeight - bottomHeight, 0/*ignore baseline*/,
 600                     getNodeMargin(c),
 601                     alignment != null? alignment.getHpos() : HPos.CENTER,
 602                     alignment != null? alignment.getVpos() : VPos.CENTER);
 603         }
 604     }
 605 




 495             height = height < minHeight ? minHeight : height;
 496             final double minWidth = minWidth(height);
 497             width = width < minWidth ? minWidth : width;
 498         }
 499 
 500         final double insideX = insets.getLeft();
 501         final double insideY = insets.getTop();
 502         final double insideWidth = width - insideX - insets.getRight();
 503         final double insideHeight = height - insideY - insets.getBottom();
 504         final Node c = getCenter();
 505         final Node r = getRight();
 506         final Node b = getBottom();
 507         final Node l = getLeft();
 508         final Node t = getTop();
 509 
 510         double topHeight = 0;
 511         if (t != null && t.isManaged()) {
 512             Insets topMargin = getNodeMargin(t);
 513             double adjustedWidth = adjustWidthByMargin(insideWidth, topMargin);
 514             double adjustedHeight = adjustHeightByMargin(insideHeight, topMargin);
 515             topHeight = snapSizeY(t.prefHeight(adjustedWidth));
 516             topHeight = Math.min(topHeight, adjustedHeight);
 517             Vec2d result = boundedNodeSizeWithBias(t, adjustedWidth,
 518                    topHeight, true, true, TEMP_VEC2D);
 519             topHeight = snapSizeY(result.y);
 520             t.resize(snapSizeX(result.x), topHeight);
 521 
 522             topHeight = snapSpaceY(topMargin.getBottom()) + topHeight + snapSpaceY(topMargin.getTop());
 523             Pos alignment = getAlignment(t);
 524             positionInArea(t, insideX, insideY, insideWidth, topHeight, 0/*ignore baseline*/,
 525                     topMargin,
 526                     alignment != null? alignment.getHpos() : HPos.LEFT,
 527                     alignment != null? alignment.getVpos() : VPos.TOP, isSnapToPixel());
 528         }
 529 
 530         double bottomHeight = 0;
 531         if (b != null && b.isManaged()) {
 532             Insets bottomMargin = getNodeMargin(b);
 533             double adjustedWidth = adjustWidthByMargin(insideWidth, bottomMargin);
 534             double adjustedHeight = adjustHeightByMargin(insideHeight - topHeight, bottomMargin);
 535             bottomHeight = snapSizeY(b.prefHeight(adjustedWidth));
 536             bottomHeight = Math.min(bottomHeight, adjustedHeight);
 537             Vec2d result = boundedNodeSizeWithBias(b, adjustedWidth,
 538                     bottomHeight, true, true, TEMP_VEC2D);
 539             bottomHeight = snapSizeY(result.y);
 540             b.resize(snapSizeX(result.x), bottomHeight);
 541 
 542             bottomHeight = snapSpaceY(bottomMargin.getBottom()) + bottomHeight + snapSpaceY(bottomMargin.getTop());
 543             Pos alignment = getAlignment(b);
 544             positionInArea(b, insideX, insideY + insideHeight - bottomHeight,
 545                     insideWidth, bottomHeight, 0/*ignore baseline*/,
 546                     bottomMargin,
 547                     alignment != null? alignment.getHpos() : HPos.LEFT,
 548                     alignment != null? alignment.getVpos() : VPos.BOTTOM, isSnapToPixel());
 549         }
 550 
 551         double leftWidth = 0;
 552         if (l != null && l.isManaged()) {
 553             Insets leftMargin = getNodeMargin(l);
 554             double adjustedWidth = adjustWidthByMargin(insideWidth, leftMargin);
 555             double adjustedHeight = adjustHeightByMargin(insideHeight - topHeight - bottomHeight, leftMargin); // ????
 556             leftWidth = snapSizeX(l.prefWidth(adjustedHeight));
 557             leftWidth = Math.min(leftWidth, adjustedWidth);
 558             Vec2d result = boundedNodeSizeWithBias(l, leftWidth, adjustedHeight,
 559                     true, true, TEMP_VEC2D);
 560             leftWidth = snapSizeX(result.x);
 561             l.resize(leftWidth, snapSizeY(result.y));
 562 
 563             leftWidth = snapSpaceX(leftMargin.getLeft()) + leftWidth + snapSpaceX(leftMargin.getRight());
 564             Pos alignment = getAlignment(l);
 565             positionInArea(l, insideX, insideY + topHeight,
 566                     leftWidth, insideHeight - topHeight - bottomHeight, 0/*ignore baseline*/,
 567                     leftMargin,
 568                     alignment != null? alignment.getHpos() : HPos.LEFT,
 569                     alignment != null? alignment.getVpos() : VPos.TOP, isSnapToPixel());
 570         }
 571 
 572         double rightWidth = 0;
 573         if (r != null && r.isManaged()) {
 574             Insets rightMargin = getNodeMargin(r);
 575             double adjustedWidth = adjustWidthByMargin(insideWidth - leftWidth, rightMargin);
 576             double adjustedHeight = adjustHeightByMargin(insideHeight - topHeight - bottomHeight, rightMargin);
 577 
 578             rightWidth = snapSizeX(r.prefWidth(adjustedHeight));
 579             rightWidth = Math.min(rightWidth, adjustedWidth);
 580             Vec2d result = boundedNodeSizeWithBias(r, rightWidth, adjustedHeight,
 581                     true, true, TEMP_VEC2D);
 582             rightWidth = snapSizeX(result.x);
 583             r.resize(rightWidth, snapSizeY(result.y));
 584 
 585             rightWidth = snapSpaceX(rightMargin.getLeft()) + rightWidth + snapSpaceX(rightMargin.getRight());
 586             Pos alignment = getAlignment(r);
 587             positionInArea(r, insideX + insideWidth - rightWidth, insideY + topHeight,
 588                     rightWidth, insideHeight - topHeight - bottomHeight, 0/*ignore baseline*/,
 589                     rightMargin,
 590                     alignment != null? alignment.getHpos() : HPos.RIGHT,
 591                     alignment != null? alignment.getVpos() : VPos.TOP, isSnapToPixel());
 592         }
 593 
 594         if (c != null && c.isManaged()) {
 595             Pos alignment = getAlignment(c);
 596 
 597             layoutInArea(c, insideX + leftWidth, insideY + topHeight,
 598                     insideWidth - leftWidth - rightWidth,
 599                     insideHeight - topHeight - bottomHeight, 0/*ignore baseline*/,
 600                     getNodeMargin(c),
 601                     alignment != null? alignment.getHpos() : HPos.CENTER,
 602                     alignment != null? alignment.getVpos() : VPos.CENTER);
 603         }
 604     }
 605