synchronized (_styledTexts) {
String nextS;
for (int i = 0; i < _styledTexts.size(); i++) {
StyledText styledText = _styledTexts.get(i);
StyleRange style = styledText.styleRange;
if (mnemonicIndex >= 0 && styledText.text.length() > mnemonicIndex - charDisplayed) {
displayMnemonic = true;
mneIndex = mnemonicIndex - charDisplayed;
}
else {
displayMnemonic = false;
}
charDisplayed += styledText.text.length();
y = textY;
if (nextFm2 == null) {
int size = (style != null &&
(style.isSuperscript() || style.isSubscript())) ? Math.round((float) defaultFontSize / style.getFontShrinkRatio()) : defaultFontSize;
font = getFont(label);
if (style != null && ((style.getFontStyle() != -1 && font.getStyle() != style.getFontStyle()) || font.getSize() != size)) {
font = FontUtils.getCachedDerivedFont(font, style.getFontStyle() == -1 ? font.getStyle() : style.getFontStyle(), size);
fm2 = label.getFontMetrics(font);
}
else {
fm2 = fm;
}
}
else {
fm2 = nextFm2;
}
g.setFont(font);
String s = styledText.text;
int strWidth = fm2.stringWidth(s);
boolean stop = false;
int widthLeft = label.getWidth() - x;
if (widthLeft < strWidth) {
// use this method to clip string
s = SwingUtilities.layoutCompoundLabel(label, fm2, s, null, label.getVerticalAlignment(), label.getHorizontalAlignment(),
label.getVerticalTextPosition(), label.getHorizontalTextPosition(), new Rectangle(x, y, widthLeft, label.getHeight()), new Rectangle(), new Rectangle(), 0);
strWidth = fm2.stringWidth(s);
stop = true;
}
else if (i < _styledTexts.size() - 1) {
BasicStyledLabelUI.StyledText nextStyledText = _styledTexts.get(i + 1);
String nextText = nextStyledText.text;
StyleRange nextStyle = nextStyledText.styleRange;
int size = (nextStyle != null &&
(nextStyle.isSuperscript() || nextStyle.isSubscript())) ? Math.round((float) defaultFontSize / nextStyle.getFontShrinkRatio()) : defaultFontSize;
font = getFont(label);
if (nextStyle != null && ((nextStyle.getFontStyle() != -1 && font.getStyle() != nextStyle.getFontStyle()) || font.getSize() != size)) {
font = FontUtils.getCachedDerivedFont(font, nextStyle.getFontStyle() == -1 ? font.getStyle() : nextStyle.getFontStyle(), size);
nextFm2 = label.getFontMetrics(font);
}
else {
nextFm2 = fm;
}