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);
descLabel.setBounds(x, y,
descLabel.getPreferredSize().width, fontHeight);
y += descLabel.getHeight();
currOffset += charCount;
}
// add an empty line after the paragraph
y += titleLabel.getHeight();
}
// remove the empty line after the last paragraph
y -= titleLabel.getHeight();
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 = ins.left;
if (tooltipInfo.getFooterImage() != null) {
footerImageLabel = new JLabel(new ImageIcon(tooltipInfo
.getFooterImage()));
richTooltipPanel.add(footerImageLabel);
footerImageLabel.setBounds(x, y, footerImageLabel
.getPreferredSize().width, footerImageLabel
.getPreferredSize().height);
x += footerImageLabel.getWidth() + 2 * gap;
}
// The footer text
int footerLabelWidth = parent.getWidth() - x - ins.right;
for (String footerText : tooltipInfo.getFooterSections()) {
AttributedString attributedDescription = new AttributedString(
footerText);
attributedDescription
.addAttribute(TextAttribute.FONT, font);
LineBreakMeasurer lineBreakMeasurer = new LineBreakMeasurer(
attributedDescription.getIterator(), frc);
int currOffset = 0;
while (true) {
TextLayout tl = lineBreakMeasurer
.nextLayout(footerLabelWidth);
if (tl == null)
break;
int charCount = tl.getCharacterCount();
String line = footerText.substring(currOffset,
currOffset + charCount);
JLabel footerLabel = new JLabel(line);
footerLabels.add(footerLabel);