Documentation Contents |
|
|||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--java.awt.Component | +--LWTextComponent
Implements a very simple lightweight text editing component. It lets the user edit a single line of text using the keyboard. The only special character that it knows about is backspace; all other characters are added to the text. Selections are not supported, so there's only a simple caret indicating the insertion point. The component also displays a component name above the editable text line, and draws a black frame whose thickness indicates whether the component has the focus.
The component can be initialized to enable or disable input through input methods. Other than that, it doesn't do anything to support input methods, so input method interaction (if any) will occur in a separate composition window. However, the component is designed to be easily extended with full input method support. It distinguishes between "displayed text" and "committed text" - here, they're the same, but in a subclass that supports on-the-spot input, the displayed text would be the combination of committed text and composed text. The component also uses TextLayout to draw the text, so it can be easily extended to handle input method highlights.
Fields inherited from class java.awt.Component |
BOTTOM_ALIGNMENT,
CENTER_ALIGNMENT,
LEFT_ALIGNMENT,
RIGHT_ALIGNMENT,
TOP_ALIGNMENT |
Constructor Summary | |
LWTextComponent(String name,
boolean enableInputMethods)
Constructs a LWTextComponent. |
Method Summary | |
void |
focusGained(FocusEvent event)
Turns on drawing of the component's thicker frame and the caret. |
void |
focusLost(FocusEvent event)
Turns off drawing of the component's thicker frame and the caret. |
TextHitInfo |
getCaret()
Returns a text hit info indicating the current caret (insertion point). |
Rectangle |
getCaretRectangle()
Returns a 0-width caret rectangle. |
Rectangle |
getCaretRectangle(TextHitInfo caret)
Returns a 0-width caret rectangle for the given text index. |
AttributedCharacterIterator |
getCommittedText()
Returns the text that the user has entered and committed. |
AttributedCharacterIterator |
getCommittedText(int beginIndex,
int endIndex)
Returns a subrange of the text that the user has entered and committed. |
int |
getCommittedTextLength()
Returns the length of the text that the user has entered and committed. |
AttributedCharacterIterator |
getDisplayText()
Returns the text that the user has entered. |
TextLayout |
getTextLayout()
Returns a text layout for the text that the user has entered. |
Point |
getTextOrigin()
Returns the origin of the text. |
void |
insertCharacter(char c)
Inserts the given character at the end of the text. |
void |
invalidateTextLayout()
Invalidates the cached text layout. |
void |
keyPressed(KeyEvent event)
Ignores key pressed events. |
void |
keyReleased(KeyEvent event)
Ignores key released events. |
void |
keyTyped(KeyEvent event)
Handles the key typed event. |
void |
paint(Graphics g)
Draws the component. |
void |
setFontSize(int size)
|
Methods inherited from class java.lang.Object |
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
wait,
wait,
wait |
Constructor Detail |
public LWTextComponent(String name, boolean enableInputMethods)
name
- the component name to be displayed above the textenableInputMethods
- whether to enable input methods for this componentMethod Detail |
public void setFontSize(int size)
public void paint(Graphics g)
public AttributedCharacterIterator getCommittedText()
public AttributedCharacterIterator getCommittedText(int beginIndex, int endIndex)
beginIndex
- the index of the first character of the subrangeendIndex
- the index of the character following the subrangepublic int getCommittedTextLength()
public AttributedCharacterIterator getDisplayText()
public TextLayout getTextLayout()
invalidateTextLayout()
,
getDisplayText()
public void invalidateTextLayout()
getTextLayout()
public Point getTextOrigin()
public Rectangle getCaretRectangle()
getCaret()
public Rectangle getCaretRectangle(TextHitInfo caret)
caret
- the text index for which to calculate a caret rectanglepublic TextHitInfo getCaret()
public void insertCharacter(char c)
c
- the character to be insertedpublic void keyTyped(KeyEvent event)
public void keyPressed(KeyEvent event)
public void keyReleased(KeyEvent event)
public void focusGained(FocusEvent event)
public void focusLost(FocusEvent event)
|
|||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
Copyright © 1995-2010 Sun Microsystems, Inc. All Rights Reserved. Please send comments using this Feedback page. |
Java Technology |