Java Code Examples for javax.swing.undo.CannotRedoException

The following examples show how to use javax.swing.undo.CannotRedoException. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: openAGV   Source File: BringToFrontAction.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void actionPerformed(java.awt.event.ActionEvent e) {
  final DrawingView view = getView();
  final LinkedList<Figure> figures = new LinkedList<>(view.getSelectedFigures());
  bringToFront(view, figures);
  fireUndoableEditHappened(new AbstractUndoableEdit() {
    @Override
    public String getPresentationName() {
      return ResourceBundleUtil.getBundle(TOOLBAR_PATH).getString("bringToFrontAction.undo.presentationName");
    }

    @Override
    public void redo()
        throws CannotRedoException {
      super.redo();
      BringToFrontAction.bringToFront(view, figures);
    }

    @Override
    public void undo()
        throws CannotUndoException {
      super.undo();
      SendToBackAction.sendToBack(view, figures);
    }
  });
}
 
Example 2
Source Project: openAGV   Source File: SendToBackAction.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void actionPerformed(java.awt.event.ActionEvent e) {
  final DrawingView view = getView();
  final LinkedList<Figure> figures = new LinkedList<>(view.getSelectedFigures());
  sendToBack(view, figures);
  fireUndoableEditHappened(new AbstractUndoableEdit() {
    @Override
    public String getPresentationName() {
      return ResourceBundleUtil.getBundle(TOOLBAR_PATH).getString("sendToBackAction.undo.presentationName");
    }

    @Override
    public void redo()
        throws CannotRedoException {
      super.redo();
      SendToBackAction.sendToBack(view, figures);
    }

    @Override
    public void undo()
        throws CannotUndoException {
      super.undo();
      BringToFrontAction.bringToFront(view, figures);
    }
  });
}
 
Example 3
Source Project: netbeans   Source File: StableCompoundEdit.java    License: Apache License 2.0 6 votes vote down vote up
@Override
   public void redo() throws CannotRedoException {
if (!canRedo()) {
    throw new CannotRedoException();
}
       int i = 0;
       int size = edits.size();
       try {
           for (; i < size; i++) {
               edits.get(i).redo();
           }
           setStatusBits(HAS_BEEN_DONE);
       } finally {
           if (i != size) { // i-th edit's redo failed => undo the ones below
               while (--i >= 0) {
                   edits.get(i).undo();
               }
           }
       }
   }
 
Example 4
Source Project: netbeans   Source File: WrapUndoEdit.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void redo() throws CannotRedoException {
    undoRedoManager.checkLogOp("WrapUndoEdit.redo", this);
    boolean savepoint = undoRedoManager.isAtSavepoint();
    if (savepoint) {
        undoRedoManager.beforeRedoAtSavepoint(this);
    }
    boolean done = false;
    try {
        delegate.redo();
        done = true;
        // This will only happen if delegate.redo() does not throw CannotRedoException
        undoRedoManager.afterRedoCheck(this);
    } finally {
        if (!done && savepoint) {
            undoRedoManager.delegateRedoFailedAtSavepoint(this);
        }
    }
}
 
Example 5
Source Project: netbeans   Source File: BaseDocument.java    License: Apache License 2.0 6 votes vote down vote up
public @Override void redo() throws CannotRedoException {
    if (previousEdit != null) {
        previousEdit.redo();
    }

    atomicLockImpl ();
    try {
        TokenHierarchyControl<?> thcInactive = thcInactive();
        try {
            super.redo();
        } finally {
            if (thcInactive != null) {
                thcInactive.setActive(true);
            }
        }
    } finally {
        atomicUnlockImpl ();
    }
}
 
Example 6
Source Project: netbeans   Source File: PropertiesOpen.java    License: Apache License 2.0 6 votes vote down vote up
/** Implements {@code UndoRedo}. Redo a previously undone edit. It finds a manager which next undo edit has the highest 
 * time stamp and makes undo on it.
 * @exception CannotRedoException if it fails
 */
@Override
public synchronized void redo () throws CannotRedoException {
    PropertiesEditorSupport.UndoRedoStampFlagManager chosenManager = (PropertiesEditorSupport.UndoRedoStampFlagManager)getNextRedo();

    if (chosenManager == null) {
        throw new CannotRedoException();
    } else {
        Object atomicFlag = chosenManager.getAtomicFlagOfEditToBeRedone();
        if (atomicFlag == null) {// not linked with other edits as one atomic action
            chosenManager.redo();
        } else { // atomic redo compound from more edits in underlying managers
            boolean redone;
            do { // the atomic action can consists from more redo edits from same manager
                redone = false;
                for (Iterator<Manager> it = managers.iterator(); it.hasNext(); ) {
                    PropertiesEditorSupport.UndoRedoStampFlagManager manager = (PropertiesEditorSupport.UndoRedoStampFlagManager)it.next();
                    if(atomicFlag.equals(manager.getAtomicFlagOfEditToBeRedone())) {
                        manager.redo();
                        redone = true;
                    }
                }
            } while(redone);
        }
    }
}
 
