Java 类javax.swing.text.AbstractDocument.DefaultDocumentEvent 实例源码

项目:cn1    文件:DefaultStyledDocument_ElementBuffer_InsertMiscTest.java   
@Override
protected void setUp() throws Exception {
    super.setUp();
    doc = new DefaultStyledDocument();
    root = doc.getDefaultRootElement();
    buf = new DefStyledDoc_Helpers.ElementBufferWithLogging(doc, root) {
        private static final long serialVersionUID = 1L;

        @Override
        public void insert(int offset, int length, ElementSpec[] spec,
                DefaultDocumentEvent event) {
            super.insert(offset, length, insertSpecs = spec, event);
        }
    };
    doc.buffer = buf;
    content = doc.getContent();
    doc.addDocumentListener(this);
    doc.writeLock();
}
项目:cn1    文件:DefaultStyledDocument_ElementBuffer_InsertTextTest.java   
/**
 * Inserting text into the start of a paragraph with the same attributes.
 * <p>
 * This test is equivalent to
 * <code>doc.insertString(insertOffset, caps, null)</code>,
 * where <code>insertOffset = paragraph.getEndOffset()</code>.
 */
public void testInsertSameAttrsParStart() throws Exception {
    insertOffset = paragraph.getEndOffset();
    // doc.insertString(insertOffset, caps, null);
    content.insertString(insertOffset, caps);
    event = doc.new DefaultDocumentEvent(insertOffset, capsLen, EventType.INSERT);
    ElementSpec[] specs = { new ElementSpec(null, ElementSpec.EndTagType),
            new ElementSpec(null, ElementSpec.StartTagType),
            new ElementSpec(null, ElementSpec.ContentType, capsLen), };
    specs[1].setDirection(ElementSpec.JoinNextDirection);
    specs[2].setDirection(ElementSpec.JoinNextDirection);
    buf.insert(insertOffset, capsLen, specs, event);
    List<?> edits = getEdits(event);
    assertEquals(2, edits.size());
    assertChange(edits.get(0), new int[] { 15, 19 }, new int[] { 15, 16 });
    assertChange(edits.get(1), new int[] { 19, 24 }, new int[] { 16, 24 });
    assertChildren(paragraph, new int[] { 0, 5, 5, 9, 9, 15, 15, 16 }, new AttributeSet[] {
            null, bold, italic, null });
    assertChildren(root.getElement(1), new int[] { 16, 24 }, new AttributeSet[] { null });
    assertEquals("^^^text\n", getText(doc.getCharacterElement(insertOffset)));
}
项目:cn1    文件:DefaultStyledDocument_ElementBuffer_InsertTextTest.java   
/**
 * Inserting text into the start of a paragraph with different attributes.
 * <p>
 * This test is equivalent to
 * <code>doc.insertString(insertOffset, caps, italic)</code>,
 * where <code>insertOffset = paragraph.getEndOffset()</code>.
 */
public void testInsertDiffAttrsParStart() throws Exception {
    insertOffset = paragraph.getEndOffset();
    // doc.insertString(insertOffset, caps, italic);
    content.insertString(insertOffset, caps);
    event = doc.new DefaultDocumentEvent(insertOffset, capsLen, EventType.INSERT);
    ElementSpec[] specs = { new ElementSpec(null, ElementSpec.EndTagType),
            new ElementSpec(null, ElementSpec.StartTagType),
            new ElementSpec(italic, ElementSpec.ContentType, capsLen), };
    specs[1].setDirection(ElementSpec.JoinNextDirection);
    buf.insert(insertOffset, capsLen, specs, event);
    List<?> edits = getEdits(event);
    assertEquals(2, edits.size());
    assertChange(edits.get(0), new int[] { 15, 19 }, new int[] { 15, 16 });
    assertChange(edits.get(1), new int[] {}, new int[] { 16, 19 });
    assertChildren(paragraph, new int[] { 0, 5, 5, 9, 9, 15, 15, 16 }, new AttributeSet[] {
            null, bold, italic, null });
    assertChildren(root.getElement(1), new int[] { 16, 19, 19, 24 }, new AttributeSet[] {
            italic, null });
    assertEquals("^^^", getText(doc.getCharacterElement(insertOffset)));
    assertEquals("text\n", getText(doc.getCharacterElement(insertOffset + capsLen)));
}
项目:cn1    文件:DefaultStyledDocument_ElementBuffer_InsertTextTest.java   
/**
 * Inserting text into the end of the document with different attributes.
 * <p>
 * This test is equivalent to
 * <code>doc.insertString(insertOffset, caps, italic)</code>,
 * where <code>insertOffset = doc.getLength()</code>.
 */
public void testInsertDiffAttrsDocEnd() throws Exception {
    insertOffset = doc.getLength();
    // doc.insertString(insertOffset, caps, italic);
    content.insertString(insertOffset, caps);
    event = doc.new DefaultDocumentEvent(insertOffset, capsLen, EventType.INSERT);
    ElementSpec spec = new ElementSpec(italic, 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[] { 16, 24 }, new int[] { 16, 20, 20, 23, 23, 24 });
    assertChildren(root.getElement(1), new int[] { 16, 20, 20, 23, 23, 24 },
            new AttributeSet[] { null, italic, null });
    assertEquals("text", getText(doc.getCharacterElement(insertOffset - 1)));
    assertEquals("^^^", getText(doc.getCharacterElement(insertOffset)));
    assertEquals("\n", getText(doc.getCharacterElement(insertOffset + capsLen)));
}
项目:cn1    文件:DefaultStyledDocument_ElementBuffer_Specs3Test.java   
@Override
protected void setUp() throws Exception {
    super.setUp();
    doc = new DefStyledDoc_Helpers.DefStyledDocWithLogging();
    root = doc.getDefaultRootElement();
    buf = new DefStyledDoc_Helpers.ElementBufferWithLogging(doc, root) {
        private static final long serialVersionUID = 1L;

        @Override
        public void insert(int offset, int length, ElementSpec[] spec,
                DefaultDocumentEvent event) {
            super.insert(offset, length, specs = spec, event);
        }
    };
    doc.buffer = buf;
    doc.insertString(doc.getLength(), "plain", null); // 5 chars
    doc.insertString(doc.getLength(), "bold", bold); // 4 chars
    doc.insertString(doc.getLength(), "italic", italic); // 6 chars
    paragraph = root.getElement(0);
    leaf = paragraph.getElement(leafIndex);
    insertOffset = leaf.getStartOffset() + 2;
    doc.addDocumentListener(this);
}
项目:cn1    文件:PlainDocumentTest.java   
@Override
protected void setUp() throws Exception {
    super.setUp();
    doc = new PlainDocument() {
        private static final long serialVersionUID = 1L;

        @Override
        protected void insertUpdate(final DefaultDocumentEvent event,
                final AttributeSet attrs) {
            insert = event;
            super.insertUpdate(event, attrs);
        }

        @Override
        protected void removeUpdate(final DefaultDocumentEvent event) {
            remove = event;
            super.removeUpdate(event);
        }
    };
    root = doc.getDefaultRootElement();
}
项目:cn1    文件:DefaultStyledDocument_ElementBuffer_Specs2Test.java   
@Override
protected void setUp() throws Exception {
    super.setUp();
    doc = new DefStyledDoc_Helpers.DefStyledDocWithLogging();
    root = doc.getDefaultRootElement();
    buf = new DefStyledDoc_Helpers.ElementBufferWithLogging(doc, root) {
        private static final long serialVersionUID = 1L;

        @Override
        public void insert(int offset, int length, ElementSpec[] spec,
                DefaultDocumentEvent event) {
            super.insert(offset, length, specs = spec, event);
        }
    };
    doc.buffer = buf;
    doc.insertString(0, "first\nsecond\nthird", null);
    modified = root.getElement(modifiedIndex);
    insertOffset = modified.getStartOffset() + 2;
    doc.addDocumentListener(this);
}
项目:cn1    文件:DefaultStyledDocument_ElementBuffer_InsertNewLineTest.java   
/**
 * Inserting text with the same attributes into the beginning of
 * the document.
 * <p>
 * This test is equivalent to
 * <code>doc.insertString(insertOffset, newLine, null)</code>,
 * where <code>insertOffset = 0</code>.
 */
