Package org.apache.pivot.wtk.text
Class Paragraph
- java.lang.Object
 - 
- org.apache.pivot.wtk.text.Node
 - 
- org.apache.pivot.wtk.text.Element
 - 
- org.apache.pivot.wtk.text.Block
 - 
- org.apache.pivot.wtk.text.Paragraph
 
 
 
 
 
- 
public class Paragraph extends Block
Element representing a paragraph.TODO Add indent property.
Every paragraph has a trailing newline ('\n') character, which is not actually present in any of its child text nodes. Therefore all the logic in here must account for this extra phantom character.
 
- 
- 
Nested Class Summary
- 
Nested classes/interfaces inherited from interface org.apache.pivot.collections.Sequence
Sequence.Tree<T> 
 - 
 
- 
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intadd(java.lang.String text)Add a piece of text to this paragraph (at the end, but before the trailing newline).Paragraphduplicate(boolean recursive)Creates a copy of this node.chargetCharacterAt(int offset)Retrieve the character at the given offset in this paragraph.intgetCharacterCount()NodegetDescendantAt(int offset)Get the descendant node at the given offset.Sequence<java.lang.Integer>getPathAt(int offset)Get the path through our descendants for the given offset into this paragraph.ParagraphgetRange(int offset, int characterCount)Get a newParagraphcontaining the given range of characters from this paragraph.voidinsert(Node node, int index)Inserts an item into the sequence at a specific index.NoderemoveRange(int offset, int characterCount)Remove a range of characters from this paragraph.- 
Methods inherited from class org.apache.pivot.wtk.text.Block
getBlockListeners, getHorizontalAlignment, setHorizontalAlignment 
- 
Methods inherited from class org.apache.pivot.wtk.text.Element
add, get, getBackgroundColor, getCharacters, getElementListeners, getFont, getForegroundColor, getLength, getNodeAt, getText, indexOf, insertRange, isStrikethrough, isUnderline, iterator, rangeInserted, rangeRemoved, remove, remove, setBackgroundColor, setBackgroundColor, setFont, setFont, setFont, setForegroundColor, setForegroundColor, setStrikethrough, setUnderline, update 
- 
Methods inherited from class org.apache.pivot.wtk.text.Node
getDocumentOffset, getDocumentSpan, getNodeListeners, getOffset, getParagraph, getParent, getUserData, nodeInserted, nodesRemoved, replaceRange, setOffset, setParent, setUserData 
 - 
 
 - 
 
- 
- 
Constructor Detail
- 
Paragraph
public Paragraph()
 
- 
Paragraph
public Paragraph(java.lang.String text)
 
- 
Paragraph
public Paragraph(Paragraph paragraph, boolean recursive)
 
 - 
 
- 
Method Detail
- 
removeRange
public Node removeRange(int offset, int characterCount)
Remove a range of characters from this paragraph.- Overrides:
 removeRangein classElement- Parameters:
 offset- Offset into this paragraph.characterCount- How many characters to remove.- Returns:
 - A new 
Nodecontaining the removed characters. 
 
- 
getRange
public Paragraph getRange(int offset, int characterCount)
Get a newParagraphcontaining the given range of characters from this paragraph. 
- 
getCharacterAt
public char getCharacterAt(int offset)
Retrieve the character at the given offset in this paragraph.- Overrides:
 getCharacterAtin classElement- Parameters:
 offset- Offset into this paragraph.- Returns:
 - The character at that position.
 
 
- 
getCharacterCount
public int getCharacterCount()
- Overrides:
 getCharacterCountin classElement- Returns:
 - The count of characters in this paragraph, which is one more than the number of characters in all child nodes (because of the trailing newline implicitly present).
 
 
- 
add
public int add(java.lang.String text)
Add a piece of text to this paragraph (at the end, but before the trailing newline). If the paragraph had no text previously then a newTextNodechild is created containing this text. Otherwise, if the last child node contains text, then just append this new text to the existing node.- Parameters:
 text- The text to add.- Returns:
 - The index of the (new or existing) text node where the text was added.
 
 
- 
insert
public void insert(Node node, int index)
Description copied from interface:SequenceInserts an item into the sequence at a specific index. 
- 
getPathAt
public Sequence<java.lang.Integer> getPathAt(int offset)
Get the path through our descendants for the given offset into this paragraph. 
- 
getDescendantAt
public Node getDescendantAt(int offset)
Get the descendant node at the given offset. If the offset is the last character in this paragraph (namely the phantom newline) then return ourselves, otherwise the normal descendant at that offset.- Overrides:
 getDescendantAtin classElement- Parameters:
 offset- Offset into this paragraph.- Returns:
 - The descendant node at that offset.
 
 
 - 
 
 -