类javax.swing.undo.UndoManager源码实例Demo

下面列出了怎么用javax.swing.undo.UndoManager的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: netbeans   文件: OverrideEditorActions.java
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();
        }
    }});
}
 
源代码2 项目: netbeans   文件: AbstractModelTest.java
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());
}
 
源代码3 项目: netbeans   文件: KerberosProfile.java
@Override()
public void displayConfig(WSDLComponent component, UndoManager undoManager) {
    UndoCounter undoCounter = new UndoCounter();
    WSDLModel model = component.getModel();
    
    model.addUndoableEditListener(undoCounter);

    JPanel profConfigPanel = new Kerberos(component, this);
    DialogDescriptor dlgDesc = new DialogDescriptor(profConfigPanel, getDisplayName());
    Dialog dlg = DialogDisplayer.getDefault().createDialog(dlgDesc);

    dlg.setVisible(true); 
    if (dlgDesc.getValue() == DialogDescriptor.CANCEL_OPTION) {
        for (int i=0; i<undoCounter.getCounter();i++) {
            if (undoManager.canUndo()) {
                undoManager.undo();
            }
        }
    }
    
    model.removeUndoableEditListener(undoCounter);
}
 
源代码4 项目: netbeans   文件: STSIssuedEndorsingProfile.java
@Override()
public void displayConfig(WSDLComponent component, UndoManager undoManager) {
    UndoCounter undoCounter = new UndoCounter();
    WSDLModel model = component.getModel();
    
    model.addUndoableEditListener(undoCounter);

    JPanel profConfigPanel = new STSIssuedEndorsing(component, this);
    DialogDescriptor dlgDesc = new DialogDescriptor(profConfigPanel, getDisplayName());
    Dialog dlg = DialogDisplayer.getDefault().createDialog(dlgDesc);

    dlg.setVisible(true); 
    if (dlgDesc.getValue() == DialogDescriptor.CANCEL_OPTION) {
        for (int i=0; i<undoCounter.getCounter();i++) {
            if (undoManager.canUndo()) {
                undoManager.undo();
            }
        }
    }
    
    model.removeUndoableEditListener(undoCounter);
}
 
@Override()
public void displayConfig(WSDLComponent component, UndoManager undoManager) {
    UndoCounter undoCounter = new UndoCounter();
    WSDLModel model = component.getModel();
    
    model.addUndoableEditListener(undoCounter);

    JPanel profConfigPanel = new STSIssuedSupportingToken(component, this);
    DialogDescriptor dlgDesc = new DialogDescriptor(profConfigPanel, getDisplayName());
    Dialog dlg = DialogDisplayer.getDefault().createDialog(dlgDesc);

    dlg.setVisible(true); 
    if (dlgDesc.getValue() == DialogDescriptor.CANCEL_OPTION) {
        for (int i=0; i<undoCounter.getCounter();i++) {
            if (undoManager.canUndo()) {
                undoManager.undo();
            }
        }
    }
    
    model.removeUndoableEditListener(undoCounter);
}
 
源代码6 项目: netbeans   文件: EndorsingCertificateProfile.java
@Override()
public void displayConfig(WSDLComponent component, UndoManager undoManager) {
    UndoCounter undoCounter = new UndoCounter();
    WSDLModel model = component.getModel();
    
    model.addUndoableEditListener(undoCounter);

    JPanel profConfigPanel = new EndorsingCertificate(component, this);
    DialogDescriptor dlgDesc = new DialogDescriptor(profConfigPanel, getDisplayName());
    Dialog dlg = DialogDisplayer.getDefault().createDialog(dlgDesc);

    dlg.setVisible(true); 
    if (dlgDesc.getValue() == DialogDescriptor.CANCEL_OPTION) {
        for (int i=0; i<undoCounter.getCounter();i++) {
            if (undoManager.canUndo()) {
                undoManager.undo();
            }
        }
    }
    
    model.removeUndoableEditListener(undoCounter);
}
 
源代码7 项目: netbeans   文件: SAMLHolderOfKeyProfile.java
@Override()
public void displayConfig(WSDLComponent component, UndoManager undoManager) {
    UndoCounter undoCounter = new UndoCounter();
    WSDLModel model = component.getModel();
    
    model.addUndoableEditListener(undoCounter);

    JPanel profConfigPanel = new SAMLHolderOfKey(component, this);
    DialogDescriptor dlgDesc = new DialogDescriptor(profConfigPanel, getDisplayName());
    Dialog dlg = DialogDisplayer.getDefault().createDialog(dlgDesc);

    dlg.setVisible(true); 
    if (dlgDesc.getValue() == DialogDescriptor.CANCEL_OPTION) {
        for (int i=0; i<undoCounter.getCounter();i++) {
            if (undoManager.canUndo()) {
                undoManager.undo();
            }
        }
    }
    
    model.removeUndoableEditListener(undoCounter);
}
 
