LineBreakMeasurerpublic final class LineBreakMeasurer extends Object The class LineBreakMeasurer provides methods to measure the graphical
representation of a text in order to determine where to add line breaks so
the resulting line of text fits its wrapping width. The wrapping width
defines the visual width of the paragraph. |
Fields Summary |
---|
private TextMeasurer | tmThe tm. | private int | positionThe position. | int | maxposThe maxpos. |
Constructors Summary |
---|
public LineBreakMeasurer(AttributedCharacterIterator text, FontRenderContext frc)Instantiates a new LineBreakMeasurer object for the specified text.
// ???AWT: this(text, BreakIterator.getLineInstance(), frc);
|
Methods Summary |
---|
public void | deleteChar(java.text.AttributedCharacterIterator newText, int pos)Deletes a character from the specified position of the text, updates this
LineBreakMeasurer object.
tm.deleteChar(newText, pos);
// ???AWT: bi.setText(newText);
position = newText.getBeginIndex();
maxpos--;
| public int | getPosition()Gets current position of this LineBreakMeasurer.
return position;
| public void | insertChar(java.text.AttributedCharacterIterator newText, int pos)Inserts a character at the specified position in the text, updates this
LineBreakMeasurer object.
tm.insertChar(newText, pos);
// ???AWT: bi.setText(newText);
position = newText.getBeginIndex();
maxpos++;
| public java.awt.font.TextLayout | nextLayout(float wrappingWidth, int offsetLimit, boolean requireNextWord)Returns the next line of text, updates current position in this
LineBreakMeasurer.
if (position == maxpos) {
return null;
}
int nextPosition = nextOffset(wrappingWidth, offsetLimit, requireNextWord);
if (nextPosition == position) {
return null;
}
TextLayout layout = tm.getLayout(position, nextPosition);
position = nextPosition;
return layout;
| public java.awt.font.TextLayout | nextLayout(float wrappingWidth)Returns the next line of text.
return nextLayout(wrappingWidth, maxpos, false);
| public int | nextOffset(float wrappingWidth)Returns the end position of the next line of text.
return nextOffset(wrappingWidth, maxpos, false);
| public int | nextOffset(float wrappingWidth, int offsetLimit, boolean requireNextWord)Returns the end position of the next line of text.
if (offsetLimit <= position) {
// awt.203=Offset limit should be greater than current position.
throw new IllegalArgumentException(Messages.getString("awt.203")); //$NON-NLS-1$
}
if (position == maxpos) {
return position;
}
int breakPos = tm.getLineBreakIndex(position, wrappingWidth);
int correctedPos = breakPos;
// This check is required because bi.preceding(maxpos) throws an
// exception
/*
* ???AWT if (breakPos == maxpos) { correctedPos = maxpos; } else if
* (Character.isWhitespace(bi.getText().setIndex(breakPos))) {
* correctedPos = bi.following(breakPos); } else { correctedPos =
* bi.preceding(breakPos); }
*/
if (position >= correctedPos) {
if (requireNextWord) {
correctedPos = position;
} else {
correctedPos = Math.max(position + 1, breakPos);
}
}
return Math.min(correctedPos, offsetLimit);
| public void | setPosition(int pos)Sets the new position of this LineBreakMeasurer.
if (tm.aci.getBeginIndex() > pos || maxpos < pos) {
// awt.33=index is out of range
throw new IllegalArgumentException(Messages.getString("awt.33")); //$NON-NLS-1$
}
position = pos;
|
|