public void testInsertSameAttrsDocStart() throws Exception {
    insertOffset = 0;
    // doc.insertString(insertOffset, newLine, null);
    content.insertString(insertOffset, newLine);
    event = doc.new DefaultDocumentEvent(insertOffset, newLineLen, EventType.INSERT);
    ElementSpec[] specs = { new ElementSpec(null, ElementSpec.ContentType, newLineLen),
            new ElementSpec(null, ElementSpec.EndTagType),
            new ElementSpec(null, ElementSpec.StartTagType) };
    specs[0].setDirection(ElementSpec.JoinPreviousDirection);
    specs[2].setDirection(ElementSpec.JoinFractureDirection);
    buf.insert(insertOffset, newLineLen, specs, event);
    List<?> edits = getEdits(event);
    assertEquals(2, edits.size());
    assertChange(edits.get(0), new int[] { 0, 6, 6, 10, 10, 16, 16, 17 },
            new int[] { 0, 1 });
    assertChange(edits.get(1), new int[] {}, new int[] { 1, 17 });
    assertChildren(root.getElement(0), new int[] { 0, 1 }, new AttributeSet[] { null });
    assertChildren(root.getElement(1), new int[] { 1, 6, 6, 10, 10, 16, 16, 17 },
            new AttributeSet[] { null, bold, italic, null });
    assertEquals("\n", getText(doc.getCharacterElement(insertOffset)));
    assertEquals("plain", getText(doc.getCharacterElement(insertOffset + newLineLen)));
}
项目:cn1    文件:DefaultStyledDocument_ElementBuffer_InsertNewLineTest.java   
/**
 * Inserting text with different attributes into the beginning of
 * the document.
 * <p>
 * This test is equivalent to
 * <code>doc.insertString(insertOffset, newLine, italic)</code>,
 * where <code>insertOffset = 0</code>.
 */
public void testInsertDiffAttrsDocStart() throws Exception {
    insertOffset = 0;
    // doc.insertString(insertOffset, newLine, italic);
    content.insertString(insertOffset, newLine);
    event = doc.new DefaultDocumentEvent(insertOffset, newLineLen, EventType.INSERT);
    ElementSpec[] specs = { new ElementSpec(italic, ElementSpec.ContentType, newLineLen),
            new ElementSpec(null, ElementSpec.EndTagType),
            new ElementSpec(null, ElementSpec.StartTagType) };
    specs[2].setDirection(ElementSpec.JoinFractureDirection);
    buf.insert(insertOffset, newLineLen, specs, event);
    List<?> edits = getEdits(event);
    assertEquals(2, edits.size());
    assertChange(edits.get(0), new int[] { 0, 6, 6, 10, 10, 16, 16, 17 },
            new int[] { 0, 1 });
    assertChange(edits.get(1), new int[] {}, new int[] { 1, 17 });
    assertChildren(root.getElement(0), new int[] { 0, 1 }, new AttributeSet[] { italic });
    assertChildren(root.getElement(1), new int[] { 1, 6, 6, 10, 10, 16, 16, 17 },
            new AttributeSet[] { null, bold, italic, null });
    assertEquals("\n", getText(doc.getCharacterElement(insertOffset)));
    assertEquals("plain", getText(doc.getCharacterElement(insertOffset + newLineLen)));
}
项目:cn1    文件:DefaultStyledDocument_ElementBuffer_InsertNewLineTest.java   
/**
 * Inserting text into middle of an element with the same attributes.
 * <p>
 * This test is equivalent to
 * <code>doc.insertString(insertOffset, newLine, bold)</code>,
 * where <code>insertOffset</code> has default value from
 * <code>setUp()</code>.
 */
public void testInsertSameAttrsMiddle() throws Exception {
    // doc.insertString(insertOffset, newLine, bold);
    content.insertString(insertOffset, newLine);
    event = doc.new DefaultDocumentEvent(insertOffset, newLineLen, EventType.INSERT);
    ElementSpec[] specs = { new ElementSpec(null, ElementSpec.ContentType, newLineLen),
            new ElementSpec(null, ElementSpec.EndTagType),
            new ElementSpec(null, ElementSpec.StartTagType) };
    specs[0].setDirection(ElementSpec.JoinPreviousDirection);
    specs[2].setDirection(ElementSpec.JoinFractureDirection);
    buf.insert(insertOffset, newLineLen, specs, event);
    List<?> edits = getEdits(event);
    assertEquals(2, edits.size());
    assertChange(edits.get(0), new int[] { 5, 10, 10, 16, 16, 17 }, new int[] { 5, 8 });
    assertChange(edits.get(1), new int[] {}, new int[] { 8, 17 });
    assertChildren(root.getElement(0), new int[] { 0, 5, 5, 8 }, new AttributeSet[] { null,
            bold });
    assertChildren(root.getElement(1), new int[] { 8, 10, 10, 16, 16, 17 },
            new AttributeSet[] { bold, italic, null });
    assertEquals("bo\n", getText(doc.getCharacterElement(insertOffset)));
    assertEquals("ld", getText(doc.getCharacterElement(insertOffset + newLineLen)));
}
项目:cn1    文件:DefaultStyledDocument_ElementBuffer_InsertNewLineTest.java   
/**
 * Inserting text into end of the an element with the same attributes;
 * the following element has different attributes.
 * <p>
 * This test is equivalent to
 * <code>doc.insertString(insertOffset, newLine, bold)</code>,
 * where 2 is added to default value of <code>insertOffset</code>.
 */
public void testInsertSameAttrsEnd() throws Exception {
    insertOffset += 2;
    // doc.insertString(insertOffset, newLine, bold);
    content.insertString(insertOffset, newLine);
    event = doc.new DefaultDocumentEvent(insertOffset, newLineLen, EventType.INSERT);
    ElementSpec[] specs = { new ElementSpec(null, ElementSpec.ContentType, newLineLen),
            new ElementSpec(null, ElementSpec.EndTagType),
            new ElementSpec(null, ElementSpec.StartTagType) };
    specs[0].setDirection(ElementSpec.JoinPreviousDirection);
    specs[2].setDirection(ElementSpec.JoinFractureDirection);
    // Spec [0] has wrong attributes (should be bold) but everything works
    // the way it supposed to.
    buf.insert(insertOffset, newLineLen, specs, event);
    List<?> edits = getEdits(event);
    assertEquals(2, edits.size());
    assertChange(edits.get(0), new int[] { 10, 16, 16, 17 }, new int[] {});
    assertChange(edits.get(1), new int[] {}, new int[] { 10, 17 });
    assertChildren(root.getElement(0), new int[] { 0, 5, 5, 10 }, new AttributeSet[] {
            null, bold });
    assertChildren(root.getElement(1), new int[] { 10, 16, 16, 17 }, new AttributeSet[] {
            italic, null });
    assertEquals("bold\n", getText(doc.getCharacterElement(insertOffset)));
    assertEquals("italic", getText(doc.getCharacterElement(insertOffset + newLineLen)));
}
项目:cn1    文件:DefaultStyledDocument_ElementBuffer_InsertNewLineTest.java   
/**
 * Inserting text into the middle of an element with different attributes.
 * <p>
 * This test is equivalent to
 * <code>doc.insertString(insertOffset, newLine, null)</code>,
 * where <code>insertOffset</code> has default value from
 * <code>setUp()</code>.
 */
