naturalWidth = maxMinimumX - minX /*+ 1*/;
}
naturalWidth += borderInsets.left + borderInsets.right;
// Add the border margins and panel margin twice (for both left and right margins)
if (pParent instanceof Panel) {
Panel aPanel = (Panel)pParent;
naturalWidth += 2*aPanel.getMargin();
// TF:02/03/2010:Compensate the locations by the difference between the real locations and the virtual locations
//naturalWidth += actualLoc.x - virtualLoc.x;
}
}
switch (widthPolicy) {
case Constants.SP_NATURAL:
minWidth = width = naturalWidth;
break;
case Constants.SP_TO_PARENT:
// To parent size: our minimum is our border insets, but we can go up to the parent size
// TF:26/07/2009:The minimum size of the panel is larger of the natural width and the borders
// This condition about the tab panel is an issue for DET-103, but may just be eratic behaviour in Forte
width = borderInsets.left + borderInsets.right;
if (width < naturalWidth && !isMinSizeEnforced) {
// TF:14/08/2009:This isn't correct in most cases, removed this change.
//width = naturalWidth;
}
minWidth = width;
if (width < pParent.getWidth()) {
width = pParent.getWidth();
}
break;
case Constants.SP_FORM:
// We form a border around the panel the size of the minX component
width = 2* minX + (maxCurrentX - minX);
width += borderInsets.left + borderInsets.right;
minWidth = width;
if (width < pParent.getWidth()) {
width = pParent.getWidth();
}
break;
case Constants.SP_TO_PARTNER:
// Our size is the size of the largest minimum size of us or our partners
JComponent partner = LayoutManagerHelper.getWidthPartner((JComponent)pParent);
width = minWidth = naturalWidth;
while (partner != null && partner != pParent && partner.isVisible()) {
// Need to perform this check to prevent infinite recursion
if (partner.isMinimumSizeSet()) {
Dimension d = LayoutManagerHelper.getMinimumSizeWithoutPartners(partner);
if (d.width >width) {
width = d.width;
}
}
partner = LayoutManagerHelper.getWidthPartner(partner);
}
break;
default:
// We're using explicit, our size cannot change
width = pParent.getWidth();
minWidth = width;
}
// TF:29/04/2008:If we're a folder in a tab pane, we can leave our width wider than
// normal, if it's already there. Otherwise, a grid which is sized to parent in a panel
// which has natural size inside a tab folder will be the wrong size (too small)
if (pParent.getParent() instanceof JTabbedPane) {
if (pParent.getWidth() > width) {
width = pParent.getWidth();
}
}
// Width can also never shrink smaller than the title width
int titleWidth = getCaptionWidth(pParent);
// TF:2/10/07: Added a margin to make the titles look like forte
if (minWidth < titleWidth + 8) {
minWidth = titleWidth + 8;
}
if (isMinSizeEnforced) {
// Tab folders have a size of the natural size + the offset of the child
if (pParent.getParent() instanceof JTabbedPane) {
naturalWidth += minX;
}
if (minWidth < naturalWidth) {
minWidth = naturalWidth;
}
}
// We can never shrink smaller than the min size
if (pParent instanceof Panel) {
int aMinWidth = ((Panel)pParent).getMinWidth();
if (aMinWidth > width) {
width = ((Panel)pParent).getMinWidth();
}
// TF:18/9/07:Separated this logic out as the width is not always the same as the minWidth
if (aMinWidth > minWidth) {
minWidth = aMinWidth;
}
}
// Enforce the minimum width
if (width < minWidth) {
width = minWidth;
}
// Now repeat with height
// TF:26/07/2009:Added in Constants.SP_TO_PARENT
if (heightPolicy == Constants.SP_NATURAL || heightPolicy == Constants.SP_TO_PARTNER || heightPolicy == Constants.SP_TO_PARENT || isMinSizeEnforced) {
// Our size is the bounding box containing all the children plus the frame size if any plus margins.
if ((ignoreInvisibleChildren && visibleChildren > 0) || (!ignoreInvisibleChildren && pParent.getComponentCount() > 0)) {
naturalHeight = maxMinimumY - minY /* + 1 */;
}
naturalHeight += borderInsets.top + borderInsets.bottom;
// Add the border margins and panel margin twice (for both left and right margins)
if (pParent instanceof Panel) {
Panel aPanel = (Panel)pParent;
naturalHeight += 2*aPanel.getMargin();
// TF:02/03/2010:Compensate the locations by the difference between the real locations and the virtual locations
// naturalHeight += actualLoc.y - virtualLoc.y;
}
}