當前位置: 首頁>>代碼示例>>Java>>正文


Java AbstractDocument.insertString方法代碼示例

本文整理匯總了Java中javax.swing.text.AbstractDocument.insertString方法的典型用法代碼示例。如果您正苦於以下問題:Java AbstractDocument.insertString方法的具體用法?Java AbstractDocument.insertString怎麽用?Java AbstractDocument.insertString使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在javax.swing.text.AbstractDocument的用法示例。


在下文中一共展示了AbstractDocument.insertString方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: test

import javax.swing.text.AbstractDocument; //導入方法依賴的package包/類
/**
 * Test the creation of several folds.
 */
public void test() throws Exception {
    FoldHierarchyTestEnv env = new FoldHierarchyTestEnv(new SimpleFoldManagerFactory());
    AbstractDocument doc = env.getDocument();
    doc.insertString(0, "1234567890", null);
    FoldHierarchy hierarchy = env.getHierarchy();
    doc.readLock();
    try {
        hierarchy.lock();
        try {
            
            Fold rootFold = hierarchy.getRootFold();
            int foldCount = rootFold.getFoldCount();
            int expectedFoldCount = 1;
            assertTrue("Incorrect fold count " + foldCount, // NOI18N
                (foldCount == expectedFoldCount)
            );
            
            Fold fold = rootFold.getFold(0);
            FoldType foldType = fold.getType();
            int foldStartOffset = fold.getStartOffset();
            int foldEndOffset = fold.getEndOffset();
            assertTrue("Incorrect fold type " + foldType, // NOI18N
                (foldType == AbstractFoldManager.REGULAR_FOLD_TYPE));
            assertTrue("Incorrect fold start offset " + foldStartOffset, // NOI18N
                (foldStartOffset == FOLD_START_OFFSET_1));
            assertTrue("Incorrect fold end offset " + foldEndOffset, // NOI18N
                (foldEndOffset == FOLD_END_OFFSET_1));
            
            // Check fold size
            assertSize("Size of the fold " , Collections.singleton(fold), // NOI18N
                MAX_FOLD_MEMORY_SIZE, new FoldMemoryFilter(fold));
            
        } finally {
            hierarchy.unlock();
        }
    } finally {
        doc.readUnlock();
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:43,代碼來源:SimpleFoldManagerTest.java

示例2: testFoldHierararchyMonitorWithProvider

import javax.swing.text.AbstractDocument; //導入方法依賴的package包/類
/**
 * A provider is registered for the hierarchy. 
 * Active == true should be reported to FoldHierarchyMonitor.
 */
public void testFoldHierararchyMonitorWithProvider() throws Exception {
    MockMimeLookup.setInstances(MimePath.parse(""), new FHM());

    FoldHierarchyTestEnv env = new FoldHierarchyTestEnv(new SimpleFoldManagerFactory());
    AbstractDocument doc = env.getDocument();
    doc.insertString(0, "1234567890", null);
    
    env.getHierarchy();
    
    assertTrue("Folds not attached", attached);
    assertTrue("Hierarchy must be active", active);
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:17,代碼來源:SimpleFoldManagerTest.java

示例3: testUpdateNoChanges

import javax.swing.text.AbstractDocument; //導入方法依賴的package包/類
/**
 * Checks that no changes (update with the same infos) will not fire events, remove or add any folds.
 * 
 * @throws Exception 
 */
public void testUpdateNoChanges() throws Exception {
    final TestFoldManager[] mgr = new TestFoldManager[1];
    FoldHierarchyTestEnv env = new FoldHierarchyTestEnv(new FoldManagerFactory() {
        @Override
        public FoldManager createFoldManager() {
            return mgr[0] = new TestFoldManager();
        }
    });
    AbstractDocument doc = env.getDocument();
    doc.insertString(0, "12345678901234567890", null);

    FoldHierarchy hierarchy = env.getHierarchy();
    
    Collection<FoldInfo> infos = new ArrayList<FoldInfo>(10);
    infos.add(FoldInfo.range(0, 1, FoldType.MEMBER));
    infos.add(FoldInfo.range(9, 10, FoldType.MEMBER));
    infos.add(FoldInfo.range(14, 16, FoldType.MEMBER));
    // not sorted, check :)
    infos.add(FoldInfo.range(3, 12, FoldType.MEMBER));
    infos.add(FoldInfo.range(5, 6, FoldType.MEMBER));
    
    doc.readLock();
    try {
        hierarchy.lock();
        TestFoldManager m = mgr[0];
        try {
            Collection<Fold> remove = new ArrayList<Fold>();
            Collection<FoldInfo> create = new ArrayList<FoldInfo>();
            
            final boolean[] changed = new boolean[1];
            
            hierarchy.addFoldHierarchyListener(new FoldHierarchyListener() {

                @Override
                public void foldHierarchyChanged(FoldHierarchyEvent evt) {
                    changed[0] = true;
                }
            });
            
            Map<FoldInfo, Fold> mapping = m.operation.update(infos, remove, create);
            
            assertEquals(m.initFolds.size(), mapping.size());
            assertTrue(m.initFolds.containsAll(mapping.values()));
            assertFalse(changed[0]);
            
        } finally {
            hierarchy.unlock();
        }
    } finally {
        doc.readUnlock();
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:58,代碼來源:FoldOperationTest.java

示例4: testUpdateCreateFold

import javax.swing.text.AbstractDocument; //導入方法依賴的package包/類
/**
 * Checks that folds are created beween two folds, encapsulating existing folds.
 * 
 * @throws Exception 
 */
public void testUpdateCreateFold() throws Exception {
    final TestFoldManager[] mgr = new TestFoldManager[1];
    FoldHierarchyTestEnv env = new FoldHierarchyTestEnv(new FoldManagerFactory() {
        @Override
        public FoldManager createFoldManager() {
            return mgr[0] = new TestFoldManager();
        }
    });
    AbstractDocument doc = env.getDocument();
    doc.insertString(0, "12345678901234567890", null);

    FoldHierarchy hierarchy = env.getHierarchy();
    
    List<FoldInfo> infos = createDefaultInfos();
    
    // add a new fold between #1 and #2
    infos.add(FoldInfo.range(2, 3, FoldType.MEMBER));
    
    // add a new fold at the end:
    infos.add(FoldInfo.range(19,20, FoldType.MEMBER));
    
    // add a fold, which encapsulates #2 - #5
    infos.add(FoldInfo.range(3, 18, FoldType.MEMBER));
    
    // add a fold, which encapsulates ##5
    infos.add(FoldInfo.range(13, 16, FoldType.MEMBER));
    
    doc.readLock();
    try {
        hierarchy.lock();
        TestFoldManager m = mgr[0];
        try {
            Collection<Fold> remove = new ArrayList<Fold>();
            Collection<FoldInfo> create = new ArrayList<FoldInfo>();
            
            final boolean[] changed = new boolean[1];
            
            hierarchy.addFoldHierarchyListener(new FoldHierarchyListener() {
                @Override
                public void foldHierarchyChanged(FoldHierarchyEvent evt) {
                    changed[0] = true;
                }
            });
            Map<FoldInfo, Fold> mapping = m.operation.update(infos, remove, create);
            
            // 3 folds added, no deleted:
            assertEquals(4, create.size());
            assertEquals(0, remove.size());
            
        } finally {
            hierarchy.unlock();
        }
    } finally {
        doc.readUnlock();
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:62,代碼來源:FoldOperationTest.java

示例5: test

import javax.swing.text.AbstractDocument; //導入方法依賴的package包/類
/**
 * Test the creation of several folds.
 */
public void test(boolean outerFirst) throws BadLocationException {
    FoldHierarchyTestEnv env = new FoldHierarchyTestEnv(new NestedFoldManagerFactory(outerFirst));
    AbstractDocument doc = env.getDocument();
    doc.insertString(0, "1234567890", null);

    FoldHierarchy hierarchy = env.getHierarchy();
    doc.readLock();
    try {
        hierarchy.lock();
        try {
            Fold rootFold = hierarchy.getRootFold();
            int foldCount = rootFold.getFoldCount();
            int expectedFoldCount = 1;
            assertTrue("Incorrect fold count " + foldCount, // NOI18N
                (foldCount == expectedFoldCount)
            );
            
            Fold fold = rootFold.getFold(0);
            FoldType foldType = fold.getType();
            int foldStartOffset = fold.getStartOffset();
            int foldEndOffset = fold.getEndOffset();
            assertTrue("Incorrect fold type " + foldType, // NOI18N
                (foldType == AbstractFoldManager.REGULAR_FOLD_TYPE));
            assertTrue("Incorrect fold start offset " + foldStartOffset, // NOI18N
                (foldStartOffset == FOLD_START_OFFSET_OUTER));
            assertTrue("Incorrect fold end offset " + foldEndOffset, // NOI18N
                (foldEndOffset == FOLD_END_OFFSET_OUTER));
            
            // Test inner fold
            Fold outerFold = fold;
            foldCount = outerFold.getFoldCount();
            expectedFoldCount = 1;
            assertTrue("Incorrect fold count " + foldCount, // NOI18N
                (foldCount == expectedFoldCount)
            );
            
            fold = outerFold.getFold(0);
            assertTrue("Folds must differ", (fold != outerFold)); // NOI18N
            foldType = fold.getType();
            foldStartOffset = fold.getStartOffset();
            foldEndOffset = fold.getEndOffset();
            assertTrue("Incorrect fold type " + foldType, // NOI18N
                (foldType == AbstractFoldManager.REGULAR_FOLD_TYPE));
            assertTrue("Incorrect fold start offset " + foldStartOffset, // NOI18N
                (foldStartOffset == FOLD_START_OFFSET_INNER));
            assertTrue("Incorrect fold end offset " + foldEndOffset, // NOI18N
                (foldEndOffset == FOLD_END_OFFSET_INNER));

        } finally {
            hierarchy.unlock();
        }
    } finally {
        doc.readUnlock();
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:59,代碼來源:NestedFoldManagerTest.java


注:本文中的javax.swing.text.AbstractDocument.insertString方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。