|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.nokia.mid.ui.CanvasItem com.nokia.mid.ui.TextEditor
public class TextEditor
A TextEditor
is an editable text component that is used with a
parent object; with Canvas
or CustomItem
. The
TextEditor
maybe set to and removed from Canvas
through setParent()
method.
The implementation presents the TextEditor
with minimal
decoration; only the caret is shown at the requested text insertion position.
It is the responsibility of the application to draw any additional decoration
like focus highlight, border or scroll bar. The animation of the caret, e.g.
blinking, is handled by the TextEditor implementation.
TextEditor
supports input constraints identically to
TextField
. In addition TextEditor
has the same concept of
actual contents and displayed contents as
TextField
.
TextEditor
supports input modes identically to
TextField
.
The text may contain line breaks. The display of the text must break accordingly and the user must be able to enter line break characters.
The TextEditor provides necessary interaction for example for touch input (handwriting recognition) on touch screen devices and selection of additional characters. The input on touch devices requires additional windows of top of the editor window which depending on the implementation may obscure the parent completely.
Application can add a TextEditorListener to the TextEditor
for
example for keeping track of user navigation (caret movement) and other
content changes such as text selection. The events are sent on all occasions
that cause the the caret position to change (including but not limited to
text typing by user, programmatic text insertion, navigation within the
TextEditor
content, and text deletion). The events must be sent
to the application prior to they have effect on the editor - for example an
event indicating caret movement must be available for the application before
the implementation actually moves the caret in the editor.
When the TextEditor
has focus all the key events that are not
consumed by TextEditor
with the current constraints or mapped to
Commands by the implementation are sent to Canvas
.
Touch pointer events are not delivered to parent object from the area of the visible TextEditor.
The implementation will scroll the TextEditor
content
automatically on user interaction and when the application calls setCaret or
setSelection methods. For example if a user clicks down on the last visible
row the TextEditor
content is scrolled accordingly by one row.
However the Java platform implementation does not draw any scroll bars, this
is left to the application.
Constructor Summary | |
---|---|
TextEditor()
|
Method Summary | |
---|---|
static TextEditor |
createTextEditor(int maxSize,
int constraints,
int width,
int rows)
Creates a new empty TextEditor with the given maximum size
in characters, constraints and editor size as number of visible rows. |
static TextEditor |
createTextEditor(java.lang.String text,
int maxSize,
int constraints,
int width,
int height)
Creates a new TextEditor object with the given initial
contents, maximum size in characters, constraints and editor size in
pixels. |
void |
delete(int offset,
int length)
Deletes characters from the TextEditor . |
int |
getBackgroundColor()
Gets the background color and alpha of this TextEditor . |
int |
getCaretPosition()
Gets the current position of the caret in the editor. |
int |
getConstraints()
Gets the current input constraints of this TextEditor . |
java.lang.String |
getContent()
Gets the string content in the TextEditor . |
int |
getContentHeight()
Gets the whole content height in this TextEditor in pixels. |
Font |
getFont()
Gets the font being used in rendering the text content in this TextEditor . |
int |
getForegroundColor()
Gets the foreground color and alpha of this TextEditor |
java.lang.String |
getInitialInputMode()
Returns the initial input mode set to the editor, or null if no initial input mode has been set. |
int |
getLineMarginHeight()
Gets the line margin height in this TextEditor in pixels. |
int |
getMaxSize()
Returns the maximum size (number of characters) that can be stored in this TextEditor . |
java.lang.String |
getSelection()
Gets the currently selected content in the TextEditor . |
int |
getVisibleContentPosition()
Gets the topmost pixel position of the topmost visible line in the editor. |
int |
getZPosition()
Returns the Z-position, or the elevation, of the item. |
boolean |
hasFocus()
Returns the focus state of TextEditor. |
void |
insert(java.lang.String text,
int position)
Inserts a string into the content of the TextEditor . |
boolean |
isMultiline()
Returns the multiline state of the TextEditor . |
void |
setBackgroundColor(int color)
Sets the background color and alpha of this TextEditor to
the specified values. |
void |
setCaret(int index)
Sets the index of the caret. |
void |
setConstraints(int constraints)
Sets the input constraints of this TextEditor . |
void |
setContent(java.lang.String content)
Sets the content of the TextEditor as a string. |
void |
setFocus(boolean focused)
Sets this TextEditor focused or removes keyboard focus. |
void |
setFont(Font font)
Sets the application preferred font for rendering the text content in this TextEditor . |
void |
setForegroundColor(int color)
Sets the foreground color and alpha of this TextEditor to
the specified values. |
void |
setHighlightBackgroundColor(int color)
Sets the highlight background color. |
void |
setHighlightForegroundColor(int color)
Sets the highlight foreground color. |
void |
setInitialInputMode(java.lang.String characterSubset)
Sets a hint to the implementation as to the input mode that should be used when the user initiates editing of this TextEditor . |
int |
setMaxSize(int maxSize)
Sets the maximum size (number of characters) that can be contained in this TextEditor . |
void |
setMultiline(boolean aMultiline)
Sets the editor to be either multi-line (true) or single-line (false). |
void |
setParent(java.lang.Object parent)
Set the parent object of this TextEditor . |
void |
setPosition(int x,
int y)
Sets the rendering position of this TextEditor . |
void |
setSelection(int index,
int length)
Sets a selection on a range of text in the TextEditor
content. |
void |
setSize(int width,
int height)
Sets the size of this TextEditor in pixels. |
void |
setTextEditorListener(TextEditorListener listener)
Sets a listener for content changes in this TextEditor ,
replacing any previous TextEditorListener . |
void |
setVisible(boolean visible)
Sets the visibility value of TextEditor . |
void |
setZPosition(int z)
Sets the Z-position, or the elevation, of the item. |
int |
size()
Gets the number of characters that are currently stored in this TextEditor . |
Methods inherited from class com.nokia.mid.ui.CanvasItem |
---|
getHeight, getParent, getPositionX, getPositionY, getWidth, isVisible |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public TextEditor()
Method Detail |
---|
public static TextEditor createTextEditor(java.lang.String text, int maxSize, int constraints, int width, int height)
Creates a new TextEditor
object with the given initial
contents, maximum size in characters, constraints and editor size in
pixels.
If the text parameter is null
, the TextEditor
is created empty.
The maxSize
parameter must be greater than zero. An
IllegalArgumentException
is thrown if the length of the
initial contents string exceeds maxSize
. However, the
implementation may assign a maximum size smaller than the application had
requested. If this occurs, and if the length of the contents exceeds the
newly assigned maximum size, the contents are truncated from the end in
order to fit, and no exception is thrown.
text
- the initial contents, or null
if the
TextEditor
is to be created emptymaxSize
- the maximum capacity in charactersconstraints
- see the input constraints in TextField
width
- the width of the bounding box, in pixelsheight
- the height of the bounding box, in pixels
java.lang.IllegalArgumentException
- if aMaxSize
is zero or less
java.lang.IllegalArgumentException
- if the value of the constraints parameter is invalid
java.lang.IllegalArgumentException
- if aText
is illegal for the specified
constraints
java.lang.IllegalArgumentException
- if the length of the string exceeds the requested maximum
capacity
java.lang.IllegalArgumentException
- if the width or height is less than one pixelpublic static TextEditor createTextEditor(int maxSize, int constraints, int width, int rows)
Creates a new empty TextEditor
with the given maximum size
in characters, constraints and editor size as number of visible rows.
The rows
parameter indicates the requested number of visible
rows in the editor. TextEditor then assigns the initial height for the
editor based on the requested number of rows and width of the editor.
The maxSize
parameter must be greater than zero. An
IllegalArgumentException
is thrown if the length of the
initial contents string exceeds maxSize
. However, the
implementation may assign a maximum size smaller than the application had
requested. If this occurs, and if the length of the contents exceeds the
newly assigned maximum size, the contents are truncated from the end in
order to fit, and no exception is thrown.
maxSize
- the maximum capacity in charactersconstraints
- see the input constraints in TextField
width
- the width of the bounding box, in pixelsrows
- the requested number of visible rows in the editor
java.lang.IllegalArgumentException
- if aMaxSize
or aRows
is zero or
less
java.lang.IllegalArgumentException
- if the value of the constraints parameter is invalid
java.lang.IllegalArgumentException
- if the length of the string exceeds the requested maximum
capacity
java.lang.IllegalArgumentException
- if the width is less than one pixelpublic void setFocus(boolean focused)
The setFocus affects to the parent key event delivery in following way: If all TextEditors are unfocused the key event delivery of parent works as if there are not any TextEditors in it, only when a focus is set via this method to a TextEditor the key event delivery is modified. The focused editor starts to capture the necessary key events and these key events are not delivered to parent. The set of key events captured depends on TextEditor implementation and device HW but in most implementations nearly all device keys are captured by the editor for text insertion, input mode changes and caret move functionalities. Especially applications should not assume to get key events from keys mapped to game actions as most probably the same keys are used to navigate the text caret within the editor. The keys that are used for Command launching in Canvas are available for applications on focused TextEditor and these keys either launch commands or send low-level key events as normally.
Setting focus does not cause any visual focus indication by the implementation other than showing the caret. Any other change in the visual appearance of the editor in focused state is the responsibility of the application; this can be done for example by drawing a focus border around the TextEditor or by changing the background color or transparency of the editor.
If this TextEditor has already been focused earlier and the editor contents has not changed after previous unfocusing, then after calling setFocus again the caret position should be retained.
If there already is another focused TextEditor on the Canvas, the focus is first removed from that TextEditor before setting this TextEditor focused.
Calling setFocus(false) disables key based text editing and returns the delivery of key events and pointer events to the underlying Canvas.
focused
- keyboard focus of the TextEditor
java.lang.IllegalStateException
- If the TextEditor is not added to CanvashasFocus()
public boolean hasFocus()
setFocus(boolean focused)
public void setParent(java.lang.Object parent)
TextEditor
.
Typically the parent object would be Canvas. Setting the parameter to
null removes the association to the parent. If
setParent(null)
is called for a TextEditor
yet
not having any parent or setParent(parent)
is called with
the same parent, the call is silently ignored.
setParent
in class CanvasItem
parent
- the parent object
java.lang.IllegalArgumentException
- if parent is not a valid object with which a
TextEditor
can be associated, or if CanvasItem
is already set to another another parentpublic void setSize(int width, int height)
TextEditor
in pixels.
setSize
in class CanvasItem
width
- width in pixelsheight
- height in pixels
java.lang.IllegalArgumentException
- if the width or height is less than one pixelpublic void setPosition(int x, int y)
Sets the rendering position of this TextEditor
. The anchor
point given is relative to the upper left corner of the parent,
Canvas
.
The TextEditor
may be placed fully off or partially of the
visible area of the parent, Canvas
, by the
setPosition
method; in this case the TextEditor
is just partly visible.
setPosition
in class CanvasItem
x
- the x coordinate of the anchor point, in pixels.y
- the y coordinate of the anchor point, in pixels.
java.lang.IllegalStateException
- if a valid parent object has not been set.setParent(java.lang.Object parent)
public void setVisible(boolean visible)
Sets the visibility value of TextEditor
. Initially
TextEditor
is not visible so it must be explicitly set to
visible in order it to appear on UI.
Setting visibility to true shows the editor with its content, but without
the caret. If the editor does not have any visible content and does not
have any background color set then this method effectively does not cause
any visual change in the display. If the editor is already visible
calling setVisible(true)
does nothing.
Setting the visibility to false hides the editor and its content. If the
TextEditor
has focus then the focus is removed. If the
editor is already hidden calling setVisible(false)
does
nothing.
setVisible
in class CanvasItem
visible
- visibility of the TextEditor
java.lang.IllegalStateException
- if a valid parent object has not been set.setParent(java.lang.Object parent)
public void setZPosition(int z)
Sets the Z-position, or the elevation, of the item.
The elevation decides the stacking order of neighboring items. An item of high Z-position will be drawn on top of an item with a lower Z-position if they share the same parent item.
The z-position is unique for each item meaning that changing a Z-position of an item may change the Z-position of the items that share the same parent item. The Z-position does not affect the item's size in any way.
When items are added with CanvasItem.setParent(java.lang.Object)
they will get a
Z-position that is increased by 1 from the item that is the top most item
at that time.
setZPosition
in class CanvasItem
z
- the Z-position of the item.
java.lang.IllegalArgumentException
- If z
< 0
java.lang.IllegalStateException
- if a valid parent object has not been set.getZPosition()
,
setParent(java.lang.Object parent)
public int getZPosition()
Returns the Z-position, or the elevation, of the item. The Z-position decides the stacking order of neighboring items.
getZPosition
in class CanvasItem
java.lang.IllegalStateException
- if a valid parent object has not been set.setZPosition(int)
,
setParent(java.lang.Object parent)
public int getLineMarginHeight()
TextEditor
in pixels.
Gets the possible line margin height that editor has in addition to the
normal font height (Font getHeight()
). The returned value is
0 if the editor does not have any additional line margins to the text
height returned from getHeight()
of Font set to the editor.
setParent(java.lang.Object parent)
public int getContentHeight()
TextEditor
in pixels.
The returned value must include the height of the whole content in the editor, not just the height of the visible content.
Note that the method returns 0, if the editor has no parent.
setParent(java.lang.Object parent)
public void setCaret(int index)
Sets the index of the caret. The caret can be used to indicate a position in the text.
The Java platform implementation must scroll the content of the
TextEditor
automatically so that the caret is within the
visible area. If the caret is set above the visible area the content
should be scrolled so that the caret is on the top most visible row. If
the caret is set below the visible area the content should be
scrolled so that the caret is on the lowest visible row.
index
- the character index before which to place the caret
java.lang.StringIndexOutOfBoundsException
- if index
does not specify a valid range within
the content of the TextEditor
public int getCaretPosition()
0
if at the beginningpublic int getVisibleContentPosition()
Gets the topmost pixel position of the topmost visible line in the editor.
The returned y coordinate value is relative to the whole content height, not just the visible part.
This method can be used by the application together with the
getContentHeight
, height of the font,
getLineMarginHeight
, and getCaretPosition
methods in drawing custom visual cues like a scroll bar or other content
sensitive pop-ups.
Note that the method returns 0, if the editor has no parent.
public Font getFont()
Gets the font being used in rendering the text content in this
TextEditor
.
TextEditor
public void setFont(Font font)
Sets the application preferred font for rendering the text content in
this TextEditor
. Setting the font is a hint to the
implementation, and the implementation may disregard the requested font.
The font
parameter must be a valid Font
object
or null
. If the font
parameter is
null
, the implementation must use its default font to render
the text content.
font
- the application preferred font to be used in this
TextEditor
public int getBackgroundColor()
TextEditor
.
public int getForegroundColor()
TextEditor
public void setBackgroundColor(int color)
TextEditor
to
the specified values. The default background color for editor is fully
transparent white.
color
- the colorpublic void setForegroundColor(int color)
TextEditor
to
the specified values. The content, e.g. text, in the editor must be drawn
with this color. The default foreground color is fully opaque black.
color
- the colorpublic void setHighlightBackgroundColor(int color)
color
- the colorpublic void setHighlightForegroundColor(int color)
color
- the colorpublic void setContent(java.lang.String content)
TextEditor
as a string. The set
string replaces any previous content in the editor.
content
- the new content of the TextEditor
as string,
null
empties the TextEditor
java.lang.IllegalArgumentException
- if aContent
is illegal for the current input
constraints
java.lang.IllegalArgumentException
- if the given text would exceed the current maximum capacity
of the editorpublic java.lang.String getContent()
TextEditor
.
public void insert(java.lang.String text, int position)
Inserts a string into the content of the TextEditor
.
The string is inserted just prior to the character indicated by the
position
parameter, where zero specifies the first character
of the content in the TextEditor
. If position
is less than or equal to zero, the insertion occurs at the beginning of
the content. If position
is greater than or equal to the
current size of the content, the insertion occurs immediately after the
end of the content.
The current size of the contents is increased by the number of inserted characters. The resulting string must fit within the current maximum capacity.
text
- the String
to be insertedposition
- the position at which insertion is to occur
java.lang.IllegalArgumentException
- if the resulting content would be illegal for the current
input constraints
java.lang.IllegalArgumentException
- if the insertion would exceed the current maximum capacity
java.lang.NullPointerException
- if text
is null
public void delete(int offset, int length)
Deletes characters from the TextEditor
.
The offset
and length
parameters must specify a
valid range of characters within the contents of the
TextEditor
. The offset
parameter must be within
the range [0..(size())]
, inclusive. The length
parameter must be a non-negative integer such that
(offset + length) <= size()
.
offset
- the beginning of the region to be deletedlength
- the number of characters to be deleted
java.lang.IllegalArgumentException
- if the resulting contents would be illegal for the current
input constraints
java.lang.StringIndexOutOfBoundsException
- if offset
and length
do not specify
a valid range within the content of the
TextEditor
public int getMaxSize()
TextEditor
.
public int setMaxSize(int maxSize)
TextEditor
. If the current content of the
TextEditor
is larger than the new maxSize
, the
content is truncated to fit.
maxSize
- the new maximum size
java.lang.IllegalArgumentException
- if maxSize
is zero or less.
java.lang.IllegalArgumentException
- if the contents after truncation would be illegal for the
current input constraintspublic int size()
TextEditor
.
public void setConstraints(int constraints)
TextEditor
. If the
current content of this TextEditor
do not match the new
constraints, the content is set to empty.
constraints
- see input constraints
java.lang.IllegalArgumentException
- if the value of the constraints parameter is invalidpublic int getConstraints()
TextEditor
.
public void setInitialInputMode(java.lang.String characterSubset)
Sets a hint to the implementation as to the input mode that should be
used when the user initiates editing of this TextEditor
. The
characterSubset
parameter names a subset of Unicode
characters that is used by the implementation to choose an initial input
mode. If null
is passed, the implementation should choose a
default input mode.
See Input Modes for a full explanation of input modes.
characterSubset
- a string naming a Unicode character subset, or
null
public java.lang.String getInitialInputMode()
setInitialInputMode(String characterSubset )
public void setSelection(int index, int length)
Sets a selection on a range of text in the TextEditor
content. The implementation should highlight the selection visually. A
selection may be set with this method or by user interaction. If there
already is a selection set, it is replaced by this new selection.
The caret must be automatically set directly after the set selection. The
Java platform implementation must scroll the content of the
TextEditor
automatically so that the caret is within the
visible area and as much as possible of the selection is visible in the
TextEditor
.
index
- the index of the first character to be selected.length
- the length of the selection in characters, 0 length clears the
selection.
java.lang.StringIndexOutOfBoundsException
- if index
and length
do not specify
a valid range within the content of the
TextEditor
public java.lang.String getSelection()
TextEditor
. A
selection may be set with setSelection method or by user interaction. If
selection is not set non-null empty string is returned.
public void setTextEditorListener(TextEditorListener listener)
Sets a listener for content changes in this TextEditor
,
replacing any previous TextEditorListener
.
A null
reference is allowed and has the effect of removing
any existing TextEditorListener
from this
TextEditor
.
Callbacks to the TextEditorListener may throw exceptions, but they must be ignored.
listener
- the new listener, or null
public boolean isMultiline()
TextEditor
.
public void setMultiline(boolean aMultiline)
aMultiline
- true if multi-line editor, false if single-line editor
java.lang.IllegalStateException
- if a valid parent object has not been set.
|
forum.nokia.com/java | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |