当前位置: 首页>>代码示例>>Java>>正文


Java Iterator类代码示例

本文整理汇总了Java中javax.swing.text.html.HTMLDocument.Iterator的典型用法代码示例。如果您正苦于以下问题:Java Iterator类的具体用法?Java Iterator怎么用?Java Iterator使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


Iterator类属于javax.swing.text.html.HTMLDocument包,在下文中一共展示了Iterator类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getAttribute

import javax.swing.text.html.HTMLDocument.Iterator; //导入依赖的package包/类
@Override public String getAttribute(final String name) {
    if ("text".equals(name)) {
        return getText();
    }
    if ("hRefIndex".equals(name)) {
        return getHRefIndex() + "";
    }
    if ("textIndex".equals(name)) {
        return getTextIndex() + "";
    }
    return EventQueueWait.exec(new Callable<String>() {
        @Override public String call() throws Exception {
            Iterator iterator = findTag((HTMLDocument) ((JEditorPane) parent.getComponent()).getDocument());
            AttributeSet attributes = iterator.getAttributes();
            Attribute attr = findAttribute(name);
            if (attr != null && attributes.isDefined(attr)) {
                return attributes.getAttribute(attr).toString();
            }
            return null;
        }
    });
}
 
开发者ID:jalian-systems,项目名称:marathonv5,代码行数:23,代码来源:JEditorPaneTagJavaElement.java

示例2: _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;
}
 
开发者ID:jalian-systems,项目名称:marathonv5,代码行数:17,代码来源:JEditorPaneTagJavaElement.java

示例3: getTextIndex

import javax.swing.text.html.HTMLDocument.Iterator; //导入依赖的package包/类
public int getTextIndex() {
    return EventQueueWait.exec(new Callable<Integer>() {
        @Override public Integer call() throws Exception {
            String href = getText();
            int hRefIndex = 0;
            int current = 0;
            JEditorPane editor = (JEditorPane) parent.getComponent();
            HTMLDocument document = (HTMLDocument) editor.getDocument();
            Iterator iterator = document.getIterator(Tag.A);
            while (iterator.isValid()) {
                if (current++ >= index) {
                    return hRefIndex;
                }
                String attribute = ((HTMLDocument) ((JEditorPane) parent.getComponent()).getDocument())
                        .getText(iterator.getStartOffset(), iterator.getEndOffset() - iterator.getStartOffset());
                if (attribute != null && attribute.equals(href)) {
                    hRefIndex++;
                }
                iterator.next();
            }
            return -1;
        }
    });
}
 
开发者ID:jalian-systems,项目名称:marathonv5,代码行数:25,代码来源:JEditorPaneTagJavaElement.java

示例4: 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();
    }
}
 
开发者ID:jalian-systems,项目名称:marathonv5,代码行数:26,代码来源:REditorPane.java

示例5: getStationAtLocation

import javax.swing.text.html.HTMLDocument.Iterator; //导入依赖的package包/类
public static String getStationAtLocation(Location l){
	System.out.println("Method called.");
	ApplicableRegionSet set = wg.getRegionManager(l.getWorld()).getApplicableRegions(l);
	System.out.println("Crazy test!");
	Set<ProtectedRegion> regions = set.getRegions();
	java.util.Iterator<ProtectedRegion> i = regions.iterator();
	while(i.hasNext()){
		ProtectedRegion r = i.next();
		List<String> stations = new ArrayList<String>();
		stations.addAll(alphaStations);
		stations.addAll(betaStations);
		stations.addAll(gammaStations);
		for(String s : stations){
			if(r.getId().equals(s.toLowerCase())){
				return s;
			}
		}
	}
	return null;
}
 
开发者ID:StarQuestMinecraft,项目名称:StarQuestCode,代码行数:21,代码来源:StationUtils.java

示例6: _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);
    }
}
 
开发者ID:jalian-systems,项目名称:marathonv5,代码行数:12,代码来源:JEditorPaneTagJavaElement.java

示例7: findTag

import javax.swing.text.html.HTMLDocument.Iterator; //导入依赖的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;
}
 
开发者ID:jalian-systems,项目名称:marathonv5,代码行数:15,代码来源:JEditorPaneTagJavaElement.java

示例8: _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);
    }
}
 
开发者ID:jalian-systems,项目名称:marathonv5,代码行数:13,代码来源:JEditorPaneTagJavaElement.java

示例9: _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);
    }
}
 
开发者ID:jalian-systems,项目名称:marathonv5,代码行数:14,代码来源:JEditorPaneTagJavaElement.java

示例10: getHRefIndex

import javax.swing.text.html.HTMLDocument.Iterator; //导入依赖的package包/类
public int getHRefIndex() {
    return EventQueueWait.exec(new Callable<Integer>() {
        @Override public Integer call() throws Exception {
            String href = getAttribute("href");
            int hRefIndex = 0;
            int current = 0;
            JEditorPane editor = (JEditorPane) parent.getComponent();
            HTMLDocument document = (HTMLDocument) editor.getDocument();
            Iterator iterator = document.getIterator(Tag.A);
            while (iterator.isValid()) {
                if (current++ >= index) {
                    return hRefIndex;
                }
                AttributeSet attributes = iterator.getAttributes();
                if (attributes != null) {
                    Object attributeObject = attributes.getAttribute(HTML.Attribute.HREF);
                    if (attributeObject != null) {
                        String attribute = attributeObject.toString();
                        if (attribute.equals(href)) {
                            hRefIndex++;
                        }
                    }
                }
                iterator.next();
            }
            return -1;
        }
    });
}
 
开发者ID:jalian-systems,项目名称:marathonv5,代码行数:30,代码来源:JEditorPaneTagJavaElement.java

示例11: fillElements

import javax.swing.text.html.HTMLDocument.Iterator; //导入依赖的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();
    }
}
 
开发者ID:jalian-systems,项目名称:marathonv5,代码行数:13,代码来源:JEditorPaneJavaElement.java

示例12: 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();
    }
}
 
开发者ID:jalian-systems,项目名称:marathonv5,代码行数:29,代码来源:REditorPane.java

示例13: 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();
    }
}
 
开发者ID:jalian-systems,项目名称:marathonv5,代码行数:50,代码来源:REditorPaneTest.java

示例14: 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;
}
 
开发者ID:dvorka,项目名称:mindraider,代码行数:75,代码来源:TextWysiwyg.java


注:本文中的javax.swing.text.html.HTMLDocument.Iterator类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。