return getPreferredSize(ribbonComponent.getDisplayPriority());
}
@Override
public void layoutContainer(Container parent) {
JRibbonComponent ribbonComp = (JRibbonComponent) parent;
Insets ins = ribbonComp.getInsets();
int gap = getLayoutGap();
int availableHeight = ribbonComp.getHeight() - ins.top - ins.bottom;
int availableWidth = ribbonComp.getWidth() - ins.left - ins.right;
HorizontalAlignment horizAlignment = ribbonComp
.getHorizontalAlignment();
JComponent mainComp = ribbonComp.getMainComponent();
Dimension prefMainDim = mainComp.getPreferredSize();
int prefMainWidth = prefMainDim.width;
int finalHeight = Math.min(prefMainDim.height, availableHeight);
boolean ltr = ribbonComp.getComponentOrientation().isLeftToRight();
if (ribbonComp.isSimpleWrapper()) {
int finalMainWidth = Math.min(availableWidth, prefMainWidth);
int offset = availableWidth - prefMainWidth;
int topMain = ins.top + (availableHeight - finalHeight) / 2;
int x = ltr ? ins.left : ribbonComp.getWidth() - ins.right;
switch (horizAlignment) {
case LEADING:
if (ltr) {
mainComp.setBounds(x, topMain, finalMainWidth,
finalHeight);
} else {
mainComp.setBounds(x - finalMainWidth, topMain,
finalMainWidth, finalHeight);
}
break;
case TRAILING:
if (ltr) {
mainComp.setBounds(x + offset, topMain, finalMainWidth,
finalHeight);
} else {
mainComp.setBounds(x - finalMainWidth - offset,
topMain, finalMainWidth, finalHeight);
}
break;
case CENTER:
if (ltr) {
mainComp.setBounds(x + offset / 2, topMain,
finalMainWidth, finalHeight);
} else {
mainComp.setBounds(x - finalMainWidth - offset / 2,
topMain, finalMainWidth, finalHeight);
}
break;
case FILL:
if (ltr) {
mainComp.setBounds(x, topMain, availableWidth,
finalHeight);
} else {
mainComp.setBounds(x - availableWidth, topMain,
availableWidth, finalHeight);
}
break;
}
mainComp.doLayout();
} else {
int x = ltr ? ins.left : ribbonComp.getWidth() - ins.right;
if (isIconVisible(ribbonComponent.getDisplayPriority())) {
if (ribbonComp.getIcon() != null) {
// icon is painted separately
int iconW = ribbonComp.getIcon().getIconWidth();
x = ltr ? x + iconW + gap : x - iconW - gap;
}
}
if (isCaptionVisible(ribbonComponent.getDisplayPriority())) {
captionLabel.setVisible(true);
Dimension prefCaptionDim = captionLabel.getPreferredSize();
if (ltr) {
captionLabel
.setBounds(
x,
ins.top
+ (availableHeight - prefCaptionDim.height)
/ 2, prefCaptionDim.width,
prefCaptionDim.height);
x += (prefCaptionDim.width + gap);
} else {
captionLabel
.setBounds(
x - prefCaptionDim.width,
ins.top
+ (availableHeight - prefCaptionDim.height)
/ 2, prefCaptionDim.width,
prefCaptionDim.height);
x -= (prefCaptionDim.width + gap);
}
} else {
captionLabel.setVisible(false);
}
int topMain = ins.top + (availableHeight - finalHeight) / 2;
int finalMainWidth = ltr ? Math.min(ribbonComp.getWidth()
- ins.right - x, prefMainWidth) : Math.min(
x - ins.left, prefMainWidth);
int offset = ltr ? ribbonComp.getWidth() - ins.right - x
- prefMainWidth : x - prefMainWidth - ins.left;
switch (horizAlignment) {
case LEADING:
if (ltr) {
mainComp.setBounds(x, topMain, finalMainWidth,
finalHeight);
} else {
mainComp.setBounds(x - finalMainWidth, topMain,
finalMainWidth, finalHeight);
}
break;
case TRAILING:
if (ltr) {
mainComp.setBounds(x + offset, topMain, finalMainWidth,
finalHeight);
} else {
mainComp.setBounds(x - finalMainWidth - offset,
topMain, finalMainWidth, finalHeight);
}
break;
case CENTER:
if (ltr) {
mainComp.setBounds(x + offset / 2, topMain,
finalMainWidth, finalHeight);
} else {
mainComp.setBounds(x - finalMainWidth - offset / 2,
topMain, finalMainWidth, finalHeight);
}
break;
case FILL:
if (ltr) {
mainComp.setBounds(x, topMain, ribbonComp.getWidth()
- ins.right - x, finalHeight);
} else {
mainComp.setBounds(ins.left, topMain, x - ins.left,
finalHeight);
}