public class Text extends StyledWidget
EMPTY_ELEMENT_ARRAY
Constructor and Description |
---|
Text()
Creates an empty text.
|
Text(java.lang.String text)
Creates a text with an initial content.
|
Text(java.lang.String text,
java.lang.String placeHolder)
Creates a text with an initial content and a place holder.
|
Modifier and Type | Method and Description |
---|---|
void |
addOnClickListener(OnClickListener onClickListener)
Adds a listener on the click events of the text.
|
void |
addOnTextChangeListener(OnTextChangeListener onTextChangeListener)
Adds a listener on the text change events of the text.
|
void |
back()
Removes the character just before the caret.
|
void |
gainFocus() |
int |
getCaret()
Gets the caret position in the text.
|
java.lang.String |
getPlaceHolder()
Gets the place holder.
|
java.lang.String |
getSelection()
Gets the part of the text that is selected.
|
int |
getSelectionEnd()
Gets the end index of the selection.
|
int |
getSelectionStart()
Gets the start index of the selection.
|
java.lang.String |
getText()
Gets the full text of the text field.
|
int |
getTextLength()
Gets the full text length of the text field.
|
boolean |
handleEvent(int event) |
void |
hideNotify() |
void |
insert(char c)
Inserts a character in the text field at the caret position.
|
void |
insert(java.lang.String text)
Inserts a string in the text field at the caret position.
|
boolean |
isEmpty()
Gets whether or not the text is empty.
|
boolean |
isInState(State state)
Gets whether or not the element is in the given state.
|
protected boolean |
isShownCaret()
Gets whether the caret is currently shown or not.
|
void |
lostFocus() |
void |
removeOnClickListener(OnClickListener onClickListener)
Removes a listener on the click events of the text.
|
void |
removeOnTextChangeListener(OnTextChangeListener onTextChangeListener)
Removes a listener on the text change events of the text.
|
void |
renderContent(ej.microui.display.GraphicsContext g,
Style style,
Rectangle bounds)
Renders the content of the renderable without the border, margin and padding specified in the style.
|
void |
setActive(boolean active)
Activates or deactivates the text.
|
void |
setCaret(int position)
Sets the caret position in the text.
|
void |
setPlaceHolder(java.lang.String placeHolder)
Sets the place holder.
|
void |
setSelection(int start,
int end)
Sets the selection range in the text.
|
void |
setText(java.lang.String text)
Sets the content text.
|
Rectangle |
validateContent(Style style,
Rectangle availableSize)
Gets the content size of the renderable without the border, margin and padding specified in the style.
|
addClassSelector, contains, getAttribute, getChild, getChildrenCount, getChildrenElements, getContentBounds, getParentElement, getStyle, hasClassSelector, isTransparent, mergeStyle, removeAllClassSelectors, removeClassSelector, removeInstanceStyle, render, setClassSelectors, setEnabled, updateStyle, updateStyleOnly, validate
getAbsoluteX, getAbsoluteX, getAbsoluteY, getAbsoluteY, getEventHandler, getHeight, getPanel, getParent, getPreferredHeight, getPreferredWidth, getRelativeX, getRelativeY, getWidgetAt, getWidth, getX, getY, hasFocus, invalidate, isEnabled, isShown, isValid, isVisible, repaint, repaint, requestFocus, requestFocus, revalidate, revalidateSubTree, setBounds, setEventHandler, setLocation, setPreferredSize, setSize, setVisible, showNotify
public Text()
public Text(java.lang.String text)
text
- the text to set.java.lang.NullPointerException
- if the given text is null
.public Text(java.lang.String text, java.lang.String placeHolder)
The place holder is displayed when the text is empty.
text
- the text to set.placeHolder
- the place holder to set.java.lang.NullPointerException
- if one or both the given text and place holder are null
.public java.lang.String getPlaceHolder()
public java.lang.String getText()
public int getTextLength()
public void setPlaceHolder(java.lang.String placeHolder)
placeHolder
- the place holder to set.java.lang.NullPointerException
- if the given place holder is null
.public void setText(java.lang.String text)
text
- the text to set.java.lang.NullPointerException
- if the given text is null
.public void back()
If a part of the text is selected, it is removed instead of the character.
If the text is modified, the state listener is notified.
public void insert(java.lang.String text)
If a part of the text is selected, it is removed.
If the text is modified, the state listener is notified.
text
- the string to insert.addOnTextChangeListener(OnTextChangeListener)
public void insert(char c)
If a part of the text is selected, it is removed.
If the text is modified, the state listener is notified.
c
- the character to insert.addOnTextChangeListener(OnTextChangeListener)
public boolean isEmpty()
true
if the text is empty, false
otherwise.public java.lang.String getSelection()
The selection is the part of text between selection start.
public int getCaret()
public int getSelectionStart()
public int getSelectionEnd()
public void setSelection(int start, int end)
start
- the selection start index.end
- the selection end index.public void setCaret(int position)
position
- the caret index.protected boolean isShownCaret()
This state changes repeatedly when the text is active and the caret is blinking.
true
if the caret is shown, false
otherwise.public void addOnTextChangeListener(OnTextChangeListener onTextChangeListener)
onTextChangeListener
- the text listener to add.java.lang.NullPointerException
- if the given listener is null
.public void removeOnTextChangeListener(OnTextChangeListener onTextChangeListener)
onTextChangeListener
- the text listener to remove.public void addOnClickListener(OnClickListener onClickListener)
onClickListener
- the click listener to add.java.lang.NullPointerException
- if the given listener is null
.public void removeOnClickListener(OnClickListener onClickListener)
onClickListener
- the click listener to remove.public void renderContent(ej.microui.display.GraphicsContext g, Style style, Rectangle bounds)
StyledRenderable
The given graphics context is translated and clipped according to the given bounds (the border, margin and padding are applied on this graphics context before).
g
- the graphics context where to render the content of the renderable.style
- the style to use.bounds
- the remaining size to render the content.Outline.apply(GraphicsContext, Rectangle)
,
Border.apply(GraphicsContext, Rectangle, int)
,
StyleHelper.renderWithoutContent(GraphicsContext, Rectangle, Style)
public Rectangle validateContent(Style style, Rectangle availableSize)
StyledRenderable
style
- the style to use.availableSize
- the bounds available for the content. A width or a height equals to MWT.NONE
means no
constraint on this dimension.public void setActive(boolean active)
When the text is active or has the focus, the cursor blinks, otherwise the cursor is not visible.
active
- true
to activate the text, false
otherwise.public void gainFocus()
gainFocus
in class StyledWidget
public void lostFocus()
lostFocus
in class StyledWidget
public void hideNotify()
hideNotify
in interface ej.mwt.Renderable
hideNotify
in class ej.mwt.Widget
public boolean isInState(State state)
Element
isInState
in interface Element
isInState
in class StyledWidget
state
- the state to check.true
if the element is in the given state, false
otherwise.public boolean handleEvent(int event)
handleEvent
in interface ej.mwt.Renderable
handleEvent
in class ej.mwt.Widget