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 class
TextPane.ScrollDirection
Enum representing a scroll direction.static interface
TextPane.Skin
Text 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 void
clearSelection()
Clears the selection.void
copy()
void
cut()
void
delete(boolean backspace)
Delete the currently selected text (ifselectionLength > 0
), or the character before or after the current cursor position, depending on thebackspace
flag.static void
dumpNode(java.lang.String msg, Node node, int indent)
Bounds
getCharacterBounds(int offset)
int
getCharacterCount()
Returns character count of the document.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.Document
getDocument()
boolean
getExpandTabs()
int
getInsertionPoint(int x, int y)
int
getNextInsertionPoint(int x, int from, TextPane.ScrollDirection direction)
int
getRowAt(int offset)
int
getRowCount()
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()
Convenience method to get all the text from the current document into a single string.java.lang.String
getText(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()
void
insert(char character)
void
insert(java.lang.String text)
void
insertComponent(Component component)
void
insertImage(Image image)
void
insertParagraph()
void
insertText(java.lang.String text, int index)
boolean
isEditable()
void
paste()
void
redo()
void
removeText(int offset, int characterCount)
Remove the text from the document starting at the given position for the given number of characters.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
setDocument(Document document)
Sets the document that backs the text pane.void
setEditable(boolean editable)
Sets the text pane's editable flag.void
setExpandTabs(boolean expandTabs)
Sets whether tab characters (\t
) are expanded to an appropriate number of spaces duringsetText(java.lang.String)
andpaste()
operations.void
setSaveHistory(boolean save)
Some document rearrangements might not be suitable for undoing, so allow users to specify when to do so.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
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)
Convenience method to create a text-only document consisting of one paragraph per line of the given text.void
setText(java.net.URL textURL)
void
undo()
-
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:Component
Sets 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
0
if 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 thebackspace
flag.- Parameters:
backspace
-true
if the single character delete is the character before the current position, orfalse
for 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
null
if 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
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).
-
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 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
null
if 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
-true
to replace tab characters with space characters (depending on the setting of theTextPane.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, 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)
-
-