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


Java UndoManager.undo方法代码示例

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


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

示例1: testSyncUndoRedo

import javax.swing.undo.UndoManager; //导入方法依赖的package包/类
public void testSyncUndoRedo() throws Exception {
    defaultSetup();
    UndoManager urListener = new UndoManager();
    mModel.addUndoableEditListener(urListener);
    assertEquals("setup: initial", 1, mModel.getRootComponent().getChildren(C.class).size());
    
    Util.setDocumentContentTo(mDoc, "resources/test2.xml");
    mModel.sync();
    assertEquals("setup: sync", 0, mModel.getRootComponent().getChildren(C.class).size());

    urListener.undo();
    assertEquals("undo sync", 1, mModel.getRootComponent().getChildren(C.class).size());

    urListener.redo();
    assertEquals("undo sync", 0, mModel.getRootComponent().getChildren(C.class).size());
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:17,代码来源:AbstractModelTest.java

示例2: testUndoRedoOnMutationFromEvent

import javax.swing.undo.UndoManager; //导入方法依赖的package包/类
public void testUndoRedoOnMutationFromEvent() throws Exception {
    defaultSetup();
    mModel.addComponentListener(new Handler());
    UndoManager um = new UndoManager();
    mModel.addUndoableEditListener(um);

    mModel.startTransaction();
    mModel.getRootComponent().appendChild("test", new D(mModel, 2));
    mModel.endTransaction();

    um.undo();
    D d = mModel.getRootComponent().getChild(D.class);
    assertNull(d);
    um.redo();
    d = mModel.getRootComponent().getChild(D.class);
    assertNotNull(d.getChild(B.class));
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:18,代码来源:AbstractModelTest.java

示例3: testUndoOnMutationFromSyncEvent

import javax.swing.undo.UndoManager; //导入方法依赖的package包/类
public void testUndoOnMutationFromSyncEvent() throws Exception {
    defaultSetup();
    mModel.addComponentListener(new Handler());
    UndoManager um = new UndoManager();
    mModel.addUndoableEditListener(um);

    Util.setDocumentContentTo(mDoc, "resources/test1_2.xml");
    mModel.sync();
    D d = mModel.getRootComponent().getChild(D.class);
    assertNotNull(d.getChild(B.class));
    um.undo();
    mModel.getAccess().flush(); // after fix for 83963 need manual flush after undo/redo

    assertNull(mModel.getRootComponent().getChild(D.class));
    mModel = Util.dumpAndReloadModel(mModel);
    assertNull(mModel.getRootComponent().getChild(D.class));
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:18,代码来源:AbstractModelTest.java

示例4: testCreateGlobalElementUndoRedo

import javax.swing.undo.UndoManager; //导入方法依赖的package包/类
public void testCreateGlobalElementUndoRedo() throws Exception {
    SchemaModel model = Util.loadSchemaModel("resources/Empty.xsd");
    UndoManager ur = new UndoManager();
    model.addUndoableEditListener(ur);
    SchemaComponentFactory fact = model.getFactory();
    GlobalElement ge = fact.createGlobalElement();
    
    model.startTransaction();
    model.getSchema().addElement(ge);
    ge.setName("Foo"); // edit #1
    LocalComplexType lct = fact.createLocalComplexType();
    Sequence seq = fact.createSequence();
    lct.setDefinition(seq); 
    ge.setInlineType(lct);
    model.endTransaction();
    
    assertEquals(1, model.getSchema().getElements().size());
    ur.undo();
    assertEquals(0, model.getSchema().getElements().size());

    ur.redo();
    ge = model.getSchema().getElements().iterator().next();
    assertEquals("Foo", ge.getName());
    assertNotNull(ge.getInlineType());
    assertNotNull(((LocalComplexType)ge.getInlineType()).getDefinition());
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:27,代码来源:SyncTest.java

示例5: testUndoRedoWithoutIdentity

import javax.swing.undo.UndoManager; //导入方法依赖的package包/类
public void testUndoRedoWithoutIdentity() throws Exception {
    mModel = Util.loadModel("resources/test1_noname.xml");
    UndoManager ur = new UndoManager();
    mModel.addUndoableEditListener(ur);

    E e1 = mModel.getRootComponent().getChild(E.class);
    assertNull(e1.getValue());
    
    mModel.startTransaction();
    String v = "new test value";
    e1.setValue(v);
    mModel.endTransaction();
    assertEquals(v, e1.getValue());

    ur.undo();
    assertNull("expect null, get "+e1.getValue(), e1.getValue());
    
    ur.redo();
    assertEquals(v, e1.getValue());
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:21,代码来源:AbstractModelTest.java

示例6: testSyncUndo

import javax.swing.undo.UndoManager; //导入方法依赖的package包/类
public void testSyncUndo() throws Exception {
    SchemaModel model = Util.loadSchemaModel(TEST_XSD);
    UndoManager um = new UndoManager();
    model.addUndoableEditListener(um);
    
    GlobalComplexType gct = (GlobalComplexType)Util.findComponent(
            model.getSchema(), "/schema/complexType[@name='PurchaseOrderType']");
    assertEquals(3, gct.getDefinition().getChildren().size());
    
    Util.setDocumentContentTo(model, "resources/PurchaseOrder_SyncUndo.xsd");
    model.sync();
    um.undo();
    assertEquals(3, gct.getDefinition().getChildren().size());

    um.redo();
    assertEquals(2, gct.getDefinition().getChildren().size());
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:18,代码来源:SyncTest.java

示例7: testUndoRemoveDSType

import javax.swing.undo.UndoManager; //导入方法依赖的package包/类
public void testUndoRemoveDSType() {
	UndoManager manager = new UndoManager();
	JDBCDataSourceType type = new JDBCDataSourceType();
	pld.addDataSourceType(type);
	pld.addUndoableEditListener(manager);
	
	assertFalse(manager.canUndo());
	assertEquals(1, pld.getDataSourceTypes().size());
	pld.removeDataSourceType(type);
	
	assertTrue(manager.canUndo());
	assertTrue(pld.getDataSourceTypes().isEmpty());
	manager.undo();
	
	assertEquals(1, pld.getDataSourceTypes().size());
	assertTrue(manager.canRedo());
	assertEquals(type, pld.getDataSourceTypes().get(0));
	
}
 
开发者ID:SQLPower,项目名称:sqlpower-library,代码行数:20,代码来源:PlDotIniListenersTest.java

示例8: onUndo

import javax.swing.undo.UndoManager; //导入方法依赖的package包/类
public void onUndo() {
	if(undoManager.canUndo() && hasChanges) {
		undoManager.undo();
	} else {
		// HACK need to call parent frames undo if we have no changes
		CommonModuleFrame cmf = CommonModuleFrame.getCurrentFrame();
		if(cmf == null) return;

		final UndoManager cmfUndoManager = cmf.getExtension(UndoManager.class);
		if(cmfUndoManager != null && cmfUndoManager.canUndo()) {
			 cmfUndoManager.undo();

			 // reset this flag - otherwise the group undo manager
			 // will attempt to undo with 'nothing' as last value
			 hasChanges = false;
		}
	}
}
 
开发者ID:phon-ca,项目名称:phon,代码行数:19,代码来源:GroupField.java

示例9: actionPerformed

import javax.swing.undo.UndoManager; //导入方法依赖的package包/类
public void actionPerformed(ActionEvent e) 
{
    Document doc = getTextComponent(e).getDocument();
    UndoManager um = getUndoManagerForDocument(doc);
    if(um != null)
    {
        try 
        {               
            um.undo();
        } 
        catch (CannotUndoException ex) 
        {
            System.out.println("Unable to undo: " + ex);
            ex.printStackTrace();
        }
        
        updateUndo(doc);
    }            
}
 
开发者ID:OpenIndex,项目名称:OpenIndex-SHEF,代码行数:20,代码来源:CompoundUndoManager.java

示例10: testSimpleUndoRedo

import javax.swing.undo.UndoManager; //导入方法依赖的package包/类
public void testSimpleUndoRedo() throws Exception {
    loggingOn();
    JEditorPane pane = ViewUpdatesTesting.createPane();
    Document doc = pane.getDocument();
    UndoManager undoManager = ViewUpdatesTesting.getUndoManager(doc);
    doc.insertString(0, "abc\ndef\nghi\n", null);
    ViewUpdatesTesting.setViewBounds(pane, 4, 8);
    pane.modelToView(0);
    doc.insertString(4, "o", null);
    doc.remove(3, 3);
    doc.insertString(4, "ab", null);
    doc.remove(7, 2);
    pane.modelToView(0);
    undoManager.undo(); // insert(7,2)
    undoManager.undo(); // remove(4,2)
    undoManager.undo(); // insert(3,3)
    undoManager.undo();
    undoManager.redo();
    undoManager.redo();
    undoManager.redo();
    undoManager.redo();
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:23,代码来源:ViewHierarchyTest.java

示例11: testLongLineUndo

import javax.swing.undo.UndoManager; //导入方法依赖的package包/类
public void testLongLineUndo() throws Exception {
    loggingOn();
    JEditorPane pane = ViewUpdatesTesting.createPane();
    Document doc = pane.getDocument();
    UndoManager undoManager = ViewUpdatesTesting.getUndoManager(doc);
    int lineLen = 4000;
    StringBuilder sb = new StringBuilder(lineLen + 10);
    for (int i = 0; i < lineLen; i++) {
        sb.append('a');
    }
    sb.append('\n');
    doc.insertString(0, sb.toString(), null);
    pane.modelToView(0);
    doc.remove(0, lineLen);
    pane.modelToView(0);
    undoManager.undo();
    undoManager.redo();
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:19,代码来源:ViewHierarchyTest.java

示例12: testBehaviour

import javax.swing.undo.UndoManager; //导入方法依赖的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

示例13: testUndoXsdImportChange

import javax.swing.undo.UndoManager; //导入方法依赖的package包/类
public void testUndoXsdImportChange() throws Exception {
    WSDLModel model = Util.loadWSDLModel("resources/HotelReservationService2.wsdl");
    UndoManager um = new UndoManager();
    model.addUndoableEditListener(um);
    WSDLSchema schema = model.getDefinitions().getTypes().getExtensibilityElements(WSDLSchema.class).get(0);
    org.netbeans.modules.xml.schema.model.Import xsdImport = 
        schema.getSchemaModel().getSchema().getImports().iterator().next();
   
   model.startTransaction();
   xsdImport.setSchemaLocation("OTA_TravelItinerary.xsd");
   model.endTransaction();
   
   um.undo();
   assertEquals("OTA_TravelItinerary2.xsd", xsdImport.getSchemaLocation());
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:16,代码来源:SyncUpdateTest.java

示例14: testRollback

import javax.swing.undo.UndoManager; //导入方法依赖的package包/类
public void testRollback() throws Exception {
    UndoManager um = new UndoManager();
    schema.getModel().addUndoableEditListener(um);
    
   GlobalElement stick = schema.getModel().getFactory().createGlobalElement();
   stick.setName("stickAfterRollbackElement");
   model.startTransaction();
   schema.addElement(stick);
   model.endTransaction();
   
   GlobalElement ge = schema.getModel().getFactory().createGlobalElement();
   ge.setName("newElement");
   int initialCount = schema.getElements().size();
   model.startTransaction();
   schema.addElement(ge);
   assertEquals(initialCount+1, schema.getElements().size());
   String text = (( AbstractDocumentModel)model).getAccess().getCurrentDocumentText();
   assertTrue(text.indexOf("newElement") > 0);
   ( (AbstractModel)model).rollbackTransaction();
   text = (( AbstractDocumentModel)model).getAccess().getCurrentDocumentText();
   assertTrue(text.indexOf("newElement") == -1);
   assertEquals(initialCount, schema.getElements().size());
   assertTrue(text.indexOf("stickAfterRollbackElement") > 0);
   
   um.undo();
   text = (( AbstractDocumentModel)model).getAccess().getCurrentDocumentText();
   assertTrue(text.indexOf("stickAfterRollbackElement") == -1);

   um.redo();
   text = (( AbstractDocumentModel)model).getAccess().getCurrentDocumentText();
   assertTrue(text.indexOf("stickAfterRollbackElement") > 0);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:33,代码来源:SchemaTest.java

示例15: testDeleteRollback

import javax.swing.undo.UndoManager; //导入方法依赖的package包/类
public void testDeleteRollback() throws Exception {
    UndoManager um = new UndoManager();
    schema.getModel().addUndoableEditListener(um);
    
   GlobalElement stick = schema.getModel().getFactory().createGlobalElement();
   stick.setName("stickAfterRollbackElement");
   model.startTransaction();
   schema.addElement(stick);
   model.endTransaction();
   
   model.startTransaction();
   ArrayList<GlobalComplexType> types = new ArrayList(schema.getComplexTypes());
   ArrayList<GlobalElement> elements = new ArrayList(schema.getElements());
   GlobalElement element = elements.get(0);
   
     if(element.getName().equals("purchaseOrder")) {
        schema.removeElement(element);
                      
        String text = (( AbstractDocumentModel)model).getAccess().getCurrentDocumentText();
        assertTrue(text.indexOf("purchaseOrder")== -1);
        ( (AbstractModel)model).rollbackTransaction();
        text = (( AbstractDocumentModel)model).getAccess().getCurrentDocumentText();
        assertTrue(text.indexOf("purchaseOrder") > 0);
        assertTrue(text.indexOf("stickAfterRollbackElement") > 0);
   
        um.undo();
        text = (( AbstractDocumentModel)model).getAccess().getCurrentDocumentText();
        assertTrue(text.indexOf("stickAfterRollbackElement") == -1);

        um.redo();
        text = (( AbstractDocumentModel)model).getAccess().getCurrentDocumentText();
        assertTrue(text.indexOf("stickAfterRollbackElement") > 0);
       
     }
   
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:37,代码来源:SchemaTest.java


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