本文整理汇总了Java中javax.swing.text.html.HTMLDocument.getText方法的典型用法代码示例。如果您正苦于以下问题:Java HTMLDocument.getText方法的具体用法?Java HTMLDocument.getText怎么用?Java HTMLDocument.getText使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.swing.text.html.HTMLDocument
的用法示例。
在下文中一共展示了HTMLDocument.getText方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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();
}
}