Example 7
Source Project: netbeans   Source File: StableCompoundEdit.java    License: Apache License 2.0 6 votes vote down vote up
@Override
   public void redo() throws CannotRedoException {
if (!canRedo()) {
    throw new CannotRedoException();
}
       int i = 0;
       int size = edits.size();
       try {
           for (; i < size; i++) {
               edits.get(i).redo();
           }
           setStatusBits(HAS_BEEN_DONE);
       } finally {
           if (i != size) { // i-th edit's redo failed => undo the ones below
               while (--i >= 0) {
                   edits.get(i).undo();
               }
           }
       }
   }
 
Example 8
Source Project: netbeans   Source File: DocumentTesting.java    License: Apache License 2.0 6 votes vote down vote up
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);
}
 
Example 9
Source Project: constellation   Source File: LockingManager.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void redo() {

    if (!canRedo() || !executed.compareAndSet(false, true)) {
        throw new CannotRedoException();
    }

    new Thread(() -> {
        // Get the global write lock because we will change the graph
        globalWriteLock.lock();
        try {
            writeContext.target.setOperationMode(GraphOperationMode.REDO);
            execute(writeContext.target);
            writeContext.target.validateKeys();
            writeContext.target.setOperationMode(GraphOperationMode.EXECUTE);

            // Switch the read context to the write context
            final Context originalReadContext = readContext;
            readContext = writeContext;

            originalReadContext.lock.writeLock().lock();
            try {
                originalReadContext.target.setOperationMode(GraphOperationMode.REDO);
                execute(originalReadContext.target);
                originalReadContext.target.validateKeys();
                originalReadContext.target.setOperationMode(GraphOperationMode.EXECUTE);
            } finally {
                originalReadContext.lock.writeLock().unlock();
            }

            // Switch the write context
            writeContext = originalReadContext;
        } finally {
            // Unlock the global write lock so new write requests can begin on the new write context
            globalWriteLock.unlock();
        }
    }).start();

    update(null, null);
}
 
Example 10
Source Project: openAGV   Source File: UndoRedoManager.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Undoes or redoes the last edit event.
 * The UndoRedoManager ignores all incoming UndoableEdit events,
 * while undo or redo is in progress.
 */
@Override
public void undoOrRedo()
    throws CannotUndoException, CannotRedoException {
  undoOrRedoInProgress = true;

  try {
    super.undoOrRedo();
  }
  finally {
    undoOrRedoInProgress = false;
    updateActions();
  }
}
 
Example 11
Source Project: openAGV   Source File: UndoRedoManager.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void actionPerformed(ActionEvent evt) {
  try {
    redo();
  }
  catch (CannotRedoException e) {
    LOG.debug("Cannot redo: {}", e);
  }
}
 
Example 12
Source Project: openAGV   Source File: AbstractTreeViewPanel.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void redo()
    throws CannotRedoException {
  super.redo();
  // TODO: Delete again ...
  for (UserObject userObject : userObjects) {
    userObject.removed();
  }
}
 
Example 13
Source Project: openAGV   Source File: CoordinateUndoActivity.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void redo()
    throws CannotRedoException {
  super.redo();

  pxModel.copyFrom(pxAfterModification);
  pyModel.copyFrom(pyAfterModification);
  pxModel.markChanged();
  pyModel.markChanged();

  saveTransformForRedo();

  pxModel.getModel().propertiesChanged(new NullAttributesChangeListener());
}
 
Example 14
Source Project: openAGV   Source File: PropertyUndoActivity.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void redo() throws CannotRedoException {
  fProperty.copyFrom(fAfterModification);
  fProperty.markChanged();
  fProperty.getModel().propertiesChanged(new NullAttributesChangeListener());
  hasBeenDone = true;
}
 
Example 15
Source Project: openAGV   Source File: DeleteEdit.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void redo() throws CannotRedoException {
  super.redo();
  for (Figure figure : figures) {
    drawingView.getDrawing().remove(figure);
  }
}
 
Example 16
public void redo() throws CannotRedoException {
    super.redo();
    try {
        string = getString(offset, length);
        // Get the Positions in the range being removed.
        posRefs = getPositionsInRange(null, offset, length);
        remove(offset, length);
    } catch (BadLocationException bl) {
      throw new CannotRedoException();
    }
}
 
Example 17
Source Project: jdk8u-jdk   Source File: GapContent.java    License: GNU General Public License v2.0 5 votes vote down vote up
public void redo() throws CannotRedoException {
    super.redo();
    try {
        insertString(offset, string);
        string = null;
        // Update the Positions that were in the range removed.
        if(posRefs != null) {
            updateUndoPositions(posRefs, offset, length);
            posRefs = null;
        }
    } catch (BadLocationException bl) {
        throw new CannotRedoException();
    }
}
 
Example 18
/**
 * Redoes a change.
 *
 * @exception CannotRedoException if the change cannot be redone
 */
