Java 类javax.swing.undo.CannotUndoException 实例源码

项目:JavaGraph    文件:SystemStore.java   
@Override
public void undo() throws CannotUndoException {
    super.undo();
    try {
        Set<QualName> deleted = new HashSet<>(this.newTexts.keySet());
        deleted.removeAll(this.oldTexts.keySet());
        doDeleteTexts(getResourceKind(), deleted);
        if (this.oldProps != null) {
            doPutProperties(this.oldProps);
        }
        doPutTexts(getResourceKind(), this.oldTexts);
    } catch (IOException exc) {
        throw new CannotUndoException();
    }
    notifyObservers(this);
}
项目:incubator-netbeans    文件:BaseDocument.java   
public @Override void undo() throws CannotUndoException {
    atomicLockImpl ();
    try {
        TokenHierarchyControl<?> thcInactive = thcInactive();
        try {
            super.undo();
        } finally {
            if (thcInactive != null) {
                thcInactive.setActive(true);
            }
        }
    } finally {
        atomicUnlockImpl ();
    }

    if (previousEdit != null) {
        previousEdit.undo();
    }

}
项目:incubator-netbeans    文件:PropertiesOpen.java   
/** Implements {@code UndoRedo}. Undo an edit. It finds a manager which next undo edit has the highest 
 * time stamp and makes undo on it.
 * @exception CannotUndoException if it fails
 */
