@Override
protected void childLayout(int breakWidth) {
TextNode textNode = (TextNode)getNode();
FontRenderContext fontRenderContext = Platform.getFontRenderContext();
CharSequenceCharacterIterator ci = new CharSequenceCharacterIterator(textNode.getCharacters(), start);
float lineWidth = 0;
int lastWhitespaceIndex = -1;
Font effectiveFont = getEffectiveFont();
char c = ci.first();
while (c != CharacterIterator.DONE
&& lineWidth < breakWidth) {
if (Character.isWhitespace(c)) {
lastWhitespaceIndex = ci.getIndex();
}
int i = ci.getIndex();
Rectangle2D characterBounds = effectiveFont.getStringBounds(ci, i, i + 1, fontRenderContext);
lineWidth += characterBounds.getWidth();
c = ci.current();
}
int end;
if (getTextPaneSkin().getWrapText()) {
if (textNode.getCharacterCount() == 0) {
end = start;
} else {
if (lineWidth < breakWidth) {
end = ci.getEndIndex();
} else {
if (lastWhitespaceIndex == -1) {
end = ci.getIndex() - 1;
if (end <= start) {
end = start + 1;
}
} else {
end = lastWhitespaceIndex + 1;
}
}
}
} else {
end = ci.getEndIndex();
}
glyphVector = getEffectiveFont().createGlyphVector(fontRenderContext,
new CharSequenceCharacterIterator(textNode.getCharacters(), start, end));
if (end < ci.getEndIndex()) {
length = end - start;
next = new TextPaneSkinTextNodeView(textNode, end);
next.setParent(getParent());
} else {
length = ci.getEndIndex() - start;
// set to null in case this node used to be broken across multiple, but is no longer
next = null;
}
Rectangle2D textBounds = glyphVector.getLogicalBounds();