Class Node
- java.lang.Object
-
- org.apache.pivot.wtk.text.Node
-
- Direct Known Subclasses:
ComponentNode
,Element
,ImageNode
,TextNode
public abstract class Node extends java.lang.Object
Abstract base class for document nodes.
-
-
Constructor Summary
Constructors Constructor Description Node()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract Node
duplicate(boolean recursive)
Creates a copy of this node.abstract char
getCharacterAt(int offsetArgument)
abstract int
getCharacterCount()
abstract java.lang.CharSequence
getCharacters()
int
getDocumentOffset()
Span
getDocumentSpan()
ListenerList<NodeListener>
getNodeListeners()
int
getOffset()
Returns the node's offset relative to its parent.Paragraph
getParagraph()
Get the parent paragraph of this node.Element
getParent()
Returns the parent element of this node.abstract Node
getRange(int offsetArgument, int characterCount)
Returns a range from the node.java.lang.Object
getUserData()
abstract void
insertRange(Node range, int offsetArgument)
Inserts a range into the node.protected void
nodeInserted(int offsetArgument)
Called to notify parent nodes and other listeners for the node that a child node has been inserted.protected void
nodesRemoved(Node node, Sequence<Node> removed, int offsetArgument)
Called to notify parent nodes and other listeners for the node that child nodes have been removed.protected void
rangeInserted(int offsetArgument, int characterCount)
Called to notify parent nodes and other listeners for the node that a range has been inserted.protected void
rangeRemoved(Node node, int offsetArgument, int characterCount, java.lang.CharSequence removedChars)
Called to notify parent nodes and other listeners for the node that a range has been removed.abstract Node
removeRange(int offsetArgument, int characterCount)
Removes a range from the node.Node
replaceRange(int offsetArgument, int characterCount, Node range)
Replaces an existing range with a new range.protected void
setOffset(int offset)
Set the offset of this node relative to its parent.protected void
setParent(Element parent)
void
setUserData(java.lang.Object userData)
Set the user data associated with this node.
-
-
-
Method Detail
-
getParent
public Element getParent()
Returns the parent element of this node.- Returns:
- The node's parent, or
null
if the node does not have a parent.
-
setParent
protected void setParent(Element parent)
-
getOffset
public int getOffset()
Returns the node's offset relative to its parent.- Returns:
- The integer offset of the node's first character within its parent element.
-
setOffset
protected void setOffset(int offset)
Set the offset of this node relative to its parent.- Parameters:
offset
- The new offset for this node.
-
getDocumentOffset
public int getDocumentOffset()
- Returns:
- The node's offset within the document, which will be the offset of our parent (if any) added to our own offset.
-
getDocumentSpan
public Span getDocumentSpan()
- Returns:
- A
Span
that describes the content range of this node relative to the whole document.
-
getParagraph
public Paragraph getParagraph()
Get the parent paragraph of this node.- Returns:
- The paragraph this node is contained within or
null
it there are none (should only be for top-level elements or the document itself).
-
insertRange
public abstract void insertRange(Node range, int offsetArgument)
Inserts a range into the node. Note that the contents of the range, rather than the range itself, is added to the node.- Parameters:
range
- The node containing the text to insert.offsetArgument
- Offset relative to this node.
-
removeRange
public abstract Node removeRange(int offsetArgument, int characterCount)
Removes a range from the node.- Parameters:
offsetArgument
- Offset relative to this node.characterCount
- Count of characters to remove.- Returns:
- The removed range. This will be a copy of the node structure relative to this node.
-
replaceRange
public Node replaceRange(int offsetArgument, int characterCount, Node range)
Replaces an existing range with a new range.- Parameters:
offsetArgument
- Offset relative to this node.characterCount
- Count of characters to replace.range
- The new range to insert.- Returns:
- The removed range. This will be a copy of the node structure relative to this node.
-
getRange
public abstract Node getRange(int offsetArgument, int characterCount)
Returns a range from the node.- Parameters:
offsetArgument
- Offset relative to this node.characterCount
- Count of characters to get.- Returns:
- A node containing a copy of the node structure spanning the given range, relative to this node.
-
getCharacterAt
public abstract char getCharacterAt(int offsetArgument)
- Parameters:
offsetArgument
- Offset relative to this node.- Returns:
- The character at the given offset.
-
getCharacterCount
public abstract int getCharacterCount()
- Returns:
- The number of characters in this node.
-
getCharacters
public abstract java.lang.CharSequence getCharacters()
- Returns:
- The character sequence in this node.
-
duplicate
public abstract Node duplicate(boolean recursive)
Creates a copy of this node.- Parameters:
recursive
- Whether to duplicate the children also.- Returns:
- A copy of the current node.
-
rangeInserted
protected void rangeInserted(int offsetArgument, int characterCount)
Called to notify parent nodes and other listeners for the node that a range has been inserted. All parents are notified first.Note: The offset used to notify parents is the given offset added to the offset of this node (that is, it will be parent-relative). Therefore the topmost node will be given the offset into the whole document. Listeners for this node will just be given the offset relative to this node.
- Parameters:
offsetArgument
- Offset relative to this node.characterCount
- Count of characters inserted.
-
rangeRemoved
protected void rangeRemoved(Node node, int offsetArgument, int characterCount, java.lang.CharSequence removedChars)
Called to notify parent nodes and other listeners for the node that a range has been removed. All parents are notified first.Note: The offset used to notify parents is the given offset added to the offset of this node (that is, it will be parent-relative). Therefore the topmost node will be given the offset into the whole document. Listeners for this node will just be given the offset relative to this node.
- Parameters:
node
- The original node (that is, NOT the parent) where the range was removed.offsetArgument
- Offset relative to the current node.characterCount
- Count of characters removed.removedChars
- The optional actual characters removed (only in the case of direct removal from a text node).
-
nodesRemoved
protected void nodesRemoved(Node node, Sequence<Node> removed, int offsetArgument)
Called to notify parent nodes and other listeners for the node that child nodes have been removed. All parents are notified first.Note: The offset used to notify parents is the given offset added to the offset of this node (that is, it will be parent-relative). Therefore the topmost node will be given the offset into the whole document. Listeners for this node will just be given the offset relative to this node.
- Parameters:
node
- The original node (that is, NOT the parent) where the nodes were removed.removed
- The actual sequence of nodes removed from that node.offsetArgument
- Offset relative to this node.
-
nodeInserted
protected void nodeInserted(int offsetArgument)
Called to notify parent nodes and other listeners for the node that a child node has been inserted. All parents are notified first.Note: The offset used to notify parents is the given offset added to the offset of this node (that is, it will be parent-relative). Therefore the topmost node will be given the offset into the whole document. Listeners for this node will just be given the offset relative to this node.
- Parameters:
offsetArgument
- Offset relative to this node.
-
getNodeListeners
public ListenerList<NodeListener> getNodeListeners()
- Returns:
- The node listener list.
-
getUserData
public java.lang.Object getUserData()
- Returns:
- The user data associated with this node.
-
setUserData
public void setUserData(java.lang.Object userData)
Set the user data associated with this node. This can be any piece of data that has meaning to the application, and is meant to link any underlying data structure used to build the document with the document itself.- Parameters:
userData
- Any piece of data that has meaning to the user application (can benull
).
-
-