Packages
 In this topic

*Constructors

*Methods

 

Packages   PreviousThis PackageNext
Package com.ms.ui   Previous This
Package
Next

 


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

Constructors

UIDrawText

public UIDrawText();

Creates an empty read-only text control.

UIDrawText

public UIDrawText(String newBuff);

Creates a read-only text control with the specified string.

ParameterDescription
newBuff The text for the control.

UIDrawText

public UIDrawText(char newBuff[]);

Creates a read-only text control with the specified character buffer.

ParameterDescription
newBuff Contains the text for the control.

Methods

addNotify

public void addNotify();

Called when the graphics context is first available to set a font.

Return Value:

No return value.

ensureNotDirty

public void ensureNotDirty(FxGraphics g);

Updates all text blocks.

Return Value:

No return value.

ParameterDescription
g The graphics context.

ensureVisible

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.

ParameterDescription
idx The index of the character that will be made visible.

ensureVisible

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.

ParameterDescription
p The client coordinates that will be made visible.

ensureVisible

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.

ParameterDescription
r The rectangle to be made visible.

eoln

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.

ParameterDescription
idx The index of a character on the line.

getCharFromScreen

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).

ParameterDescription
scrnX The x coordinate, in pixels.
scrnY The y coordinate, in pixels.

getCharFromScreen

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).

ParameterDescription
scrnPos The coordinates of the point, in pixels.

getCharLocation

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.

ParameterDescription
iPos The index of the character to query.

getCurrIndex

public int getCurrIndex();

Retrieves the current caret position.

Return Value:

Returns the character index where the caret is located.

getHorizAlign

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

getIndexHeight

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).

ParameterDescription
index An index of a character in an FxFormattedText buffer. If the index is invalid, 1 is returned.

getLength

public int getLength();

Retrieves the length of the text in the control.

Return Value:

Returns the number of characters in the control.

getMinimumSize

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

getOutline

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

getPasswordChar

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

getPreferredSize

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

getPreferredSize

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.

ParameterDescription
size The Dimension to constrain the preferred size to.

getRoleCode

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.

getSelectedText

public String getSelectedText();

Retrieves the selected text in the control.

Return Value:

Returns a String object that contains the selected text of the control.

getSelectionEnd

public int getSelectionEnd();

Retrieves the ending point of the selection.

Return Value:

Returns the character index of the ending point of the selection.

getSelectionStart

public int getSelectionStart();

Retrieves the starting point of the selection.

Return Value:

Returns the character index of the starting point of the selection.

getValueText

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

getVertAlign

public int getVertAlign();

Retrieves the vertical alignment for the text.

Return Value:

Returns the vertical alignment.

See Also: setVertAlign

getWordEdge

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.

ParameterDescription
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.

getWordWrap

public int getWordWrap();

Retrieves the word wrapping style.

Return Value:

Returns the word wrapping style. For a list of possible values, see setWordWrap.

gotFocus

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.

ParameterDescription
evt The event posted to the control.
what The object that previously had the focus.

See Also: lostFocus

hideCaret

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.

isAlwaysShowSelection

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

isAutoResizable

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

isBordered

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

isSingleLine

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.

keyDown

public boolean keyDown(Event evt, int key);

Processes a key down event.

Return Value:

Returns true if the event was handled; otherwise, returns false.

ParameterDescription
evt The event posted to the control.
key The key that was pressed.

lostFocus

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.

ParameterDescription
evt The event posted to the control.
what The object that is gaining the focus.

mouseDown

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.

ParameterDescription
evt The event posted to the control.
x The x coordinate of the event.
y The y coordinate of the event.

mouseDrag

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.

ParameterDescription
evt The event posted to the control.
x The x coordinate of the event.
y The y coordinate of the event.

paint

public void paint(FxGraphics g);

Draws the control.

Return Value:

No return value.

ParameterDescription
g The graphics context.

paint

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.

ParameterDescription
g The graphics context.
startPos Specifies the starting character index.
endPos Specifies the ending character index.
wantOpaque True for opaque text.

processKeyEvent

