Class UIDrawText
public class UIDrawText extends UICanvas implements
IFxTextConstants, IFxGraphicsConstants
{
// Constructors
public UIDrawText();
public UIDrawText(String newBuff);
public UIDrawText(char newBuff[]);
// Methods
public void addNotify();
public void ensureNotDirty(FxGraphics g);
public boolean ensureVisible(int idx);
public boolean ensureVisible(Point p);
public boolean ensureVisible(Rectangle r);
protected int eoln(int idx);
public int getCharFromScreen(int scrnX, int scrnY);
public int getCharFromScreen(Point scrnPos);
public Point getCharLocation(int iPos);
public int getCurrIndex();
public int getHorizAlign();
public int getIndexHeight(int index);
public int getLength();
public Dimension getMinimumSize();
public IFxShape getOutline();
public char getPasswordChar();
public Dimension getPreferredSize();
public Dimension getPreferredSize(Dimension size);
public int getRoleCode();
public String getSelectedText();
public int getSelectionEnd();
public int getSelectionStart();
public String getValueText();
public int getVertAlign();
protected int getWordEdge(int iPos, boolean pleaseMoveLeft,
boolean givePrevious);
public int getWordWrap();
public boolean gotFocus(Event evt, Object what);
public void hideCaret();
public boolean isAlwaysShowSelection();
public boolean isAutoResizable();
public boolean isBordered();
public boolean isSingleLine();
public boolean keyDown(Event evt, int key);
public boolean lostFocus(Event evt, Object what);
public boolean mouseDown(Event evt, int x, int y);
public boolean mouseDrag(Event evt, int x, int y);
public void paint(FxGraphics g);
protected synchronized void paint(FxGraphics g, int startPos, int
endPos, boolean wantOpaque);
protected void processKeyEvent(KeyEvent ke);
public void selectAll();
public void setAlwaysShowSelection(boolean on);
public void setAutoResizable(boolean auto);
public void setBackground(Color c);
public void setBordered(boolean b);
public void setBounds(int x, int y, int width, int height);
public void setCurrIndex(int idx, boolean showCaretNow);
public void setCurrIndex(int idx);
public void setFont(Font f);
public void setForeground(Color c);
public void setHorizAlign(int h);
public void setInputMethod( InputMethodListener ime );
public void setLocation(int x, int y);
public void setOutline(IFxShape outline);
public void setPasswordChar(char c);
public void setRefresh(boolean r);
public void setSelection(int selStart, int selEnd);
public void setSingleLine(boolean sl);
public void setSize(int width, int height);
public void setTabs(int tabs[]);
public void setTextCallback(IFxTextCallback tcb);
public void setValueText(char newBuff[], int offset, int len);
public void setValueText(String value);
public void setVertAlign(int v);
public void setWordWrap(int ww);
public void showCaret();
public synchronized void showCaret(int iPos);
public void update(FxGraphics g);
}
This class manages the display of read-only text. Although the text cannot be changed through user interaction, it can be changed programatically. The UIEdit class allows a user to directly edit the control.
The UIDrawText component can also be associated with an InputMethodListener object. Use the setInputMethod method to set the input method editor (IME), and the showCaret methods to display an IME composition window, once when the listener is set.
UIComponent
|
+--UIStateComponent
|
+--UICanvas
|
+--UIDrawText
public UIDrawText();
Creates an empty read-only text control.
public UIDrawText(String newBuff);
Creates a read-only text control with the specified string.
Parameter | Description |
newBuff
| The text for the control.
|
public UIDrawText(char newBuff[]);
Creates a read-only text control with the specified character buffer.
Parameter | Description |
newBuff
| Contains the text for the control.
|
public void addNotify();
Called when the graphics context is first available to set a font.
Return Value:
No return value.
public void ensureNotDirty(FxGraphics g);
Updates all text blocks.
Return Value:
No return value.
Parameter | Description |
g
| The graphics context.
|
public boolean ensureVisible(int idx);
Ensures that a character index is visible and scrolls the control, if necessary.
Note UIDrawText objects to not have class-level scrolling capabilities. This methods only succeeds if the UIDrawText object is contained in an IUIContainer that has scrolling capabilities (for example, UIScrollViewer).
Return Value:
Returns true if the method was successful; otherwise, returns false.
Parameter | Description |
idx
| The index of the character that will be made visible.
|
public boolean ensureVisible(Point p);
Ensures that a position in the control is visible and scrolls the control, if necessary.
Note UIDrawText objects do not have class-level scrolling capabilities. This methods only succeeds if the UIDrawText object is contained in an IUIContainer that has scrolling capabilities (for example, UIScrollViewer).
Return Value:
Returns true if the method was successful; otherwise, returns false.
Parameter | Description |
p
| The client coordinates that will be made visible.
|
public boolean ensureVisible(Rectangle r);
Ensures that a specified rectangle is visible and resizes the control, if necessary.
Note UIDrawText objects do not have class-level scrolling capabilities. This method only succeeds if the UIDrawText object is contained in an IUIContainer that has scrolling capabilities (for example, UIScrollViewer).
Return Value:
Returns true if the method was successful; otherwise, returns false.
Parameter | Description |
r
| The rectangle to be made visible.
|
protected int eoln(int idx);
Retrieves the end-of-line character index for the current line.
Return Value:
Returns the index of the end-of-line character. This index indicates where the caret would be positioned if it were at the end of the line.
Parameter | Description |
idx
| The index of a character on the line.
|
public int getCharFromScreen(int scrnX, int scrnY);
Retrieves the character at the specified coordinates.
Return Value:
Returns the index of the character at the specified position. If there is no character at that position, the character returned will be the last one on the nearest line. Before you use the returned index, you must check if the index is a valid index for the string (as it is possible to index past the end of the string using the mouse, which may then return an invalid index).
Parameter | Description |
scrnX
| The x coordinate, in pixels.
|
scrnY
| The y coordinate, in pixels.
|
public int getCharFromScreen(Point scrnPos);
Retrieves the character at the specified point.
Return Value:
Returns the index of the character at the specified position. If there is no character at that position, the character returned will be the last one on the nearest line. Before you use the returned index, you must check if the index is a valid index for the string (as it is possible to index past the end of the string using the mouse, which may then return an invalid index).
Parameter | Description |
scrnPos
| The coordinates of the point, in pixels.
|
public Point getCharLocation(int iPos);
Retrieves the position that the character would be drawn at if drawn alone. Typically, this is used for placing the caret.
Return Value:
Returns a Point object that contains the client coordinates of the character.
Parameter | Description |
iPos
| The index of the character to query.
|
public int getCurrIndex();
Retrieves the current caret position.
Return Value:
Returns the character index where the caret is located.
public int getHorizAlign();
Retrieves the horizontal alignment of the text.
Return Value:
Returns the horizontal alignment.
Remarks:
One of the following values defined by the IFxTextConstants interface will be returned.
See Also: setHorizAlign, setVertAlign, getVertAlign
public int getIndexHeight(int index);
Retrieves the height of the font used to paint the character at a given index. This method is used internally by the keyDown method.
Return Value:
Returns the height of a font (in pixels).
Parameter | Description |
index
| An index of a character in an FxFormattedText buffer. If the index is invalid, 1 is returned.
|
public int getLength();
Retrieves the length of the text in the control.
Return Value:
Returns the number of characters in the control.
public Dimension getMinimumSize();
Retrieves the minimum size (in pixels) of the control.
Return Value:
Returns a Dimension object containing the minimum size.
See Also: getPreferredSize
public IFxShape getOutline();
Retrieves the outline along which text is drawn.
Return Value:
Returns an IFxShape object that specifies the outline.
Remarks:
For example, if the outline is an ellipse, the text that the AwtUIDrawText object is created with is drawn along the outline of this ellipse.
See Also: setOutline
public char getPasswordChar();
Retrieves the character that the control displays for password characters.
Return Value:
Returns the character that the control displays for password characters.
See Also: setPasswordChar
public Dimension getPreferredSize();
Retrieves the preferred size (in pixels) of the control.
Return Value:
Returns a Dimension object containing the preferred size.
See Also: getMinimumSize
public Dimension getPreferredSize(Dimension size);
Retrieves the preferred layout size of the control (in pixels), given a constraint. The Dimension parameter that is passed is typically the size of the container hosting the control.
For example, if the UIDrawText object has word wrapping set, the returned Dimension will have a width no greater than size.width, and a height that is large enough to hold all the text. If the UIDrawText object has no word wrapping set, the size constraint is ignored and the method is equivalent to calling getPreferredSize().
Return Value:
Returns a Dimension that describes the preferred layout size.
Parameter | Description |
size
| The Dimension to constrain the preferred size to.
|
public int getRoleCode();
Retrieves the ROLE_SYSTEM code that best describes the role of the text control.
Return Value:
Returns the ROLE_SYSTEM_STATICTEXT code.
public String getSelectedText();
Retrieves the selected text in the control.
Return Value:
Returns a String object that contains the selected text of the control.
public int getSelectionEnd();
Retrieves the ending point of the selection.
Return Value:
Returns the character index of the ending point of the selection.
public int getSelectionStart();
Retrieves the starting point of the selection.
Return Value:
Returns the character index of the starting point of the selection.
public String getValueText();
Retrieves the text in the control.
Return Value:
Returns a String object that contains the text of the control.
See Also: setValueText
public int getVertAlign();
Retrieves the vertical alignment for the text.
Return Value:
Returns the vertical alignment.
See Also: setVertAlign
protected int getWordEdge(int iPos, boolean pleaseMoveLeft,
boolean givePrevious);
Searches for and retrieves the character index of the first or last character in a word.
Return Value:
Returns the index of the first or the last character of the word, depending upon givePrevious.
Parameter | Description |
iPos
| Specifies the position where the search should start.
|
pleaseMoveLeft
| Specifies the direction of the search. If true, the search will be to the left of iPos. If false, the search will be to the right of iPos.
|
givePrevious
| Specifies if the index of the beginning or end of the word will be returned. If true, the index of the first character will be returned. If false, the index of the last character will be returned.
|
public int getWordWrap();
Retrieves the word wrapping style.
Return Value:
Returns the word wrapping style. For a list of possible values, see setWordWrap.
public boolean gotFocus(Event evt, Object what);
Called when the component receives the input focus. The caret associated with the UIDrawText object is activated when the control receives focus.
Return Value:
Returns true if the event was handled; otherwise, returns false.
Parameter | Description |
evt
| The event posted to the control.
|
what
| The object that previously had the focus.
|
See Also: lostFocus
public void hideCaret();
Hides the caret.
Return Value:
No return value.
Remarks:
The hideCaret and showCaret methods are used internally, and only when the UIDrawText or UIEdit control has focus. These methods are not directly used by the application.
public boolean isAlwaysShowSelection();
Determines whether the Always Show Selection mode is set.
This is equivalent to the ES_NOHIDESEL Win32 edit style flag.
Return Value:
Returns true if the text drawing mode is set to
Always Show Selection; otherwise, returns false.
See Also: setAlwaysShowSelection
public boolean isAutoResizable();
Determines whether the bounding box of the control's text will automatically adjust to the size of the control when the control is resized or reshaped.
Return Value:
Returns true if the auto-resize attribute is set; otherwise, returns false.
See Also: setAutoResizable
public boolean isBordered();
Determines whether the control has a border.
Return Value:
Returns true if the control has a border; otherwise, returns false.
See Also: setBordered
public boolean isSingleLine();
Retrieves the control's single-line attribute.
Return Value:
Returns true if the control's text can be displayed on a single line; otherwise, returns false.
public boolean keyDown(Event evt, int key);
Processes a key down event.
Return Value:
Returns true if the event was handled; otherwise, returns false.
Parameter | Description |
evt
| The event posted to the control.
|
key
| The key that was pressed.
|
public boolean lostFocus(Event evt, Object what);
Called when the component loses the input focus. The caret associated with the UIDrawText object is hidden when the control loses focus.
Return Value:
Returns true if the event was handled; otherwise, returns false.
Parameter | Description |
evt
| The event posted to the control.
|
what
| The object that is gaining the focus.
|
public boolean mouseDown(Event evt, int x, int y);
Processes a mouse down event.
Return Value:
Returns true if the event was handled; otherwise, returns false.
Parameter | Description |
evt
| The event posted to the control.
|
x
| The x coordinate of the event.
|
y
| The y coordinate of the event.
|
public boolean mouseDrag(Event evt, int x, int y);
Processes a mouse drag event.
Return Value:
Returns true if the event was handled; otherwise, returns false.
Parameter | Description |
evt
| The event posted to the control.
|
x
| The x coordinate of the event.
|
y
| The y coordinate of the event.
|
public void paint(FxGraphics g);
Draws the control.
Return Value:
No return value.
Parameter | Description |
g
| The graphics context.
|
protected synchronized void paint(FxGraphics g, int startPos, int endPos,
boolean wantOpaque);
Draws a portion of the control's text.
Return Value:
No return value.
Parameter | Description |
g
| The graphics context.
|
startPos
| Specifies the starting character index.
|
endPos
| Specifies the ending character index.
|
wantOpaque
| True for opaque text.
|
protected void processKeyEvent(KeyEvent ke);
Processes the specified key event.
Return Value:
No return value.
Parameter | Description |
ke
| The key event.
|
public void selectAll();
Selects all the text in the control.
Return Value:
No return value.
public void setAlwaysShowSelection(boolean on);
Sets the text drawing Always Show Selection mode to on Off. When this
mode is set to On, it is equivalent to the ES_NOHIDESEL Win32 edit style flag.
Return Value:
No return value.
Parameter | Description |
on
| If true,
the always show selection mode is set to on.
|
See Also: isAlwaysShowSelection
public void setAutoResizable(boolean auto);
Sets the control's auto-resize attribute.
Return Value:
No return value.
Parameter | Description |
auto
| If true, the bounding box of the control's text will automatically adjust to the size of the control when the control is resized or reshaped.
|
See Also: isAutoResizable
public void setBackground(Color c);
Sets the background color of the control.
Return Value:
No return value.
Parameter | Description |
c
| A Color object that specifies the background color.
|
public void setBordered(boolean b);
Sets or clears the control's border.
Return Value:
No return value.
Parameter | Description |
b
| If true, the control has a border; otherwise, it does not.
|
public void setBounds(int x, int y, int width, int height);
Sets the bounding rectangle of the UIDrawText object, according to the specified coordinates and dimensions. This method ensures that various blocks are set to the correct dimension, unless isAutoResizable returns false.
Return Value:
No return value.
Parameter | Description |
x
| The x coordinate of the upper-left corner of the block (in pixels).
|
y
| The y coordinate of the upper-left corner of the block (in pixels).
|
width
| The width of the bounding rectangle (in pixels).
|
height
| The height of the bounding rectangle (in pixels).
|
public void setCurrIndex(int idx, boolean showCaretNow);
Note This method is replaced by setCurrIndex(int idx).
public void setCurrIndex(int idx);
Sets the position of the caret. The caret's current display state remains unchanged.
Return Value:
No return value.
Parameter | Description |
idx
| The character index where the caret will be placed.
|
public void setFont(Font f);
Sets the font for all the text.
Return Value:
No return value.
Parameter | Description |
f
| A Font object that specifies the font.
|
public void setForeground(Color c);
Sets the text color of the control.
Return Value:
No return value.
Parameter | Description |
c
| A Color object that specifies the text color.
|
public void setHorizAlign(int h);
Sets the horizontal alignment of the control's text.
Return Value:
No return value.
Parameter | Description |
h
| The horizontal alignment. You can pass one of the following values, defined by the IFxTextConstants interface.
|
h
| The horizontal alignment.
|
Remarks:
Some of the vertical and horizontal alignment values are script and locale dependant. Although all values are valid, the ensureNotDirty method may use default values (htaLeft and vtaTop) if the horizontal or vertical alignments are not appropriate for the current locale or script direction.
public void setInputMethod( InputMethodListener ime );
Sets the InputMethodListener for the UIDrawText component. If an InputMethodListener is set, an FxCaret object will display the IME composition window near the caret.
Return Value:
No return value.
Parameter | Description |
ime
| The InputMethodListener to be set.
|
public void setLocation(int x, int y);
Sets the location of the control.
Return Value:
No return value.
Parameter | Description |
x
| The x coordinate for the upper-left corner of the control.
|
y
| The y coordinate for the upper-left corner of the control.
|
public void setOutline(IFxShape outline);
Sets an outline that the text buffer is drawn along.
Return Value:
No return value.
Parameter | Description |
outline
| An IFxShape object that specifies the outline.
|
See Also: getOutline
public void setPasswordChar(char c);
Sets the character that is displayed in the control when a password is entered. When you use this method and enter a password, word wrap settings are ignored and the text becomes a single line.
Return Value:
No return value.
Parameter | Description |
c
| Specifies the character that will be displayed in place of password characters. If this value is zero, the password character is cleared.
|
See Also: getPasswordChar
public void setRefresh(boolean r);
Sets the refresh flag.
Return Value:
No return value.
Parameter | Description |
r
| If true, the control will be automatically updated whenever a parameter is changed; otherwise, the control will not be updated when a parameter changes.
|
public void setSelection(int selStart, int selEnd);
Sets the current selection from the specified start index to the end index (non-inclusive).
Return Value:
No return value.
Parameter | Description |
selStart
| The starting index of the selection.
|
selEnd
| The ending index of the selection.
|
public void setSingleLine(boolean sl);
Changes the control's single line attribute.
Return Value:
No return value.
Parameter | Description |
sl
| Set to false if the control's text is displayed on multiple lines; otherwise, the text is displayed on a single line.
|
public void setSize(int width, int height);
Sets the size of the control.
Return Value:
No return value.
Parameter | Description |
width
| The new width of the control (in pixels).
|
height
| The new height of the control (in pixels).
|
public void setTabs(int tabs[]);
Sets the tab stops (in pixels) for the UIDrawText control. The tabs are set the same for each FxFormattedText block.
Return Value:
No return value.
Parameter | Description |
tabs
| An array of tab positions. If the length of the tabs array is 1, the tab stops will all be multiples of tabs[0].
|
See Also: com.ms.fx.FxFormattedText.setTabs
public void setTextCallback(IFxTextCallback tcb);
Sets the IFxTextCallback interface associated with the current UIDrawText object as the IFxTextCallback for each FxFormattedText object that uses the UIDrawText object to draw formatted text buffers.
Return Value:
No return value.
Parameter | Description |
tcb
| The IFxTextCallback interface associated with the UIDrawText object.
|
public void setValueText(char newBuff[], int offset, int len);
Sets the text in the control.
Return Value:
No return value.
Parameter | Description |
newBuff
| The array of characters that contains the text.
|
offset
| The offset of the newBuff text buffer where the text starts.
|
len
| The length of the text.
|
See Also: getValueText
public void setValueText(String value);
Sets the text in the control.
Return Value:
No return value.
Parameter | Description |
s
| A String object that specifies the new text.
|
See Also: getValueText
public void setVertAlign(int v);
Sets the vertical alignment of the control's text.
Return Value:
No return value.
Parameter | Description |
v
| The vertical alignment. You can pass one of the following values, defined by the IFxTextConstants interface.
|
Remarks:
Some of the vertical and horizontal alignment values are script and locale dependant. Although all values are valid, the ensureNotDirty method may use default values (htaLeft and vtaTop) if the horizontal or vertical alignments are not appropriate for the current locale or script direction.
public void setWordWrap(int ww);
Sets the word wrapping style.
Return Value:
No return value.
Parameter | Description |
ww
| The style of word wrapping. You can use one of the following values, defined by the IFxTextConstants interface.
|
public void showCaret();
Shows the caret at the current position. If an InputMethodListener object is associated with the UIDrawText object, an IME composition window is displayed near the caret.
Return Value:
No return value.
Remarks:
The hideCaret and showCaret methods are used internally, and only when the UIDrawText or UIEdit control has focus. These methods are not directly used by the application.
public synchronized void showCaret(int iPos);
Positions and displays the caret at the specified position. If an InputMethodListener object is associated with the UIDrawText object, an IME composition window is displayed near the caret.
Return Value:
No return value.
Parameter | Description |
iPos
| The character index where the caret will be positioned.
|
Remarks:
The hideCaret and showCaret methods are used internally, and only when the UIDrawText or UIEdit control has focus. These methods are not directly used by the application.
public void update(FxGraphics g);
Updates the drawing of the control, using the specified graphics context.
Return Value:
No return value.
Parameter | Description |
g
| The graphics context.
|
Remarks:
This method implements update in the IUIComponent interface. update fills the control with its background color, and then calls paint to redraw the control using the control's foreground color.
See Also: getBackground, getForeground