public void testInsertDiffAttrsMiddle() throws Exception {
    // doc.insertString(insertOffset, newLine, null);
    content.insertString(insertOffset, newLine);
    event = doc.new DefaultDocumentEvent(insertOffset, newLineLen, EventType.INSERT);
    ElementSpec[] specs = { new ElementSpec(null, ElementSpec.ContentType, newLineLen),
            new ElementSpec(null, ElementSpec.EndTagType),
            new ElementSpec(null, ElementSpec.StartTagType) };
    specs[2].setDirection(ElementSpec.JoinFractureDirection);
    buf.insert(insertOffset, newLineLen, specs, event);
    List<?> edits = getEdits(event);
    assertEquals(2, edits.size());
    assertChange(edits.get(0), new int[] { 5, 10, 10, 16, 16, 17 },
            new int[] { 5, 7, 7, 8 });
    assertChange(edits.get(1), new int[] {}, new int[] { 8, 17 });
    assertChildren(root.getElement(0), new int[] { 0, 5, 5, 7, 7, 8 }, new AttributeSet[] {
            null, bold, null });
    assertChildren(root.getElement(1), new int[] { 8, 10, 10, 16, 16, 17 },
            new AttributeSet[] { bold, italic, null });
    assertEquals("\n", getText(doc.getCharacterElement(insertOffset)));
    assertEquals("ld", getText(doc.getCharacterElement(insertOffset + newLineLen)));
}
项目:cn1    文件:DefaultStyledDocument_ElementBuffer_InsertNewLineTest.java   
/**
 * Inserting text into element boundary; the text and both elements have
 * different attributes.
 * <p>
 * This test is equivalent to
 * <code>doc.insertString(insertOffset, newLine, null)</code>,
 * where 2 is added to default value of <code>insertOffset</code>.
 */
public void testInsertDiffAttrsEnd() throws Exception {
    insertOffset += 2;
    // doc.insertString(insertOffset, newLine, null);
    content.insertString(insertOffset, newLine);
    event = doc.new DefaultDocumentEvent(insertOffset, newLineLen, EventType.INSERT);
    ElementSpec[] specs = { new ElementSpec(null, ElementSpec.ContentType, newLineLen),
            new ElementSpec(null, ElementSpec.EndTagType),
            new ElementSpec(null, ElementSpec.StartTagType) };
    specs[2].setDirection(ElementSpec.JoinFractureDirection);
    buf.insert(insertOffset, newLineLen, specs, event);
    List<?> edits = getEdits(event);
    assertEquals(2, edits.size());
    assertChange(edits.get(0), new int[] { 5, 10, 10, 16, 16, 17 },
            new int[] { 5, 9, 9, 10 });
    assertChange(edits.get(1), new int[] {}, new int[] { 10, 17 });
    assertChildren(root.getElement(0), new int[] { 0, 5, 5, 9, 9, 10 }, new AttributeSet[] {
            null, bold, null });
    assertChildren(root.getElement(1), new int[] { 10, 16, 16, 17 }, new AttributeSet[] {
            italic, null });
    assertEquals("\n", getText(doc.getCharacterElement(insertOffset)));
    assertEquals("italic", getText(doc.getCharacterElement(insertOffset + newLineLen)));
}
项目:cn1    文件:DefaultStyledDocument_ElementBuffer_InsertNewLineTest.java   
/**
 * Inserting text into element boundary; the attributes of the text and
 * the following element are the same, the attributes of the previous
 * element are different.
 * <p>
 * This test is equivalent to
 * <code>doc.insertString(insertOffset, newLine, italic)</code>,
 * where 2 is added to default value of <code>insertOffset</code>.
 */
public void testInsertDiffSameAttrsEnd() throws Exception {
    insertOffset += 2;
    // doc.insertString(insertOffset, newLine, italic);
    content.insertString(insertOffset, newLine);
    event = doc.new DefaultDocumentEvent(insertOffset, newLineLen, EventType.INSERT);
    ElementSpec[] specs = { new ElementSpec(italic, ElementSpec.ContentType, newLineLen),
            new ElementSpec(null, ElementSpec.EndTagType),
            new ElementSpec(null, ElementSpec.StartTagType) };
    specs[2].setDirection(ElementSpec.JoinFractureDirection);
    buf.insert(insertOffset, newLineLen, specs, event);
    List<?> edits = getEdits(event);
    assertEquals(2, edits.size());
    assertChange(edits.get(0), new int[] { 5, 10, 10, 16, 16, 17 },
            new int[] { 5, 9, 9, 10 });
    assertChange(edits.get(1), new int[] {}, new int[] { 10, 17 });
    assertChildren(root.getElement(0), new int[] { 0, 5, 5, 9, 9, 10 }, new AttributeSet[] {
            null, bold, italic });
    assertChildren(root.getElement(1), new int[] { 10, 16, 16, 17 }, new AttributeSet[] {
            italic, null });
    assertEquals("\n", getText(doc.getCharacterElement(insertOffset)));
    assertEquals("italic", getText(doc.getCharacterElement(insertOffset + newLineLen)));
}
项目:cn1    文件:DefaultStyledDocument_ElementBuffer_InsertNewLineTest.java   
/**
 * Inserting text into the start of a paragraph with the same attributes.
 * <p>
 * This test is equivalent to
 * <code>doc.insertString(insertOffset, newLine, null)</code>,
 * where <code>insertOffset = paragraph.getEndOffset()</code>.
 */
public void testInsertSameAttrsParStart() throws Exception {
    insertOffset = paragraph.getEndOffset();
    // doc.insertString(insertOffset, newLine, null);
    content.insertString(insertOffset, newLine);
    event = doc.new DefaultDocumentEvent(insertOffset, newLineLen, EventType.INSERT);
    ElementSpec[] specs = { new ElementSpec(null, ElementSpec.EndTagType),
            new ElementSpec(null, ElementSpec.StartTagType),
            new ElementSpec(null, ElementSpec.ContentType, newLineLen),
            new ElementSpec(null, ElementSpec.EndTagType),
            new ElementSpec(null, ElementSpec.StartTagType) };
    specs[4].setDirection(ElementSpec.JoinNextDirection);
    buf.insert(insertOffset, newLineLen, specs, event);
    List<?> edits = getEdits(event);
    assertEquals(3, edits.size());
    assertChange(edits.get(0), new int[] { 15, 17 }, new int[] { 15, 16 });
    assertChange(edits.get(1), new int[] {}, new int[] { 16, 17 });
    assertChange(edits.get(2), new int[] {}, new int[] { 16, 17 });
    assertChildren(root.getElement(0), new int[] { 0, 5, 5, 9, 9, 15, 15, 16 },
            new AttributeSet[] { null, bold, italic, null });
    assertChildren(root.getElement(1), new int[] { 16, 17 }, new AttributeSet[] { null });
    assertChildren(root.getElement(2), new int[] { 17, 22 }, new AttributeSet[] { null });
    assertEquals("\n", getText(doc.getCharacterElement(insertOffset)));
    assertEquals("text\n", getText(doc.getCharacterElement(insertOffset + newLineLen)));
}
项目:cn1    文件:DefaultStyledDocument_ElementBuffer_InsertNewLineTest.java   
/**
 * Inserting text into the start of a paragraph with different attributes.
 * <p>
 * This test is equivalent to
 * <code>doc.insertString(insertOffset, newLine, italic)</code>,
 * where <code>insertOffset = paragraph.getEndOffset()</code>.
 */
