Methods Summary |
---|
public java.text.AttributedCharacterIterator | cancelLatestCommittedText(java.text.AttributedCharacterIterator.Attribute[] attributes)Returns null to indicate that the "Undo Commit" feature is not supported
by this simple text component.
return null;
|
public void | caretPositionChanged(java.awt.event.InputMethodEvent event)Handles changes to the caret within composed text.
The caret defined in the event is saved and will
be returned by getCaret if there is composed text. The
component is redrawn.
caret = event.getCaret();
event.consume();
repaint();
|
public java.awt.font.TextHitInfo | getCaret()Returns a text hit info indicating the current caret (insertion point).
This override returns the caret provided by the input method while
there is composed text; otherwise it returns a caret at the end
of the committed text. The caret provided by the input method may be null.
if (composedText == null) {
return super.getCaret();
} else if (caret == null) {
return null;
} else {
// the caret provided by the input method is relative
// to the composed text, so translate it to the entire text
return caret.getOffsetHit(getCommittedTextLength());
}
|
public java.text.AttributedCharacterIterator | getCommittedText(int beginIndex, int endIndex, java.text.AttributedCharacterIterator.Attribute[] attributes)Gets an iterator providing access to the entire text and attributes
contained in the text editing component except for uncommitted
text.
return getCommittedText(beginIndex, endIndex);
|
public java.text.AttributedCharacterIterator | getDisplayText()Returns the text that the user has entered.
This override returns the concatenation of committed text
and composed text.
if (composedText == null) {
return super.getDisplayText();
} else {
// We don't want to copy all the text and attribute data here.
// Instead, we return a CompositeIterator which iterates over
// the concatenation of two iterators.
return new CompositeIterator(super.getDisplayText(), composedText);
}
|
public java.awt.im.InputMethodRequests | getInputMethodRequests()Implements getInputMethodRequests for ActiveClient by returning "this".
return this;
|
public int | getInsertPositionOffset()Gets the offset of the insert position in the committed text contained
in the text editing component. In this simple component, that's always
at the end of the committed text.
return getCommittedTextLength();
|
public java.awt.font.TextHitInfo | getLocationOffset(int x, int y)Gets the offset within the composed text for the specified absolute x
and y coordinates on the screen.
// translate from screen coordinates to coordinates in the text layout
Point location = getLocationOnScreen();
Point textOrigin = getTextOrigin();
x -= location.x + textOrigin.x;
y -= location.y + textOrigin.y;
// TextLayout maps locations far outside its bounds to locations within.
// To avoid false hits, we use it only if it actually contains the location.
// We also have to translate the TextHitInfo to be relative to composed text.
TextLayout textLayout = getTextLayout();
if (textLayout != null &&
textLayout.getBounds().contains(x, y)) {
return textLayout.hitTestChar(x, y).getOffsetHit(-getCommittedTextLength());
} else {
return null;
}
|
public java.text.AttributedCharacterIterator | getSelectedText(java.text.AttributedCharacterIterator.Attribute[] attributes)Gets the currently selected text from the text editing component.
Since this simple text component doesn't support selections, this is
always an iterator over empty text.
return EMPTY_TEXT;
|
public java.awt.Rectangle | getTextLocation(java.awt.font.TextHitInfo offset)Gets the location of a specified offset in the current composed text,
or of the selection in committed text.
// determine the text location in component coordinates
Rectangle rectangle;
if (offset == null) {
// no composed text: return caret for committed text
rectangle = getCaretRectangle();
} else {
// composed text: return caret within composed text
TextHitInfo globalOffset = offset.getOffsetHit(getCommittedTextLength());
rectangle = getCaretRectangle(globalOffset);
}
// translate to screen coordinates
Point location = getLocationOnScreen();
rectangle.translate(location.x, location.y);
return rectangle;
|
public void | inputMethodTextChanged(java.awt.event.InputMethodEvent event)Handles changes to the text entered through an input method.
Committed text contained in the event is appended to the
committed text of the text component. Composed text contained
in the event replaces any existing composed text in the text
component.
The caret defined in the event is saved and will
be returned by getCaret if there is composed text. The
component is redrawn.
In this simple component, we only
keep input method highlight attributes. Smarter components may want to
keep language, reading, input method segment, and other
attributes as well.
int committedCharacterCount = event.getCommittedCharacterCount();
AttributedCharacterIterator text = event.getText();
composedText = null;
char c;
if (text != null) {
// copy the committed text
int toCopy = committedCharacterCount;
c = text.first();
while (toCopy-- > 0) {
insertCharacter(c);
c = text.next();
}
// copy the composed text
if (text.getEndIndex() - (text.getBeginIndex() + committedCharacterCount) > 0) {
composedTextString = new AttributedString(text,
text.getBeginIndex() + committedCharacterCount, // skip over committed text
text.getEndIndex(), IM_ATTRIBUTES);
// add font information because TextLayout requires it
composedTextString.addAttribute(TextAttribute.FONT, getFont());
composedText = composedTextString.getIterator();
}
}
event.consume();
invalidateTextLayout();
caret = event.getCaret();
repaint();
|
public void | setFontSize(int size)Adjusts composed text for new font size.
super.setFontSize(size);
if (composedTextString != null) {
composedTextString.addAttribute(TextAttribute.FONT, getFont());
}
|