protected void processKeyEvent(KeyEvent ke);

Processes the specified key event.

Return Value:

No return value.

ParameterDescription
ke The key event.

selectAll

public void selectAll();

Selects all the text in the control.

Return Value:

No return value.

setAlwaysShowSelection

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.

ParameterDescription
on If true, the always show selection mode is set to on.

See Also: isAlwaysShowSelection

setAutoResizable

public void setAutoResizable(boolean auto);

Sets the control's auto-resize attribute.

Return Value:

No return value.

ParameterDescription
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

setBackground

public void setBackground(Color c);

Sets the background color of the control.

Return Value:

No return value.

ParameterDescription
c A Color object that specifies the background color.

setBordered

public void setBordered(boolean b);

Sets or clears the control's border.

Return Value:

No return value.

ParameterDescription
b If true, the control has a border; otherwise, it does not.

setBounds

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.

ParameterDescription
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).

setCurrIndex

public void setCurrIndex(int idx, boolean showCaretNow);

Note This method is replaced by setCurrIndex(int idx).

setCurrIndex

public void setCurrIndex(int idx);

Sets the position of the caret. The caret's current display state remains unchanged.

Return Value:

No return value.

ParameterDescription
idx The character index where the caret will be placed.

setFont

public void setFont(Font f);

Sets the font for all the text.

Return Value:

No return value.

ParameterDescription
f A Font object that specifies the font.

setForeground

public void setForeground(Color c);

Sets the text color of the control.

Return Value:

No return value.

ParameterDescription
c A Color object that specifies the text color.

setHorizAlign

public void setHorizAlign(int h);

Sets the horizontal alignment of the control's text.

Return Value:

No return value.

ParameterDescription
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.

setInputMethod

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.

ParameterDescription
ime The InputMethodListener to be set.

setLocation

public void setLocation(int x, int y);

Sets the location of the control.

Return Value:

No return value.

ParameterDescription
x The x coordinate for the upper-left corner of the control.
y The y coordinate for the upper-left corner of the control.

setOutline

public void setOutline(IFxShape outline);

Sets an outline that the text buffer is drawn along.

Return Value:

No return value.

ParameterDescription
outline An IFxShape object that specifies the outline.

See Also: getOutline

setPasswordChar

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.

ParameterDescription
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

setRefresh

public void setRefresh(boolean r);

Sets the refresh flag.

Return Value:

No return value.

ParameterDescription
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.

setSelection

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.

ParameterDescription
selStart The starting index of the selection.
selEnd The ending index of the selection.

setSingleLine

public void setSingleLine(boolean sl);

Changes the control's single line attribute.

Return Value:

No return value.

ParameterDescription
sl Set to false if the control's text is displayed on multiple lines; otherwise, the text is displayed on a single line.

setSize

public void setSize(int width, int height);

Sets the size of the control.

Return Value:

No return value.

ParameterDescription
width The new width of the control (in pixels).
height The new height of the control (in pixels).

setTabs

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.

ParameterDescription
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

setTextCallback

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.

ParameterDescription
tcb The IFxTextCallback interface associated with the UIDrawText object.

setValueText

public void setValueText(char newBuff[], int offset, int len);

Sets the text in the control.

Return Value:

No return value.

ParameterDescription
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

setValueText

public void setValueText(String value);

Sets the text in the control.

Return Value:

No return value.

ParameterDescription
s A String object that specifies the new text.

See Also: getValueText

setVertAlign

public void setVertAlign(int v);

Sets the vertical alignment of the control's text.

Return Value:

No return value.

ParameterDescription
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.

setWordWrap

public void setWordWrap(int ww);

Sets the word wrapping style.

Return Value:

No return value.

ParameterDescription
ww The style of word wrapping. You can use one of the following values, defined by the IFxTextConstants interface.

showCaret

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.

showCaret

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.

ParameterDescription
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.

update

public void update(FxGraphics g);

Updates the drawing of the control, using the specified graphics context.

Return Value:

No return value.

ParameterDescription
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

upnrm.gif © 1998 Microsoft Corporation. All rights reserved. Terms of use.