下面列出了怎么用javax.swing.undo.CannotUndoException的API类实例代码及写法,或者点击链接到github查看源代码。
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);
}
void setColorUI(final Color color, boolean allowUndo) {
final Color oldColor = getColor();
if (allowUndo){
AbstractUndoableEdit auEdit = new AbstractUndoableEdit(){
@Override
public void undo() throws CannotUndoException {
super.undo();
setColorUI(oldColor, false);
}
@Override
public void redo() throws CannotRedoException {
super.redo();
setColorUI(color, true);
}
};
ExplorerTopComponent.addUndoableEdit(auEdit);
}
motionDisplayer.setDefaultExperimentalMarkerColor(color);
refreshNode();
}
void setColorUI(final Color color, boolean allowUndo) {
final Color oldColor = getColor();
if (allowUndo){
AbstractUndoableEdit auEdit = new AbstractUndoableEdit(){
@Override
public void undo() throws CannotUndoException {
super.undo();
setColorUI(oldColor, false);
}
@Override
public void redo() throws CannotRedoException {
super.redo();
setColorUI(color, true);
}
};
ExplorerTopComponent.addUndoableEdit(auEdit);
}
motionDisplayer.setDefaultForceColor(color);
refreshNode();
}
@Override
public void deleteFigures(boolean performDelete, Figure... figures) {
Debug.trace("VectorDataFigureEditor.deleteFigures " + performDelete + ", " + figures.length);
if (vectorDataNode != null) {
List<SimpleFeature> simpleFeatures = toSimpleFeatureList(figures);
vectorDataNode.getFeatureCollection().removeAll(simpleFeatures);
getUndoContext().postEdit(new FigureDeleteEdit(this, performDelete, figures) {
@Override
public void undo() throws CannotUndoException {
super.undo();
vectorDataNode.getFeatureCollection().addAll(simpleFeatures);
}
@Override
public void redo() throws CannotRedoException {
super.redo();
vectorDataNode.getFeatureCollection().removeAll(simpleFeatures);
}
});
} else {
// warn
super.deleteFigures(performDelete, figures);
}
}
@Override
public void undo() throws CannotUndoException {
super.undo();
int n = blob.getPointCount();
for (int i = 0; i < n; i++) {
Point2D.Float pi = blob.getPoint(i);
newPoints.add(new Point2D.Float(pi.x, pi.y));
}
blob.setPoints(oldPoints);
view.getModel().refreshPowerArray();
view.getModel().refreshTemperatureBoundaryArray();
view.getModel().refreshMaterialPropertyArrays();
if (view.isViewFactorLinesOn())
view.getModel().generateViewFactorMesh();
view.setSelectedManipulable(selectedManipulable);
view.repaint();
}
@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() {
public void run() {
scene.setScrollPosition(oldScrollPosition);
}
});
scene.setUndoRedoEnabled(b);
}
@Override
public void undo() throws CannotUndoException {
super.undo();
int n = polygon.getVertexCount();
for (int i = 0; i < n; i++) {
Point2D.Float pi = polygon.getVertex(i);
newPoints.add(new Point2D.Float(pi.x, pi.y));
}
polygon.setVertices(oldPoints);
view.getModel().refreshPowerArray();
view.getModel().refreshTemperatureBoundaryArray();
view.getModel().refreshMaterialPropertyArrays();
if (view.isViewFactorLinesOn())
view.getModel().generateViewFactorMesh();
view.setSelectedManipulable(selectedManipulable);
view.repaint();
}
@Override
public void undo() throws CannotUndoException {
super.undo();
comp.deleteLayer(newLayer, false);
comp.setActiveLayer(activeLayerBefore);
viewModeBefore.activate(comp, activeLayerBefore);
}
/**
* Redoes the last undone edit event.
* The UndoRedoManager ignores all incoming UndoableEdit events,
* while redo is in progress.
*/
@Override
public void redo()
throws CannotUndoException {
undoOrRedoInProgress = true;
try {
super.redo();
}
finally {
undoOrRedoInProgress = false;
updateActions();
}
}
@Override
public void perform() throws Exception {
try{
manager.redo();
}catch(CannotUndoException ex){
ex.printStackTrace();
}
}
@Override
public void undo() throws CannotUndoException {
super.undo();
boolean noMoreLeft = path.deleteLastSubPath();
assert wasFirstSP == noMoreLeft;
if (noMoreLeft) {
Tools.PEN.removePath();
}
path.setBuildState(NO_INTERACTION);
comp.repaint();
}
@Override
public void undo() throws CannotUndoException {
if (fireException) {
throw new CannotUndoException();
}
super.undo();
}
@Override
public void redo() throws CannotUndoException {
super.redo();
scene.getDrawings().add(drawing);
setSelectedScene(scene);
goToScene(scene);
trackerPanel.repaint();
}
@Override
public void undo() throws CannotUndoException {
super.undo();
if (selectedManipulable instanceof Part) {
Shape shape = selectedManipulable.getShape();
if (shape instanceof TransformableShape) {
TransformableShape s = (TransformableShape) shape;
switch (flipDirection) {
case 0:
s.flipX();
break;
case 1:
s.flipY();
break;
}
if (s instanceof Blob2D) {
((Blob2D) s).update();
}
model.refreshPowerArray();
model.refreshTemperatureBoundaryArray();
model.refreshMaterialPropertyArrays();
if (view.isViewFactorLinesOn())
model.generateViewFactorMesh();
}
}
view.setSelectedManipulable(selectedManipulable);
view.repaint();
}
@Override public void actionPerformed(ActionEvent e) {
try {
undoManager.undo();
} catch (CannotUndoException ex) {
Toolkit.getDefaultToolkit().beep();
}
}
private void handleConnectionChange(final String oldValue, final String v, boolean supportUndo) {
try {
context.setSocketConnecteePath(connector, v);
} catch (IOException iae) {
new JOptionPane(iae.getMessage(),
JOptionPane.ERROR_MESSAGE).createDialog(null, "Error").setVisible(true);
return; // change failed, no harm done
}
handleConnectionChangeCommon();
if (supportUndo) {
AbstractUndoableEdit auEdit = new AbstractUndoableEdit() {
@Override
public void undo() throws CannotUndoException {
super.undo();
setConnectedToPathAndPropagateChange(oldValue, false);
}
@Override
public String getUndoPresentationName() {
return "Undo "+connector.getName()+" change";
}
@Override
public void redo() throws CannotRedoException {
super.redo();
setConnectedToPathAndPropagateChange(v, true);
}
@Override
public String getRedoPresentationName() {
return "Redo "+connector.getName()+" change";
}
};
ExplorerTopComponent.addUndoableEdit(auEdit);
}
}
/**
* Undoes a change.
*
* @exception CannotUndoException if the change cannot be undone
*/
public void undo() throws CannotUndoException {
super.undo();
MutableAttributeSet as = (MutableAttributeSet)element.getAttributes();
as.removeAttributes(as);
as.addAttributes(copy);
}
private void jButton_ZoomUndoActionPerformed(ActionEvent evt) {
try {
zoomUndoManager.undo();
} catch (CannotUndoException cre) {
}
this.refreshZoomUndoRedo();
}
@Override
public void undo() throws CannotUndoException {
super.undo();
if (selectedManipulable instanceof Part) {
Shape shape = selectedManipulable.getShape();
if (shape instanceof TransformableShape) {
TransformableShape s = (TransformableShape) shape;
s.rotateBy(-rotationAngle);
if (s instanceof Blob2D) {
((Blob2D) s).update();
}
model.refreshPowerArray();
model.refreshTemperatureBoundaryArray();
model.refreshMaterialPropertyArrays();
if (view.isViewFactorLinesOn())
model.generateViewFactorMesh();
}
} else if (selectedManipulable instanceof Particle) {
} else if (selectedManipulable instanceof Fan) {
} else if (selectedManipulable instanceof HeatFluxSensor) {
HeatFluxSensor heatFluxSensor = (HeatFluxSensor) selectedManipulable;
newAngle = heatFluxSensor.getAngle();
heatFluxSensor.setAngle(oldAngle);
}
view.setSelectedManipulable(selectedManipulable);
view.repaint();
}
@Override
public void undo() throws CannotUndoException {
super.undo();
ro.getWorld().addChild(entity);
ro.updateEntityTree();
ro.pickEntity(entity);
}
public void redo() throws CannotUndoException {
super.redo();
launcher.postEdits = false;
launcher.open(args);
launcher.refreshGUI();
launcher.postEdits = true;
}
/**
* Undoes a change.
*
* @exception CannotUndoException if the change cannot be undone
*/
public void undo() throws CannotUndoException {
super.undo();
MutableAttributeSet as = (MutableAttributeSet)element.getAttributes();
as.removeAttributes(as);
as.addAttributes(copy);
}
/**
* Undoes a change.
*
* @exception CannotUndoException if the change cannot be undone
*/
public void undo() throws CannotUndoException {
super.undo();
MutableAttributeSet as = (MutableAttributeSet)element.getAttributes();
as.removeAttributes(as);
as.addAttributes(copy);
}
@Override
public void undo() throws CannotUndoException {
super.undo();
if(toBeEdited == null){
this.editor.getElementEditor().setAttribute(attribute, oldValue);
}else{
this.editor.getElementEditor(toBeEdited).setAttribute(attribute, oldValue);
}
}
@Override
public void undo() throws CannotUndoException {
super.undo();
subPath.deleteLast();
comp.repaint();
}
@Override
public void undo() throws CannotUndoException {
if (!canUndo()) {
throw new CannotUndoException();
}
MyCompoundEdit u=edits.get(pointer);
u.undo();
pointer--;
refreshControls();
}
public void undo() throws CannotUndoException {
super.undo();
try {
// Get the Positions in the range being removed.
posRefs = getPositionsInRange(null, offset, length);
string = getString(offset, length);
remove(offset, length);
} catch (BadLocationException bl) {
throw new CannotUndoException();
}
}
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();
}
}
@Override
public synchronized void undo() throws CannotUndoException {
super.undo();
for ( UndoRedoListener listener: list ) {
listener.redoHappened();
}
}
/**
* Undoes a change.
*
* @exception CannotUndoException if the change cannot be undone
*/
public void undo() throws CannotUndoException {
super.undo();
MutableAttributeSet as = (MutableAttributeSet)element.getAttributes();
as.removeAttributes(as);
as.addAttributes(copy);
}