public void testInsertDiffAttrsParStart() throws Exception {
    insertOffset = paragraph.getEndOffset();
    // doc.insertString(insertOffset, newLine, italic);
    content.insertString(insertOffset, newLine);
    event = doc.new DefaultDocumentEvent(insertOffset, newLineLen, EventType.INSERT);
    ElementSpec[] specs = { new ElementSpec(null, ElementSpec.EndTagType),
            new ElementSpec(null, ElementSpec.StartTagType),
            new ElementSpec(italic, ElementSpec.ContentType, newLineLen),
            new ElementSpec(null, ElementSpec.EndTagType),
            new ElementSpec(null, ElementSpec.StartTagType) };
    specs[4].setDirection(ElementSpec.JoinNextDirection);
    buf.insert(insertOffset, newLineLen, specs, event);
    List<?> edits = getEdits(event);
    assertEquals(3, edits.size());
    assertChange(edits.get(0), new int[] { 15, 17 }, new int[] { 15, 16 });
    assertChange(edits.get(1), new int[] {}, new int[] { 16, 17 });
    assertChange(edits.get(2), new int[] {}, new int[] { 16, 17 });
    assertChildren(root.getElement(0), new int[] { 0, 5, 5, 9, 9, 15, 15, 16 },
            new AttributeSet[] { null, bold, italic, null });
    assertChildren(root.getElement(1), new int[] { 16, 17 }, new AttributeSet[] { italic });
    assertChildren(root.getElement(2), new int[] { 17, 22 }, new AttributeSet[] { null });
    assertEquals("\n", getText(doc.getCharacterElement(insertOffset)));
    assertEquals("text\n", getText(doc.getCharacterElement(insertOffset + newLineLen)));
}
项目:cn1    文件:DefaultStyledDocument_ElementBuffer_InsertNewLineTest.java   
/**
 * Inserting text into the end of the document with the same attributes.
 * <p>
 * This test is equivalent to
 * <code>doc.insertString(insertOffset, newLine, null)</code>,
 * where <code>insertOffset = doc.getLength()</code>.
 */
public void testInsertSameAttrsDocEnd() throws Exception {
    insertOffset = doc.getLength();
    // doc.insertString(insertOffset, newLine, null);
    content.insertString(insertOffset, newLine);
    event = doc.new DefaultDocumentEvent(insertOffset, newLineLen, EventType.INSERT);
    ElementSpec[] specs = { new ElementSpec(null, ElementSpec.ContentType, newLineLen),
            new ElementSpec(null, ElementSpec.EndTagType),
            new ElementSpec(null, ElementSpec.StartTagType) };
    specs[0].setDirection(ElementSpec.JoinPreviousDirection);
    specs[2].setDirection(ElementSpec.JoinFractureDirection);
    buf.insert(insertOffset, newLineLen, specs, event);
    List<?> edits = getEdits(event);
    assertEquals(2, edits.size());
    assertChange(edits.get(0), new int[] { 16, 22 }, new int[] { 16, 21 });
    assertChange(edits.get(1), new int[] {}, new int[] { 21, 22 });
    assertChildren(root.getElement(1), new int[] { 16, 21 }, new AttributeSet[] { null });
    assertChildren(root.getElement(2), new int[] { 21, 22 }, new AttributeSet[] { null });
    assertEquals("text\n", getText(doc.getCharacterElement(insertOffset)));
    assertEquals("\n", getText(doc.getCharacterElement(insertOffset + newLineLen)));
}
项目:cn1    文件:DefaultStyledDocument_ElementBuffer_InsertNewLineTest.java   
/**
 * Inserting text into the end of the document with different attributes.
 * <p>
 * This test is equivalent to
 * <code>doc.insertString(insertOffset, newLine, italic)</code>,
 * where <code>insertOffset = doc.getLength()</code>.
 */
public void testInsertDiffAttrsDocEnd() throws Exception {
    insertOffset = doc.getLength();
    // doc.insertString(insertOffset, newLine, italic);
    content.insertString(insertOffset, newLine);
    event = doc.new DefaultDocumentEvent(insertOffset, newLineLen, EventType.INSERT);
    ElementSpec[] specs = { new ElementSpec(italic, ElementSpec.ContentType, newLineLen),
            new ElementSpec(null, ElementSpec.EndTagType),
            new ElementSpec(null, ElementSpec.StartTagType) };
    specs[2].setDirection(ElementSpec.JoinFractureDirection);
    buf.insert(insertOffset, newLineLen, specs, event);
    List<?> edits = getEdits(event);
    assertEquals(2, edits.size());
    assertChange(edits.get(0), new int[] { 16, 22 }, new int[] { 16, 20, 20, 21 });
    assertChange(edits.get(1), new int[] {}, new int[] { 21, 22 });
    assertChildren(root.getElement(1), new int[] { 16, 20, 20, 21 }, new AttributeSet[] {
            null, italic });
    assertChildren(root.getElement(2), new int[] { 21, 22 }, new AttributeSet[] { null });
    assertEquals("text", getText(doc.getCharacterElement(insertOffset - 1)));
    assertEquals("\n", getText(doc.getCharacterElement(insertOffset)));
    assertEquals("\n", getText(doc.getCharacterElement(insertOffset + newLineLen)));
}
项目:cn1    文件:DefaultStyledDocument_ElementBuffer_Specs1Test.java   
@Override
protected void setUp() throws Exception {
    super.setUp();
    doc = new DefStyledDoc_Helpers.DefStyledDocWithLogging();
    root = doc.getDefaultRootElement();
    buf = new DefStyledDoc_Helpers.ElementBufferWithLogging(doc, root) {
        private static final long serialVersionUID = 1L;

        @Override
        public void insert(int offset, int length, ElementSpec[] spec,
                DefaultDocumentEvent event) {
            super.insert(offset, length, specs = spec, event);
        }
    };
    doc.buffer = buf;
    doc.addDocumentListener(this);
}
项目:mmj2    文件:CompoundUndoManager.java   
/**
 * Whenever an UndoableEdit happens the edit will either be absorbed by the
 * current compound edit or a new compound edit will be started
 */
@Override
public void undoableEditHappened(final UndoableEditEvent e) {
    final boolean prog = document.isProgrammatic();
    final DefaultDocumentEvent edit = (DefaultDocumentEvent)e.getEdit();
    if (compoundEdit == null)
        // start a new compound edit
        compoundEdit = startCompoundEdit(edit);
    else if (edit.getType() == EventType.CHANGE)
        compoundEdit.addEdit(edit);
    else if (lastProgrammatic && prog || !lastProgrammatic && !prog
        && isIncremental(edit))
        // append to existing edit
        compoundEdit.addEdit(edit, document.getTextPane()
            .getCaretPosition());
    else {
        // close this compound edit and start a new one
        compoundEdit.end();
        compoundEdit = startCompoundEdit(edit);
    }
    lastProgrammatic = prog;
    updateCursorPosition();
}
项目:freeVM    文件:DefaultStyledDocument_ElementBuffer_Specs1Test.java   
@Override
protected void setUp() throws Exception {
    super.setUp();
    doc = new DefStyledDoc_Helpers.DefStyledDocWithLogging();
    root = doc.getDefaultRootElement();
    buf = new DefStyledDoc_Helpers.ElementBufferWithLogging(doc, root) {
        private static final long serialVersionUID = 1L;

        @Override
        public void insert(int offset, int length, ElementSpec[] spec,
                DefaultDocumentEvent event) {
            super.insert(offset, length, specs = spec, event);
        }
    };
    doc.buffer = buf;
    doc.addDocumentListener(this);
}
项目:freeVM    文件:DefaultStyledDocument_ElementBuffer_InsertTextTest.java   
/**
 * Inserting text into the start of a paragraph with different attributes.
 * <p>
 * This test is equivalent to
 * <code>doc.insertString(insertOffset, caps, italic)</code>,
 * where <code>insertOffset = paragraph.getEndOffset()</code>.
 */
