Examples of ElementSpec


Examples of javax.swing.text.DefaultStyledDocument.ElementSpec

    MutableAttributeSet a2 = new SimpleAttributeSet();

    a1.addAttribute(StyleConstants.NameAttribute, "MY_FIRST");
    a2.addAttribute(StyleConstants.NameAttribute, "MY_SECOND");

    ElementSpec s1 = new ElementSpec(a1, ElementSpec.ContentType,
                                     "1".toCharArray(), 0, 1);
    ElementSpec s2 = new ElementSpec(a2, ElementSpec.ContentType,
                                     "2".toCharArray(), 0, 1);

    OpenDocument d = new OpenDocument();

    try
      {
        d.insert(0, new ElementSpec[] { s1, s2 });

        harness.check(d.getLength(), 2, "Length");       
        harness.check("12", d.getText(0, d.getLength()));
        Element[] e = d.getRootElements();

        StringBuffer b = new StringBuffer();
        for (int i = 0; i < e.length; i++)
          {
            dump(b, e[i]);
          }
       
        String r = b.toString();
       
        // Both elements must be included somewhere. They positions must match.
        harness.check(r.indexOf("MY_FIRST:0-1") >=0);
        harness.check(r.indexOf("MY_SECOND:1-2") >=0);
       
        // Insert the third element in between.
        MutableAttributeSet a3 = new SimpleAttributeSet();
        a1.addAttribute(StyleConstants.NameAttribute, "MY_MIDDLE");
        ElementSpec sm = new ElementSpec(a1, ElementSpec.ContentType,
                                     "m".toCharArray(), 0, 1);
       
        d.insert(1, new ElementSpec[] { sm });
        harness.check(d.getLength(), 3, "Length");
        harness.check("1m2", d.getText(0, d.getLength()));
View Full Code Here

Examples of javax.swing.text.DefaultStyledDocument.ElementSpec

    a1.addAttribute(StyleConstants.NameAttribute, "MY_FIRST");
    a2.addAttribute(StyleConstants.NameAttribute, "MY_SECOND");
    a3.addAttribute(StyleConstants.NameAttribute, "MY_MIDDLE");

    ElementSpec s1 = new ElementSpec(a1, ElementSpec.ContentType,
                                     "1".toCharArray(), 0, 1);
    ElementSpec s2 = new ElementSpec(a2, ElementSpec.ContentType,
                                     "2".toCharArray(), 0, 1);

    ElementSpec sm = new ElementSpec(a3, ElementSpec.ContentType,
                                     "m".toCharArray(), 0, 1);

    OpenDocument d = new OpenDocument();

    d.create(new ElementSpec[] { s1, sm, s2 });
View Full Code Here

Examples of javax.swing.text.DefaultStyledDocument.ElementSpec

    public void testInsertSameAttrsDocStart() throws Exception {
        insertOffset = 0;
        // doc.insertString(insertOffset, caps, null);
        content.insertString(insertOffset, caps);
        event = doc.new DefaultDocumentEvent(insertOffset, capsLen, EventType.INSERT);
        ElementSpec spec = new ElementSpec(null, ElementSpec.ContentType, capsLen);
        spec.setDirection(ElementSpec.JoinPreviousDirection);
        buf.insert(insertOffset, capsLen, new ElementSpec[] { spec }, event);
        List<?> edits = getEdits(event);
        assertEquals(0, edits.size());
        assertEquals("^^^plain", getText(doc.getCharacterElement(insertOffset)));
    }
View Full Code Here

Examples of javax.swing.text.DefaultStyledDocument.ElementSpec

    public void testInsertDiffAttrsDocStart() throws Exception {
        insertOffset = 0;
        // doc.insertString(insertOffset, caps, italic);
        content.insertString(insertOffset, caps);
        event = doc.new DefaultDocumentEvent(insertOffset, capsLen, EventType.INSERT);
        ElementSpec spec = new ElementSpec(null, ElementSpec.ContentType, capsLen);
        buf.insert(insertOffset, capsLen, new ElementSpec[] { spec }, event);
        List<?> edits = getEdits(event);
        assertEquals(1, edits.size());
        assertChange(edits.get(0), new int[] { 0, 8 }, new int[] { 0, 3, 3, 8 });
        assertEquals("^^^", getText(doc.getCharacterElement(insertOffset)));
View Full Code Here

Examples of javax.swing.text.DefaultStyledDocument.ElementSpec

     */
    public void testInsertSameAttrsMiddle() throws Exception {
        // doc.insertString(insertOffset, caps, bold);
        content.insertString(insertOffset, caps);
        event = doc.new DefaultDocumentEvent(insertOffset, capsLen, EventType.INSERT);
        ElementSpec spec = new ElementSpec(null, ElementSpec.ContentType, capsLen);
        spec.setDirection(ElementSpec.JoinPreviousDirection);
        buf.insert(insertOffset, capsLen, new ElementSpec[] { spec }, event);
        List<?> edits = getEdits(event);
        assertEquals(0, edits.size());
        assertEquals("bo^^^ld", getText(doc.getCharacterElement(insertOffset)));
    }
View Full Code Here

Examples of javax.swing.text.DefaultStyledDocument.ElementSpec

    public void testInsertSameAttrsEnd() throws Exception {
        insertOffset += 2;
        // doc.insertString(insertOffset, caps, bold);
        content.insertString(insertOffset, caps);
        event = doc.new DefaultDocumentEvent(insertOffset, capsLen, EventType.INSERT);
        ElementSpec spec = new ElementSpec(null, ElementSpec.ContentType, capsLen);
        spec.setDirection(ElementSpec.JoinPreviousDirection);
        buf.insert(insertOffset, capsLen, new ElementSpec[] { spec }, event);
        List<?> edits = getEdits(event);
        assertEquals(0, edits.size());
        assertEquals("bold^^^", getText(doc.getCharacterElement(insertOffset)));
    }
View Full Code Here

Examples of javax.swing.text.DefaultStyledDocument.ElementSpec

   
    public void testFlush_Create() throws Exception {
        final String text = "tag";
        SimpleAttributeSet attr = new SimpleAttributeSet();
        attr.addAttribute(StyleConstants.NameAttribute, Tag.B.toString());
        reader.parseBuffer.add(new ElementSpec(attr, ElementSpec.StartTagType));
        reader.parseBuffer.add(new ElementSpec(new SimpleAttributeSet(), ElementSpec.ContentType, text.toCharArray(), 0, 3));
        reader.parseBuffer.add(new ElementSpec(attr, ElementSpec.EndTagType));
        assertEquals(3, reader.parseBuffer.size());
        reader.flush();
        assertEquals(0, reader.parseBuffer.size());
        assertTrue(createMarker.isOccurred());
        assertFalse(insertMarker.isOccurred());
View Full Code Here

Examples of javax.swing.text.DefaultStyledDocument.ElementSpec

    public void testFlush_Create_PushPopNull() throws Exception {
        final String text = "tag";
        SimpleAttributeSet attr = new SimpleAttributeSet();
        attr.addAttribute(StyleConstants.NameAttribute, Tag.B);
        reader = (HTMLReader)doc.getReader(0, 5, 5, null);
        reader.parseBuffer.add(new ElementSpec(attr, ElementSpec.StartTagType));
        reader.parseBuffer.add(new ElementSpec(new SimpleAttributeSet(), ElementSpec.ContentType, text.toCharArray(), 0, 3));
        reader.parseBuffer.add(new ElementSpec(attr, ElementSpec.EndTagType));
        assertEquals(3, reader.parseBuffer.size());
        reader.flush();
        assertEquals(0, reader.parseBuffer.size());
        assertTrue(createMarker.isOccurred());
        assertFalse(insertMarker.isOccurred());
View Full Code Here

Examples of javax.swing.text.DefaultStyledDocument.ElementSpec

    public void testFlush_Insert_Tag() throws Exception {
        final String text = "tag";
        SimpleAttributeSet attr = new SimpleAttributeSet();
        attr.addAttribute(StyleConstants.NameAttribute, Tag.B);
        reader = (HTMLReader)doc.getReader(0, 0, 0, Tag.B);
        reader.parseBuffer.add(new ElementSpec(attr, ElementSpec.StartTagType));
        reader.parseBuffer.add(new ElementSpec(new SimpleAttributeSet(), ElementSpec.ContentType, text.toCharArray(), 0, 3));
        reader.parseBuffer.add(new ElementSpec(attr, ElementSpec.EndTagType));
        assertEquals(3, reader.parseBuffer.size());
        reader.flush();
        assertEquals(0, reader.parseBuffer.size());
        assertFalse(createMarker.isOccurred());
        assertTrue(insertMarker.isOccurred());
View Full Code Here

Examples of javax.swing.text.DefaultStyledDocument.ElementSpec

    public void testInsertDiffAttrsEnd() throws Exception {
        insertOffset += 2;
        // doc.insertString(insertOffset, caps, null);
        content.insertString(insertOffset, caps);
        event = doc.new DefaultDocumentEvent(insertOffset, capsLen, EventType.INSERT);
        ElementSpec spec = new ElementSpec(null, ElementSpec.ContentType, capsLen);
        buf.insert(insertOffset, capsLen, new ElementSpec[] { spec }, event);
        List<?> edits = getEdits(event);
        assertEquals(1, edits.size());
        assertChange(edits.get(0), new int[] { 5, 12 }, new int[] { 5, 9, 9, 12 });
        assertEquals("bold", getText(doc.getCharacterElement(insertOffset - 1)));
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.