@Override
public synchronized void undo () throws CannotUndoException {
    PropertiesEditorSupport.UndoRedoStampFlagManager chosenManager = (PropertiesEditorSupport.UndoRedoStampFlagManager)getNextUndo();

    if (chosenManager == null) {
        throw new CannotUndoException();
    } else {
        Object atomicFlag = chosenManager.getAtomicFlagOfEditToBeUndone();
        if (atomicFlag == null) {// not linked with other edits as one atomic action
            chosenManager.undo();
        } else { // atomic undo compound from more edits in underlying managers
            boolean undone;
            do { // the atomic action can consists from more undo edits from same manager
                undone = false;
                for (Iterator<Manager> it = managers.iterator(); it.hasNext(); ) {
                    PropertiesEditorSupport.UndoRedoStampFlagManager manager = (PropertiesEditorSupport.UndoRedoStampFlagManager)it.next();
                    if(atomicFlag.equals(manager.getAtomicFlagOfEditToBeUndone())) {
                        manager.undo();
                        undone = true;
                    }
                }
            } while(undone);
        }
    }
}
项目:incubator-netbeans    文件:StableCompoundEditTest.java   
public void testBasicFailUndo0() throws Exception {
    StableCompoundEdit cEdit = new StableCompoundEdit();
    TestEdit e0 = new TestEdit(true);
    TestEdit e1 = new TestEdit();
    cEdit.addEdit(e0);
    cEdit.addEdit(e1);
    NbTestCase.assertFalse("Not ended yet", cEdit.canUndo());
    NbTestCase.assertFalse("Not ended yet", cEdit.canRedo());
    cEdit.end();
    NbTestCase.assertTrue("Expected undoable", cEdit.canUndo());
    NbTestCase.assertFalse("Expected non-redoable", cEdit.canRedo());

    try {
        cEdit.undo();
        fail("Was expecting CannotUndoException exception.");
    } catch (CannotUndoException ex) {
        // Expected
    }
    NbTestCase.assertTrue("Expected undoable", cEdit.canUndo());
    NbTestCase.assertFalse("Expected non-redoable", cEdit.canRedo());
    NbTestCase.assertTrue("Expected undoable", e0.canUndo());
    NbTestCase.assertFalse("Expected non-redoable", e0.canRedo());
    NbTestCase.assertTrue("Expected undoable", e1.canUndo());
    NbTestCase.assertFalse("Expected non-redoable", e1.canRedo());

}
项目:incubator-netbeans    文件:StableCompoundEditTest.java   
public void testBasicFailUndo1() throws Exception {
    StableCompoundEdit cEdit = new StableCompoundEdit();
    TestEdit e0 = new TestEdit();
    TestEdit e1 = new TestEdit(true);
    cEdit.addEdit(e0);
    cEdit.addEdit(e1);
    NbTestCase.assertFalse("Not ended yet", cEdit.canUndo());
    NbTestCase.assertFalse("Not ended yet", cEdit.canRedo());
    cEdit.end();
    NbTestCase.assertTrue("Expected undoable", cEdit.canUndo());
    NbTestCase.assertFalse("Expected non-redoable", cEdit.canRedo());

    try {
        cEdit.undo();
        fail("Was expecting CannotUndoException exception.");
    } catch (CannotUndoException ex) {
        // Expected
    }
    NbTestCase.assertTrue("Expected undoable", cEdit.canUndo());
    NbTestCase.assertFalse("Expected non-redoable", cEdit.canRedo());
    NbTestCase.assertTrue("Expected undoable", e0.canUndo());
    NbTestCase.assertFalse("Expected non-redoable", e0.canRedo());
    NbTestCase.assertTrue("Expected undoable", e1.canUndo());
    NbTestCase.assertFalse("Expected non-redoable", e1.canRedo());

}
项目:incubator-netbeans    文件:DocumentTesting.java   
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);
}
项目:oxygen-git-plugin    文件:UndoSupportInstaller.java   
@Override
public void undo() {
    if (!canUndo()) {
        throw new CannotUndoException();
    }

    MyCompoundEdit u = edits.get(pointer);
    u.undo();
    pointer--;

}
项目:AgentWorkbench    文件:PasteNetworkModel.java   
@Override
public void undo() throws CannotUndoException {
    super.undo();

    // --- Remove the added components --------------
    HashSet<NetworkComponent> netComps2Remove = new HashSet<NetworkComponent>();
    for (NetworkComponent networkComponentPasted : this.pastedNetworkModel.getNetworkComponents().values()) {
        String netCompID = networkComponentPasted.getId();
        NetworkComponent netCompRemove = this.graphController.getNetworkModel().getNetworkComponent(netCompID);
        netComps2Remove.add(netCompRemove);
        this.graphController.removeAgent(networkComponentPasted);
    }
    this.graphController.getNetworkModel().removeNetworkComponents(netComps2Remove);

    NetworkModelNotification  notification = new NetworkModelNotification(NetworkModelNotification.NETWORK_MODEL_Component_Removed);
    notification.setInfoObject(netComps2Remove);
    this.graphController.notifyObservers(notification);

}
项目:Pogamut3    文件:LapTreeMVElement.java   
@Override
public void undo() throws CannotUndoException {
    try {
        ignore = true;

        // take text from position - 1
        String planText = history.get(position - 1);
        // parse it
        PoshParser parser = new PoshParser(new StringReader(planText));
        PoshPlan plan = parser.parsePlan();
        // synchronize with the editor tree
        lapTree.synchronize(plan);

        if (position > 0) {
            --position;
        }
    } catch (ParseException ex) {
        throw new CannotUndoException();
    } finally {
        ignore = false;
        cs.fireChange();
    }
}
项目:JavaGraph    文件:SystemStore.java   
@Override
public void undo() throws CannotUndoException {
    super.undo();
    try {
        boolean layout = getType() == LAYOUT;
        if (!layout) {
            Set<QualName> deleted = getNames(this.newGraphs);
            deleted.removeAll(getNames(this.oldGraphs));
            doDeleteGraphs(getResourceKind(), deleted);
            if (this.oldProps != null) {
                doPutProperties(this.oldProps);
            }
        }
        doPutGraphs(getResourceKind(), this.oldGraphs, layout);
    } catch (IOException exc) {
        throw new CannotUndoException();
    }
    notifyObservers(this);
}
项目:MaxSim    文件:DiagramScene.java   
@Override
public void undo() throws CannotUndoException {
    super.undo();
    boolean b = scene.getUndoRedoEnabled();
    scene.setUndoRedoEnabled(false);
    scene.getModel().getViewChangedEvent().addListener(this);
    scene.getModel().setData(oldModel);
    scene.getModel().getViewChangedEvent().removeListener(this);

    SwingUtilities.invokeLater(new Runnable() {

        @Override
        public void run() {
            scene.setScrollPosition(oldScrollPosition);
        }
    });

    scene.setUndoRedoEnabled(b);
}
项目:openjdk-jdk10    文件:DiagramScene.java   
@Override
public void undo() throws CannotUndoException {
    super.undo();
    boolean b = scene.getUndoRedoEnabled();
    scene.setUndoRedoEnabled(false);
    scene.getModel().getViewChangedEvent().addListener(this);
    scene.getModel().setData(oldModel);
    scene.getModel().getViewChangedEvent().removeListener(this);

    SwingUtilities.invokeLater(new Runnable() {

        @Override
        public void run() {
            scene.setScrollPosition(oldScrollPosition);
        }
    });

    scene.setUndoRedoEnabled(b);
}
项目:Neukoelln_SER316    文件:HTMLEditor.java   
public void actionPerformed(ActionEvent e) {
    try {
        undo.undo();
    } catch (CannotUndoException ex) {
        System.out.println("Unable to undo: " + ex);
        ex.printStackTrace();
    }
    update();
    redoAction.update();
}
项目:incubator-netbeans    文件:UndoRedoSupport.java   
@Override
public void undo() throws CannotUndoException {
    if (edit != null) {
        edit.end();
    }
    super.undo();
    edit = null;
}
项目:incubator-netbeans    文件:UndoRedoSupport.java   
@Override
public void undo() throws CannotUndoException {
    synchronized(delegates) {
        for (CompoundUndoManager cm : delegates) {
            if(cm.hasFocus()) {
                cm.undo();
                return;
            }
        }
    }
}
项目:incubator-netbeans    文件:BaseDocument.java   
private void undoAtomicEdits() {
    if (atomicEdits != null && atomicEdits.size() > 0) {
        atomicEdits.end();
        if (atomicEdits.canUndo()) {
            atomicEdits.undo();
        } else {
            LOG.log(Level.WARNING,
                    "Cannot UNDO: " + atomicEdits.toString() + // NOI18N
                    " Edits: " + atomicEdits.getEdits(),       // NOI18N
                    new CannotUndoException());
        }
        atomicEdits = null;
    }
}
项目:incubator-netbeans    文件:GuardedDocumentEvent.java   
public void undo() throws CannotUndoException {
    GuardedDocument gdoc = (GuardedDocument)getDocument();
    boolean origBreak = gdoc.breakGuarded;
    gdoc.breakGuarded = true;
    super.undo();
    if (!origBreak) {
        gdoc.breakGuarded = false;
    }
}
项目:incubator-netbeans    文件:DocumentContent.java   
public @Override void undo() throws CannotUndoException {
    super.undo();

    if (debugUndo) {
        /*DEBUG*/System.err.println("UNDO-" + dump()); // NOI18N
    }
    undoOrRedo(-length, true);
}
项目:Dahlem_SER316    文件:HTMLEditor.java   
public void actionPerformed(ActionEvent e) {
    try {
        undo.undo();
    } catch (CannotUndoException ex) {
        System.out.println("Unable to undo: " + ex);
        ex.printStackTrace();
    }
    update();
    redoAction.update();
}
项目:incubator-netbeans    文件:UndoableWrapper.java   
@Override
public void undo() throws CannotUndoException {
    JTextComponent focusedComponent = EditorRegistry.focusedComponent();
    if (focusedComponent != null) {
        if (focusedComponent.getDocument() == ces.getDocument()) {
            //call global undo only for focused component
            undoManager.undo(session, ces.getDocument());
        }
    }
    //delegate.undo();
    inner.undo();
}
项目:Reinickendorf_SER316    文件:HTMLEditor.java   
public void actionPerformed(ActionEvent e) {
    try {
        undo.undo();
    } catch (CannotUndoException ex) {
        System.out.println("Unable to undo: " + ex);
        ex.printStackTrace();
    }
    update();
    redoAction.update();
}
项目:incubator-netbeans    文件:Deadlock207571Test.java   
public void undo() throws CannotUndoException {
    assert (!undone) : "Already undone";
    if (undoFail) {
        undoFailedCount++;
        throw new CannotUndoException();
    }
    undone = true;
}
项目:incubator-netbeans    文件:InstantRefactoringPerformer.java   
@Override public void undo() throws CannotUndoException {
    InstantRefactoringPerformer perf = performer.get();

    if (perf != null) {
        perf.release(true);
    }
}
项目:incubator-netbeans    文件:InstantRefactoringPerformer.java   
@Override
            public void undo() throws CannotUndoException {
//                JTextComponent focusedComponent = EditorRegistry.focusedComponent();
//                if (focusedComponent != null) {
//                    if (focusedComponent.getDocument() == ces.getDocument()) {
//                        //call global undo only for focused component
//                        undoManager.undo(session);
//                    }
//                }
                //delegate.undo();
                inner.undo();
            }
