Package org.apache.pivot.wtk
Class TextPane
- java.lang.Object
-
- org.apache.pivot.wtk.Component
-
- org.apache.pivot.wtk.Container
-
- org.apache.pivot.wtk.TextPane
-
- All Implemented Interfaces:
java.lang.Iterable<Component>,Sequence<Component>,ConstrainedVisual,Visual
@DefaultProperty("document") public class TextPane extends Container
Component that allows a user to enter and edit multiple lines of (optionally formatted) text.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classTextPane.ScrollDirectionEnum representing a scroll direction.static interfaceTextPane.SkinText pane skin interface.-
Nested classes/interfaces inherited from class org.apache.pivot.wtk.Container
Container.EDTChecker
-
Nested classes/interfaces inherited from class org.apache.pivot.wtk.Component
Component.DecoratorSequence, Component.StyleDictionary, Component.UserDataDictionary
-
Nested classes/interfaces inherited from interface org.apache.pivot.collections.Sequence
Sequence.Tree<T>
-
-
Constructor Summary
Constructors Constructor Description TextPane()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclearSelection()Clears the selection.voidcopy()voidcut()voiddelete(boolean backspace)Delete the currently selected text (ifselectionLength > 0), or the character before or after the current cursor position, depending on thebackspaceflag.static voiddumpNode(java.lang.String msg, Node node, int indent)BoundsgetCharacterBounds(int offset)intgetCharacterCount()Returns character count of the document.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.DocumentgetDocument()booleangetExpandTabs()intgetInsertionPoint(int x, int y)intgetNextInsertionPoint(int x, int from, TextPane.ScrollDirection direction)intgetRowAt(int offset)intgetRowCount()java.lang.StringgetSelectedText()Returns the currently selected text.SpangetSelection()Returns a span representing the current selection.intgetSelectionLength()intgetSelectionStart()java.lang.StringgetText()Convenience method to get all the text from the current document into a single string.java.lang.StringgetText(int beginIndex, int endIndex)Convenience method to get a portion of the document text into a single string.ListenerList<TextPaneCharacterListener>getTextPaneCharacterListeners()ListenerList<TextPaneListener>getTextPaneListeners()ListenerList<TextPaneSelectionListener>getTextPaneSelectionListeners()voidinsert(char character)voidinsert(java.lang.String text)voidinsertComponent(Component component)voidinsertImage(Image image)voidinsertParagraph()voidinsertText(java.lang.String text, int index)booleanisEditable()voidpaste()voidredo()voidremoveText(int offset, int characterCount)Remove the text from the document starting at the given position for the given number of characters.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).voidsetDocument(Document document)Sets the document that backs the text pane.voidsetEditable(boolean editable)Sets the text pane's editable flag.voidsetExpandTabs(boolean expandTabs)Sets whether tab characters (\t) are expanded to an appropriate number of spaces duringsetText(java.lang.String)andpaste()operations.voidsetSaveHistory(boolean save)Some document rearrangements might not be suitable for undoing, so allow users to specify when to do so.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.voidsetText(java.io.File f)voidsetText(java.io.File f, java.nio.charset.Charset cs)voidsetText(java.io.Reader textReader)voidsetText(java.lang.String text)Convenience method to create a text-only document consisting of one paragraph per line of the given text.voidsetText(java.net.URL textURL)voidundo()-
Methods inherited from class org.apache.pivot.wtk.Container
add, assertEventDispatchThread, assertEventDispatchThread, clear, containsFocus, descendantAdded, descendantGainedFocus, descendantLostFocus, descendantRemoved, get, getComponentAt, getContainerListeners, getContainerMouseListeners, getDescendantAt, getFocusTraversalPolicy, getGraphics, getLength, getNamedComponent, indexOf, insert, invalidate, isAncestor, isDoubleBuffered, iterator, layout, load, mouseClick, mouseDown, mouseMove, mouseOut, mouseUp, mouseWheel, move, paint, remove, remove, removeAll, repaint, requestFocus, setDoubleBuffered, setEventDispatchThreadChecker, setFocusTraversalPolicy, setParent, setVisible, store, transferFocus, update
-
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, 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, isBlocked, isEnabled, isFocusable, isFocused, isMouseOver, isOpaque, isPreferredHeightSet, isPreferredSizeSet, isPreferredWidthSet, isShowing, isValid, isVisible, keyPressed, keyReleased, keyTyped, mapPointFromAncestor, mapPointFromAncestor, mapPointToAncestor, mapPointToAncestor, mouseOver, offsetToScreen, putStyle, putStyle, reenterMouse, repaint, repaint, repaint, repaint, repaint, scrollAreaToVisible, scrollAreaToVisible, setAttribute, setAutomationID, setAutomationID, setCursor, setDragSource, setDropTarget, setEnabled, setFocused, setHeight, setHeightLimits, setHeightLimits, setLocation, setLocation, setMaximumHeight, setMaximumWidth, setMenuHandler, setMinimumHeight, setMinimumWidth, setName, setPreferredHeight, setPreferredSize, setPreferredSize, setPreferredWidth, setSize, setSize, setStyleName, setStyleNames, setStyleNames, setStyles, setStyles, setTooltipDelay, setTooltipText, setTooltipWrapText, setWidth, setWidthLimits, setWidthLimits, setX, setY, toString, transferFocus, validate
-
-
-
-
Method Detail
-
setSkin
protected void setSkin(Skin skin)
Description copied from class:ComponentSets the skin, replacing any previous skin.
-
getDocument
public Document getDocument()
- Returns:
- The document that backs the text pane.
-
setDocument
public void setDocument(Document document)
Sets the document that backs the text pane. Documents are not shareable across multiple TextPanes; because a Document may contain Components, and a Component may only be in one Container at a time.- Parameters:
document- The new document to be displayed by this text pane.
-
setSaveHistory
public void setSaveHistory(boolean save)
Some document rearrangements might not be suitable for undoing, so allow users to specify when to do so.- Parameters:
save- Whether or not to save history at this time.
-
insert
public void insert(char character)
-
insert
public void insert(java.lang.String text)
-
insertText
public void insertText(java.lang.String text, int index)
-
insertImage
public void insertImage(Image image)
-
insertComponent
public void insertComponent(Component component)
-
insertParagraph
public void insertParagraph()
-
getCharacterCount
public int getCharacterCount()
Returns character count of the document.- Returns:
- The document's character count, or
0if the document isnull.
-
delete
public void delete(boolean backspace)
Delete the currently selected text (ifselectionLength > 0), or the character before or after the current cursor position, depending on thebackspaceflag.- Parameters:
backspace-trueif the single character delete is the character before the current position, orfalsefor the character after (at) the current position.
-
removeText
public void removeText(int offset, int characterCount)Remove the text from the document starting at the given position for the given number of characters.- Parameters:
offset- Starting location to remove text.characterCount- The number of characters to remove.
-
cut
public void cut()
-
copy
public void copy()
-
paste
public void paste()
-
undo
public void undo()
-
redo
public void redo()
-
getText
public java.lang.String getText()
Convenience method to get all the text from the current document into a single string.- Returns:
- The complete text of the document as a string.
- See Also:
setText(java.lang.String)
-
getText
public java.lang.String getText(int beginIndex, int endIndex)Convenience method to get a portion of the document text into a single string.- Parameters:
beginIndex- The 0-based offset where to start retrieving text.endIndex- The ending offset + 1 of the text to retrieve.- Returns:
- The specified portion of the document text if there is any, or
nullif there is no document.
-
setText
public void setText(java.lang.String text)
Convenience method to create a text-only document consisting of one paragraph per line of the given text.- Parameters:
text- The new complete text for the document.
-
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
-
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).
-
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
nullif 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 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 new span describing the selection.- Throws:
java.lang.IllegalArgumentException- if the 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 void selectAll()
Selects all text.
-
clearSelection
public void clearSelection()
Clears the selection.
-
getSelectedText
public java.lang.String getSelectedText()
Returns the currently selected text.- Returns:
- A new string containing a copy of the text in the selected range,
or
nullif nothing is selected.
-
isEditable
public boolean isEditable()
- Returns:
- The text pane's editable flag.
-
setEditable
public void setEditable(boolean editable)
Sets the text pane's editable flag.- Parameters:
editable- Whether or not the text should be editable now.
-
getExpandTabs
public boolean getExpandTabs()
-
setExpandTabs
public void setExpandTabs(boolean expandTabs)
Sets whether tab characters (\t) are expanded to an appropriate number of spaces duringsetText(java.lang.String)andpaste()operations. Note: doing this for keyboard input is handled in the skin.- Parameters:
expandTabs-trueto replace tab characters with space characters (depending on the setting of theTextPane.Skin.getTabWidth()value) orfalseto 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, TextPane.ScrollDirection direction)
-
getRowAt
public int getRowAt(int offset)
-
getRowCount
public int getRowCount()
-
getCharacterBounds
public Bounds getCharacterBounds(int offset)
-
getTextPaneListeners
public ListenerList<TextPaneListener> getTextPaneListeners()
-
getTextPaneCharacterListeners
public ListenerList<TextPaneCharacterListener> getTextPaneCharacterListeners()
-
getTextPaneSelectionListeners
public ListenerList<TextPaneSelectionListener> getTextPaneSelectionListeners()
-
dumpNode
public static void dumpNode(java.lang.String msg, Node node, int indent)
-
-