Package javax.swing.text.AbstractDocument

Examples of javax.swing.text.AbstractDocument.LeafElement


            html.addAttribute(ELEMENT_NAME, "html");
            final BranchElement body = createBranch(html);
            body.addAttribute(ELEMENT_NAME, "body");
            final BranchElement p = createBranch(body);
            p.addAttribute(ELEMENT_NAME, "p");
            final LeafElement content = createLeaf(p, 0, 1);
            content.addAttribute(ELEMENT_NAME, "leaf1");
            p.replace(0, 0, new Element[] { content });
            body.replace(0, 0, new Element[] { p });
            html.replace(0, 1, new Element[] { body });
        } finally {
            doc.writeUnlock();
View Full Code Here


            testDoc = new PlainDocument() {
                private static final long serialVersionUID = 1L;

                @Override
                protected AbstractElement createDefaultRoot() {
                    AbstractElement root = new LeafElement(null, null, 0, 1);
                    return root;
                }
            };
            if (BasicSwingTestCase.isHarmony()) {
                fail("ClassCastException must be thrown");
            }
        } catch (ClassCastException e) {
        }
        if (BasicSwingTestCase.isHarmony()) {
            assertNull(testDoc);
            return;
        }
        AbstractElement root = (AbstractElement) testDoc.getDefaultRootElement();
        assertTrue(root instanceof LeafElement);
        assertEquals(AbstractDocument.ContentElementName, root.getName());
        assertEquals(0, root.getElementCount());
        assertFalse(root.getAllowsChildren());
        // Try to insert some text
        try {
            testDoc.insertString(0, "text", null);
            fail("ClassCastException must be thrown");
        } catch (ClassCastException e) {
View Full Code Here

                StyleContextTest.addAttribute(null, 5, 2) };
        doc = new DisAbstractedDocument(new GapContent());
        doc.insertString(0, "0123456789", as[0]);
        doc.writeLock();
        BranchElement branch = doc.new BranchElement(null, as[1]);
        leaf1 = doc.new LeafElement(null, as[2], 0, 3);
        leaf2 = doc.new LeafElement(branch, as[2], 5, 8);
        doc.writeUnlock();
    }
View Full Code Here

        assertEquals(0, leaf1.getElementCount());
    }

    public void testLeafElement() {
        doc.writeLock();
        AbstractDocument.LeafElement leaf = doc.new LeafElement(leaf1, as[2], 3, 9);
        assertSame(leaf1, leaf.getParent());
        assertSame(leaf1, leaf.getParentElement());
        assertSame(leaf, leaf.getAttributes());
        assertEquals(as[2].getAttributeCount(), leaf.getAttributeCount());
        assertEquals(3, leaf.getStartOffset());
        assertEquals(9, leaf.getEndOffset());
        int[] start = { -1, 3, 3, 3 }; // start offset
        int[] expStart = { 0, 3, 3, 3 }; // expectations for start offset
        int[] end = { 9, -1, 1, 20 }; // end offset
        int[] expEnd = { 9, 0, 1, 20 }; // expectations for end offset
        int[] intEnd = { 9, 3, 3, 20 }; // expectations for our end offset
        for (int i = 0; i < start.length; i++) {
            leaf = doc.new LeafElement(null, null, start[i], end[i]);
            assertEquals("Start (" + i + ")", expStart[i], leaf.getStartOffset());
            assertEquals("End (" + i + ")", BasicSwingTestCase.isHarmony() ? intEnd[i]
                    : expEnd[i], leaf.getEndOffset());
        }
        doc.writeUnlock();
    }
View Full Code Here

     */
    public void testBreakViewCreate() throws Exception {
        view = new GlyphView(root) {
            @Override
            public View createFragment(int startOffset, int endOffset) {
                final Element part = ((AbstractDocument) doc).new LeafElement(null, null,
                        startOffset, endOffset);
                return new LabelView(part);
            };
        };
        final float width = metrics.stringWidth(FULL_TEXT.substring(0, 2));
View Full Code Here

            html.addAttribute(ELEMENT_NAME, "html");
            final BranchElement head = createBranch(html);
            head.addAttribute(ELEMENT_NAME, "head");
            final BranchElement implied = createBranch(head);
            implied.addAttribute(ELEMENT_NAME, "p-implied");
            final LeafElement content0 = createLeaf(implied, 0, 1);
            content0.addAttribute(ELEMENT_NAME, "head-content");
            final BranchElement body = createBranch(html);
            body.addAttribute(ELEMENT_NAME, "body");
            final BranchElement p1 = createBranch(body);
            p1.addAttribute(ELEMENT_NAME, "p1");
            final LeafElement content1 = createLeaf(p1, 1, 5);
            content1.addAttribute(ELEMENT_NAME, "leaf1");
            final LeafElement content2 = createLeaf(p1, 5, 6);
            content2.addAttribute(ELEMENT_NAME, "leaf2");
            implied.replace(0, 0, new Element[] { content0 });
            p1.replace(0, 0, new Element[] { content1, content2 });
            head.replace(0, 0, new Element[] { implied });
            body.replace(0, 0, new Element[] { p1 });
            html.replace(0, 1, new Element[] { head, body });
View Full Code Here

            html.addAttribute(ELEMENT_NAME, "html");
            final BranchElement body = createBranch(html);
            body.addAttribute(ELEMENT_NAME, "body");
            final BranchElement p = createBranch(body);
            p.addAttribute(ELEMENT_NAME, "p");
            final LeafElement content = createLeaf(p, 0, 1);
            content.addAttribute(ELEMENT_NAME, "leaf1");
            p.replace(0, 0, new Element[] { content });
            body.replace(0, 0, new Element[] { p });
            html.replace(0, 1, new Element[] { body });
        } finally {
            doc.writeUnlock();
View Full Code Here

        private BranchElement defRoot;

        protected void createRoot() {
            writeLock();
            defRoot = new BranchElement(null, null);
            defRoot.replace(0, 0, new Element[] { new LeafElement(defRoot, null, 0, 1) });
            writeUnlock();
        }
View Full Code Here

                    } catch (URISyntaxException ex) {
                        Logger.getLogger(RoomPane.class.getName()).log(Level.SEVERE, null, ex);
                    }
                } else {
                    // From our own server! try to do something clever. (like get the file name from the associated hidden title.)
                    LeafElement be = (LeafElement) e.getSourceElement();
                    Enumeration names = be.getAttributes().getAttributeNames();
                    String fileName = null;
                    while (names.hasMoreElements()) {
                        Object name = names.nextElement();
                        if (HTML.Tag.A.equals(name)) {
                            AttributeSet obj = (AttributeSet) be.getAttribute(name);
                            fileName = (String) obj.getAttribute(HTML.Attribute.TITLE);
                        }
                    }
                    System.err.println(fileName);
                    File file = null;
View Full Code Here

TOP

Related Classes of javax.swing.text.AbstractDocument.LeafElement

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.