当前位置: 首页>>代码示例>>Java>>正文


Java PlainDocument类代码示例

本文整理汇总了Java中javax.swing.text.PlainDocument的典型用法代码示例。如果您正苦于以下问题:Java PlainDocument类的具体用法?Java PlainDocument怎么用?Java PlainDocument使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


PlainDocument类属于javax.swing.text包,在下文中一共展示了PlainDocument类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: inputChange

import javax.swing.text.PlainDocument; //导入依赖的package包/类
private void inputChange(PlainDocument doc, JTextArea area, String directionToCompare) {
	try {
		String str = doc.getText(doc.getLength() - 2, 1);
		if (str.equals(directionToCompare)) {
			if (movementCounter < 9) {
				movementCounter++;
				doc.remove(doc.getLength() - 1, 1);
				area.append(Integer.toString(movementCounter));
			}
			else {
				movementCounter = 0;
				area.append(directionToCompare + Integer.toString(movementCounter));
			}
		}
		else {
			movementCounter = 0;
			area.append(directionToCompare + Integer.toString(movementCounter));
		}
	}
	catch (BadLocationException e) {
		e.printStackTrace();
	}
}
 
开发者ID:tommai78101,项目名称:PokemonWalking,代码行数:24,代码来源:ScriptChanger.java

示例2: testExcludeTwoLayers

