Font font = FlamingoUtilities.getFont(parent, "Ribbon.font",
"Button.font", "Panel.font");
Insets ins = richTooltipPanel.getInsets();
int y = ins.top;
RichTooltip tooltipInfo = richTooltipPanel.getTooltipInfo();
FontRenderContext frc = new FontRenderContext(
new AffineTransform(), true, false);
int gap = getLayoutGap();
int fontHeight = parent.getFontMetrics(font).getHeight();
Font titleFont = font.deriveFont(Font.BOLD);
boolean ltr = richTooltipPanel.getComponentOrientation()
.isLeftToRight();
// The title label
int titleLabelWidth = parent.getWidth() - ins.left - ins.right;
AttributedString titleAtributedDescription = new AttributedString(
tooltipInfo.getTitle());
titleAtributedDescription.addAttribute(TextAttribute.FONT,
titleFont);
LineBreakMeasurer titleLineBreakMeasurer = new LineBreakMeasurer(
titleAtributedDescription.getIterator(), frc);
int titleCurrOffset = 0;
while (true) {
TextLayout tl = titleLineBreakMeasurer
.nextLayout(titleLabelWidth);
if (tl == null)
break;
int charCount = tl.getCharacterCount();
String line = tooltipInfo.getTitle().substring(titleCurrOffset,
titleCurrOffset + charCount);
JLabel titleLabel = new JLabel(line);
titleLabel.setFont(titleFont);
titleLabels.add(titleLabel);
richTooltipPanel.add(titleLabel);
int currLabelWidth = titleLabel.getPreferredSize().width;
if (ltr) {
titleLabel.setBounds(ins.left, y, currLabelWidth,
fontHeight);
} else {
titleLabel.setBounds(parent.getWidth() - ins.right
- currLabelWidth, y, currLabelWidth, fontHeight);
}
y += titleLabel.getHeight();
titleCurrOffset += charCount;
}
y += gap;
// The main image
int x = ltr ? ins.left : parent.getWidth() - ins.right;
if (tooltipInfo.getMainImage() != null) {
mainImageLabel = new JLabel(new ImageIcon(tooltipInfo
.getMainImage()));
richTooltipPanel.add(mainImageLabel);
int mainImageWidth = mainImageLabel.getPreferredSize().width;
if (ltr) {
mainImageLabel.setBounds(x, y, mainImageWidth,
mainImageLabel.getPreferredSize().height);
x += mainImageWidth;
} else {
mainImageLabel.setBounds(x - mainImageWidth, y,
mainImageWidth,
mainImageLabel.getPreferredSize().height);
x -= mainImageWidth;
}
}
if (ltr) {
x += 2 * gap;
} else {
x -= 2 * gap;
}
// The description text
int descLabelWidth = ltr ? parent.getWidth() - x - ins.right : x
- ins.left;
for (String descText : tooltipInfo.getDescriptionSections()) {
AttributedString attributedDescription = new AttributedString(
descText);
attributedDescription.addAttribute(TextAttribute.FONT, font);
LineBreakMeasurer lineBreakMeasurer = new LineBreakMeasurer(
attributedDescription.getIterator(), frc);
int currOffset = 0;
while (true) {
TextLayout tl = lineBreakMeasurer
.nextLayout(descLabelWidth);
if (tl == null)
break;
int charCount = tl.getCharacterCount();
String line = descText.substring(currOffset, currOffset
+ charCount);
JLabel descLabel = new JLabel(line);
descriptionLabels.add(descLabel);
richTooltipPanel.add(descLabel);
int currDescWidth = descLabel.getPreferredSize().width;
if (ltr) {
descLabel.setBounds(x, y, currDescWidth, fontHeight);
} else {
descLabel.setBounds(x - currDescWidth, y,
currDescWidth, fontHeight);
}
y += descLabel.getHeight();
currOffset += charCount;
}
// add an empty line after the paragraph
y += fontHeight;
}
// remove the empty line after the last paragraph
y -= fontHeight;
if (mainImageLabel != null) {
y = Math.max(y, mainImageLabel.getY()
+ mainImageLabel.getHeight());
}
if ((tooltipInfo.getFooterImage() != null)
|| (tooltipInfo.getFooterSections().size() > 0)) {
y += gap;
// The footer separator
footerSeparator = new JSeparator(JSeparator.HORIZONTAL);
richTooltipPanel.add(footerSeparator);
footerSeparator.setBounds(ins.left, y, parent.getWidth()
- ins.left - ins.right, footerSeparator
.getPreferredSize().height);
y += footerSeparator.getHeight() + gap;
// The footer image
x = ltr ? ins.left : parent.getWidth() - ins.right;
if (tooltipInfo.getFooterImage() != null) {
footerImageLabel = new JLabel(new ImageIcon(tooltipInfo
.getFooterImage()));
richTooltipPanel.add(footerImageLabel);
int footerImageWidth = footerImageLabel.getPreferredSize().width;
if (ltr) {
footerImageLabel.setBounds(x, y, footerImageWidth,
footerImageLabel.getPreferredSize().height);
x += footerImageWidth + 2 * gap;
} else {
footerImageLabel.setBounds(x - footerImageWidth, y,
footerImageWidth, footerImageLabel
.getPreferredSize().height);
x -= (footerImageWidth + 2 * gap);
}
}
// The footer text
int footerLabelWidth = ltr ? parent.getWidth() - x - ins.right
: x - ins.left;
for (String footerText : tooltipInfo.getFooterSections()) {
AttributedString attributedDescription = new AttributedString(
footerText);
attributedDescription
.addAttribute(TextAttribute.FONT, font);
LineBreakMeasurer lineBreakMeasurer = new LineBreakMeasurer(