public void testInsertDiffAttrsParStart() throws Exception {
    insertOffset = paragraph.getEndOffset();
    // doc.insertString(insertOffset, caps, italic);
    content.insertString(insertOffset, caps);
    event = doc.new DefaultDocumentEvent(insertOffset, capsLen, EventType.INSERT);
    ElementSpec[] specs = { new ElementSpec(null, ElementSpec.EndTagType),
            new ElementSpec(null, ElementSpec.StartTagType),
            new ElementSpec(italic, ElementSpec.ContentType, capsLen), };
    specs[1].setDirection(ElementSpec.JoinNextDirection);
    buf.insert(insertOffset, capsLen, specs, event);
    List<?> edits = getEdits(event);
    assertEquals(2, edits.size());
    assertChange(edits.get(0), new int[] { 15, 19 }, new int[] { 15, 16 });
    assertChange(edits.get(1), new int[] {}, new int[] { 16, 19 });
    assertChildren(paragraph, new int[] { 0, 5, 5, 9, 9, 15, 15, 16 }, new AttributeSet[] {
            null, bold, italic, null });
    assertChildren(root.getElement(1), new int[] { 16, 19, 19, 24 }, new AttributeSet[] {
            italic, null });
    assertEquals("^^^", getText(doc.getCharacterElement(insertOffset)));
    assertEquals("text\n", getText(doc.getCharacterElement(insertOffset + capsLen)));
}
项目:freeVM    文件:DefaultStyledDocument_ElementBuffer_InsertNewLineTest.java   
/**
 * Inserting text into the middle of an element with different attributes.
 * <p>
 * This test is equivalent to
 * <code>doc.insertString(insertOffset, newLine, null)</code>,
 * where <code>insertOffset</code> has default value from
 * <code>setUp()</code>.
 */
public void testInsertDiffAttrsMiddle() throws Exception {
    // doc.insertString(insertOffset, newLine, null);
    content.insertString(insertOffset, newLine);
    event = doc.new DefaultDocumentEvent(insertOffset, newLineLen, EventType.INSERT);
    ElementSpec[] specs = { new ElementSpec(null, ElementSpec.ContentType, newLineLen),
            new ElementSpec(null, ElementSpec.EndTagType),
            new ElementSpec(null, ElementSpec.StartTagType) };
    specs[2].setDirection(ElementSpec.JoinFractureDirection);
    buf.insert(insertOffset, newLineLen, specs, event);
    List<?> edits = getEdits(event);
    assertEquals(2, edits.size());
    assertChange(edits.get(0), new int[] { 5, 10, 10, 16, 16, 17 },
            new int[] { 5, 7, 7, 8 });
    assertChange(edits.get(1), new int[] {}, new int[] { 8, 17 });
    assertChildren(root.getElement(0), new int[] { 0, 5, 5, 7, 7, 8 }, new AttributeSet[] {
            null, bold, null });
    assertChildren(root.getElement(1), new int[] { 8, 10, 10, 16, 16, 17 },
            new AttributeSet[] { bold, italic, null });
    assertEquals("\n", getText(doc.getCharacterElement(insertOffset)));
    assertEquals("ld", getText(doc.getCharacterElement(insertOffset + newLineLen)));
}
项目:freeVM    文件:DefaultStyledDocument_ElementBuffer_InsertTextTest.java   
/**
 * Inserting text into the start of a paragraph with the same attributes.
 * <p>
 * This test is equivalent to
 * <code>doc.insertString(insertOffset, caps, null)</code>,
 * where <code>insertOffset = paragraph.getEndOffset()</code>.
 */
public void testInsertSameAttrsParStart() throws Exception {
    insertOffset = paragraph.getEndOffset();
    // doc.insertString(insertOffset, caps, null);
    content.insertString(insertOffset, caps);
    event = doc.new DefaultDocumentEvent(insertOffset, capsLen, EventType.INSERT);
    ElementSpec[] specs = { new ElementSpec(null, ElementSpec.EndTagType),
            new ElementSpec(null, ElementSpec.StartTagType),
            new ElementSpec(null, ElementSpec.ContentType, capsLen), };
    specs[1].setDirection(ElementSpec.JoinNextDirection);
    specs[2].setDirection(ElementSpec.JoinNextDirection);
    buf.insert(insertOffset, capsLen, specs, event);
    List<?> edits = getEdits(event);
    assertEquals(2, edits.size());
    assertChange(edits.get(0), new int[] { 15, 19 }, new int[] { 15, 16 });
    assertChange(edits.get(1), new int[] { 19, 24 }, new int[] { 16, 24 });
    assertChildren(paragraph, new int[] { 0, 5, 5, 9, 9, 15, 15, 16 }, new AttributeSet[] {
            null, bold, italic, null });
    assertChildren(root.getElement(1), new int[] { 16, 24 }, new AttributeSet[] { null });
    assertEquals("^^^text\n", getText(doc.getCharacterElement(insertOffset)));
}
项目:freeVM    文件:DefaultStyledDocument_ElementBuffer_InsertTextTest.java   
/**
 * Inserting text into the start of a paragraph with different attributes.
 * <p>
 * This test is equivalent to
 * <code>doc.insertString(insertOffset, caps, italic)</code>,
 * where <code>insertOffset = paragraph.getEndOffset()</code>.
 */
public void testInsertDiffAttrsParStart() throws Exception {
    insertOffset = paragraph.getEndOffset();
    // doc.insertString(insertOffset, caps, italic);
    content.insertString(insertOffset, caps);
    event = doc.new DefaultDocumentEvent(insertOffset, capsLen, EventType.INSERT);
    ElementSpec[] specs = { new ElementSpec(null, ElementSpec.EndTagType),
            new ElementSpec(null, ElementSpec.StartTagType),
            new ElementSpec(italic, ElementSpec.ContentType, capsLen), };
    specs[1].setDirection(ElementSpec.JoinNextDirection);
    buf.insert(insertOffset, capsLen, specs, event);
    List<?> edits = getEdits(event);
    assertEquals(2, edits.size());
    assertChange(edits.get(0), new int[] { 15, 19 }, new int[] { 15, 16 });
    assertChange(edits.get(1), new int[] {}, new int[] { 16, 19 });
    assertChildren(paragraph, new int[] { 0, 5, 5, 9, 9, 15, 15, 16 }, new AttributeSet[] {
            null, bold, italic, null });
    assertChildren(root.getElement(1), new int[] { 16, 19, 19, 24 }, new AttributeSet[] {
            italic, null });
    assertEquals("^^^", getText(doc.getCharacterElement(insertOffset)));
    assertEquals("text\n", getText(doc.getCharacterElement(insertOffset + capsLen)));
}
项目:freeVM    文件:DefaultStyledDocument_ElementBuffer_Specs3Test.java   
@Override
protected void setUp() throws Exception {
    super.setUp();
    doc = new DefStyledDoc_Helpers.DefStyledDocWithLogging();
    root = doc.getDefaultRootElement();
    buf = new DefStyledDoc_Helpers.ElementBufferWithLogging(doc, root) {
        private static final long serialVersionUID = 1L;

        @Override
        public void insert(int offset, int length, ElementSpec[] spec,
                DefaultDocumentEvent event) {
            super.insert(offset, length, specs = spec, event);
        }
    };
    doc.buffer = buf;
    doc.insertString(doc.getLength(), "plain", null); // 5 chars
    doc.insertString(doc.getLength(), "bold", bold); // 4 chars
    doc.insertString(doc.getLength(), "italic", italic); // 6 chars
    paragraph = root.getElement(0);
    leaf = paragraph.getElement(leafIndex);
    insertOffset = leaf.getStartOffset() + 2;
    doc.addDocumentListener(this);
}
项目:freeVM    文件:DefaultStyledDocument_ElementBuffer_Specs3Test.java   
@Override
protected void setUp() throws Exception {
    super.setUp();
    doc = new DefStyledDoc_Helpers.DefStyledDocWithLogging();
    root = doc.getDefaultRootElement();
    buf = new DefStyledDoc_Helpers.ElementBufferWithLogging(doc, root) {
        private static final long serialVersionUID = 1L;

        @Override
        public void insert(int offset, int length, ElementSpec[] spec,
                DefaultDocumentEvent event) {
            super.insert(offset, length, specs = spec, event);
        }
    };
    doc.buffer = buf;
    doc.insertString(doc.getLength(), "plain", null); // 5 chars
    doc.insertString(doc.getLength(), "bold", bold); // 4 chars
    doc.insertString(doc.getLength(), "italic", italic); // 6 chars
    paragraph = root.getElement(0);
    leaf = paragraph.getElement(leafIndex);
    insertOffset = leaf.getStartOffset() + 2;
    doc.addDocumentListener(this);
}
项目:freeVM    文件:DefaultStyledDocument_ElementBuffer_InsertTextTest.java   
/**
 * Inserting text into the end of the document with different attributes.
 * <p>
 * This test is equivalent to
 * <code>doc.insertString(insertOffset, caps, italic)</code>,
 * where <code>insertOffset = doc.getLength()</code>.
 */
