Package javax.swing.text.html.HTMLDocument

Examples of javax.swing.text.html.HTMLDocument.Iterator


        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();
        }
    }
View Full Code Here


    }

    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();
        }
    }
View Full Code Here

            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) {
                e1.printStackTrace();
                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) {
                        e.printStackTrace();
                    }
                    return;
                }
            }
            iterator.next();
        }
        throw new ComponentException("extra info for last click is invalid : " + spec, finder.getScriptModel(), windowMonitor);
    }
View Full Code Here

        attr.addAttribute(StyleConstants.NameAttribute, Tag.B.toString());
        htmlDoc.insertString(0, "0000", attr);
        StyleConstants.setItalic(attr, true);
        htmlDoc.insertString(4, "1111", attr);
       
        final Iterator iterator1 = htmlDoc.getIterator(Tag.HTML);
        final Iterator iterator2 = htmlDoc.getIterator(Tag.HTML);
        final Iterator iterator3 = htmlDoc.getIterator(Tag.A);
        final Iterator iterator4 = htmlDoc.getIterator(Tag.P);
        final Iterator iterator5 = htmlDoc.getIterator(Tag.B);
        assertNotNull(iterator1);
        assertNotNull(iterator2);
        assertNotNull(iterator3);
        if (isHarmony()) {
            assertNotNull(iterator4);
        }
        assertNotNull(iterator5);
        assertNotSame(iterator1, iterator2);
        assertNotSame(iterator2, iterator3);
        assertNotSame(iterator3, iterator5);

        assertEquals(Tag.HTML, iterator1.getTag());
        if (isHarmony()) {
            assertTrue(iterator1.isValid());
            assertEquals(0, iterator1.getStartOffset());
            assertEquals(9, iterator1.getEndOffset());
            assertNotNull(iterator1.getAttributes());
            iterator1.next();
            assertFalse(iterator1.isValid());
            assertEquals(-1, iterator1.getStartOffset());
            assertEquals(-1, iterator1.getEndOffset());
            assertNull(iterator1.getAttributes());
        }

        assertEquals(Tag.HTML, iterator2.getTag());
        if (isHarmony()) {
            assertTrue(iterator2.isValid());
            assertEquals(0, iterator2.getStartOffset());
            assertEquals(9, iterator2.getEndOffset());
            assertNotNull(iterator2.getAttributes());
            iterator2.next();
            assertFalse(iterator2.isValid());
            assertEquals(-1, iterator2.getStartOffset());
            assertEquals(-1, iterator2.getEndOffset());
            assertNull(iterator2.getAttributes());
        }

        assertEquals(Tag.A, iterator3.getTag());
        if (isHarmony()) {
            assertFalse(iterator3.isValid());
            assertNull(iterator3.getAttributes());
            iterator3.next();
            assertEquals(-1, iterator3.getStartOffset());
            assertEquals(-1, iterator3.getEndOffset());
        }

        if (isHarmony()) {
            assertEquals(Tag.P, iterator4.getTag());
            assertTrue(iterator4.isValid());
            assertEquals(0, iterator4.getStartOffset());
            assertEquals(9, iterator4.getEndOffset());
            iterator4.next();
            assertFalse(iterator4.isValid());
            assertEquals(-1, iterator4.getStartOffset());
            assertEquals(-1, iterator4.getEndOffset());
            assertNull(iterator4.getAttributes());
        }

        assertEquals(Tag.B, iterator5.getTag());
        if (isHarmony()) {
            assertTrue(iterator5.isValid());
            assertEquals(0, iterator5.getStartOffset());
            assertEquals(4, iterator5.getEndOffset());
            assertFalse(StyleConstants.isBold(iterator5.getAttributes()));
            assertFalse(StyleConstants.isItalic(iterator5.getAttributes()));
            iterator5.next();
            assertTrue(iterator5.isValid());
            assertEquals(4, iterator5.getStartOffset());
            assertEquals(8, iterator5.getEndOffset());
            assertFalse(StyleConstants.isBold(iterator5.getAttributes()));
            assertTrue(StyleConstants.isItalic(iterator5.getAttributes()));
            iterator5.next();
            assertFalse(iterator5.isValid());
            assertEquals(-1, iterator5.getStartOffset());
            assertEquals(-1, iterator5.getEndOffset());
            assertNull(iterator5.getAttributes());
        }
    }
View Full Code Here

TOP

Related Classes of javax.swing.text.html.HTMLDocument.Iterator

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.