本文整理汇总了Java中javax.swing.text.PlainDocument.insertString方法的典型用法代码示例。如果您正苦于以下问题:Java PlainDocument.insertString方法的具体用法?Java PlainDocument.insertString怎么用?Java PlainDocument.insertString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.swing.text.PlainDocument
的用法示例。
在下文中一共展示了PlainDocument.insertString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testZeroPosition
import javax.swing.text.PlainDocument; //导入方法依赖的package包/类
public void testZeroPosition() throws BadLocationException {
PlainDocument doc = new PlainDocument();
TestHighlighsContainer thc = new TestHighlighsContainer();
CompoundHighlightsContainer chc = new CompoundHighlightsContainer();
chc.setLayers(doc, new HighlightsContainer[] { thc });
doc.insertString(0, "0123456789", null);
chc.getHighlights(0, Integer.MAX_VALUE);
assertEquals("Should have been queried", 2, thc.queries.size());
assertEquals("Wrong query startOffset", 0, (int) thc.queries.get(0));
thc.queries.clear();
doc.insertString(0, "abcd", null);
assertEquals("Should not have been queried", 0, thc.queries.size());
chc.getHighlights(0, Integer.MAX_VALUE);
assertEquals("Should have been queried again", 2, thc.queries.size());
assertEquals("Wrong query startOffset", 0, (int) thc.queries.get(0));
thc.queries.clear();
chc.getHighlights(0, Integer.MAX_VALUE);
assertEquals("Should not have been queried again", 0, thc.queries.size());
}
示例2: testMark
import javax.swing.text.PlainDocument; //导入方法依赖的package包/类
@Test
public void testMark() throws Exception {
PlainDocument doc = new PlainDocument();
doc.insertString(0, "0123456789", null);
DocumentReader r = new DocumentReader(doc);
Assert.assertEquals('0', r.read());
r.mark(5);
Assert.assertEquals('1', r.read());
Assert.assertEquals('2', r.read());
r.reset();
Assert.assertEquals('1', r.read());
Assert.assertEquals('2', r.read());
r.close();
}
示例3: testRead_intArg
import javax.swing.text.PlainDocument; //导入方法依赖的package包/类
@Test
public void testRead_intArg() throws Exception {
PlainDocument doc = new PlainDocument();
doc.insertString(0, "0123456789", null);
DocumentReader r = new DocumentReader(doc);
Assert.assertEquals('0', r.read());
Assert.assertEquals('1', r.read());
Assert.assertEquals('2', r.read());
Assert.assertEquals('3', r.read());
Assert.assertEquals('4', r.read());
Assert.assertEquals('5', r.read());
Assert.assertEquals('6', r.read());
Assert.assertEquals('7', r.read());
Assert.assertEquals('8', r.read());
Assert.assertEquals('9', r.read());
Assert.assertEquals(-1, r.read());
Assert.assertEquals(-1, r.read());
r.close();
}
示例4: testRead_charArrayArg_allAtOnce
import javax.swing.text.PlainDocument; //导入方法依赖的package包/类
@Test
public void testRead_charArrayArg_allAtOnce() throws Exception {
String content = "0123456789";
PlainDocument doc = new PlainDocument();
doc.insertString(0, content, null);
DocumentReader r = new DocumentReader(doc);
char[] array = new char[10];
Assert.assertEquals(10, r.read(array));
Assert.assertEquals(content, new String(array));
Assert.assertEquals(-1, r.read(array));
Assert.assertEquals(-1, r.read());
r.close();
}
示例5: testRead_3Arg_allAtOnce
import javax.swing.text.PlainDocument; //导入方法依赖的package包/类
@Test
public void testRead_3Arg_allAtOnce() throws Exception {
String content = "0123456789";
PlainDocument doc = new PlainDocument();
doc.insertString(0, content, null);
DocumentReader r = new DocumentReader(doc);
char[] array = new char[10];
Assert.assertEquals(10, r.read(array, 0, array.length));
Assert.assertEquals(content, new String(array));
Assert.assertEquals(-1, r.read(array, 0, array.length));
Assert.assertEquals(-1, r.read());
r.close();
}
示例6: testReset_NoMarkedOffset
import javax.swing.text.PlainDocument; //导入方法依赖的package包/类
@Test
public void testReset_NoMarkedOffset() throws Exception {
String content = "0123456789";
PlainDocument doc = new PlainDocument();
doc.insertString(0, content, null);
DocumentReader r = new DocumentReader(doc);
Assert.assertEquals('0', r.read());
Assert.assertEquals('1', r.read());
Assert.assertEquals('2', r.read());
r.reset();
Assert.assertEquals('0', r.read());
Assert.assertEquals('1', r.read());
Assert.assertEquals('2', r.read());
r.close();
}
示例7: testReset_MarkedOffset
import javax.swing.text.PlainDocument; //导入方法依赖的package包/类
@Test
public void testReset_MarkedOffset() throws Exception {
String content = "0123456789";
PlainDocument doc = new PlainDocument();
doc.insertString(0, content, null);
DocumentReader r = new DocumentReader(doc);
Assert.assertEquals('0', r.read());
r.mark(5);
Assert.assertEquals('1', r.read());
Assert.assertEquals('2', r.read());
r.reset();
Assert.assertEquals('1', r.read());
Assert.assertEquals('2', r.read());
r.close();
}
示例8: testSeek_WithinDocument
import javax.swing.text.PlainDocument; //导入方法依赖的package包/类
@Test
public void testSeek_WithinDocument() throws Exception {
String content = "0123456789";
PlainDocument doc = new PlainDocument();
doc.insertString(0, content, null);
DocumentReader r = new DocumentReader(doc);
Assert.assertEquals('0', r.read());
r.seek(6);
Assert.assertEquals('6', r.read());
Assert.assertEquals('7', r.read());
Assert.assertEquals('8', r.read());
Assert.assertEquals('9', r.read());
Assert.assertEquals(-1, r.read());
r.close();
}
示例9: testSkip_WithinDocument
import javax.swing.text.PlainDocument; //导入方法依赖的package包/类
@Test
public void testSkip_WithinDocument() throws Exception {
String content = "0123456789";
PlainDocument doc = new PlainDocument();
doc.insertString(0, content, null);
DocumentReader r = new DocumentReader(doc);
Assert.assertEquals('0', r.read());
r.skip(6);
Assert.assertEquals('7', r.read());
Assert.assertEquals('8', r.read());
Assert.assertEquals('9', r.read());
Assert.assertEquals(-1, r.read());
r.close();
}
示例10: testDebugOffset
import javax.swing.text.PlainDocument; //导入方法依赖的package包/类
public void testDebugOffset() throws Exception {
PlainDocument doc = new PlainDocument(); // tabSize is 8
// 0123 45 678 90123456 789
doc.insertString(0, "abc\na\tbc\nabcdefg\thij", null);
assertEquals("0[1:1]", DocumentUtilities.debugOffset(doc, 0));
assertEquals("5[2:2]", DocumentUtilities.debugOffset(doc, 5));
assertEquals("6[2:9]", DocumentUtilities.debugOffset(doc, 6));
assertEquals("7[2:10]", DocumentUtilities.debugOffset(doc, 7));
assertEquals("16[3:8]", DocumentUtilities.debugOffset(doc, 16));
assertEquals("17[3:9]", DocumentUtilities.debugOffset(doc, 17));
assertEquals("19[3:11]", DocumentUtilities.debugOffset(doc, 19));
}
示例11: testGetText
import javax.swing.text.PlainDocument; //导入方法依赖的package包/类
public void testGetText() throws Exception {
PlainDocument doc = new PlainDocument();
CharSequence text = DocumentUtilities.getText(doc);
assertEquals(1, text.length());
assertEquals('\n', text.charAt(0));
text = DocumentUtilities.getText(doc);
doc.insertString(0, "a\nb", null);
for (int i = 0; i < doc.getLength() + 1; i++) {
assertEquals(doc.getText(i, 1).charAt(0), text.charAt(i));
}
}
示例12: clear
import javax.swing.text.PlainDocument; //导入方法依赖的package包/类
public void clear(String text) {
this.currentUndoManager = null;
PlainDocument doc = new PlainDocument();
try {
doc.insertString(0, text, (AttributeSet) null);
} catch (BadLocationException var4) {
;
}
this.setDocument(doc);
}
示例13: testRead_charArrayArg_multipleReads
import javax.swing.text.PlainDocument; //导入方法依赖的package包/类
@Test
public void testRead_charArrayArg_multipleReads() throws Exception {
String content = "0123456789";
PlainDocument doc = new PlainDocument();
doc.insertString(0, content, null);
DocumentReader r = new DocumentReader(doc);
char[] array = new char[3];
Assert.assertEquals(3, r.read(array));
Assert.assertEquals("012", new String(array));
Assert.assertEquals(3, r.read(array));
Assert.assertEquals("345", new String(array));
Assert.assertEquals(3, r.read(array));
Assert.assertEquals("678", new String(array));
Assert.assertEquals(1, r.read(array));
Assert.assertEquals('9', array[0]);
Assert.assertEquals(-1, r.read(array));
Assert.assertEquals(-1, r.read());
r.close();
}
示例14: testRead_3Arg_multipleReads
import javax.swing.text.PlainDocument; //导入方法依赖的package包/类
@Test
public void testRead_3Arg_multipleReads() throws Exception {
String content = "0123456789";
PlainDocument doc = new PlainDocument();
doc.insertString(0, content, null);
DocumentReader r = new DocumentReader(doc);
char[] array = new char[10];
Assert.assertEquals(3, r.read(array, 0, 3));
Assert.assertEquals("012", new String(array, 0, 3));
Assert.assertEquals(3, r.read(array, 0, 3));
Assert.assertEquals("345", new String(array, 0, 3));
Assert.assertEquals(3, r.read(array, 0, 3));
Assert.assertEquals("678", new String(array, 0, 3));
Assert.assertEquals(1, r.read(array, 0, 3));
Assert.assertEquals('9', array[0]);
Assert.assertEquals(-1, r.read(array, 0, 3));
Assert.assertEquals(-1, r.read());
r.close();
}
示例15: testSeek_PastDocumentEnd
import javax.swing.text.PlainDocument; //导入方法依赖的package包/类
@Test
public void testSeek_PastDocumentEnd() throws Exception {
String content = "0123456789";
PlainDocument doc = new PlainDocument();
doc.insertString(0, content, null);
DocumentReader r = new DocumentReader(doc);
Assert.assertEquals('0', r.read());
r.seek(1000);
Assert.assertEquals(-1, r.read());
r.close();
}