Package org.apache.pivot.wtk
Class TextInput
- java.lang.Object
-
- org.apache.pivot.wtk.Component
-
- org.apache.pivot.wtk.TextInput
-
- All Implemented Interfaces:
ConstrainedVisual
,Visual
public class TextInput extends Component
A component that allows a user to enter a single line of unformatted text.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
TextInput.Skin
Text input skin interface.static interface
TextInput.TextBindMapping
Translates between text and context data during data binding.-
Nested classes/interfaces inherited from class org.apache.pivot.wtk.Component
Component.DecoratorSequence, Component.StyleDictionary, Component.UserDataDictionary
-
-
Field Summary
Fields Modifier and Type Field Description static int
DEFAULT_TEXT_SIZE
-
Constructor Summary
Constructors Constructor Description TextInput()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
clear()
Clears any bound values in the component.void
clearSelection()
Clears the selection.void
copy()
Places any selected text on the clipboard.void
cut()
Places any selected text on the clipboard and deletes it from the text input.char
getCharacterAt(int index)
Bounds
getCharacterBounds(int index)
int
getCharacterCount()
java.lang.CharSequence
getCharacters()
java.lang.CharSequence
getCharacters(int start, int end)
CharSpan
getCharSelection()
Returns a character span (start, length) representing the current selection.AttributedStringCharacterIterator
getComposedText()
Return the current text that is in process of being composed using the Input Method Editor.int
getInsertionPoint(int x)
int
getMaximumLength()
Returns the maximum length of the text input's text content.java.lang.String
getPrompt()
java.lang.String
getSelectedText()
Returns the currently selected text.Span
getSelection()
Returns a span representing the current selection.int
getSelectionLength()
int
getSelectionStart()
java.lang.String
getText()
Returns the text content of the text input.java.lang.String
getText(int beginIndex, int endIndex)
Returns a portion of the text content of the text input.TextInput.TextBindMapping
getTextBindMapping()
BindType
getTextBindType()
ListenerList<TextInputBindingListener>
getTextInputBindingListeners()
ListenerList<TextInputContentListener>
getTextInputContentListeners()
ListenerList<TextInputListener>
getTextInputListeners()
ListenerList<TextInputSelectionListener>
getTextInputSelectionListeners()
java.lang.String
getTextKey()
Returns the text input's text key.int
getTextSize()
Returns the text size.Validator
getValidator()
void
insertText(java.lang.CharSequence text, int index)
boolean
isEditable()
boolean
isPassword()
Returns the password flag.boolean
isStrictValidation()
boolean
isTextValid()
Reports whether this text input's text is currently valid as defined by its validator.void
load(java.lang.Object context)
Copies bound values from the bind context to the component.void
paste()
Inserts text from the clipboard into the text input.void
removeText(int index, int count)
void
selectAll()
Selects all text.void
setComposedText(AttributedStringCharacterIterator composedText)
Called from the Input Method Editor callbacks to set the current composed text (that is, the text currently being composed into something meaningful).void
setEditable(boolean editable)
Sets the text area's editable flag.void
setMaximumLength(int maximumLength)
Sets the maximum length of the text input's text content.void
setPassword(boolean password)
Sets or clears the password flag.void
setPrompt(java.lang.String prompt)
Sets the text input's prompt.void
setSelection(int selectionStart, int selectionLength)
Sets the selection.void
setSelection(CharSpan selection)
Sets the selection.void
setSelection(Span selection)
Sets the selection.protected void
setSkin(Skin skin)
Sets the skin, replacing any previous skin.void
setStrictValidation(boolean strictValidation)
Sets the text input's strict validation flag.void
setText(java.lang.CharSequence text)
void
setText(java.lang.String text)
void
setTextBindMapping(TextInput.TextBindMapping textBindMapping)
void
setTextBindType(BindType textBindType)
void
setTextKey(java.lang.String textKey)
Sets the text input's text key.void
setTextSize(int textSize)
Sets the text size.void
setValidator(Validator validator)
Sets the validator associated with this text input.void
store(java.lang.Object context)
Copies bound values from the component to the bind context.void
undo()
-
Methods inherited from class org.apache.pivot.wtk.Component
checkSkin, clearFocus, contains, copyStyle, copyStyle, getAncestor, getAncestor, getAttribute, getAutomationID, getBaseline, getBaseline, getBounds, getComponentClassListeners, getComponentDataListeners, getComponentDecoratorListeners, getComponentKeyListeners, getComponentListeners, getComponentMouseButtonListeners, getComponentMouseListeners, getComponentMouseWheelListeners, getComponentStateListeners, getComponentStyleListeners, getComponentTooltipListeners, getCursor, getDecoratedBounds, getDecorators, getDisplay, getDragSource, getDropTarget, getFocusedComponent, getGraphics, getHeight, getHeightLimits, getLocation, getMaximumHeight, getMaximumWidth, getMenuHandler, getMinimumHeight, getMinimumWidth, getMouseLocation, getName, getNamedStyles, getParent, getPreferredHeight, getPreferredHeight, getPreferredSize, getPreferredWidth, getPreferredWidth, getScreenBounds, getSize, getSkin, getStyle, getStyle, getStyleBoolean, getStyleBoolean, getStyleColor, getStyleColor, getStyleFont, getStyleFont, getStyleInt, getStyleInt, getStyles, getTextInputMethodListener, getTooltipDelay, getTooltipText, getTooltipWrapText, getTypedStyles, getUserData, getVisibleArea, getVisibleArea, getVisibleArea, getWidth, getWidthLimits, getWindow, getX, getY, indexBoundsCheck, installSkin, invalidate, isBlocked, isEnabled, isFocusable, isFocused, isMouseOver, isOpaque, isPreferredHeightSet, isPreferredSizeSet, isPreferredWidthSet, isShowing, isValid, isVisible, keyPressed, keyReleased, keyTyped, layout, mapPointFromAncestor, mapPointFromAncestor, mapPointToAncestor, mapPointToAncestor, mouseClick, mouseDown, mouseMove, mouseOut, mouseOver, mouseUp, mouseWheel, offsetToScreen, paint, putStyle, putStyle, reenterMouse, repaint, repaint, repaint, repaint, repaint, repaint, requestFocus, scrollAreaToVisible, scrollAreaToVisible, setAttribute, setAutomationID, setAutomationID, setCursor, setDragSource, setDropTarget, setEnabled, setFocused, setHeight, setHeightLimits, setHeightLimits, setLocation, setLocation, setMaximumHeight, setMaximumWidth, setMenuHandler, setMinimumHeight, setMinimumWidth, setName, setParent, setPreferredHeight, setPreferredSize, setPreferredSize, setPreferredWidth, setSize, setSize, setStyleName, setStyleNames, setStyleNames, setStyles, setStyles, setTooltipDelay, setTooltipText, setTooltipWrapText, setVisible, setWidth, setWidthLimits, setWidthLimits, setX, setY, toString, transferFocus, validate
-
-
-
-
Field Detail
-
DEFAULT_TEXT_SIZE
public static final int DEFAULT_TEXT_SIZE
- See Also:
- Constant Field Values
-
-
Method Detail
-
setSkin
protected void setSkin(Skin skin)
Description copied from class:Component
Sets the skin, replacing any previous skin.
-
getText
public java.lang.String getText()
Returns the text content of the text input.- Returns:
- A string containing a copy of the text input's text content.
-
getText
public java.lang.String getText(int beginIndex, int endIndex)
Returns a portion of the text content of the text input.- Parameters:
beginIndex
- The starting index of the text to retrieve (inclusive).endIndex
- The ending index of the text (exclusive).- Returns:
- A string containing a copy of the text area's text content.
-
setText
public void setText(java.lang.String text)
-
setText
public void setText(java.lang.CharSequence text)
-
insertText
public void insertText(java.lang.CharSequence text, int index)
-
removeText
public void removeText(int index, int count)
-
getComposedText
public AttributedStringCharacterIterator getComposedText()
Return the current text that is in process of being composed using the Input Method Editor. This is temporary text that must be displayed, scrolled, etc. but is not a permanent part of what would be returned fromgetText()
for instance.- Returns:
- The current composed text or
null
if we're not using an IME or we're in English input mode, or user just committed or deleted the composed text.
-
setComposedText
public void setComposedText(AttributedStringCharacterIterator composedText)
Called from the Input Method Editor callbacks to set the current composed text (that is, the text currently being composed into something meaningful).- Parameters:
composedText
- The current composed text (which can benull
for many different reasons).
-
getCharacters
public java.lang.CharSequence getCharacters()
- Returns:
- A character sequence representing the text input's content.
-
getCharacters
public java.lang.CharSequence getCharacters(int start, int end)
- Parameters:
start
- The start of the sequence (inclusive).end
- The end of the sequence (exclusive).- Returns:
- A (sub) character sequence representing the contents between the given indices.
-
getCharacterAt
public char getCharacterAt(int index)
- Parameters:
index
- Location of the character to retrieve.- Returns:
- The character at a given index.
-
getCharacterCount
public int getCharacterCount()
- Returns:
- The number of characters in the text input.
-
cut
public void cut()
Places any selected text on the clipboard and deletes it from the text input.
-
copy
public void copy()
Places any selected text on the clipboard.
-
paste
public void paste()
Inserts text from the clipboard into the text input.
-
undo
public void undo()
-
getSelectionStart
public final int getSelectionStart()
- Returns:
- The starting index of the selection.
-
getSelectionLength
public final int getSelectionLength()
- Returns:
- The length of the selection; may be
0
.
-
getSelection
public final Span getSelection()
Returns a span representing the current selection.- Returns:
- A span containing the current selection. Both start and end
points are inclusive. Returns
null
if the selection length is0
.
-
getCharSelection
public final CharSpan getCharSelection()
Returns a character span (start, length) representing the current selection.- Returns:
- A char span with the start and length values.
-
setSelection
public final void setSelection(int selectionStart, int selectionLength)
Sets the selection. The sum of the selection start and length must be less than the length of the text input's content.- Parameters:
selectionStart
- The starting index of the selection.selectionLength
- The length of the selection.
-
setSelection
public final void setSelection(Span selection)
Sets the selection.- Parameters:
selection
- The span (start inclusive to end inclusive).- Throws:
java.lang.IllegalArgumentException
- if the selection span isnull
.- See Also:
setSelection(int, int)
-
setSelection
public final void setSelection(CharSpan selection)
Sets the selection.- Parameters:
selection
- The character span (start and length) for the selection.- Throws:
java.lang.IllegalArgumentException
- if the character span isnull
.- See Also:
setSelection(int, int)
-
selectAll
public final void selectAll()
Selects all text.
-
clearSelection
public final void clearSelection()
Clears the selection.
-
getSelectedText
public final java.lang.String getSelectedText()
Returns the currently selected text.- Returns:
- A new string containing a copy of the text in the selected range.
-
getTextSize
public final int getTextSize()
Returns the text size.- Returns:
- The number of characters to display in the text input.
-
setTextSize
public final void setTextSize(int textSize)
Sets the text size.- Parameters:
textSize
- The number of characters to display in the text input.- Throws:
java.lang.IllegalArgumentException
- if the size value is negative.
-
getMaximumLength
public final int getMaximumLength()
Returns the maximum length of the text input's text content.- Returns:
- The maximum length of the text input's text content.
-
setMaximumLength
public final void setMaximumLength(int maximumLength)
Sets the maximum length of the text input's text content.- Parameters:
maximumLength
- The maximum length of the text input's text content.- Throws:
java.lang.IllegalArgumentException
- if the length value is negative.
-
isPassword
public final boolean isPassword()
Returns the password flag.- Returns:
true
if this is a password text input;false
, otherwise.
-
setPassword
public final void setPassword(boolean password)
Sets or clears the password flag. If the password flag is set, the text input will visually mask its contents.- Parameters:
password
-true
if this is a password text input;false
, otherwise.
-
getPrompt
public final java.lang.String getPrompt()
- Returns:
- The text input's prompt.
-
setPrompt
public final void setPrompt(java.lang.String prompt)
Sets the text input's prompt.- Parameters:
prompt
- The prompt text, ornull
for no prompt.
-
getTextKey
public final java.lang.String getTextKey()
Returns the text input's text key.- Returns:
- The text key, or
null
if no text key is set.
-
setTextKey
public final void setTextKey(java.lang.String textKey)
Sets the text input's text key.- Parameters:
textKey
- The text key, ornull
to clear the binding.
-
getTextBindType
public final BindType getTextBindType()
-
setTextBindType
public final void setTextBindType(BindType textBindType)
-
getTextBindMapping
public final TextInput.TextBindMapping getTextBindMapping()
-
setTextBindMapping
public final void setTextBindMapping(TextInput.TextBindMapping textBindMapping)
-
load
public void load(java.lang.Object context)
Description copied from class:Component
Copies bound values from the bind context to the component. This functionality must be provided by the subclass; the base implementation is a no-op.
-
store
public void store(java.lang.Object context)
Description copied from class:Component
Copies bound values from the component to the bind context. This functionality must be provided by the subclass; the base implementation is a no-op.
-
clear
public void clear()
Description copied from class:Component
Clears any bound values in the component. This functionality must be provided by the subclass; the base implementation is a no-op.
-
getInsertionPoint
public final int getInsertionPoint(int x)
-
getCharacterBounds
public final Bounds getCharacterBounds(int index)
-
getValidator
public final Validator getValidator()
- Returns:
- The validator associated with this text input.
-
setValidator
public final void setValidator(Validator validator)
Sets the validator associated with this text input.- Parameters:
validator
- The validator to use, ornull
to use no validator.
-
isStrictValidation
public final boolean isStrictValidation()
- Returns:
- The text input's strict validation flag.
-
setStrictValidation
public final void setStrictValidation(boolean strictValidation)
Sets the text input's strict validation flag. When enabled, only valid text will be accepted by the text input.- Parameters:
strictValidation
- The new flag setting.
-
isTextValid
public final boolean isTextValid()
Reports whether this text input's text is currently valid as defined by its validator.- Returns:
true
if the text is valid or no validator is installed;false
, otherwise.
-
isEditable
public final boolean isEditable()
- Returns:
- The text area's editable flag.
-
setEditable
public final void setEditable(boolean editable)
Sets the text area's editable flag.- Parameters:
editable
- The new flag setting.
-
getTextInputListeners
public ListenerList<TextInputListener> getTextInputListeners()
- Returns:
- The text input listener list.
-
getTextInputContentListeners
public ListenerList<TextInputContentListener> getTextInputContentListeners()
- Returns:
- The text input content listener list.
-
getTextInputSelectionListeners
public ListenerList<TextInputSelectionListener> getTextInputSelectionListeners()
- Returns:
- The text input selection listener list.
-
getTextInputBindingListeners
public ListenerList<TextInputBindingListener> getTextInputBindingListeners()
- Returns:
- The text input binding listener list.
-
-