本文整理汇总了Java中javax.swing.text.html.HTMLDocument.Iterator.getStartOffset方法的典型用法代码示例。如果您正苦于以下问题:Java Iterator.getStartOffset方法的具体用法?Java Iterator.getStartOffset怎么用?Java Iterator.getStartOffset使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.swing.text.html.HTMLDocument.Iterator
的用法示例。
在下文中一共展示了Iterator.getStartOffset方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: _makeVisible
import javax.swing.text.html.HTMLDocument.Iterator; //导入方法依赖的package包/类
@Override public Object _makeVisible() {
JEditorPane editor = (JEditorPane) parent.getComponent();
Iterator iterator = findTag((HTMLDocument) editor.getDocument());
int startOffset = iterator.getStartOffset();
int endOffset = iterator.getEndOffset();
try {
Rectangle bounds = editor.modelToView(startOffset + (endOffset - startOffset) / 2);
if (bounds != null) {
bounds.height = editor.getVisibleRect().height;
editor.scrollRectToVisible(bounds);
}
} catch (BadLocationException e) {
throw new InvalidElementStateException("Unable to get text for tag " + tag + " in document with index " + index, e);
}
return null;
}
示例2: setHRef
import javax.swing.text.html.HTMLDocument.Iterator; //导入方法依赖的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: _getText
import javax.swing.text.html.HTMLDocument.Iterator; //导入方法依赖的package包/类
@Override public String _getText() {
Iterator iterator = findTag((HTMLDocument) ((JEditorPane) parent.getComponent()).getDocument());
int startOffset = iterator.getStartOffset();
int endOffset = iterator.getEndOffset();
try {
return ((HTMLDocument) ((JEditorPane) parent.getComponent()).getDocument()).getText(startOffset,
endOffset - startOffset);
} catch (BadLocationException e) {
throw new InvalidElementStateException("Unable to get text for tag " + tag + " in document with index " + index, e);
}
}
示例4: _moveto
import javax.swing.text.html.HTMLDocument.Iterator; //导入方法依赖的package包/类
@Override public void _moveto() {
JEditorPane editor = (JEditorPane) parent.getComponent();
Iterator iterator = findTag((HTMLDocument) editor.getDocument());
int startOffset = iterator.getStartOffset();
int endOffset = iterator.getEndOffset();
try {
Rectangle bounds = editor.modelToView(startOffset + (endOffset - startOffset) / 2);
getDriver().getDevices().moveto(parent.getComponent(), bounds.x + bounds.width / 2, bounds.y + bounds.height / 2);
} catch (BadLocationException e) {
throw new InvalidElementStateException("Unable to get text for tag " + tag + " in document with index " + index, e);
}
}
示例5: _getMidpoint
import javax.swing.text.html.HTMLDocument.Iterator; //导入方法依赖的package包/类
@Override public Point _getMidpoint() {
JEditorPane editor = (JEditorPane) parent.getComponent();
Iterator iterator = findTag((HTMLDocument) editor.getDocument());
int startOffset = iterator.getStartOffset();
int endOffset = iterator.getEndOffset();
try {
Rectangle bounds = editor.modelToView(startOffset + (endOffset - startOffset) / 2);
return new Point(bounds.x + bounds.width / 2, bounds.y + bounds.height / 2);
} catch (BadLocationException e) {
throw new InvalidElementStateException("Unable to get text for tag " + tag + " in document with index " + index + "("
+ "StartOffset: " + startOffset + " EndOffset: " + endOffset + ")", e);
}
}
示例6: setIndexOfHrefAndText
import javax.swing.text.html.HTMLDocument.Iterator; //导入方法依赖的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();
}
}
示例7: searchAsText
import javax.swing.text.html.HTMLDocument.Iterator; //导入方法依赖的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();
}
}
示例8: injectLinksToText
import javax.swing.text.html.HTMLDocument.Iterator; //导入方法依赖的package包/类
/**
* Inject hyperlinks to text.
*
* @param text
* annotation.
* @param mrHyperlink
* hyperlink to be included (in MR format
* {@link NoteInterlinking}). Can be null.
* @param offset
* where to include hyperlink.
* @return annotation with injected links.
*/
private String injectLinksToText(String text, String mrHyperlink, int offset) {
logger.debug("=-> injectLinksToText");
// convert links to MR notation
Iterator iterator = ((HTMLDocument) getDocument()).getIterator(HTML.getTag("a"));
int lastIndex = 0;
boolean injected = true;
if (mrHyperlink != null && offset >= 0) {
injected = false;
}
StringBuffer linked = new StringBuffer();
do {
if (iterator.getStartOffset() > 0) {
// injection: is it between the last position and the next
// injection?
if (!injected && offset < iterator.getStartOffset()) {
injectLinksToTextAppend(mrHyperlink, text, offset, lastIndex, linked);
lastIndex = offset;
injected = true;
}
// process regular links
String hrefText = text.substring(iterator.getStartOffset(), iterator.getEndOffset());
Object hrefAttribute = iterator.getAttributes().getAttribute(HTML.Attribute.HREF);
if(hrefAttribute==null) {
linked.append(text.substring(lastIndex, iterator.getStartOffset()));
} else {
String href = hrefAttribute.toString();
logger.debug(" [" + iterator.getStartOffset() + "-" + iterator.getEndOffset() + "]: "
+ hrefText + " # " + href);
if (NoteInterlinking.isMindRaiderLink(href)) {
injectLinksToTextAppend("%GREEN%[[" + href + "][" + hrefText + "]]%ENDCOLOR%",
text,
iterator.getStartOffset(),
lastIndex,
linked);
} else {
injectLinksToTextAppend("[[" + href + "][" + hrefText + "]]",
text,
iterator.getStartOffset(),
lastIndex,
linked);
}
}
lastIndex = iterator.getEndOffset();
iterator.next();
} else {
break;
}
} while (true);
// check whether injection is in the last part
if (!injected) {
injectLinksToTextAppend(mrHyperlink, text, offset, lastIndex, linked);
lastIndex = offset;
}
linked.append(text.substring(lastIndex));
String result = linked.toString();
return result;
}