源代码8 项目: netbeans   文件: STSIssuedCertProfile.java
@Override()
public void displayConfig(WSDLComponent component, UndoManager undoManager) {
    UndoCounter undoCounter = new UndoCounter();
    WSDLModel model = component.getModel();
    
    model.addUndoableEditListener(undoCounter);

    JPanel profConfigPanel = new STSIssuedCert(component, this);
    DialogDescriptor dlgDesc = new DialogDescriptor(profConfigPanel, getDisplayName());
    Dialog dlg = DialogDisplayer.getDefault().createDialog(dlgDesc);

    dlg.setVisible(true); 
    if (dlgDesc.getValue() == DialogDescriptor.CANCEL_OPTION) {
        for (int i=0; i<undoCounter.getCounter();i++) {
            if (undoManager.canUndo()) {
                undoManager.undo();
            }
        }
    }
    
    model.removeUndoableEditListener(undoCounter);
}
 
源代码9 项目: netbeans   文件: AbstractModelTest.java
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));
}
 
源代码10 项目: netbeans   文件: ViewHierarchyTest.java
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();
}
 
源代码11 项目: netbeans   文件: PlainDocumentTest.java
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);
}
 
源代码12 项目: netbeans   文件: SyncTest.java
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());
}
 
源代码13 项目: netbeans   文件: SyncTest.java
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());
}
 
源代码14 项目: netbeans   文件: AbstractModelTest.java
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));
}
 
源代码15 项目: netbeans   文件: AbstractModelTest.java
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());
}
 
源代码16 项目: ganttproject   文件: UndoManagerImpl.java
public UndoManagerImpl(IGanttProject project, ParserFactory parserFactory, DocumentManager documentManager) {
  myProject = project;
  myParserFactory = parserFactory;
  myDocumentManager = documentManager;
  mySwingUndoManager = new UndoManager();
  myUndoEventDispatcher = new UndoableEditSupport();
  GanttLanguage.getInstance().addListener(new GanttLanguage.Listener() {
    public void languageChanged(Event event) {
      UIManager.getDefaults().put("AbstractUndoableEdit.undoText", GanttLanguage.getInstance().getText("undo"));
      UIManager.getDefaults().put("AbstractUndoableEdit.redoText", GanttLanguage.getInstance().getText("redo"));
    }
  });
}
 
源代码17 项目: SikuliX1   文件: EditorPaneUndoRedo.java
public EditorPaneUndoRedo(EditorPane pane) {
    undoManager = new UndoManager();
    undoAction = new UndoAction();
    redoAction = new RedoAction();
    editorPane = pane;

//    editorPane.getInputMap().put(undoKeystroke, "undoKeystroke");
//    editorPane.getActionMap().put("undoKeystroke", undoAction);
//
//    editorPane.getInputMap().put(redoKeystroke, "redoKeystroke");
//    editorPane.getActionMap().put("redoKeystroke", redoAction);
  }
 
源代码18 项目: Robot-Overlord-App   文件: CommandUndo.java
public CommandUndo(UndoManager undo) {
    super("Undo");  
	this.undo=undo;
    setEnabled(false);
    
    putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_Z, ActionEvent.CTRL_MASK));
}
 
源代码19 项目: netbeans   文件: AbstractModelTest.java
public void testRedoWithFaultInFindComponent() throws Exception {
    setupForUndoRedoFault(new FaultInjector() {
        @Override
        public void injectFaultAndCheck(Object actor) throws Exception { 
            ((UndoManager)actor).undo();
            mModel.injectFaultInFindComponent();
            ((UndoManager)actor).redo();
        }
    }, true);
}
 
源代码20 项目: netbeans   文件: CustomizationWSEditor.java
private void initializeModels(Node node) throws Exception {
    if (wsdlModels.isEmpty()) {
        undoManager = new UndoManager();
        WSDLModel primaryModel = getPrimaryModel(node);
        populateAllModels(primaryModel);
        Set<WSDLModel> modelSet = wsdlModels.keySet();
        for (WSDLModel wsdlModel : modelSet) {
            wsdlModel.addUndoableEditListener(undoManager);
        }
    }
}
 