项目:incubator-netbeans    文件:UndoRedoSupport.java   
@Override
public void undo() throws CannotUndoException {
    if (edit != null) {
        edit.end();
    }
    super.undo();
    edit = null;
}
项目:AntIDE    文件:MyGapContent.java   
public void undo() throws CannotUndoException {
    super.undo();
    try {
    insertString(offset, string);
    // Update the Positions that were in the range removed.
    if(posRefs != null) {
        updateUndoPositions(posRefs, offset, length);
        posRefs = null;
    }
    string = null;
    } catch (BadLocationException bl) {
      throw new CannotUndoException();
    }
}
项目:incubator-netbeans    文件:PropertiesEditorSupport.java   
/** Overrides superclass method. Updates time stamp for the edit. */
@Override
public synchronized void undo() throws CannotUndoException {
    UndoableEdit anEdit = editToBeUndone();
    if(anEdit != null) {
        Object atomicFlag = stampFlags.get(anEdit).getAtomicFlag(); // atomic flag remains
        super.undo();
        stampFlags.put(anEdit, new StampFlag(System.currentTimeMillis(), atomicFlag));
    }
}
项目:incubator-netbeans    文件:InstantRenamePerformer.java   
@Override public void undo() throws CannotUndoException {
    InstantRenamePerformer perf = performer.get();

    if (perf != null) {
        perf.release();
    }
}
项目:incubator-netbeans    文件:AbstractModel.java   
@Override
public void undo() throws CannotUndoException {
    boolean undoStartedTransaction = false;
    boolean needsRefresh = true;
    try {
        startTransaction(true, true); //start pseudo transaction for event firing
        undoStartedTransaction = true;
        AbstractModel.this.getAccess().prepareForUndoRedo();
        super.undo(); 
        AbstractModel.this.getAccess().finishUndoRedo();
        endTransaction();
        needsRefresh = false;
    } catch(CannotUndoException ex) {
        needsRefresh = false;
        throw ex;
    } finally {
        if (undoStartedTransaction && isIntransaction()) {
            try {
                endTransaction(true); // do not fire events
            } catch(Exception e) {
                Logger.getLogger(getClass().getName()).log(Level.INFO, "Undo error", e); //NOI18N
            }
        }
        if (needsRefresh) {
            setState(State.NOT_SYNCED); 
            refresh(); 
        }
    }
}
项目:incubator-netbeans    文件:ContentEdit.java   
@Override
   public void undo() throws CannotUndoException {
if (!canUndo()) {
    throw new CannotUndoException();
}
statusBits &= ~HAS_BEEN_DONE; // hasBeenDone = false;
   }
