|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Object
|
+--net.rim.device.api.ui.Field
|
+--net.rim.device.api.ui.component.TextField
|
+--net.rim.device.api.ui.component.RichTextField
Read-only field that supports richly formatted text.
Behaviour
A readonly text field for showing text in a variety of fonts and formatting.
When building a rich text field that contains formatted text, you specify a list of offsets. These offsets define the boundaries of the various formatting regions for the field's text. The first offset position in the list marks the beginning of the field's text (thus is zero), and the last offset position in the list marks the end of the field's text (this is equal to the field's text length).
The field also has an attribute list, corresponding to the regions described in the offset list. (The attribute list thus has one less element in it than the offset list.) Each element's value in the attribute list is an index into the fonts list.
The fonts list contains the various formatting styles used by the field's contained text (and thus will have no more elements than the attribute list, and most likely less). Any font element with a null value that's used by the attribute list simply indicates that the field should draw the text region using the default font.
You can also build a rich text field with a list of cookie objects corresponding to the offset list. As with the attribute list, each element in the cookie list is associated with one formatting region, and thus the list has one less element than the offset list.
You can use the Field.NON_FOCUSABLE style to build a rich text field that
cannot accept the focus.
| Field Summary | ||
static long |
JUMP_FOCUS_AT_END
Enables jump-to-end of field behaviour. |
|
static long |
NO_COMPLEX_INPUT
Suggests complex input (e.g. |
|
static long |
NO_LEARNING
Suggests auto learning feature disable for current text component. |
|
static int |
TEXT_ALIGN_HCENTER
Align contained text to the central vertical axis of this field. |
|
static int |
TEXT_ALIGN_LEFT
Align contained text to the left edge of this field. |
|
static int |
TEXT_ALIGN_RIGHT
Align contained text to the right edge of this field. |
|
static int |
USE_TEXT_WIDTH
This field is economical with width. |
|
| Fields inherited from class net.rim.device.api.ui.Field |
EDITABLE, EDITABLE_MASK, FIELD_BOTTOM, FIELD_HALIGN_MASK, FIELD_HCENTER, FIELD_LEFT, FIELD_RIGHT, FIELD_TOP, FIELD_VALIGN_MASK, FIELD_VCENTER, FOCUSABLE, FOCUSABLE_MASK, HIGHLIGHT_FOCUS, HIGHLIGHT_SELECT, NON_FOCUSABLE, READONLY, USE_ALL_HEIGHT, USE_ALL_WIDTH |
| Constructor Summary | ||
RichTextField()
Constructs a plain, empty RichTextField object. |
||
RichTextField(long style)
Constructs a plain, empty RichTextField in the specified style. |
||
RichTextField(String text)
Constructs a plain RichTextField object. |
||
RichTextField(String text,
int[] offsets,
byte[] attributes,
Font[] fonts,
long style)
Constructs a formatted RichTextField object in the specified style. |
||
RichTextField(String text,
int[] offsets,
byte[] attributes,
Font[] fonts,
Object[] cookies,
long style)
Constructs a formatted RichTextField object in the specified style, and with corresponding cookies. |
||
RichTextField(String text,
long style)
Constructs a plain RichTextField object in the specified style. |
||
| Method Summary | ||
char |
charAt(int offset)
Retrieves a specific contained character from this field. |
|
protected void |
drawFocus(Graphics graphics,
boolean on)
Draws the focus indicator for this field. |
|
protected byte[] |
getAttributes()
Retrieves this field's attributes list. |
|
protected int[] |
getBackgroundColors()
Retrieves this field's background color list. |
|
int |
getCursorPosition()
Retrieves index of current cursor position. |
|
void |
getFocusRect(XYRect rect)
Retrieves the extent of the focus region. |
|
protected Font[] |
getFonts()
Retrieves this field's font list. |
|
protected int[] |
getForegroundColors()
Retrieves this field's foreground color list. |
|
protected int |
getLabelLength()
Retrieves the length of this field's label. |
|
protected int[] |
getOffsets()
Retrieves this field's offset list. |
|
int |
getRegion(int offset)
Retrieves the formatting region index containing specified character position. |
|
Object |
getRegionCookie()
Retrieves the cookie for the formatting region containing the current offset. |
|
Object |
getRegionCookie(int region)
Retrieves the cookie for a specified formatting region. |
|
Font |
getRegionFont()
Retrieves font format used in the formatting region containing the current offset. |
|
Font |
getRegionFont(int region)
Retrieves font format used in a specified region. |
|
String |
getRegionText()
Retrieves raw text in the formatting region containing the current offset. |
|
String |
getRegionText(int region)
Retrieves raw text in a specified formatting region. |
|
String |
getText()
Retrieves this field's text. |
|
String |
getText(int offset,
int length)
Retrieves a substring of this field's contained text. |
|
int |
getTextLength()
Retrieves the number of characters in this field's contained text. |
|
boolean |
isPasteable()
Determines if this field supports paste operations. |
|
boolean |
isSelectable()
Determines if this field supports selection. |
|
boolean |
isSelecting()
Determines if this field is currently selecting text. |
|
boolean |
isSelectionCopyable()
Determines if this field supports copy operations. |
|
boolean |
isSelectionDeleteable()
Determines if this field supports cut operations. |
|
protected boolean |
keyChar(char key,
int status,
int time)
Traps character generation events. |
|
protected void |
layout(int width,
int height)
Lays out this field's contents. |
|
int |
moveFocus(int amount,
int status,
int time)
Handles moving focus within this field. |
|
protected void |
moveFocus(int x,
int y,
int status,
int time)
Handles moving the focus to an exact position within this field. |
|
protected void |
onFocus(int direction)
Positions cursor when this field first receives the focus. |
|
protected void |
paint(Graphics graphics)
Redraws this field. |
|
void |
select(boolean toggle)
Sets or unsets selection mode. |
|
void |
selectionCopy(Clipboard cb)
Copies the current selection to the clipboard. |
|
void |
setCursorPosition(int offset)
Places cursor on specific character within this field, at user request. |
|
protected void |
setCursorPosition(int offset,
int context)
Sets the cursor position to the specified offset. |
|
void |
setFont(Font font)
Sets the font used by this field if only one in the list of fonts (see class description). |
|
void |
setText(String text)
Provides new text for this field to show. |
|
void |
setText(String text,
int[] offsets,
byte[] attributes,
Font[] fonts)
Provides new, foramtted text for this field to show, with associated cookies. |
|
void |
setText(String text,
int[] offsets,
byte[] attributes,
Font[] fonts,
Object[] cookies)
Provides new, foramtted text for this field to show, with associated cookies. |
|
String |
toString()
Retrieves this field's text in a string. |
|
| Methods inherited from class net.rim.device.api.ui.Field |
drawHighlightRegion, fieldChangeNotify, focusAdd, focusRemove, getChangeListener, getContextMenu, getCookie, getExtent, getExtent, getFieldStyle, getFocusListener, getFont, getHeight, getIndex, getLeafFieldWithFocus, getLeft, getManager, getOriginal, getPreferredHeight, getPreferredWidth, getScreen, getStyle, getTop, getWidth, invalidate, invalidate, isDirty, isEditable, isFocusable, isMuddy, isSelectionCutable, isStyle, isVisible, keyControl, keyDown, keyRepeat, keyStatus, keyUp, makeContextMenu, onDisplay, onExposed, onMenuDismissed, onObscured, onUndisplay, onUnfocus, onVisibilityChange, paste, selectionCut, selectionDelete, setChangeListener, setCookie, setDirty, setEditable, setExtent, setFocus, setFocusListener, setMuddy, setPosition, trackwheelClick, trackwheelUnclick, updateLayout |
| Methods inherited from class java.lang.Object |
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
public static final int USE_TEXT_WIDTH
Fields built with this style render themselves either in their specified width, or the length of the longest line of contained text, whichever is the smaller value.
public static final int TEXT_ALIGN_LEFT
public static final int TEXT_ALIGN_RIGHT
public static final int TEXT_ALIGN_HCENTER
public static final long NO_COMPLEX_INPUT
public static final long NO_LEARNING
public static final long JUMP_FOCUS_AT_END
In fields built with this style, when rolling down out of this field the cursor first jumps to the end of the field, rather than exiting the field. Normally, focus leaves on a roll down if the cursor is already at the last character of the field.
| Constructor Detail |
public RichTextField(long style)
style - Style for this field; set to
Field.NON_FOCUSABLE if the field should not have focus.public RichTextField(String text)
text - Initial text to show in this field.public RichTextField(String text, long style)
If you want to build a field that does not accept the focus, specify
the Field.NON_FOCUSABLE style.
text - Initial text to show in this field.style - Style for this field.public RichTextField(String text, int[] offsets, byte[] attributes, Font[] fonts, long style)
See the class description for field behaviour regarding formatting.
If you want to build a field that does not accept the focus, specify
the Field.NON_FOCUSABLE style.
text - Text to show in this field.offsets - List of character offsets that mark formatting changes.attributes - List that associates this field's formatting regions
with the font formats used.fonts - List of fonts formats for this field.style - Styles for this field.IllegalArgumentException - If one of the parameters is invalid (for
instance an offsets array with the final position not equal to the length
of the text, or an attributes array that is not one less in length than
the offsets array).public RichTextField(String text, int[] offsets, byte[] attributes, Font[] fonts, Object[] cookies, long style)
See the class description for field behaviour regarding formatting.
If you want to build a field that does not accept the focus, specify
the Field.NON_FOCUSABLE style.
text - Text to show in this field.offsets - List of character offsets that mark formatting changes.attributes - List that associates this field's formatting regions
with the font formats used.fonts - List of fonts formats for this field.cookies - List of object cookies corresponding to the offset list.style - Styles for this field.IllegalArgumentException - If one of the parameters is invalid (for
instance an offsets array with the final position not equal to the length
of the text, or an attributes array that is not one less in length than
the offsets array).| Method Detail |
public int getCursorPosition()
getCursorPosition in class net.rim.device.api.ui.component.TextFieldpublic String getText()
getText in class net.rim.device.api.ui.component.TextField
protected boolean keyChar(char key,
int status,
int time)
This method, invoked by this field's manager, handles key generation events. This method does not consume the key event, except in the following cases:
key - Character generated by the event.status - Modifier key status.time - Number of milliseconds since the device was turned on.
public int moveFocus(int amount,
int status,
int time)
This field's manager invokes this method to prompt this field to handle a focus move event. If the event is an ALT-roll, then the focus move happens horizontally (character by character); otherwise, the focus movement happens vertically (line by line).
If this field has an empty text buffer, then this method returns the entire scroll amount. Otherwise, it just returns any scroll amount not used when the focus leaves the field.
moveFocus in class net.rim.device.api.ui.component.TextFieldamount - Number of positions to move, positive means down, negative
up.status - Modifier key statustime - Number of milliseconds since the device was turned on.public void setText(String text)
Notice that calling this method wipes any text formatting this field previously had.
text - New text to show in this field.public void setText(String text, int[] offsets, byte[] attributes, Font[] fonts)
If you provide a null offsets parameter, then this method assumes your text is not formatted, and so ignores the attributes and fonts parameters.
See the class description for information on field formatting.
text - New text to show in this field.offsets - List of character offsets that mark formatting changes.attributes - List that associates this field's formatting regions
with the font formats used.fonts - List of fonts formats for the new text.IllegalArgumentException - If one of the parameters is invalid (for
instance an offsets array with the final position not equal to the length
of the text, or an attributes array that is not one less in length than
the offsets array).public void setText(String text, int[] offsets, byte[] attributes, Font[] fonts, Object[] cookies)
If you provide a null offsets parameter, then this method assumes your text is not formatted, and so ignores the attributes, fonts, and cookies parameters.
See the class description for information on field formatting.
text - New text to show in this field.offsets - List of character offsets that mark formatting changes.attributes - List that associates this field's formatting regions
with the font formats used.fonts - List of fonts formats for the new text.cookies - List of cookie objects for the new text.IllegalArgumentException - If one of the parameters is invalid (for
instance an offsets array with the final position not equal to the length
of the text, or an attributes array that is not one less in length than
the offsets array).public void setCursorPosition(int offset)
setCursorPosition in class net.rim.device.api.ui.component.TextFieldoffset - Character index to receive the cursor, counting from the
first character in this field's buffer.public String getText(int offset, int length)
getText in class net.rim.device.api.ui.component.TextFieldoffset - First character in the substring to retrieve.length - Number of characters in the substring to retrieve.IndexOutOfBoundsException - If the offset is negative, or the
length is larger than the total text length, or if the offset is greater
than the length.public int getTextLength()
getTextLength in class net.rim.device.api.ui.component.TextFieldpublic boolean isSelectable()
If this field was built with Field.NON_FOCUSABLE or if this field
currently has no characters, then this method returns false;
otherwise it returns true.
isSelectable in class net.rim.device.api.ui.component.TextFieldpublic char charAt(int offset)
charAt in class net.rim.device.api.ui.component.TextFieldoffset - Position of specified character within this field. The
first character in the field has an offset of 0.IndexOutOfBoundsException - If the offset argument is negative or
larger than the length of this field's contained text.public int getRegion(int offset)
offset - Character position for which to determine containing
formatting region.public Object getRegionCookie()
public Object getRegionCookie(int region)
region - Index of the formatting region within this field's offset
list (see class description).public String getRegionText()
public String getRegionText(int region)
region - Index of the formatting region within this field's offset
list (see class description).public Font getRegionFont()
public Font getRegionFont(int region)
region - Index of the formatting region within this field's offset
list (see class description).protected Font[] getFonts()
Use this method to retrieve the list of font formats used by this field (see class description).
protected int[] getOffsets()
Use this method to retrieve the list of offsets that define this field's formatting regions (see class description).
protected byte[] getAttributes()
Use this method to retrieve this field's attribute list (the list that matches the regions described in the offsets list with the formats described in the fonts list--see class description).
protected int[] getForegroundColors()
Use this method to retrieve this field's foreground color list
protected int[] getBackgroundColors()
Use this method to retrieve this field's background color list
protected void drawFocus(Graphics graphics, boolean on)
This field's manager invokes this method after painting the field, in order to overpaint the focus indicator. By default, this method simply inverts the pixels in the focus's extent.
Note that if currently selecting more than one character in this field, then the focus region occupies the entire extent of the selected text.
graphics - Graphics context for drawing the focus.on - This parameter is ignored -- the focus is aways set at the
location at which it is drawn.public void getFocusRect(XYRect rect)
The framework invokes this method to retrieve this field's current focus region.
getFocusRect in class Fieldrect - To contain the focus extent for this field, in local
coordinates.protected int getLabelLength()
By default, this method returns 0; extending classes that support field labels should override this method.
public final boolean isSelecting()
isSelecting in class Fieldpublic boolean isSelectionCopyable()
This method returns true if there is currently a selection (fields that can select text always have a selection, even if it's zero characters in size).
isSelectionCopyable in class Fieldpublic boolean isSelectionDeleteable()
isSelectionDeleteable in class Fieldpublic boolean isPasteable()
isPasteable in class FieldField.EDITABLE; otherwise, false.
protected void moveFocus(int x,
int y,
int status,
int time)
This field's manager invokes this method when moving the focus to an exact position within this field, and only when this field already has the focus.
x - Distance from left edge of this field for new focus position.y - Distance from top edge of this field for new focus position.status - Modifier key status.time - Number of milliseconds since the device was turned on.protected void onFocus(int direction)
Text fields exhibit special behaviour for onFocus.
If no cursor position was currently set... If the focus entered this field from the "top", then this method places the initial cursor at the first character in this field's value.
If the focus entered this field from the "bottom", then this method places the initial cursor on the last character in this field's value.
If the focus event indicated no direction, this method does nothing.
If the cursor position was already set...
If the cursor position was preivously set externally (ie through a call
to TextField.setCursorPosition(int), then the cursor is rendered at the
set position. However, this state is erased once the control gains
focus.
direction - Direction of cursor movement; greater than zero means it
came from above this field, less than zero means it came from below this
field, zero means focus is being set to the field directly (that is, not
by means of a trackwhell roll).public void select(boolean toggle)
Invoking this method to false sets the current selection to zero characters, and turns off the behaviour of increasing the selection with cursor movement. There's always a current selection, since that's the key indicator we use to prove this field is supports selection.
toggle - True to turn on selecting mode; false to turn it off.public void selectionCopy(Clipboard cb)
Note that this method always succeeds, even if zero characters are copied onto the clipboard. If at least one character exists in the selection to copy, then this method overwrites the clipboard's previous contents.
selectionCopy in class Fieldcb - Clipboard to contain copied text.
protected void setCursorPosition(int offset,
int context)
offset - Offset from the beginning of the text to set the cursor position.context - Information specifying the origin of the change.
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
Copyright 1999-2004 Research In Motion Limited. 295 Phillip Street, Waterloo, Ontario, Canada, N2L 3W8. All Rights Reserved.
Copyright 1993-2003 Sun Microsystems, Inc. 901 San Antonio Road, Palo Alto, California, 94303, U.S.A.
Copyright 2002-2003 Nokia Corporation All Rights Reserved.
Java is a trademark or registered trademark of Sun Microsystems, Inc. in the US and other countries.