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


Java Document.addUndoableEditListener方法代码示例

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


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

示例1: addEditorPane

import javax.swing.text.Document; //导入方法依赖的package包/类
private void addEditorPane( JEditorPane pane, Icon icon, File file, boolean created, boolean focus ) {
    final JComponent c = (pane.getUI() instanceof BaseTextUI) ?
    Utilities.getEditorUI(pane).getExtComponent() : new JScrollPane( pane );
    Document doc = pane.getDocument();
    
    doc.addDocumentListener( new MarkingDocumentListener( c ) );
    doc.putProperty( FILE, file );
    doc.putProperty( CREATED, created  ? Boolean.TRUE : Boolean.FALSE );
    
    UndoManager um = new UndoManager();
    doc.addUndoableEditListener( um );
    doc.putProperty( BaseDocument.UNDO_MANAGER_PROP, um );
    
    com2text.put( c, pane );
    tabPane.addTab( file.getName(), icon, c, file.getAbsolutePath() );
    if (focus) {
        tabPane.setSelectedComponent( c );
        pane.requestFocus();
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:21,代码来源:Editor.java

示例2: setDocument

import javax.swing.text.Document; //导入方法依赖的package包/类
/**
 * Sets the document used by this text area.
 *
 * @param document The new document to use.
 * @throws IllegalArgumentException If the document is not an instance of
 *         {@link RDocument}.
 */
@Override
public void setDocument(Document document) {
	if (!(document instanceof RDocument)) {
		throw new IllegalArgumentException("RTextArea requires " +
			"instances of RDocument for its document");
	}
	if (undoManager!=null) { // First time through, undoManager==null
		Document old = getDocument();
		if (old!=null) {
			old.removeUndoableEditListener(undoManager);
		}
	}
	super.setDocument(document);
	if (undoManager!=null) {
		document.addUndoableEditListener(undoManager);
		discardAllEdits();
	}
}
 
开发者ID:Thecarisma,项目名称:powertext,代码行数:26,代码来源:RTextArea.java

示例3: testBehaviour

import javax.swing.text.Document; //导入方法依赖的package包/类
public void testBehaviour() throws Exception {
    Document doc = new PlainDocument();
    doc.insertString(0, "test hello world", null);
    UndoManager undo = new UndoManager();
    doc.addUndoableEditListener(undo);
    Position pos = doc.createPosition(2);
    doc.remove(0, 3);
    assert (pos.getOffset() == 0);
    undo.undo();
    assert (pos.getOffset() == 2);
    
    Position pos2 = doc.createPosition(5);
    doc.remove(4, 2);
    Position pos3 = doc.createPosition(4);
    assertSame(pos2, pos3);
    undo.undo();
    assert (pos3.getOffset() == 5);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:19,代码来源:PlainDocumentTest.java

示例4: subscribeActual

import javax.swing.text.Document; //导入方法依赖的package包/类
@Override
protected void subscribeActual(Observer<? super UndoableEditEvent> observer) {
    Document w = widget;

    UndoableEditEventConsumer aec = new UndoableEditEventConsumer(observer, w);
    observer.onSubscribe(aec);

    w.addUndoableEditListener(aec);
    if (aec.get() == null) {
        aec.onDispose(w);
    }
}
 
开发者ID:akarnokd,项目名称:RxJava2Swing,代码行数:13,代码来源:UndoableEditEventObservable.java

示例5: createContainer

import javax.swing.text.Document; //导入方法依赖的package包/类
public static RandomTestContainer createContainer() {
    RandomTestContainer container = new RandomTestContainer();
    container.addCheck(new DocumentContentCheck());
    Document doc = getDocument(container);
    Document expectedDoc = getExpectedDocument(container);
    if (expectedDoc == null) {
        expectedDoc = new ExpectedDocument();
        container.putProperty(ExpectedDocument.class, expectedDoc);
    }
    if (doc == null) {
        doc = new TestEditorDocument();
        container.putProperty(Document.class, doc);
    }
    ((ExpectedDocument)expectedDoc).setTestDocument((TestEditorDocument)doc);
    UndoManager undoManager = getUndoManager(container);
    if (undoManager == null) {
        undoManager = new UndoMgr(container);
        container.putProperty(UndoManager.class, undoManager);
        doc.putProperty(UndoManager.class, undoManager);
        // Add them here to be sure they are added just once (not correct - should analyze existing listeners)
        doc.addUndoableEditListener(undoManager);
        expectedDoc.addUndoableEditListener(undoManager);
    }
    container.putProperty(UNDO_REDO_INVERSE_RATIO, 0.3f);

    // Init a default random text if not yet inited (can be reinited later)
    if (container.getInstanceOrNull(RandomText.class) == null) {
        RandomText randomText = RandomText.join(
                RandomText.lowerCaseAZ(3),
                RandomText.spaceTabNewline(1),
                RandomText.phrase("   ", 1),
                RandomText.phrase("\n\n", 1),
                RandomText.phrase("\t\tabcdef\t", 1));
        container.putProperty(RandomText.class, randomText);
    }

    container.addOp(new InsertOp(INSERT_CHAR));
    container.addOp(new InsertOp(INSERT_TEXT));
    container.addOp(new InsertOp(INSERT_PHRASE));
    container.addOp(new RemoveOp(REMOVE_CHAR));
    container.addOp(new RemoveOp(REMOVE_TEXT));
    container.addOp(new UndoRedoOp(UNDO));
    container.addOp(new UndoRedoOp(REDO));
    container.addOp(new PositionOp(CREATE_POSITION));
    container.addOp(new PositionOp(CREATE_BACKWARD_BIAS_POSITION));
    container.addOp(new PositionOp(RELEASE_POSITION));
    return container;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:49,代码来源:DocumentContentTesting.java

示例6: testSourceEditSyncUndo

import javax.swing.text.Document; //导入方法依赖的package包/类
public void testSourceEditSyncUndo() throws Exception {
    defaultSetup();
    UndoManager urListener = new UndoManager();
    Document doc = mModel.getBaseDocument();
    mModel.addUndoableEditListener(urListener);
    
    mModel.startTransaction();
    B b2 = new B(mModel, 2);
    mModel.getRootComponent().addAfter(b2.getName(), b2, TestComponent3._A);
    mModel.endTransaction();
    assertEquals("first edit setup", 2, mModel.getRootComponent().getChildren(B.class).size());
    
    // see fix for issue 83963, with this fix we need coordinate edits from
    // on XDM model and on document buffer.  This reduce XDM undo/redo efficiency,
    // but is the best we can have to satisfy fine-grained text edit undo requirements.
    mModel.removeUndoableEditListener(urListener);
    doc.addUndoableEditListener(urListener);
    
    Util.setDocumentContentTo(doc, "resources/test2.xml");
    assertEquals("undo sync", 1, mModel.getRootComponent().getChildren(C.class).size());
    mModel.sync();
    doc.removeUndoableEditListener(urListener);
    
    assertEquals("sync setup", 1, mModel.getRootComponent().getChildren(B.class).size());
    assertEquals("sync setup", 0, mModel.getRootComponent().getChildren(C.class).size());
    
    // setDocumentContentTo did delete all, then insert, hence 2 undo's'
    urListener.undo(); urListener.undo(); 
    mModel.sync(); // the above undo's are just on document buffer, needs sync (inefficient).
    assertEquals("undo sync", 1, mModel.getRootComponent().getChildren(C.class).size());
    assertEquals("undo sync", 2, mModel.getRootComponent().getChildren(B.class).size());

    urListener.undo();
    assertEquals("undo first edit before sync", 1, mModel.getRootComponent().getChildren(B.class).size());

    urListener.redo();
    assertEquals("redo first edit", 1, mModel.getRootComponent().getChildren(C.class).size());
    assertEquals("redo first edit", 2, mModel.getRootComponent().getChildren(B.class).size());

    // needs to back track the undo's, still needs sync'
    urListener.redo(); urListener.redo();
    mModel.sync();
    assertEquals("redo to sync", 1, mModel.getRootComponent().getChildren(B.class).size());
    assertEquals("redo to sync", 0, mModel.getRootComponent().getChildren(C.class).size());
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:46,代码来源:AbstractModelTest.java

示例7: performTest

import javax.swing.text.Document; //导入方法依赖的package包/类
private void performTest(String sourceCode, int offset, KeyEvent[] kes, int selectionEnd, String golden, boolean stillInRename) throws Exception {
        clearWorkDir();
        
        FileObject root = FileUtil.toFileObject(getWorkDir());
        
        FileObject sourceDir = root.createFolder("src");
        FileObject buildDir = root.createFolder("build");
        FileObject cacheDir = root.createFolder("cache");
        FileObject testDir  = sourceDir.createFolder("test");
        
        FileObject source = testDir.createData("Test.java");
        
        TestUtilities.copyStringToFile(source, sourceCode.replaceFirst(Pattern.quote("|"), ""));
        
        SourceUtilsTestUtil.prepareTest(sourceDir, buildDir, cacheDir, new FileObject[0]);
        SourceUtilsTestUtil.compileRecursively(sourceDir);
        
        DataObject od = DataObject.find(source);
        
        assertTrue(od instanceof JavaDataObject);
        
        EditorCookie ec = od.getCookie(EditorCookie.class);
        Document doc = ec.openDocument();
        
        assertTrue(doc instanceof BaseDocument);
        
        UndoManager um = new UndoManager();

        doc.addUndoableEditListener(um);
        doc.putProperty(BaseDocument.UNDO_MANAGER_PROP, um);
        doc.putProperty(Language.class, JavaTokenId.language());
        doc.putProperty("mimeType", "text/x-java");
        
        C p = new C();
        
//        p.setEditorKit(new JavaKit());
        
        p.setDocument(doc);
        
        p.setCaretPosition(sourceCode.indexOf('|'));
        
        InstantRenamePerformer.invokeInstantRename(p);
        
        p.setCaretPosition(offset);

        if (selectionEnd != (-1)) {
            p.moveCaretPosition(selectionEnd);
        }
        
        processKeyevents(p, kes);
        
        assertEquals(stillInRename, p.getClientProperty(InstantRenamePerformer.class) != null);
        assertEquals(golden, doc.getText(0, doc.getLength()));
    }
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:55,代码来源:InstantRenamePerformerTest.java


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