项目:oxygen-git-plugin    文件:UndoSupportInstaller.java   
@Override
public void redo() {
    if (!canRedo()) {
        throw new CannotUndoException();
    }

    pointer++;
    MyCompoundEdit u = edits.get(pointer);
    u.redo();

}
项目:SER316-Aachen    文件:HTMLEditor.java   
public void actionPerformed(ActionEvent e) {
    try {
        undo.undo();
    } catch (CannotUndoException ex) {
        System.out.println("Unable to undo: " + ex);
        ex.printStackTrace();
    }
    update();
    redoAction.update();
}
项目:incubator-netbeans    文件:ExpectedDocumentContent.java   
@Override
public void undo() throws CannotUndoException {
    super.undo();
    if (removal) {
        insertEdit(this);
    } else {
        removeEdit(this);
    }
}
项目:incubator-netbeans    文件:PositionSyncList.java   
@Override
public void undo() throws CannotUndoException {
    super.undo();
    if (mayDifferPairs != null) {
        for (PositionPair pair : mayDifferPairs) {
            assert (!pair.mayDiffer) : "Invalid pair: " + pair; // NOI18N
            pair.mayDiffer = true;
        }
    }
    assert (mayDifferUndoItem == this) : "Invalid mayDifferUndoItem=" + mayDifferUndoItem;
    mayDifferUndoItem = previousItem;
}
项目:incubator-netbeans    文件:StableCompoundEditTest.java   
@Override
public void undo() throws CannotUndoException {
    if (fireException) {
        throw new CannotUndoException();
    }
    super.undo();
}
项目:incubator-netbeans    文件:GapBranchElement.java   
public void undo() throws CannotUndoException {
    super.undo();

    replace(index, childrenAdded.length, childrenRemoved);

    // Switch childrenAdded with childrenRemoved
    Element[] tmp = childrenRemoved;
    childrenRemoved = childrenAdded;
    childrenAdded = tmp;
}
项目:incubator-netbeans    文件:XDMModelUndoableEdit.java   
@Override
public void undo() throws CannotUndoException {
    super.undo();
       try {
           model.resetDocument(oldDocument);
       } catch (RuntimeException ex) {
           if (oldDocument != model.getCurrentDocument()) {
               CannotUndoException e = new CannotUndoException();
               e.initCause(ex);
               throw e;
           } else {
               throw ex;
           }
       }
}
项目:incubator-netbeans    文件:UndoRedoTest.java   
@Override
public void undo() throws CannotUndoException {
    if (undoFails) {
        throw new CannotUndoException();
    }
    undo++;
}
项目:incubator-netbeans    文件:CodeTemplateInsertHandler.java   
@Override
public void undo() throws CannotUndoException {
    super.undo();
    if (!inactive) {
        inactive = true;
        CodeTemplateInsertHandler handler = (CodeTemplateInsertHandler) doc.getProperty(CT_HANDLER_DOC_PROPERTY);
        if (handler != null) {
            handler.release();
        }
    }
}
项目:incubator-netbeans    文件:IssueTopComponent.java   
@Override
public void undo() throws CannotUndoException {
    if(delegate != null) {
        delegate.undo();
    } else {
        UndoRedo.NONE.undo();
    }
}