public void testInsertDiffAttrsDocEnd() throws Exception {
    insertOffset = doc.getLength();
    // doc.insertString(insertOffset, caps, italic);
    content.insertString(insertOffset, caps);
    event = doc.new DefaultDocumentEvent(insertOffset, capsLen, EventType.INSERT);
    ElementSpec spec = new ElementSpec(italic, 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[] { 16, 24 }, new int[] { 16, 20, 20, 23, 23, 24 });
    assertChildren(root.getElement(1), new int[] { 16, 20, 20, 23, 23, 24 },
            new AttributeSet[] { null, italic, null });
    assertEquals("text", getText(doc.getCharacterElement(insertOffset - 1)));
    assertEquals("^^^", getText(doc.getCharacterElement(insertOffset)));
    assertEquals("\n", getText(doc.getCharacterElement(insertOffset + capsLen)));
}
项目:freeVM    文件:DefaultStyledDocument_ElementBuffer_Specs2Test.java   
@Override
protected void setUp() throws Exception {
    super.setUp();
    doc = new DefStyledDoc_Helpers.DefStyledDocWithLogging();
    root = doc.getDefaultRootElement();
    buf = new DefStyledDoc_Helpers.ElementBufferWithLogging(doc, root) {
        private static final long serialVersionUID = 1L;

        @Override
        public void insert(int offset, int length, ElementSpec[] spec,
                DefaultDocumentEvent event) {
            super.insert(offset, length, specs = spec, event);
        }
    };
    doc.buffer = buf;
    doc.insertString(0, "first\nsecond\nthird", null);
    modified = root.getElement(modifiedIndex);
    insertOffset = modified.getStartOffset() + 2;
    doc.addDocumentListener(this);
}
项目:freeVM    文件:DefaultStyledDocument_ElementBuffer_InsertNewLineTest.java   
/**
 * Inserting text into the end of the document with different attributes.
 * <p>
 * This test is equivalent to
 * <code>doc.insertString(insertOffset, newLine, italic)</code>,
 * where <code>insertOffset = doc.getLength()</code>.
 */
public void testInsertDiffAttrsDocEnd() throws Exception {
    insertOffset = doc.getLength();
    // doc.insertString(insertOffset, newLine, italic);
    content.insertString(insertOffset, newLine);
    event = doc.new DefaultDocumentEvent(insertOffset, newLineLen, EventType.INSERT);
    ElementSpec[] specs = { new ElementSpec(italic, ElementSpec.ContentType, newLineLen),
            new ElementSpec(null, ElementSpec.EndTagType),
            new ElementSpec(null, ElementSpec.StartTagType) };
    specs[2].setDirection(ElementSpec.JoinFractureDirection);
    buf.insert(insertOffset, newLineLen, specs, event);
    List<?> edits = getEdits(event);
    assertEquals(2, edits.size());
    assertChange(edits.get(0), new int[] { 16, 22 }, new int[] { 16, 20, 20, 21 });
    assertChange(edits.get(1), new int[] {}, new int[] { 21, 22 });
    assertChildren(root.getElement(1), new int[] { 16, 20, 20, 21 }, new AttributeSet[] {
            null, italic });
    assertChildren(root.getElement(2), new int[] { 21, 22 }, new AttributeSet[] { null });
    assertEquals("text", getText(doc.getCharacterElement(insertOffset - 1)));
    assertEquals("\n", getText(doc.getCharacterElement(insertOffset)));
    assertEquals("\n", getText(doc.getCharacterElement(insertOffset + newLineLen)));
}
项目:freeVM    文件:DefaultStyledDocument_ElementBuffer_InsertNewLineTest.java   
/**
 * Inserting text into middle of an element with the same attributes.
 * <p>
 * This test is equivalent to
 * <code>doc.insertString(insertOffset, newLine, bold)</code>,
 * where <code>insertOffset</code> has default value from
 * <code>setUp()</code>.
 */
public void testInsertSameAttrsMiddle() throws Exception {
    // doc.insertString(insertOffset, newLine, bold);
    content.insertString(insertOffset, newLine);
    event = doc.new DefaultDocumentEvent(insertOffset, newLineLen, EventType.INSERT);
    ElementSpec[] specs = { new ElementSpec(null, ElementSpec.ContentType, newLineLen),
            new ElementSpec(null, ElementSpec.EndTagType),
            new ElementSpec(null, ElementSpec.StartTagType) };
    specs[0].setDirection(ElementSpec.JoinPreviousDirection);
    specs[2].setDirection(ElementSpec.JoinFractureDirection);
    buf.insert(insertOffset, newLineLen, specs, event);
    List<?> edits = getEdits(event);
    assertEquals(2, edits.size());
    assertChange(edits.get(0), new int[] { 5, 10, 10, 16, 16, 17 }, new int[] { 5, 8 });
    assertChange(edits.get(1), new int[] {}, new int[] { 8, 17 });
    assertChildren(root.getElement(0), new int[] { 0, 5, 5, 8 }, new AttributeSet[] { null,
            bold });
    assertChildren(root.getElement(1), new int[] { 8, 10, 10, 16, 16, 17 },
            new AttributeSet[] { bold, italic, null });
    assertEquals("bo\n", getText(doc.getCharacterElement(insertOffset)));
    assertEquals("ld", getText(doc.getCharacterElement(insertOffset + newLineLen)));
}
项目:freeVM    文件:DefaultStyledDocument_ElementBuffer_InsertTextTest.java   
/**
 * Inserting text into the start of a paragraph with the same attributes.
 * <p>
 * This test is equivalent to
 * <code>doc.insertString(insertOffset, caps, null)</code>,
 * where <code>insertOffset = paragraph.getEndOffset()</code>.
 */
