• 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏吧

Java UndoManager类的典型用法代码示例

java 10次浏览

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

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

示例1: flushUndoQueue

点赞 3

import javax.swing.undo.UndoManager; //导入依赖的package包/类
static void flushUndoQueue(Document d) {
    SwingUtilities.invokeLater(() -> {
    if (d == null) {
        return;
    }
    for (TopComponent tc : TopComponent.getRegistry().getOpened()) {
        if (!(tc instanceof ConsoleEditor)) {
            continue;
        }
        ConsoleEditor cake = (ConsoleEditor)tc;
        if (cake.getEditorPane() == null) {
            continue;
        }
        Document check = cake.getEditorPane().getDocument();
        if (check != d) {
            continue;
        }
        UndoRedo ur = tc.getUndoRedo();
        if (ur instanceof UndoManager) {
            ((UndoManager)ur).discardAllEdits();
        }
    }});
}
 

开发者ID:apache,
项目名称:incubator-netbeans,
代码行数:24,
代码来源:OverrideEditorActions.java

示例2: undo

点赞 3

import javax.swing.undo.UndoManager; //导入依赖的package包/类
public static void undo(Context context, final int count) throws Exception {
    final Document doc = getDocument(context);
    final UndoManager undoManager = (UndoManager) doc.getProperty(UndoManager.class);
    logUndoRedoOp(context, "UNDO", count);
    invoke(context, new Runnable() {
        @Override
        public void run() {
            try {
                int cnt = count;
                while (undoManager.canUndo() && --cnt >= 0) {
                    undoManager.undo();
                }
            } catch (CannotUndoException e) {
                throw new IllegalStateException(e);
            }
        }
    });
    logPostUndoRedoOp(context, count);
}
 

开发者ID:apache,
项目名称:incubator-netbeans,
代码行数:20,
代码来源:DocumentTesting.java

示例3: redo

点赞 3

import javax.swing.undo.UndoManager; //导入依赖的package包/类
public static void redo(Context context, final int count) throws Exception {
    final Document doc = getDocument(context);
    final UndoManager undoManager = (UndoManager) doc.getProperty(UndoManager.class);
    logUndoRedoOp(context, "REDO", count);
    invoke(context, new Runnable() {
        @Override
        public void run() {
            try {
                int cnt = count;
                while (undoManager.canRedo() && --cnt >= 0) {
                    undoManager.redo();
                }
            } catch (CannotRedoException e) {
                throw new IllegalStateException(e);
            }
        }
    });
    logPostUndoRedoOp(context, count);
}
 

开发者ID:apache,
项目名称:incubator-netbeans,
代码行数:20,
代码来源:DocumentTesting.java

示例4: testCreateGlobalElementUndoRedo

点赞 3

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: testSetAttributeOnGlobalComplexTypeUndoRedo

点赞 3

import javax.swing.undo.UndoManager; //导入依赖的package包/类
public void testSetAttributeOnGlobalComplexTypeUndoRedo() throws Exception {
    SchemaModel model = Util.loadSchemaModel("resources/PurchaseOrder.xsd");
    UndoManager ur = new UndoManager();
    model.addUndoableEditListener(ur);
    GlobalComplexType potype = model.getSchema().getComplexTypes().iterator().next();
    assertEquals("PurchaseOrderType", potype.getName());
    
    model.startTransaction();
    potype.setAbstract(Boolean.TRUE);
    model.endTransaction();
    
    ur.undo();
    assertNull(potype.getAttribute(SchemaAttributes.ABSTRACT));

    ur.redo();
    assertNotNull(potype.getAttribute(SchemaAttributes.ABSTRACT));
}
 

开发者ID:apache,
项目名称:incubator-netbeans,
代码行数:18,
代码来源:SyncTest.java

示例6: testSyncUndo

点赞 3

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: testSyncUndoRename

点赞 3

import javax.swing.undo.UndoManager; //导入依赖的package包/类
public void testSyncUndoRename() throws Exception {
    SchemaModel model = Util.loadSchemaModel(TEST_XSD);
    UndoManager um = new UndoManager();
    model.addUndoableEditListener(um);
    assertEquals(2, model.getSchema().getElements().size());
    
    Util.setDocumentContentTo(model, "resources/PurchaseOrder_SyncUndoRename.xsd");
    model.sync();
    assertEquals(2, model.getSchema().getElements().size());
    assertEquals("purchaseOrder2", model.getSchema().getElements().iterator().next().getName());

    um.undo();
    assertEquals(2, model.getSchema().getElements().size());
    assertEquals("purchaseOrder", model.getSchema().getElements().iterator().next().getName());

    um.redo();
    assertEquals(2, model.getSchema().getElements().size());
    assertEquals("purchaseOrder2", model.getSchema().getElements().iterator().next().getName());
}
 

