Package javax.swing.text.AbstractDocument

Examples of javax.swing.text.AbstractDocument.LeafElement


   */
  private void testIllegalDocumentLocation(TestHarness h)
  {
    h.checkPoint("illegalDocumentLocation");
    PlainDocument doc = new PlainDocument();
    AbstractDocument.LeafElement l = doc.new LeafElement(null, null, 10, 20);
    h.check(doc.getLength(), 0);
    h.check(l.getStartOffset(), 10);
  }
View Full Code Here


    h.checkPoint("contentChange");
    try
      {
        PlainDocument doc = new PlainDocument();
        doc.insertString(0, "hallo", null);
        AbstractDocument.LeafElement l = doc.new LeafElement(null, null, 20, 5);
        h.check(l.getStartOffset(), 20);
        doc.insertString(0, "hiyo", null);
        h.check(l.getStartOffset(), 24);
      }
    catch (BadLocationException ex)
      {
        h.fail("BadLocationException");
      }
View Full Code Here

      }
   
    BranchElement el = (BranchElement) doc.getDefaultRootElement();
    // Modify the element structure a little and seen how the initial
    // elements are created then.
    LeafElement el1 = doc.new LeafElement(el, null, 0, 3);
    LeafElement el2 = doc.new LeafElement(el, null, 3, 7);
    LeafElement el3 = doc.new LeafElement(el, null, 7, 11);
    el.replace(0, 1, new Element[]{el1, el2, el3});


    TestZoneView zv = new TestZoneView(el, View.Y_AXIS);
    // Set the maximum zone size somewhere inside the second element.
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

     * Test getElementIndex behavior if some elements are zero-length,
     * i.e. start and end offsets are the same.
     */
    public void testGetElementIndex02() {
        BranchElement root = doc.new BranchElement(null, null);
        LeafElement[] leaves = { doc.new LeafElement(root, null, 0, 0), // [0]
                doc.new LeafElement(root, null, 0, 1), // [1]
                doc.new LeafElement(root, null, 0, 1), // [2]
                doc.new LeafElement(root, null, 1, 1), // [3]
                doc.new LeafElement(root, null, 1, 1), // [4]
                doc.new LeafElement(root, null, 1, 2), // [5]
                doc.new LeafElement(root, null, 2, 3) // [6]
        };
        root.replace(0, 0, leaves);
        assertEquals(0, root.getElementIndex(-1));
        assertEquals(1, root.getElementIndex(0));
        assertEquals(5 /*2*/, root.getElementIndex(1));
View Full Code Here

        assertEquals("BranchElement(bidi root) 0,15\n", bidi.toString());
        assertEquals("BranchElement(paragraph) 0,15\n", par.toString());
    }

    private Element createLeaf(final int start, final int end) {
        return doc.new LeafElement(par, null, start, end);
    }
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

                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

            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

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.