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 interfaceTextInput.SkinText input skin interface.static interfaceTextInput.TextBindMappingTranslates 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 intDEFAULT_TEXT_SIZE
-
Constructor Summary
Constructors Constructor Description TextInput()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclear()Clears any bound values in the component.voidclearSelection()Clears the selection.voidcopy()Places any selected text on the clipboard.voidcut()Places any selected text on the clipboard and deletes it from the text input.chargetCharacterAt(int index)BoundsgetCharacterBounds(int index)intgetCharacterCount()java.lang.CharSequencegetCharacters()java.lang.CharSequencegetCharacters(int start, int end)CharSpangetCharSelection()Returns a character span (start, length) representing the current selection.AttributedStringCharacterIteratorgetComposedText()Return the current text that is in process of being composed using the Input Method Editor.intgetInsertionPoint(int x)intgetMaximumLength()Returns the maximum length of the text input's text content.java.lang.StringgetPrompt()java.lang.StringgetSelectedText()Returns the currently selected text.SpangetSelection()Returns a span representing the current selection.intgetSelectionLength()intgetSelectionStart()java.lang.StringgetText()Returns the text content of the text input.java.lang.StringgetText(int beginIndex, int endIndex)Returns a portion of the text content of the text input.TextInput.TextBindMappinggetTextBindMapping()BindTypegetTextBindType()ListenerList<TextInputBindingListener>getTextInputBindingListeners()ListenerList<TextInputContentListener>getTextInputContentListeners()ListenerList<TextInputListener>getTextInputListeners()ListenerList<TextInputSelectionListener>getTextInputSelectionListeners()java.lang.StringgetTextKey()Returns the text input's text key.intgetTextSize()Returns the text size.ValidatorgetValidator()voidinsertText(java.lang.CharSequence text, int index)booleanisEditable()booleanisPassword()Returns the password flag.booleanisStrictValidation()booleanisTextValid()Reports whether this text input's text is currently valid as defined by its validator.voidload(java.lang.Object context)Copies bound values from the bind context to the component.voidpaste()Inserts text from the clipboard into the text input.voidremoveText(int index, int count)voidselectAll()Selects all text.voidsetComposedText(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).voidsetEditable(boolean editable)Sets the text area's editable flag.voidsetMaximumLength(int maximumLength)Sets the maximum length of the text input's text content.voidsetPassword(boolean password)Sets or clears the password flag.voidsetPrompt(java.lang.String prompt)Sets the text input's prompt.voidsetSelection(int selectionStart, int selectionLength)Sets the selection.voidsetSelection(CharSpan selection)Sets the selection.voidsetSelection(Span selection)Sets the selection.protected voidsetSkin(Skin skin)Sets the skin, replacing any previous skin.voidsetStrictValidation(boolean strictValidation)Sets the text input's strict validation flag.voidsetText(java.lang.CharSequence text)voidsetText(java.lang.String text)voidsetTextBindMapping(TextInput.TextBindMapping textBindMapping)voidsetTextBindType(BindType textBindType)voidsetTextKey(java.lang.String textKey)Sets the text input's text key.voidsetTextSize(int textSize)Sets the text size.voidsetValidator(Validator validator)Sets the validator associated with this text input.voidstore(java.lang.Object context)Copies bound values from the component to the bind context.voidundo()-
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:ComponentSets 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
nullif 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 benullfor 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
nullif 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:
trueif 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-trueif 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, ornullfor no prompt.
-
getTextKey
public final java.lang.String getTextKey()
Returns the text input's text key.- Returns:
- The text key, or
nullif 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, ornullto 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:ComponentCopies 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:ComponentCopies 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:ComponentClears 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, ornullto 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:
trueif 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.
-
-