public void testInsertSameAttrsParStart() throws Exception {
    insertOffset = paragraph.getEndOffset();
    // doc.insertString(insertOffset, caps, null);
    content.insertString(insertOffset, caps);
    event = doc.new DefaultDocumentEvent(insertOffset, capsLen, EventType.INSERT);
    ElementSpec[] specs = { new ElementSpec(null, ElementSpec.EndTagType),
            new ElementSpec(null, ElementSpec.StartTagType),
            new ElementSpec(null, ElementSpec.ContentType, capsLen), };
    specs[1].setDirection(ElementSpec.JoinNextDirection);
    specs[2].setDirection(ElementSpec.JoinNextDirection);
    buf.insert(insertOffset, capsLen, specs, event);
    List<?> edits = getEdits(event);
    assertEquals(2, edits.size());
    assertChange(edits.get(0), new int[] { 15, 19 }, new int[] { 15, 16 });
    assertChange(edits.get(1), new int[] { 19, 24 }, new int[] { 16, 24 });
    assertChildren(paragraph, new int[] { 0, 5, 5, 9, 9, 15, 15, 16 }, new AttributeSet[] {
            null, bold, italic, null });
    assertChildren(root.getElement(1), new int[] { 16, 24 }, new AttributeSet[] { null });
    assertEquals("^^^text\n", getText(doc.getCharacterElement(insertOffset)));
}
项目:freeVM    文件:DefaultStyledDocument_ElementBuffer_InsertNewLineTest.java   
/**
 * Inserting text into element boundary; the text and both elements have
 * different attributes.
 * <p>
 * This test is equivalent to
 * <code>doc.insertString(insertOffset, newLine, null)</code>,
 * where 2 is added to default value of <code>insertOffset</code>.
 */
public void testInsertDiffAttrsEnd() throws Exception {
    insertOffset += 2;
    // doc.insertString(insertOffset, newLine, null);
    content.insertString(insertOffset, newLine);
    event = doc.new DefaultDocumentEvent(insertOffset, newLineLen, EventType.INSERT);
    ElementSpec[] specs = { new ElementSpec(null, ElementSpec.ContentType, newLineLen),
            new ElementSpec(null, ElementSpec.EndTagType),
            new ElementSpec(null, ElementSpec.StartTagType) };
    specs[2].setDirection(ElementSpec.JoinFractureDirection);
    buf.insert(insertOffset, newLineLen, specs, event);
    List<?> edits = getEdits(event);
    assertEquals(2, edits.size());
    assertChange(edits.get(0), new int[] { 5, 10, 10, 16, 16, 17 },
            new int[] { 5, 9, 9, 10 });
    assertChange(edits.get(1), new int[] {}, new int[] { 10, 17 });
    assertChildren(root.getElement(0), new int[] { 0, 5, 5, 9, 9, 10 }, new AttributeSet[] {
            null, bold, null });
    assertChildren(root.getElement(1), new int[] { 10, 16, 16, 17 }, new AttributeSet[] {
            italic, null });
    assertEquals("\n", getText(doc.getCharacterElement(insertOffset)));
    assertEquals("italic", getText(doc.getCharacterElement(insertOffset + newLineLen)));
}
项目:freeVM    文件:DefaultStyledDocument_ElementBuffer_InsertNewLineTest.java   
/**
 * Inserting text into element boundary; the attributes of the text and
 * the following element are the same, the attributes of the previous
 * element are different.
 * <p>
 * This test is equivalent to
 * <code>doc.insertString(insertOffset, newLine, italic)</code>,
 * where 2 is added to default value of <code>insertOffset</code>.
 */
public void testInsertDiffSameAttrsEnd() throws Exception {
    insertOffset += 2;
    // doc.insertString(insertOffset, newLine, italic);
    content.insertString(insertOffset, newLine);
    event = doc.new DefaultDocumentEvent(insertOffset, newLineLen, EventType.INSERT);
    ElementSpec[] specs = { new ElementSpec(italic, ElementSpec.ContentType, newLineLen),
            new ElementSpec(null, ElementSpec.EndTagType),
            new ElementSpec(null, ElementSpec.StartTagType) };
    specs[2].setDirection(ElementSpec.JoinFractureDirection);
    buf.insert(insertOffset, newLineLen, specs, event);
    List<?> edits = getEdits(event);
    assertEquals(2, edits.size());
    assertChange(edits.get(0), new int[] { 5, 10, 10, 16, 16, 17 },
            new int[] { 5, 9, 9, 10 });
    assertChange(edits.get(1), new int[] {}, new int[] { 10, 17 });
    assertChildren(root.getElement(0), new int[] { 0, 5, 5, 9, 9, 10 }, new AttributeSet[] {
            null, bold, italic });
    assertChildren(root.getElement(1), new int[] { 10, 16, 16, 17 }, new AttributeSet[] {
            italic, null });
    assertEquals("\n", getText(doc.getCharacterElement(insertOffset)));
    assertEquals("italic", getText(doc.getCharacterElement(insertOffset + newLineLen)));
}
项目:freeVM    文件:DefaultStyledDocument_ElementBuffer_InsertNewLineTest.java   
/**
 * Inserting text into the start of a paragraph with different attributes.
 * <p>
 * This test is equivalent to
 * <code>doc.insertString(insertOffset, newLine, italic)</code>,
 * where <code>insertOffset = paragraph.getEndOffset()</code>.
 */
public void testInsertDiffAttrsParStart() throws Exception {
    insertOffset = paragraph.getEndOffset();
    // doc.insertString(insertOffset, newLine, italic);
    content.insertString(insertOffset, newLine);
    event = doc.new DefaultDocumentEvent(insertOffset, newLineLen, EventType.INSERT);
    ElementSpec[] specs = { new ElementSpec(null, ElementSpec.EndTagType),
            new ElementSpec(null, ElementSpec.StartTagType),
            new ElementSpec(italic, ElementSpec.ContentType, newLineLen),
            new ElementSpec(null, ElementSpec.EndTagType),
            new ElementSpec(null, ElementSpec.StartTagType) };
    specs[4].setDirection(ElementSpec.JoinNextDirection);
    buf.insert(insertOffset, newLineLen, specs, event);
    List<?> edits = getEdits(event);
    assertEquals(3, edits.size());
    assertChange(edits.get(0), new int[] { 15, 17 }, new int[] { 15, 16 });
    assertChange(edits.get(1), new int[] {}, new int[] { 16, 17 });
    assertChange(edits.get(2), new int[] {}, new int[] { 16, 17 });
    assertChildren(root.getElement(0), new int[] { 0, 5, 5, 9, 9, 15, 15, 16 },
            new AttributeSet[] { null, bold, italic, null });
    assertChildren(root.getElement(1), new int[] { 16, 17 }, new AttributeSet[] { italic });
    assertChildren(root.getElement(2), new int[] { 17, 22 }, new AttributeSet[] { null });
    assertEquals("\n", getText(doc.getCharacterElement(insertOffset)));
    assertEquals("text\n", getText(doc.getCharacterElement(insertOffset + newLineLen)));
}
项目:freeVM    文件:DefaultStyledDocument_ElementBuffer_InsertNewLineTest.java   
/**
 * Inserting text into the end of the document with the same attributes.
 * <p>
 * This test is equivalent to
 * <code>doc.insertString(insertOffset, newLine, null)</code>,
 * where <code>insertOffset = doc.getLength()</code>.
 */