public void redo() throws CannotRedoException {
    super.redo();
    MutableAttributeSet as = (MutableAttributeSet)element
                             .getAttributes();
    if(isReplacing)
        as.removeAttributes(as);
    as.addAttributes(newAttributes);
}
 
Example 19
Source Project: MeteoInfo   Source File: FrmMain.java    License: GNU Lesser General Public License v3.0 5 votes vote down vote up
private void jMenuItem_RedoActionPerformed(ActionEvent evt) {
    try {
        currentUndoManager.redo();
    } catch (CannotRedoException cre) {
    }
    this.refreshUndoRedo();
}
 
Example 20
Source Project: Bytecoder   Source File: GapContent.java    License: Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
public void redo() throws CannotRedoException {
    super.redo();
    try {
        string = getString(offset, length);
        // Get the Positions in the range being removed.
        posRefs = getPositionsInRange(null, offset, length);
        remove(offset, length);
    } catch (BadLocationException bl) {
      throw new CannotRedoException();
    }
}
 
Example 21
Source Project: dragonwell8_jdk   Source File: GapContent.java    License: GNU General Public License v2.0 5 votes vote down vote up
public void redo() throws CannotRedoException {
    super.redo();
    try {
        insertString(offset, string);
        string = null;
        // Update the Positions that were in the range removed.
        if(posRefs != null) {
            updateUndoPositions(posRefs, offset, length);
            posRefs = null;
        }
    } catch (BadLocationException bl) {
        throw new CannotRedoException();
    }
}
 
Example 22
@Override
public synchronized void redo() throws CannotRedoException {
    startProgress();
    for (int i = groupEdits.size() - 1; i >= 0; i--) {
        groupEdits.get(i).redo();
    }
    super.redo();
    stopProgress();
}
 
Example 23
/**
 * Redoes a change.
 *
 * @exception CannotRedoException if the change cannot be redone
 */
public void redo() throws CannotRedoException {
    super.redo();
    MutableAttributeSet as = (MutableAttributeSet)element
                             .getAttributes();
    if(isReplacing)
        as.removeAttributes(as);
    as.addAttributes(newAttributes);
}
 
Example 24
Source Project: TencentKona-8   Source File: DiagramScene.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Override
public void redo() throws CannotRedoException {
    super.redo();
    boolean b = scene.getUndoRedoEnabled();
    scene.setUndoRedoEnabled(false);
    scene.getModel().getViewChangedEvent().addListener(this);
    scene.getModel().setData(newModel);
    scene.getModel().getViewChangedEvent().removeListener(this);
    scene.setUndoRedoEnabled(b);
}
 
Example 25
Source Project: TencentKona-8   Source File: GapContent.java    License: GNU General Public License v2.0 5 votes vote down vote up
public void redo() throws CannotRedoException {
    super.redo();
    try {
        string = getString(offset, length);
        // Get the Positions in the range being removed.
        posRefs = getPositionsInRange(null, offset, length);
        remove(offset, length);
    } catch (BadLocationException bl) {
      throw new CannotRedoException();
    }
}
 
Example 26
/**
 * Redoes a change.
 *
 * @exception CannotRedoException if the change cannot be redone
 */
public void redo() throws CannotRedoException {
    super.redo();
    MutableAttributeSet as = (MutableAttributeSet)element
                             .getAttributes();
    if(isReplacing)
        as.removeAttributes(as);
    as.addAttributes(newAttributes);
}
 
Example 27
@Override
public void redo() throws CannotRedoException {
    startProgress();
    if (added) {
        getModel().insertRow(row, values);
    } else {
        getModel().removeRow(row);
    }
    super.redo();
    stopProgress();
}
 
Example 28
Source Project: jdk8u60   Source File: DiagramScene.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Override
public void redo() throws CannotRedoException {
    super.redo();
    boolean b = scene.getUndoRedoEnabled();
    scene.setUndoRedoEnabled(false);
    scene.getModel().getViewChangedEvent().addListener(this);
    scene.getModel().setData(newModel);
    scene.getModel().getViewChangedEvent().removeListener(this);
    scene.setUndoRedoEnabled(b);
}
 
Example 29
Source Project: jdk8u60   Source File: GapContent.java    License: GNU General Public License v2.0 5 votes vote down vote up
public void redo() throws CannotRedoException {
    super.redo();
    try {
        insertString(offset, string);
        string = null;
        // Update the Positions that were in the range removed.
        if(posRefs != null) {
            updateUndoPositions(posRefs, offset, length);
            posRefs = null;
        }
    } catch (BadLocationException bl) {
        throw new CannotRedoException();
    }
}
 
Example 30
Source Project: openjdk-jdk9   Source File: GapContent.java    License: GNU General Public License v2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
public void redo() throws CannotRedoException {
    super.redo();
    try {
        string = getString(offset, length);
        // Get the Positions in the range being removed.
        posRefs = getPositionsInRange(null, offset, length);
        remove(offset, length);
    } catch (BadLocationException bl) {
      throw new CannotRedoException();
    }
}