开发者ID:apache,
项目名称:incubator-netbeans,
代码行数:20,
代码来源:SyncTest.java

示例8: testMultipleMutationUndoRedo

点赞 3

import javax.swing.undo.UndoManager; //导入依赖的package包/类
public void testMultipleMutationUndoRedo() throws Exception {
    mModel = Util.loadModel("resources/Empty.xml");
    UndoManager urListener = new UndoManager();
    mModel.addUndoableEditListener(urListener);
		
    //setup
    mModel.startTransaction();
    B b2 = new B(mModel, 2);
    mModel.getRootComponent().addAfter(b2.getName(), b2, TestComponent3._A);
    String v = "testComponentListener.b2";
    b2.setValue(v);
    mModel.endTransaction();
    
    b2 = mModel.getRootComponent().getChild(B.class);
    assertEquals(v, b2.getAttribute(TestAttribute3.VALUE));
    
    urListener.undo();
    b2 = mModel.getRootComponent().getChild(B.class);
    assertNull(b2);

    urListener.redo();
    b2 = mModel.getRootComponent().getChild(B.class);
    assertEquals(v, b2.getAttribute(TestAttribute3.VALUE));
}
 

开发者ID:apache,
项目名称:incubator-netbeans,
代码行数:25,
代码来源:AbstractModelTest.java

示例9: testSyncUndoRedo

点赞 3

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

示例10: testUndoRedoWithIdentity

点赞 3

