// may be added as many TextPaneSkinTextNodeView's.
// Break the views into multiple rows
int breakWidth = getBreakWidth();
Paragraph paragraph = (Paragraph)getNode();
rows = new ArrayList<Row>();
Row row = new Row();
for (Node node : paragraph) {
TextPaneSkinNodeView nodeView = textPaneSkin.createNodeView(node);
nodeView.setBreakWidth(Math.max(breakWidth - (row.width
+ PARAGRAPH_TERMINATOR_WIDTH), 0));
nodeView.validate();
int nodeViewWidth = nodeView.getWidth();
if (row.width + nodeViewWidth > breakWidth
&& row.width > 0) {
// The view is too big to fit in the remaining space,
// and it is not the only view in this row
rows.add(row);
row = new Row();
row.width = 0;
}
// Add the view to the row
row.nodeViews.add(nodeView);
row.width += nodeViewWidth;
// If the view was split into multiple views, add them to
// their own rows
nodeView = nodeView.getNext();
while (nodeView != null) {
rows.add(row);
row = new Row();
nodeView.setBreakWidth(breakWidth);
nodeView.validate();
row.nodeViews.add(nodeView);
row.width = nodeView.getWidth();
nodeView = nodeView.getNext();
}
}
// Add the last row
if (row.nodeViews.getLength() > 0) {
rows.add(row);
}
// Clear all existing views
remove(0, getLength());
// Add the row views to this view, lay out, and calculate height
int x = 0;
int width = 0;
int height = 0;
for (int i = 0, n = rows.getLength(); i < n; i++) {
row = rows.get(i);
row.y = height;
width = Math.max(width, row.width);
// Determine the row height
for (TextPaneSkinNodeView nodeView : row.nodeViews) {
row.height = Math.max(row.height, nodeView.getHeight());
}
if (paragraph.getHorizontalAlignment() == HorizontalAlignment.LEFT) {
x = 0;
} else if (paragraph.getHorizontalAlignment() == HorizontalAlignment.CENTER) {
x = (width - row.width) / 2;
} else {
// right alignment
x = width - row.width;
}