An iterator to iterate over a particular type of tag.
| Method from javax.swing.text.html.HTMLDocument$LeafIterator Detail: |
public AttributeSet getAttributes() {
Element elem = pos.current();
if (elem != null) {
AttributeSet a = (AttributeSet)
elem.getAttributes().getAttribute(tag);
if (a == null) {
a = (AttributeSet)elem.getAttributes();
}
return a;
}
return null;
}
Returns the attributes for this tag. |
public int getEndOffset() {
return endOffset;
}
Returns the end of the range for which the current occurrence of
the tag is defined and has the same attributes. |
public int getStartOffset() {
Element elem = pos.current();
if (elem != null) {
return elem.getStartOffset();
}
return -1;
}
Returns the start of the range for which the current occurrence of
the tag is defined and has the same attributes. |
public HTML.Tag getTag() {
return tag;
}
Returns the type of tag this iterator represents. |
public boolean isValid() {
return (pos.current() != null);
}
Returns true if the current position is not null. |
public void next() {
for (nextLeaf(pos); isValid(); nextLeaf(pos)) {
Element elem = pos.current();
if (elem.getStartOffset() >= endOffset) {
AttributeSet a = pos.current().getAttributes();
if (a.isDefined(tag) ||
a.getAttribute(StyleConstants.NameAttribute) == tag) {
// we found the next one
setEndOffset();
break;
}
}
}
}
Moves the iterator forward to the next occurrence
of the tag it represents. |
void nextLeaf(ElementIterator iter) {
for (iter.next(); iter.current() != null; iter.next()) {
Element e = iter.current();
if (e.isLeaf()) {
break;
}
}
}
Moves the given iterator to the next leaf element. |
void setEndOffset() {
AttributeSet a0 = getAttributes();
endOffset = pos.current().getEndOffset();
ElementIterator fwd = (ElementIterator) pos.clone();
for (nextLeaf(fwd); fwd.current() != null; nextLeaf(fwd)) {
Element e = fwd.current();
AttributeSet a1 = (AttributeSet) e.getAttributes().getAttribute(tag);
if ((a1 == null) || (! a1.equals(a0))) {
break;
}
endOffset = e.getEndOffset();
}
}
Marches a cloned iterator forward to locate the end
of the run. This sets the value of endOffset. |