下面列出了javax.swing.undo.AbstractUndoableEdit#javax.swing.undo.CannotRedoException 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@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);
}
});
}
@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);
}
});
}
@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();
}
}
}
}
@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);
}
}
}
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 ();
}
}
/** 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);
}
}
}
@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();
}
}
}
}
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);
}
@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);
}
/**
* 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();
}
}
@Override
public void actionPerformed(ActionEvent evt) {
try {
redo();
}
catch (CannotRedoException e) {
LOG.debug("Cannot redo: {}", e);
}
}
@Override
public void redo()
throws CannotRedoException {
super.redo();
// TODO: Delete again ...
for (UserObject userObject : userObjects) {
userObject.removed();
}
}
@Override
public void redo()
throws CannotRedoException {
super.redo();
pxModel.copyFrom(pxAfterModification);
pyModel.copyFrom(pyAfterModification);
pxModel.markChanged();
pyModel.markChanged();
saveTransformForRedo();
pxModel.getModel().propertiesChanged(new NullAttributesChangeListener());
}
@Override
public void redo() throws CannotRedoException {
fProperty.copyFrom(fAfterModification);
fProperty.markChanged();
fProperty.getModel().propertiesChanged(new NullAttributesChangeListener());
hasBeenDone = true;
}
@Override
public void redo() throws CannotRedoException {
super.redo();
for (Figure figure : figures) {
drawingView.getDrawing().remove(figure);
}
}
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();
}
}
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();
}
}
/**
* 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);
}
private void jMenuItem_RedoActionPerformed(ActionEvent evt) {
try {
currentUndoManager.redo();
} catch (CannotRedoException cre) {
}
this.refreshUndoRedo();
}
@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();
}
}
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();
}
}
@Override
public synchronized void redo() throws CannotRedoException {
startProgress();
for (int i = groupEdits.size() - 1; i >= 0; i--) {
groupEdits.get(i).redo();
}
super.redo();
stopProgress();
}
/**
* 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);
}
@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);
}
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();
}
}
/**
* 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);
}
@Override
public void redo() throws CannotRedoException {
startProgress();
if (added) {
getModel().insertRow(row, values);
} else {
getModel().removeRow(row);
}
super.redo();
stopProgress();
}
@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);
}
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();
}
}
@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();
}
}