Package org.apache.pivot.wtk
Class TextArea
- java.lang.Object
-
- org.apache.pivot.wtk.Component
-
- org.apache.pivot.wtk.TextArea
-
- All Implemented Interfaces:
ConstrainedVisual
,Visual
- Direct Known Subclasses:
TableViewTextAreaCellRenderer
public class TextArea extends Component
A component that allows a user to enter multiple lines of unformatted text.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
TextArea.Paragraph
Class representing a paragraph of text.static interface
TextArea.ParagraphListener
Paragraph listener interface.class
TextArea.ParagraphSequence
Text area paragraph sequence.static class
TextArea.ScrollDirection
Enum representing a scroll direction.static interface
TextArea.Skin
Text area skin interface.static interface
TextArea.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
-
-
Constructor Summary
Constructors Constructor Description TextArea()
-
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.boolean
getExpandTabs()
int
getInsertionPoint(int x, int y)
int
getMaximumLength()
int
getNextInsertionPoint(int x, int from, TextArea.ScrollDirection direction)
int
getParagraphAt(int index)
TextArea.ParagraphSequence
getParagraphs()
int
getRowAt(int index)
java.lang.CharSequence
getRowCharacters(int index)
int
getRowCount()
int
getRowLength(int index)
int
getRowOffset(int index)
java.lang.String
getSelectedText()
Returns the 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 area.java.lang.String
getText(int beginIndex, int endIndex)
Returns a portion of the text content of the text area.ListenerList<TextAreaBindingListener>
getTextAreaBindingListeners()
ListenerList<TextAreaContentListener>
getTextAreaContentListeners()
ListenerList<TextAreaListener>
getTextAreaListeners()
ListenerList<TextAreaSelectionListener>
getTextAreaSelectionListeners()
TextArea.TextBindMapping
getTextBindMapping()
BindType
getTextBindType()
java.lang.String
getTextKey()
Returns the text area's text key.void
insertText(java.lang.CharSequence text, int index)
boolean
isEditable()
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
removeText(CharSpan charSelection)
void
selectAll()
Selects all text.void
setComposedText(AttributedStringCharacterIterator currentComposedText)
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 editableValue)
Sets the text area's editable flag.void
setExpandTabs(boolean expandValue)
Sets whether tab characters (\t
) are expanded to an appropriate number of spaces duringsetText(java.lang.String)
andinsertText(java.lang.CharSequence, int)
operations.void
setMaximumLength(int newMaximum)
Sets the maximum length of the text area's text content.void
setSelection(int newStart, int newLength)
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
setText(java.io.File f)
void
setText(java.io.File f, java.nio.charset.Charset cs)
void
setText(java.io.Reader textReader)
void
setText(java.lang.String text)
Sets the text content of the text area.void
setText(java.net.URL textURL)
void
setTextBindMapping(TextArea.TextBindMapping newTextBindMapping)
void
setTextBindType(BindType newTextBindType)
void
setTextKey(java.lang.String newTextKey)
Sets the text area's text key.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
-
-
-
-
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 area.- Returns:
- A string containing a copy of the text area's text content.
-
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 currentComposedText)
Called from the Input Method Editor callbacks to set the current composed text (that is, the text currently being composed into something meaningful).- Parameters:
currentComposedText
- The current composed text (which can benull
for many different reasons).
-
getText
public java.lang.String getText(int beginIndex, int endIndex)
Returns a portion of the text content of the text area.- Parameters:
beginIndex
- The beginning location (inclusive) to obtain text from.endIndex
- The ending location (exclusive) of the text segment to fetch.- Returns:
- A string containing a copy of the text area's text content.
-
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.
-
setText
public void setText(java.lang.String text)
Sets the text content of the text area.- Parameters:
text
- The new text for the control (cannot benull
).
-
setText
public void setText(java.net.URL textURL) throws java.io.IOException
- Throws:
java.io.IOException
-
setText
public void setText(java.io.File f) throws java.io.IOException
- Throws:
java.io.IOException
-
setText
public void setText(java.io.File f, java.nio.charset.Charset cs) throws java.io.IOException
- Throws:
java.io.IOException
-
setText
public void setText(java.io.Reader textReader) throws java.io.IOException
- Throws:
java.io.IOException
-
insertText
public void insertText(java.lang.CharSequence text, int index)
-
removeText
public void removeText(CharSpan charSelection)
-
removeText
public void removeText(int index, int count)
-
getParagraphs
public TextArea.ParagraphSequence getParagraphs()
- Returns:
- The text area's paragraph sequence.
-
getParagraphAt
public int getParagraphAt(int index)
- Parameters:
index
- The character index to check ([0..characterCount]
).- Returns:
- The index of the paragraph containing a given character index.
-
getCharacterAt
public char getCharacterAt(int index)
- Parameters:
index
- The index of the character to fetch ([0..characterCount-1]
).- Returns:
- The character at a given index.
-
getCharacterCount
public int getCharacterCount()
- Returns:
- The number of characters in the text area, including line break characters.
-
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 int getSelectionStart()
- Returns:
- The starting index of the selection.
-
getSelectionLength
public int getSelectionLength()
- Returns:
- The length of the selection; may be
0
.
-
getSelection
public 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 is empty.
-
getCharSelection
public CharSpan getCharSelection()
Returns a character span (start, length) representing the current selection.- Returns:
- A char span with the start and length values.
-
setSelection
public void setSelection(int newStart, int newLength)
Sets the selection. The sum of the selection start and length must be less than the length of the text area's content.- Parameters:
newStart
- The starting index of the selection.newLength
- The length of the selection.
-
setSelection
public final void setSelection(Span selection)
Sets the selection.- Parameters:
selection
- The new span of text to select.- 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 void selectAll()
Selects all text.
-
clearSelection
public void clearSelection()
Clears the selection.
-
getSelectedText
public java.lang.String getSelectedText()
Returns the selected text.- Returns:
- A string containing a copy of the selected text.
-
getMaximumLength
public int getMaximumLength()
- Returns:
- The maximum length of the text area's text content.
-
setMaximumLength
public void setMaximumLength(int newMaximum)
Sets the maximum length of the text area's text content.- Parameters:
newMaximum
- The maximum length of the text area's text content.
-
isEditable
public boolean isEditable()
- Returns:
- The text area's editable flag.
-
setEditable
public void setEditable(boolean editableValue)
Sets the text area's editable flag.- Parameters:
editableValue
- Whether or not the text should now be editable.
-
getTextKey
public java.lang.String getTextKey()
Returns the text area's text key.- Returns:
- The text key, or
null
if no text key is set.
-
setTextKey
public void setTextKey(java.lang.String newTextKey)
Sets the text area's text key.- Parameters:
newTextKey
- The text key, ornull
to clear the binding.
-
getTextBindType
public BindType getTextBindType()
-
setTextBindType
public void setTextBindType(BindType newTextBindType)
-
getTextBindMapping
public TextArea.TextBindMapping getTextBindMapping()
-
setTextBindMapping
public void setTextBindMapping(TextArea.TextBindMapping newTextBindMapping)
-
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.
-
getExpandTabs
public boolean getExpandTabs()
-
setExpandTabs
public void setExpandTabs(boolean expandValue)
Sets whether tab characters (\t
) are expanded to an appropriate number of spaces duringsetText(java.lang.String)
andinsertText(java.lang.CharSequence, int)
operations.- Parameters:
expandValue
-true
to replace tab characters with space characters (depending on the setting of theTextArea.Skin.getTabWidth()
value) orfalse
to leave tabs alone. Note: this only affects tabs encountered during program operations; tabs entered via the keyboard by the user are always expanded, regardless of this setting.
-
getInsertionPoint
public int getInsertionPoint(int x, int y)
-
getNextInsertionPoint
public int getNextInsertionPoint(int x, int from, TextArea.ScrollDirection direction)
-
getRowAt
public int getRowAt(int index)
-
getRowOffset
public int getRowOffset(int index)
-
getRowLength
public int getRowLength(int index)
-
getRowCharacters
public java.lang.CharSequence getRowCharacters(int index)
-
getRowCount
public int getRowCount()
-
getCharacterBounds
public Bounds getCharacterBounds(int index)
-
getTextAreaListeners
public ListenerList<TextAreaListener> getTextAreaListeners()
-
getTextAreaContentListeners
public ListenerList<TextAreaContentListener> getTextAreaContentListeners()
-
getTextAreaSelectionListeners
public ListenerList<TextAreaSelectionListener> getTextAreaSelectionListeners()
-
getTextAreaBindingListeners
public ListenerList<TextAreaBindingListener> getTextAreaBindingListeners()
-
-