public void testInsertSameAttrsDocEnd() throws Exception {
    insertOffset = doc.getLength();
    // doc.insertString(insertOffset, newLine, null);
    content.insertString(insertOffset, newLine);
    event = doc.new DefaultDocumentEvent(insertOffset, newLineLen, EventType.INSERT);
    ElementSpec[] specs = { new ElementSpec(null, ElementSpec.ContentType, newLineLen),
            new ElementSpec(null, ElementSpec.EndTagType),
            new ElementSpec(null, ElementSpec.StartTagType) };
    specs[0].setDirection(ElementSpec.JoinPreviousDirection);
    specs[2].setDirection(ElementSpec.JoinFractureDirection);
    buf.insert(insertOffset, newLineLen, specs, event);
    List<?> edits = getEdits(event);
    assertEquals(2, edits.size());
    assertChange(edits.get(0), new int[] { 16, 22 }, new int[] { 16, 21 });
    assertChange(edits.get(1), new int[] {}, new int[] { 21, 22 });
    assertChildren(root.getElement(1), new int[] { 16, 21 }, new AttributeSet[] { null });
    assertChildren(root.getElement(2), new int[] { 21, 22 }, new AttributeSet[] { null });
    assertEquals("text\n", getText(doc.getCharacterElement(insertOffset)));
    assertEquals("\n", getText(doc.getCharacterElement(insertOffset + newLineLen)));
}
项目:freeVM    文件:DefaultStyledDocument_ElementBuffer_InsertNewLineTest.java   
/**
 * Inserting text into element boundary; the text and both elements have
 * different attributes.
 * <p>
 * This test is equivalent to
 * <code>doc.insertString(insertOffset, newLine, null)</code>,
 * where 2 is added to default value of <code>insertOffset</code>.
 */
public void testInsertDiffAttrsEnd() throws Exception {
    insertOffset += 2;
    // doc.insertString(insertOffset, newLine, null);
    content.insertString(insertOffset, newLine);
    event = doc.new DefaultDocumentEvent(insertOffset, newLineLen, EventType.INSERT);
    ElementSpec[] specs = { new ElementSpec(null, ElementSpec.ContentType, newLineLen),
            new ElementSpec(null, ElementSpec.EndTagType),
            new ElementSpec(null, ElementSpec.StartTagType) };
    specs[2].setDirection(ElementSpec.JoinFractureDirection);
    buf.insert(insertOffset, newLineLen, specs, event);
    List<?> edits = getEdits(event);
    assertEquals(2, edits.size());
    assertChange(edits.get(0), new int[] { 5, 10, 10, 16, 16, 17 },
            new int[] { 5, 9, 9, 10 });
    assertChange(edits.get(1), new int[] {}, new int[] { 10, 17 });
    assertChildren(root.getElement(0), new int[] { 0, 5, 5, 9, 9, 10 }, new AttributeSet[] {
            null, bold, null });
    assertChildren(root.getElement(1), new int[] { 10, 16, 16, 17 }, new AttributeSet[] {
            italic, null });
    assertEquals("\n", getText(doc.getCharacterElement(insertOffset)));
    assertEquals("italic", getText(doc.getCharacterElement(insertOffset + newLineLen)));
}
项目:freeVM    文件:DefaultStyledDocument_ElementBuffer_InsertNewLineTest.java   
/**
 * Inserting text into end of the an element with the same attributes;
 * the following element has different attributes.
 * <p>
 * This test is equivalent to
 * <code>doc.insertString(insertOffset, newLine, bold)</code>,
 * where 2 is added to default value of <code>insertOffset</code>.
 */
public void testInsertSameAttrsEnd() throws Exception {
    insertOffset += 2;
    // doc.insertString(insertOffset, newLine, bold);
    content.insertString(insertOffset, newLine);
    event = doc.new DefaultDocumentEvent(insertOffset, newLineLen, EventType.INSERT);
    ElementSpec[] specs = { new ElementSpec(null, ElementSpec.ContentType, newLineLen),
            new ElementSpec(null, ElementSpec.EndTagType),
            new ElementSpec(null, ElementSpec.StartTagType) };
    specs[0].setDirection(ElementSpec.JoinPreviousDirection);
    specs[2].setDirection(ElementSpec.JoinFractureDirection);
    // Spec [0] has wrong attributes (should be bold) but everything works
    // the way it supposed to.
    buf.insert(insertOffset, newLineLen, specs, event);
    List<?> edits = getEdits(event);
    assertEquals(2, edits.size());
    assertChange(edits.get(0), new int[] { 10, 16, 16, 17 }, new int[] {});
    assertChange(edits.get(1), new int[] {}, new int[] { 10, 17 });
    assertChildren(root.getElement(0), new int[] { 0, 5, 5, 10 }, new AttributeSet[] {
            null, bold });
    assertChildren(root.getElement(1), new int[] { 10, 16, 16, 17 }, new AttributeSet[] {
            italic, null });
    assertEquals("bold\n", getText(doc.getCharacterElement(insertOffset)));
    assertEquals("italic", getText(doc.getCharacterElement(insertOffset + newLineLen)));
}
项目:freeVM    文件:DefaultStyledDocument_ElementBuffer_InsertNewLineTest.java   
/**
 * Inserting text into element boundary; the attributes of the text and
 * the following element are the same, the attributes of the previous
 * element are different.
 * <p>
 * This test is equivalent to
 * <code>doc.insertString(insertOffset, newLine, italic)</code>,
 * where 2 is added to default value of <code>insertOffset</code>.
 */
public void testInsertDiffSameAttrsEnd() throws Exception {
    insertOffset += 2;
    // doc.insertString(insertOffset, newLine, italic);
    content.insertString(insertOffset, newLine);
    event = doc.new DefaultDocumentEvent(insertOffset, newLineLen, EventType.INSERT);
    ElementSpec[] specs = { new ElementSpec(italic, ElementSpec.ContentType, newLineLen),
            new ElementSpec(null, ElementSpec.EndTagType),
            new ElementSpec(null, ElementSpec.StartTagType) };
    specs[2].setDirection(ElementSpec.JoinFractureDirection);
    buf.insert(insertOffset, newLineLen, specs, event);
    List<?> edits = getEdits(event);
    assertEquals(2, edits.size());
    assertChange(edits.get(0), new int[] { 5, 10, 10, 16, 16, 17 },
            new int[] { 5, 9, 9, 10 });
    assertChange(edits.get(1), new int[] {}, new int[] { 10, 17 });
    assertChildren(root.getElement(0), new int[] { 0, 5, 5, 9, 9, 10 }, new AttributeSet[] {
            null, bold, italic });
    assertChildren(root.getElement(1), new int[] { 10, 16, 16, 17 }, new AttributeSet[] {
            italic, null });
    assertEquals("\n", getText(doc.getCharacterElement(insertOffset)));
    assertEquals("italic", getText(doc.getCharacterElement(insertOffset + newLineLen)));
}
项目:jpexs-decompiler    文件:CompoundUndoMan.java   
/**
 *  Whenever an UndoableEdit happens the edit will either be absorbed
 *  by the current compound edit or a new compound edit will be started
 */
@Override
public void undoableEditHappened(UndoableEditEvent e) {
    //  Start a new compound edit

    AbstractDocument.DefaultDocumentEvent docEvt = (DefaultDocumentEvent) e.getEdit();

    if (compoundEdit == null) {
        compoundEdit = startCompoundEdit(e.getEdit());
        startCombine = false;
        return;
    }

    int editLine = ((SyntaxDocument)docEvt.getDocument()).getLineNumberAt(docEvt.getOffset());

    //  Check for an incremental edit or backspace.
    //  The Change in Caret position and Document length should both be
    //  either 1 or -1.
    if ((startCombine || Math.abs(docEvt.getLength()) == 1) && editLine == lastLine) {
        compoundEdit.addEdit(e.getEdit());
        startCombine = false;
        return;
    }

    //  Not incremental edit, end previous edit and start a new one
    lastLine = editLine;

    compoundEdit.end();
    compoundEdit = startCompoundEdit(e.getEdit());
}