本文整理汇总了Java中javax.swing.text.AbstractDocument.DefaultDocumentEvent类的典型用法代码示例。如果您正苦于以下问题:Java DefaultDocumentEvent类的具体用法?Java DefaultDocumentEvent怎么用?Java DefaultDocumentEvent使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DefaultDocumentEvent类属于javax.swing.text.AbstractDocument包,在下文中一共展示了DefaultDocumentEvent类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: setUp
import javax.swing.text.AbstractDocument.DefaultDocumentEvent; //导入依赖的package包/类
@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();
}
开发者ID:shannah,项目名称:cn1,代码行数:20,代码来源:DefaultStyledDocument_ElementBuffer_InsertMiscTest.java
示例2: testInsertSameAttrsParStart
import javax.swing.text.AbstractDocument.DefaultDocumentEvent; //导入依赖的package包/类
/**
* 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)));
}
开发者ID:shannah,项目名称:cn1,代码行数:28,代码来源:DefaultStyledDocument_ElementBuffer_InsertTextTest.java
示例3: testInsertDiffAttrsParStart
import javax.swing.text.AbstractDocument.DefaultDocumentEvent; //导入依赖的package包/类
/**
* 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)));
}
开发者ID:shannah,项目名称:cn1,代码行数:29,代码来源:DefaultStyledDocument_ElementBuffer_InsertTextTest.java
示例4: testInsertDiffAttrsDocEnd
import javax.swing.text.AbstractDocument.DefaultDocumentEvent; //导入依赖的package包/类
/**
* 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)));
}
开发者ID:shannah,项目名称:cn1,代码行数:24,代码来源:DefaultStyledDocument_ElementBuffer_InsertTextTest.java
示例5: setUp
import javax.swing.text.AbstractDocument.DefaultDocumentEvent; //导入依赖的package包/类
@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);
}
开发者ID:shannah,项目名称:cn1,代码行数:24,代码来源:DefaultStyledDocument_ElementBuffer_Specs3Test.java
示例6: setUp
import javax.swing.text.AbstractDocument.DefaultDocumentEvent; //导入依赖的package包/类
@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();
}
开发者ID:shannah,项目名称:cn1,代码行数:22,代码来源:PlainDocumentTest.java
示例7: setUp
import javax.swing.text.AbstractDocument.DefaultDocumentEvent; //导入依赖的package包/类
@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);
}
开发者ID:shannah,项目名称:cn1,代码行数:21,代码来源:DefaultStyledDocument_ElementBuffer_Specs2Test.java
示例8: testInsertSameAttrsDocStart
import javax.swing.text.AbstractDocument.DefaultDocumentEvent; //导入依赖的package包/类
/**
* 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)));
}
开发者ID:shannah,项目名称:cn1,代码行数:31,代码来源:DefaultStyledDocument_ElementBuffer_InsertNewLineTest.java
示例9: testInsertDiffAttrsDocStart
import javax.swing.text.AbstractDocument.DefaultDocumentEvent; //导入依赖的package包/类
/**
* 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)));
}
开发者ID:shannah,项目名称:cn1,代码行数:30,代码来源:DefaultStyledDocument_ElementBuffer_InsertNewLineTest.java
示例10: testInsertSameAttrsMiddle
import javax.swing.text.AbstractDocument.DefaultDocumentEvent; //导入依赖的package包/类
/**
* 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)));
}
开发者ID:shannah,项目名称:cn1,代码行数:30,代码来源:DefaultStyledDocument_ElementBuffer_InsertNewLineTest.java
示例11: testInsertSameAttrsEnd
import javax.swing.text.AbstractDocument.DefaultDocumentEvent; //导入依赖的package包/类
/**
* 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)));
}
开发者ID:shannah,项目名称:cn1,代码行数:33,代码来源:DefaultStyledDocument_ElementBuffer_InsertNewLineTest.java
示例12: testInsertDiffAttrsMiddle
import javax.swing.text.AbstractDocument.DefaultDocumentEvent; //导入依赖的package包/类
/**
* 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)));
}
开发者ID:shannah,项目名称:cn1,代码行数:30,代码来源:DefaultStyledDocument_ElementBuffer_InsertNewLineTest.java
示例13: testInsertDiffAttrsEnd
import javax.swing.text.AbstractDocument.DefaultDocumentEvent; //导入依赖的package包/类
/**
* 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)));
}
开发者ID:shannah,项目名称:cn1,代码行数:31,代码来源:DefaultStyledDocument_ElementBuffer_InsertNewLineTest.java
示例14: testInsertDiffSameAttrsEnd
import javax.swing.text.AbstractDocument.DefaultDocumentEvent; //导入依赖的package包/类
/**
* 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)));
}
开发者ID:shannah,项目名称:cn1,代码行数:32,代码来源:DefaultStyledDocument_ElementBuffer_InsertNewLineTest.java
示例15: testInsertSameAttrsParStart
import javax.swing.text.AbstractDocument.DefaultDocumentEvent; //导入依赖的package包/类
/**
* 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)));
}
开发者ID:shannah,项目名称:cn1,代码行数:32,代码来源:DefaultStyledDocument_ElementBuffer_InsertNewLineTest.java
示例16: testInsertDiffAttrsParStart
import javax.swing.text.AbstractDocument.DefaultDocumentEvent; //导入依赖的package包/类
/**
* 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)));
}
开发者ID:shannah,项目名称:cn1,代码行数:32,代码来源:DefaultStyledDocument_ElementBuffer_InsertNewLineTest.java
示例17: testInsertSameAttrsDocEnd
import javax.swing.text.AbstractDocument.DefaultDocumentEvent; //导入依赖的package包/类
/**
* 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)));
}
开发者ID:shannah,项目名称:cn1,代码行数:28,代码来源:DefaultStyledDocument_ElementBuffer_InsertNewLineTest.java
示例18: testInsertDiffAttrsDocEnd
import javax.swing.text.AbstractDocument.DefaultDocumentEvent; //导入依赖的package包/类
/**
* 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)));
}
开发者ID:shannah,项目名称:cn1,代码行数:29,代码来源:DefaultStyledDocument_ElementBuffer_InsertNewLineTest.java
示例19: setUp
import javax.swing.text.AbstractDocument.DefaultDocumentEvent; //导入依赖的package包/类
@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);
}
开发者ID:shannah,项目名称:cn1,代码行数:18,代码来源:DefaultStyledDocument_ElementBuffer_Specs1Test.java
示例20: undoableEditHappened
import javax.swing.text.AbstractDocument.DefaultDocumentEvent; //导入依赖的package包/类
/**
* 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();
}
开发者ID:digama0,项目名称:mmj2,代码行数:27,代码来源:CompoundUndoManager.java
注:本文中的javax.swing.text.AbstractDocument.DefaultDocumentEvent类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论