源代码21 项目: jadx   文件: TextStandardActions.java
public TextStandardActions(JTextComponent textComponent) {
	this.textComponent = textComponent;
	this.undoManager = new UndoManager();

	initActions();
	addPopupItems();
	addKeyActions();

	registerListeners();
}
 
源代码22 项目: netbeans   文件: NbEditorKit.java
public @Override void actionPerformed(ActionEvent evt, JTextComponent target) {
    Document doc = target.getDocument();
    if (doc.getProperty(BaseDocument.UNDO_MANAGER_PROP) != null ||
        doc.getProperty(UndoManager.class) != null )
    {
        super.actionPerformed(evt, target);
    } else { // Deleagte to system undo action
        // Delegate to system redo action
        RedoAction ra = (RedoAction)SystemAction.get(RedoAction.class);
        if (ra != null && ra.isEnabled()) {
            ra.actionPerformed(evt);
        }
    }
}
 
源代码23 项目: netbeans   文件: ServiceTopComponent.java
public ServiceTopComponent(Service service, 
            JaxWsModel jaxWsModel, WSDLModel wsdlModel, Node node, UndoManager undoManager) {
    setLayout(new BorderLayout());
    this.wsdlModel = wsdlModel;
    this.undoManager = undoManager;
    this.node = node;
    this.service = service;
    this.jaxWsModel = jaxWsModel;
}
 
源代码24 项目: groovy   文件: TextUndoManager.java
protected void trimEdits(int from, int to) {
    boolean undoable = canUndo();
    boolean redoable = canRedo();

    boolean changed = hasChanged();
    super.trimEdits(from, to);

    firePropertyChangeEvent(UndoManager.UndoName, undoable, canUndo());
    firePropertyChangeEvent(UndoManager.RedoName, redoable, canRedo());
}
 
源代码25 项目: gcs   文件: RedoCommand.java
@Override
public void adjust() {
    Undoable undoable = getTarget(Undoable.class);
    if (undoable != null) {
        UndoManager mgr = undoable.getUndoManager();
        setEnabled(mgr.canRedo());
        setTitle(mgr.getRedoPresentationName());
    } else {
        setEnabled(false);
        setTitle(I18n.Text("Can't Redo"));
    }
}
 
源代码26 项目: gcs   文件: UndoCommand.java
@Override
public void adjust() {
    Undoable undoable = getTarget(Undoable.class);
    if (undoable != null) {
        UndoManager mgr = undoable.getUndoManager();
        setEnabled(mgr.canUndo());
        setTitle(mgr.getUndoPresentationName());
    } else {
        setEnabled(false);
        setTitle(I18n.Text("Can't Undo"));
    }
}
 
源代码27 项目: netbeans   文件: AbstractModelTest.java
public void testRedoWithFaultInSyncUpdater() throws Exception {
    setupForUndoRedoFault(new FaultInjector() {
        @Override
        public void injectFaultAndCheck(Object actor) throws Exception { 
            ((UndoManager)actor).undo();
            mModel.injectFaultInSyncUpdater();
            ((UndoManager)actor).redo();
        }
    }, true);
}
 
源代码28 项目: netbeans   文件: AbstractModel.java
@Override
public synchronized void addUndoableRefactorListener(UndoableEditListener uel) {
    //
    savedUndoableEditListeners = ues.getUndoableEditListeners();
    if (savedUndoableEditListeners != null) {
        for (UndoableEditListener saved : savedUndoableEditListeners) {
            if (saved instanceof UndoManager) {
                ((UndoManager)saved).discardAllEdits();
            }
        }
    }
    ues = new ModelUndoableEditSupport();
    ues.addUndoableEditListener(uel);
}
 
源代码29 项目: netbeans   文件: DocumentContentTesting.java
public static UndoManager getValidUndoManager(PropertyProvider provider) {
    UndoManager undoManager = getUndoManager(provider);
    if (undoManager == null) {
        throw new IllegalStateException("Null UndoManager for property provider " + provider); // NOI18N
    }
    return undoManager;
}
 
源代码30 项目: netbeans   文件: AbstractModelTest.java
public void testUndoWithFaultInEventFiring() throws Exception {
    setupForUndoRedoFault(new FaultInjector() {
        @Override
        public void injectFaultAndCheck(Object actor) throws Exception { 
            mModel.injectFaultInEventFiring();
            ((UndoManager)actor).undo();
        }
    }, false);
}
 
 类所在包
 同包方法