import javax.swing.undo.UndoManager; //导入依赖的package包/类
public void testUndoRedoWithIdentity() throws Exception {
    mModel = Util.loadModel("resources/test1_name.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

示例11: testUndoRedoWithoutIdentity

点赞 3

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

示例12: testUndoRedoOnMutationFromEvent

点赞 3

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

示例13: testUndoOnMutationFromSyncEvent

点赞 3

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

示例14: addEditorPane

点赞 3

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

示例15: setUndoRedoButtonsEnabled

点赞 3

import javax.swing.undo.UndoManager; //导入依赖的package包/类
/**
   * Sets the undo and redo buttons enabled or not. 
   * Additionally the ToolTipText will be set.
   */
  private void setUndoRedoButtonsEnabled() {
  	SwingUtilities.invokeLater(new Runnable() {
	@Override
	public void run() {
		UndoManager undoManager = graphController.getNetworkModelAdapter().getUndoManager();
		
		getJButtonUndo().setEnabled(undoManager.canUndo());
		getJButtonUndo().setToolTipText(undoManager.getUndoPresentationName());
		
		getJButtonRedo().setEnabled(undoManager.canRedo());
		getJButtonRedo().setToolTipText(undoManager.getRedoPresentationName());
		
	}
});
  }
 

开发者ID:EnFlexIT,
项目名称:AgentWorkbench,
代码行数:20,
代码来源:BasicGraphGuiTools.java

示例16: run

点赞 3

import javax.swing.undo.UndoManager; //导入依赖的package包/类
public void run() {
	Display display = Display.getDefault();
	Cursor waitCursor = new Cursor(display, SWT.CURSOR_WAIT);		
	
	Shell shell = getParentShell();
	shell.setCursor(waitCursor);
       
	try {
   		ProjectExplorerView explorerView = getProjectExplorerView();
   		if (explorerView != null) {
   			UndoManager undoManager = explorerView.getUndoManager();
   			undoManager.redo();
   		}
	}
	catch (Throwable e) {
		ConvertigoPlugin.logException(e, "Unable to redo the last action.");
	}
       finally {
		shell.setCursor(null);
		waitCursor.dispose();
       }
}
 

开发者ID:convertigo,
项目名称:convertigo-eclipse,
代码行数:23,
代码来源:RedoAction.java

示例17: run

点赞 3

import javax.swing.undo.UndoManager; //导入依赖的package包/类
public void run() {
	Display display = Display.getDefault();
	Cursor waitCursor = new Cursor(display, SWT.CURSOR_WAIT);		
	
	Shell shell = getParentShell();
	shell.setCursor(waitCursor);
       
	try {
   		ProjectExplorerView explorerView = getProjectExplorerView();
   		if (explorerView != null) {
   			UndoManager undoManager = explorerView.getUndoManager();
   			undoManager.undo();
   		}
	}
	catch (Throwable e) {
		ConvertigoPlugin.logException(e, "Unable to undo the last action.");
	}
       finally {
		shell.setCursor(null);
		waitCursor.dispose();
       }
}
 

开发者ID:convertigo,
项目名称:convertigo-eclipse,
代码行数:23,
代码来源:UndoAction.java

示例18: XMap

点赞 3

import javax.swing.undo.UndoManager; //导入依赖的package包/类
public XMap(Object app, Projection proj, BufferedImage image) {
	this.app = app;
	this.proj = proj;
	this.image = image;
	width = image.getWidth();
	height = image.getHeight();
	overlays = new Vector();
	overlayAlphas = new HashMap<Overlay, Float>();
	mapInsets = null;
	zoom = 1d;
	rotation = 0;
	try {
		CylindricalProjection p = (CylindricalProjection) proj;
		wrap = Math.rint(360.*(p.getX(10.)-p.getX(9.)));
	} catch (ClassCastException ex) {
		wrap = -1.;
	}

	// GMA 1.6.4: Add mouse motion listener to perform pan, mouse listener to perform center
	addMouseMotionListener(this);
	addMouseListener(this);
	undoManager = new UndoManager();
	undoManager.setLimit(8);
	zoomActionTrack.getDocument().addUndoableEditListener(undoManager);
}
 

开发者ID:iedadata,
项目名称:geomapapp,
代码行数:26,
代码来源:XMap.java

示例19: XMLTextEditor

点赞 3

import javax.swing.undo.UndoManager; //导入依赖的package包/类
/** Creates a new instance of XMLEditorPane */
public XMLTextEditor() {
    super();
    XMLEditorKit kit = new XMLEditorKit();
    setEditorKitForContentType(XMLEditorKit.XML_MIME_TYPE, kit);
    setContentType(XMLEditorKit.XML_MIME_TYPE);
    setBackground(Color.white);
    //setFont(new Font("Monospaced", Font.PLAIN, 12));
            
    // add undoable edit
    undoManager = new UndoManager();
    UndoableEditListener undoableEditHandler = new UndoableEditListener() {
        public void undoableEditHappened(UndoableEditEvent e) {
            undoManager.addEdit(e.getEdit());
        }
    };
    getDocument().addUndoableEditListener(undoableEditHandler);
}
 

开发者ID:git-moss,
项目名称:Push2Display,
代码行数:19,
代码来源:XMLTextEditor.java

示例20: GUIPepaModelEditor

点赞 3

import javax.swing.undo.UndoManager; //导入依赖的package包/类
/** Creates a new instance of GUIPepaModelEditor */
public GUIPepaModelEditor(GUIMultiModelHandler handler)
{
	editor = new JEditorPane();
	PepaEditorKit kit = new PepaEditorKit();
	editor.setEditorKitForContentType("text/pepa", kit);
	editor.setContentType("text/pepa");
	undoManager = new UndoManager();
	undoManager.setLimit(200);
	//editor.setForeground(FOREGROUND_COLOR);
	this.handler = handler;
	d = (PlainDocument)editor.getDocument();
	editor.getDocument().addDocumentListener(this);
	initComponents();
	
}
 

开发者ID:musaeed,
项目名称:Prism-gsoc16,
代码行数:17,
代码来源:GUIPepaModelEditor.java

示例21: testUndoRemoveDSType

点赞 3

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

示例22: formWindowOpened

点赞 3

import javax.swing.undo.UndoManager; //导入依赖的package包/类
private void formWindowOpened(java.awt.event.WindowEvent evt) {
        // TODO add your handling code here:
        //_mapView.setLockViewUpdate(true);
        //_mapDocument.setIsLayoutView(false);
        //_mapView.setIsLayoutMap(false);
        this._mapLayout.setLockViewUpdate(true);
        _mapView.zoomToExtent(_mapView.getViewExtent());
        //_mapView.setLockViewUpdate(false);
        this.zoomUndoManager = new UndoManager();

        //Open MeteoData form
        _frmMeteoData = new FrmMeteoData(this, false);
        //_frmMeteoData.setSize(500, 280);
        _frmMeteoData.setLocation(this.getX() + 10, this.getY() + this.getHeight() - _frmMeteoData.getHeight() - 40);
        _frmMeteoData.setVisible(this._options.isShowStartMeteoDataDlg());
//        if (this._options.isShowStartMeteoDataDlg()) {
//            _frmMeteoData = new FrmMeteoData(this, false);
//            //_frmMeteoData.setSize(500, 280);
//            _frmMeteoData.setLocation(this.getX() + 10, this.getY() + this.getHeight() - _frmMeteoData.getHeight() - 40);
//            _frmMeteoData.setVisible(this._options.isShowStartMeteoDataDlg());
//        }
    }
 

开发者ID:meteoinfo,
项目名称:MeteoInfoMap,
代码行数:23,
代码来源:FrmMain.java


版权声明:本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系管理员进行删除。
喜欢 (0)