import javax.swing.text.PlainDocument; //导入依赖的package包/类
public void testExcludeTwoLayers() {
    OffsetsBag bag = new OffsetsBag(new PlainDocument());
    
    MemoryMimeDataProvider.reset(null);
    MemoryMimeDataProvider.addInstances(
        "text/plain", new SingletonLayerFactory("layer", ZOrder.DEFAULT_RACK, true, bag));

    JEditorPane pane = new JEditorPane();
    String [] removed = new String[] {"^org\\.netbeans\\.modules\\.editor\\.lib2\\.highlighting\\..*$", "^org\\.netbeans\\.modules\\.editor\\.lib2\\.highlighting\\.TextSelectionHighlighting$"};
    pane.putClientProperty("HighlightsLayerExcludes", removed);
    pane.setContentType("text/plain");
    assertEquals("The pane has got wrong mime type", "text/plain", pane.getContentType());
    
    HighlightingManager hm = HighlightingManager.getInstance(pane);
    HighlightsContainer hc = hm.getHighlights(HighlightsLayerFilter.IDENTITY);

    assertNotNull("Can't get fixed HighlightsContainer", hc);
    assertFalse("There should be no fixed highlights", hc.getHighlights(0, Integer.MAX_VALUE).moveNext());
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:20,代码来源:HighlightingManagerTest.java

示例3: testSimple

import javax.swing.text.PlainDocument; //导入依赖的package包/类
public void testSimple() {
    PlainDocument doc = new PlainDocument();
    HighlightsContainer layer = createRandomBag(doc, "layer");
    HighlightsSequence highlights = layer.getHighlights(0, 100);
    
    ProxyHighlightsContainer proxyLayer = new ProxyHighlightsContainer(doc, new HighlightsContainer [] { layer });
    HighlightsSequence proxyHighlights = proxyLayer.getHighlights(0, 100);

    for ( ; highlights.moveNext(); ) {
        // Ignore empty highlights
        if (highlights.getStartOffset() == highlights.getEndOffset()) {
            continue;
        }

        assertTrue("Wrong number of proxy highlights", proxyHighlights.moveNext());

        assertEquals("Start offset does not match", highlights.getStartOffset(), proxyHighlights.getStartOffset());
        assertEquals("End offset does not match", highlights.getEndOffset(), proxyHighlights.getEndOffset());
        assertTrue("Attributes do not match", highlights.getAttributes().isEqual(proxyHighlights.getAttributes()));
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:22,代码来源:ProxyHighlightsContainerTest.java

示例4: testOrdering

import javax.swing.text.PlainDocument; //导入依赖的package包/类
public void testOrdering() {
    PlainDocument doc = new PlainDocument();
    PositionsBag hsA = new PositionsBag(doc);
    PositionsBag hsB = new PositionsBag(doc);

    SimpleAttributeSet attribsA = new SimpleAttributeSet();
    SimpleAttributeSet attribsB = new SimpleAttributeSet();
    
    attribsA.addAttribute("attribute", "value-A");
    attribsB.addAttribute("attribute", "value-B");
    
    hsA.addHighlight(new SimplePosition(5), new SimplePosition(15), attribsA);
    hsB.addHighlight(new SimplePosition(10), new SimplePosition(20), attribsB);
    
    ProxyHighlightsContainer chc = new ProxyHighlightsContainer(doc, new HighlightsContainer [] { hsA, hsB });
    HighlightsSequence highlights = chc.getHighlights(0, Integer.MAX_VALUE);

    assertTrue("Wrong number of highlights", highlights.moveNext());
    assertEquals("1. highlight - wrong attribs", "value-A", highlights.getAttributes().getAttribute("attribute"));

    assertTrue("Wrong number of highlights", highlights.moveNext());
    assertEquals("2. highlight - wrong attribs", "value-B", highlights.getAttributes().getAttribute("attribute"));

    assertTrue("Wrong number of highlights", highlights.moveNext());
    assertEquals("3. highlight - wrong attribs", "value-B", highlights.getAttributes().getAttribute("attribute"));
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:27,代码来源:ProxyHighlightsContainerTest.java

示例5: testEvents

import javax.swing.text.PlainDocument; //导入依赖的package包/类
public void testEvents() {
    PlainDocument doc = new PlainDocument();
    PositionsBag hsA = new PositionsBag(doc);
    PositionsBag hsB = new PositionsBag(doc);
    
    ProxyHighlightsContainer chc = new ProxyHighlightsContainer(doc, new HighlightsContainer [] { hsA, hsB });
    Listener listener = new Listener();
    chc.addHighlightsChangeListener(listener);
    
    hsA.addHighlight(new SimplePosition(10), new SimplePosition(20), new SimpleAttributeSet());
    assertEquals("Wrong number of events", 1, listener.eventsCnt);
    assertEquals("Wrong change start offset", 10, listener.lastEventStartOffset);
    assertEquals("Wrong change end offset", 20, listener.lastEventEndOffset);

    listener.reset();
    hsB.addHighlight(new SimplePosition(11), new SimplePosition(12), new SimpleAttributeSet());
    assertEquals("Wrong number of events", 1, listener.eventsCnt);
    assertEquals("Wrong change start offset", 11, listener.lastEventStartOffset);
    assertEquals("Wrong change end offset", 12, listener.lastEventEndOffset);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:21,代码来源:ProxyHighlightsContainerTest.java

示例6: testEvents2

import javax.swing.text.PlainDocument; //导入依赖的package包/类
public void testEvents2() {
    PlainDocument doc = new PlainDocument();
    PositionsBag hsA = new PositionsBag(doc);
    PositionsBag hsB = new PositionsBag(doc);

    hsA.addHighlight(new SimplePosition(10), new SimplePosition(20), new SimpleAttributeSet());
    hsB.addHighlight(new SimplePosition(11), new SimplePosition(12), new SimpleAttributeSet());

    ProxyHighlightsContainer chc = new ProxyHighlightsContainer();
    Listener listener = new Listener();
    chc.addHighlightsChangeListener(listener);

    // changing delegate layers fires event covering 'all' offsets
    chc.setLayers(doc, new HighlightsContainer [] { hsA, hsB });
    assertEquals("Wrong number of events", 1, listener.eventsCnt);
    assertEquals("Wrong change start offset", 0, listener.lastEventStartOffset);
    assertEquals("Wrong change end offset", Integer.MAX_VALUE, listener.lastEventEndOffset);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:19,代码来源:ProxyHighlightsContainerTest.java

示例7: createContainer

import javax.swing.text.PlainDocument; //导入依赖的package包/类
public static RandomTestContainer createContainer() {
    RandomTestContainer container = new RandomTestContainer();
    Document doc = new PlainDocument();
    container.putProperty(Document.class, doc);
    // Fill document
    try {
        doc.insertString(0, "abcdef\n", null);
        int docLen;
        while ((docLen = doc.getLength()) < DOCUMENT_LENGTH) {
            int insertLen = Math.min(docLen, DOCUMENT_LENGTH - docLen);
            doc.insertString(docLen, doc.getText(0, insertLen), null);
        }
    } catch (BadLocationException ex) {
        throw new IllegalStateException(ex);
    }
    container.putProperty(DirectMergeContainer.class, new DirectMergeContainer(new HighlightsContainer[0], false));
    container.putProperty(CompoundHighlightsContainer.class,
            new CompoundHighlightsContainer(doc, new HighlightsContainer[0]));

    container.addOp(new AddLayerOp(ADD_LAYER));
    container.addOp(new AddLayerOp(ADD_EMPTY_LAYER));
    container.addOp(new RemoveLayerOp(REMOVE_LAYER));
    container.addCheck(new MergeCheck());
    return container;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:26,代码来源:HighlightsMergeTesting.java

示例8: testSimple

import javax.swing.text.PlainDocument; //导入依赖的package包/类
public void testSimple() {
    PlainDocument doc = new PlainDocument();
    HighlightsContainer layer = createRandomBag(doc, "layer");
    HighlightsSequence highlights = layer.getHighlights(0, 100);
    
    CompoundHighlightsContainer proxyLayer = new CompoundHighlightsContainer(doc, new HighlightsContainer [] { layer });
    HighlightsSequence proxyHighlights = proxyLayer.getHighlights(0, 100);

    for ( ; highlights.moveNext(); ) {
        // Ignore empty highlights
        if (highlights.getStartOffset() == highlights.getEndOffset()) {
            continue;
        }

        assertTrue("Wrong number of proxy highlights", proxyHighlights.moveNext());

        assertEquals("Start offset does not match", highlights.getStartOffset(), proxyHighlights.getStartOffset());
        assertEquals("End offset does not match", highlights.getEndOffset(), proxyHighlights.getEndOffset());
        assertTrue("Attributes do not match", highlights.getAttributes().isEqual(proxyHighlights.getAttributes()));
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:22,代码来源:CompoundHighlightsContainerTest.java

示例9: testOrdering

import javax.swing.text.PlainDocument; //导入依赖的package包/类
public void testOrdering() {
    PlainDocument doc = new PlainDocument();
    PositionsBag hsA = new PositionsBag(doc);
    PositionsBag hsB = new PositionsBag(doc);

    SimpleAttributeSet attribsA = new SimpleAttributeSet();
    SimpleAttributeSet attribsB = new SimpleAttributeSet();
    
    attribsA.addAttribute("attribute", "value-A");
    attribsB.addAttribute("attribute", "value-B");
    
    hsA.addHighlight(new SimplePosition(5), new SimplePosition(15), attribsA);
    hsB.addHighlight(new SimplePosition(10), new SimplePosition(20), attribsB);
    
    CompoundHighlightsContainer chc = new CompoundHighlightsContainer(doc, new HighlightsContainer [] { hsA, hsB });
    HighlightsSequence highlights = chc.getHighlights(0, Integer.MAX_VALUE);

    assertTrue("Wrong number of highlights", highlights.moveNext());
    assertEquals("1. highlight - wrong attribs", "value-A", highlights.getAttributes().getAttribute("attribute"));

    assertTrue("Wrong number of highlights", highlights.moveNext());
    assertEquals("2. highlight - wrong attribs", "value-B", highlights.getAttributes().getAttribute("attribute"));

    assertTrue("Wrong number of highlights", highlights.moveNext());
    assertEquals("3. highlight - wrong attribs", "value-B", highlights.getAttributes().getAttribute("attribute"));
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:27,代码来源:CompoundHighlightsContainerTest.java

示例10: testConcurrentModification

import javax.swing.text.PlainDocument; //导入依赖的package包/类
public void testConcurrentModification() throws Exception {
    PlainDocument doc = new PlainDocument();
    PositionsBag bag = createRandomBag(doc, "layer");
    HighlightsContainer [] layers = new HighlightsContainer [] { bag };
    
    CompoundHighlightsContainer hb = new CompoundHighlightsContainer(doc, layers);
    HighlightsSequence hs = hb.getHighlights(0, Integer.MAX_VALUE);
    
    assertTrue("No highlights", hs.moveNext());
    int s = hs.getStartOffset();
    int e = hs.getEndOffset();
    AttributeSet a = hs.getAttributes();

    // Change the layers
    hb.setLayers(doc, layers);
    
    assertEquals("Different startOffset", s, hs.getStartOffset());
    assertEquals("Different endOffset", e, hs.getEndOffset());
    assertEquals("Different attributes", a, hs.getAttributes());
    
    assertFalse("There should be no further highlighs after co-modification", hs.moveNext());
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:23,代码来源:CompoundHighlightsContainerTest.java

示例11: testEvents

import javax.swing.text.PlainDocument; //导入依赖的package包/类
public void testEvents() {
    PlainDocument doc = new PlainDocument();
    PositionsBag hsA = new PositionsBag(doc);
    PositionsBag hsB = new PositionsBag(doc);
    
    CompoundHighlightsContainer chc = new CompoundHighlightsContainer(doc, new HighlightsContainer [] { hsA, hsB });
    Listener listener = new Listener();
    chc.addHighlightsChangeListener(listener);
    
    hsA.addHighlight(new SimplePosition(10), new SimplePosition(20), new SimpleAttributeSet());
    assertEquals("Wrong number of events", 1, listener.eventsCnt);
    assertEquals("Wrong change start offset", 10, listener.lastEventStartOffset);
    assertEquals("Wrong change end offset", 20, listener.lastEventEndOffset);

    listener.reset();
    hsB.addHighlight(new SimplePosition(11), new SimplePosition(12), new SimpleAttributeSet());
    assertEquals("Wrong number of events", 1, listener.eventsCnt);
    assertEquals("Wrong change start offset", 11, listener.lastEventStartOffset);
    assertEquals("Wrong change end offset", 12, listener.lastEventEndOffset);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:21,代码来源:CompoundHighlightsContainerTest.java

示例12: testEvents2

import javax.swing.text.PlainDocument; //导入依赖的package包/类
public void testEvents2() {
    PlainDocument doc = new PlainDocument();
    PositionsBag hsA = new PositionsBag(doc);
    PositionsBag hsB = new PositionsBag(doc);

    hsA.addHighlight(new SimplePosition(10), new SimplePosition(20), new SimpleAttributeSet());
    hsB.addHighlight(new SimplePosition(11), new SimplePosition(12), new SimpleAttributeSet());

    CompoundHighlightsContainer chc = new CompoundHighlightsContainer();
    Listener listener = new Listener();
    chc.addHighlightsChangeListener(listener);

    // changing delegate layers fires event covering 'all' offsets
    chc.setLayers(doc, new HighlightsContainer [] { hsA, hsB });
    assertEquals("Wrong number of events", 1, listener.eventsCnt);
    assertEquals("Wrong change start offset", 0, listener.lastEventStartOffset);
    assertEquals("Wrong change end offset", Integer.MAX_VALUE, listener.lastEventEndOffset);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:19,代码来源:CompoundHighlightsContainerTest.java

示例13: 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());
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:25,代码来源:CompoundHighlightsContainerTest.java

示例14: testOffset0Forward

import javax.swing.text.PlainDocument; //导入依赖的package包/类
public void testOffset0Forward() throws Exception {
    Document doc = new PlainDocument();
    WordMatch wordMatch = WordMatch.get(doc);
    //                   012345678901234567890123456789
    doc.insertString(0, "abc abc dab ab a abab+c", null);
    int docLen = doc.getLength();
    wordMatch.matchWord(0, true);
    compareText(doc, 0, "abca", docLen + 3);
    wordMatch.matchWord(0, true);
    compareText(doc, 0, "daba", docLen + 3);
    wordMatch.matchWord(0, true);
    compareText(doc, 0, "aba", docLen + 2);
    wordMatch.matchWord(0, true);
    compareText(doc, 0, "aa", docLen + 1);
    wordMatch.matchWord(0, true);
    compareText(doc, 0, "ababa", docLen + 4);
    wordMatch.matchWord(0, true);
    compareText(doc, 0, "ca", docLen + 1);
    wordMatch.matchWord(0, true);
    compareText(doc, 0, "ca", docLen + 1);

    wordMatch.matchWord(0, false);
    compareText(doc, 0, "ababa", docLen + 4);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:25,代码来源:WordMatchTest.java

示例15: testOffsetDocLenBackward

import javax.swing.text.PlainDocument; //导入依赖的package包/类
public void testOffsetDocLenBackward() throws Exception {
    Document doc = new PlainDocument();
    WordMatch wordMatch = WordMatch.get(doc);
    //                   012345678901234567890123456789
    doc.insertString(0, "abc abc dab ab a", null);
    int docLen = doc.getLength();
    wordMatch.matchWord(docLen, false);
    compareText(doc, docLen - 1, "ab", docLen + 1);
    wordMatch.matchWord(docLen, false);
    compareText(doc, docLen - 1, "abc", docLen + 2);
    wordMatch.matchWord(docLen, false);
    compareText(doc, docLen - 1, "abc", docLen + 2);

    wordMatch.matchWord(docLen, true);
    compareText(doc, docLen - 1, "ab", docLen + 1);
    wordMatch.matchWord(docLen, true);
    compareText(doc, docLen - 1, "a", docLen);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:19,代码来源:WordMatchTest.java


注:本文中的javax.swing.text.PlainDocument类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。