javax.swing.text
Interface Element

All Known Implementing Classes:
AbstractDocument.AbstractElement sample code for javax.swing.text.AbstractDocument.AbstractElement definition code for javax.swing.text.AbstractDocument.AbstractElement , AbstractDocument.BranchElement sample code for javax.swing.text.AbstractDocument.BranchElement definition code for javax.swing.text.AbstractDocument.BranchElement , AbstractDocument.LeafElement sample code for javax.swing.text.AbstractDocument.LeafElement definition code for javax.swing.text.AbstractDocument.LeafElement , DefaultStyledDocument.SectionElement sample code for javax.swing.text.DefaultStyledDocument.SectionElement definition code for javax.swing.text.DefaultStyledDocument.SectionElement , HTMLDocument.BlockElement sample code for javax.swing.text.html.HTMLDocument.BlockElement definition code for javax.swing.text.html.HTMLDocument.BlockElement , HTMLDocument.RunElement sample code for javax.swing.text.html.HTMLDocument.RunElement definition code for javax.swing.text.html.HTMLDocument.RunElement

public interface Element

Interface to describe a structural piece of a document. It is intended to capture the spirit of an SGML element.


Method Summary
 AttributeSet sample code for javax.swing.text.AttributeSet definition code for javax.swing.text.AttributeSet getAttributes sample code for javax.swing.text.Element.getAttributes() definition code for javax.swing.text.Element.getAttributes() ()
          Fetches the collection of attributes this element contains.
 Document sample code for javax.swing.text.Document definition code for javax.swing.text.Document getDocument sample code for javax.swing.text.Element.getDocument() definition code for javax.swing.text.Element.getDocument() ()
          Fetches the document associated with this element.
 Element sample code for javax.swing.text.Element definition code for javax.swing.text.Element getElement sample code for javax.swing.text.Element.getElement(int) definition code for javax.swing.text.Element.getElement(int) (int index)
          Fetches the child element at the given index.
 int getElementCount sample code for javax.swing.text.Element.getElementCount() definition code for javax.swing.text.Element.getElementCount() ()
          Gets the number of child elements contained by this element.
 int getElementIndex sample code for javax.swing.text.Element.getElementIndex(int) definition code for javax.swing.text.Element.getElementIndex(int) (int offset)
          Gets the child element index closest to the given offset.
 int getEndOffset sample code for javax.swing.text.Element.getEndOffset() definition code for javax.swing.text.Element.getEndOffset() ()
          Fetches the offset from the beginning of the document that this element ends at.
 String sample code for java.lang.String definition code for java.lang.String getName sample code for javax.swing.text.Element.getName() definition code for javax.swing.text.Element.getName() ()
          Fetches the name of the element.
 Element sample code for javax.swing.text.Element definition code for javax.swing.text.Element getParentElement sample code for javax.swing.text.Element.getParentElement() definition code for javax.swing.text.Element.getParentElement() ()
          Fetches the parent element.
 int getStartOffset sample code for javax.swing.text.Element.getStartOffset() definition code for javax.swing.text.Element.getStartOffset() ()
          Fetches the offset from the beginning of the document that this element begins at.
 boolean isLeaf sample code for javax.swing.text.Element.isLeaf() definition code for javax.swing.text.Element.isLeaf() ()
          Is this element a leaf element? An element that may have children, even if it currently has no children, would return false.
 

Method Detail

getDocument sample code for javax.swing.text.Element.getDocument() definition code for javax.swing.text.Element.getDocument()

Document sample code for javax.swing.text.Document definition code for javax.swing.text.Document  getDocument()
Fetches the document associated with this element.

Returns:
the document

getParentElement sample code for javax.swing.text.Element.getParentElement() definition code for javax.swing.text.Element.getParentElement()

Element sample code for javax.swing.text.Element definition code for javax.swing.text.Element  getParentElement()
Fetches the parent element. If the element is a root level element returns null.

Returns:
the parent element

getName sample code for javax.swing.text.Element.getName() definition code for javax.swing.text.Element.getName()

String sample code for java.lang.String definition code for java.lang.String  getName()
Fetches the name of the element. If the element is used to represent some type of structure, this would be the type name.

Returns:
the element name

getAttributes sample code for javax.swing.text.Element.getAttributes() definition code for javax.swing.text.Element.getAttributes()

AttributeSet sample code for javax.swing.text.AttributeSet definition code for javax.swing.text.AttributeSet  getAttributes()
Fetches the collection of attributes this element contains.

Returns:
the attributes for the element

getStartOffset sample code for javax.swing.text.Element.getStartOffset() definition code for javax.swing.text.Element.getStartOffset()

int getStartOffset()
Fetches the offset from the beginning of the document that this element begins at. If this element has children, this will be the offset of the first child. As a document position, there is an implied forward bias.

Returns:
the starting offset >= 0 and < getEndOffset();
See Also:
Document sample code for javax.swing.text.Document definition code for javax.swing.text.Document , AbstractDocument sample code for javax.swing.text.AbstractDocument definition code for javax.swing.text.AbstractDocument

getEndOffset sample code for javax.swing.text.Element.getEndOffset() definition code for javax.swing.text.Element.getEndOffset()

int getEndOffset()
Fetches the offset from the beginning of the document that this element ends at. If this element has children, this will be the end offset of the last child. As a document position, there is an implied backward bias.

All the default Document implementations descend from AbstractDocument. AbstractDocument models an implied break at the end of the document. As a result of this, it is possible for this to return a value greater than the length of the document.

Returns:
the ending offset > getStartOffset() and <= getDocument().getLength() + 1
See Also:
Document sample code for javax.swing.text.Document definition code for javax.swing.text.Document , AbstractDocument sample code for javax.swing.text.AbstractDocument definition code for javax.swing.text.AbstractDocument

getElementIndex sample code for javax.swing.text.Element.getElementIndex(int) definition code for javax.swing.text.Element.getElementIndex(int)

int getElementIndex(int offset)
Gets the child element index closest to the given offset. The offset is specified relative to the beginning of the document. Returns -1 if the Element is a leaf, otherwise returns the index of the Element that best represents the given location. Returns 0 if the location is less than the start offset. Returns getElementCount() - 1 if the location is greater than or equal to the end offset.

Parameters:
offset - the specified offset >= 0
Returns:
the element index >= 0

getElementCount sample code for javax.swing.text.Element.getElementCount() definition code for javax.swing.text.Element.getElementCount()

int getElementCount()
Gets the number of child elements contained by this element. If this element is a leaf, a count of zero is returned.

Returns:
the number of child elements >= 0

getElement sample code for javax.swing.text.Element.getElement(int) definition code for javax.swing.text.Element.getElement(int)

Element sample code for javax.swing.text.Element definition code for javax.swing.text.Element  getElement(int index)
Fetches the child element at the given index.

Parameters:
index - the specified index >= 0
Returns:
the child element

isLeaf sample code for javax.swing.text.Element.isLeaf() definition code for javax.swing.text.Element.isLeaf()

boolean isLeaf()
Is this element a leaf element? An element that may have children, even if it currently has no children, would return false.

Returns:
true if a leaf element else false