本文整理汇总了Java中javax.swing.text.html.HTMLDocument.getIterator方法的典型用法代码示例。如果您正苦于以下问题:Java HTMLDocument.getIterator方法的具体用法?Java HTMLDocument.getIterator怎么用?Java HTMLDocument.getIterator使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.swing.text.html.HTMLDocument
的用法示例。
在下文中一共展示了HTMLDocument.getIterator方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: showInThreads
import javax.swing.text.html.HTMLDocument; //导入方法依赖的package包/类
public void showInThreads(Instance instance) {
if (!showThreads) {
showThreads = true;
instanceToSelect = instance;
refreshSummary();
return;
}
String referenceId = String.valueOf(instance.getInstanceId());
dataArea.scrollToReference(referenceId);
Document d = dataArea.getDocument();
HTMLDocument doc = (HTMLDocument) d;
HTMLDocument.Iterator iter = doc.getIterator(HTML.Tag.A);
for (; iter.isValid(); iter.next()) {
AttributeSet a = iter.getAttributes();
String nm = (String) a.getAttribute(HTML.Attribute.NAME);
if ((nm != null) && nm.equals(referenceId)) {
dataArea.select(iter.getStartOffset(),iter.getEndOffset());
dataArea.requestFocusInWindow();
}
}
}
示例2: setHRef
import javax.swing.text.html.HTMLDocument; //导入方法依赖的package包/类
public void setHRef(int pos, Document doc) {
hRef = null;
text = null;
if (!(doc instanceof HTMLDocument)) {
return;
}
HTMLDocument hdoc = (HTMLDocument) doc;
Iterator iterator = hdoc.getIterator(HTML.Tag.A);
while (iterator.isValid()) {
if (pos >= iterator.getStartOffset() && pos < iterator.getEndOffset()) {
AttributeSet attributes = iterator.getAttributes();
if (attributes != null && attributes.getAttribute(HTML.Attribute.HREF) != null) {
try {
text = hdoc.getText(iterator.getStartOffset(), iterator.getEndOffset() - iterator.getStartOffset()).trim();
hRef = attributes.getAttribute(HTML.Attribute.HREF).toString();
setIndexOfHrefAndText(hdoc, pos, text, hRef);
} catch (BadLocationException e) {
e.printStackTrace();
}
return;
}
}
iterator.next();
}
}
示例3: findTag
import javax.swing.text.html.HTMLDocument; //导入方法依赖的package包/类
private Iterator findTag(HTMLDocument doc) {
Iterator iterator = doc.getIterator(tag);
int current = 0;
while (iterator.isValid()) {
if (current++ == index) {
break;
}
iterator.next();
}
if (!iterator.isValid()) {
throw new NoSuchElementException("Unable to find tag " + tag + " in document with index " + index, null);
}
return iterator;
}
示例4: fillElements
import javax.swing.text.html.HTMLDocument; //导入方法依赖的package包/类
private void fillElements(Tag tag, ArrayList<IJavaElement> r, Predicate predicate) {
HTMLDocument document = (HTMLDocument) ((JEditorPane) getComponent()).getDocument();
Iterator iterator = document.getIterator(tag);
int index = 0;
while (iterator.isValid()) {
JEditorPaneTagJavaElement e = new JEditorPaneTagJavaElement(this, tag, index++);
if (predicate.isValid(e)) {
r.add(e);
}
iterator.next();
}
}
示例5: setIndexOfHrefAndText
import javax.swing.text.html.HTMLDocument; //导入方法依赖的package包/类
private void setIndexOfHrefAndText(HTMLDocument hdoc, int pos, String text, String hRef) {
this.hRefIndex = 0;
this.textIndex = 0;
Iterator iterator = hdoc.getIterator(HTML.Tag.A);
while (iterator.isValid()) {
if (pos >= iterator.getStartOffset() && pos < iterator.getEndOffset()) {
return;
} else {
AttributeSet attributes = iterator.getAttributes();
if (attributes != null && attributes.getAttribute(HTML.Attribute.HREF) != null) {
try {
String t = hdoc.getText(iterator.getStartOffset(), iterator.getEndOffset() - iterator.getStartOffset())
.trim();
String h = attributes.getAttribute(HTML.Attribute.HREF).toString();
if (t.equals(text)) {
this.textIndex++;
}
if (h.equals(hRef)) {
this.hRefIndex++;
}
} catch (BadLocationException e) {
e.printStackTrace();
}
}
}
iterator.next();
}
}
示例6: searchAsText
import javax.swing.text.html.HTMLDocument; //导入方法依赖的package包/类
private void searchAsText(String spec, boolean isText) {
Document document = getEditor().getDocument();
hRef = null;
text = null;
hRefIndex = 0;
textIndex = 0;
linkPosition = -1;
int lastIndexOf = spec.lastIndexOf('(');
if (lastIndexOf != -1) {
if (isText) {
textIndex = Integer.parseInt(spec.substring(lastIndexOf + 1, spec.length() - 1));
} else {
hRefIndex = Integer.parseInt(spec.substring(lastIndexOf + 1, spec.length() - 1));
}
spec = spec.substring(0, lastIndexOf);
}
if (!(document instanceof HTMLDocument)) {
return;
}
HTMLDocument hdoc = (HTMLDocument) document;
Iterator iterator = hdoc.getIterator(HTML.Tag.A);
int curIndex = 0;
while (iterator.isValid()) {
String t;
AttributeSet attributes = iterator.getAttributes();
try {
if (isText) {
t = hdoc.getText(iterator.getStartOffset(), iterator.getEndOffset() - iterator.getStartOffset());
} else {
t = attributes.getAttribute(HTML.Attribute.HREF).toString();
}
} catch (BadLocationException e1) {
return;
}
if (t.contains(spec) && (isText && curIndex++ == textIndex || !isText && curIndex++ == hRefIndex)) {
if (attributes != null && attributes.getAttribute(HTML.Attribute.HREF) != null) {
try {
text = hdoc.getText(iterator.getStartOffset(), iterator.getEndOffset() - iterator.getStartOffset()).trim();
hRef = attributes.getAttribute(HTML.Attribute.HREF).toString();
linkPosition = (iterator.getStartOffset() + iterator.getEndOffset()) / 2;
} catch (BadLocationException e) {
return;
}
return;
}
}
iterator.next();
}
}