Java Code Examples for javax.swing.undo.CannotUndoException

The following examples show how to use javax.swing.undo.CannotUndoException. 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: netbeans   Source File: DocumentTesting.java    License: Apache License 2.0 6 votes vote down vote up
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);
}
 
Example 2
Source Project: opensim-gui   Source File: ExperimentalMarkerSetNode.java    License: Apache License 2.0 6 votes vote down vote up
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();
}
 
Example 3
Source Project: opensim-gui   Source File: ExperimentalForceSetNode.java    License: Apache License 2.0 6 votes vote down vote up
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();
}
 
Example 4
@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);
    }
}
 
Example 5
Source Project: energy2d   Source File: UndoEditBlob.java    License: GNU Lesser General Public License v3.0 6 votes vote down vote up
@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();
}
 
Example 6
Source Project: openjdk-8   Source File: DiagramScene.java    License: GNU General Public License v2.0 6 votes vote down vote up
@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);
}
 
Example 7
@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();
}
 
Example 8
Source Project: Pixelitor   Source File: NewLayerEdit.java    License: GNU General Public License v3.0 5 votes vote down vote up
@Override
public void undo() throws CannotUndoException {
    super.undo();

    comp.deleteLayer(newLayer, false);
    comp.setActiveLayer(activeLayerBefore);

    viewModeBefore.activate(comp, activeLayerBefore);
}
 
Example 9
Source Project: openAGV   Source File: UndoRedoManager.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 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();
  }
}
 
Example 10
Source Project: niftyeditor   Source File: RedoCommand.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void perform() throws Exception {
    try{
        manager.redo();
    }catch(CannotUndoException ex){
        ex.printStackTrace(); 
    }
}
 
Example 11
Source Project: Pixelitor   Source File: SubPathStartEdit.java    License: GNU General Public License v3.0 5 votes vote down vote up
@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();
}
 
Example 12
Source Project: netbeans   Source File: StableCompoundEditTest.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void undo() throws CannotUndoException {
    if (fireException) {
        throw new CannotUndoException();
    }
    super.undo();
}
 
Example 13
Source Project: tracker   Source File: PencilControl.java    License: GNU General Public License v3.0 5 votes vote down vote up
@Override
public void redo() throws CannotUndoException {
  super.redo();
  scene.getDrawings().add(drawing);
  setSelectedScene(scene);
  goToScene(scene);
  trackerPanel.repaint();
}
 
Example 14
@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();
}
 
Example 15
Source Project: java-swing-tips   Source File: MainPanel.java    License: MIT License 5 votes vote down vote up
@Override public void actionPerformed(ActionEvent e) {
  try {
    undoManager.undo();
  } catch (CannotUndoException ex) {
    Toolkit.getDefaultToolkit().beep();
  }
}
 
Example 16
Source Project: opensim-gui   Source File: ConnectionEditor.java    License: Apache License 2.0 5 votes vote down vote up
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);
        }
    }
 
Example 17
/**
 * 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);
}
 
Example 18
Source Project: MeteoInfo   Source File: FrmMain.java    License: GNU Lesser General Public License v3.0 5 votes vote down vote up
private void jButton_ZoomUndoActionPerformed(ActionEvent evt) {
    try {
        zoomUndoManager.undo();
    } catch (CannotUndoException cre) {
    }
    this.refreshZoomUndoRedo();
}
 
Example 19
@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();
}
 
Example 20
@Override
public void undo() throws CannotUndoException {
	super.undo();
	ro.getWorld().addChild(entity);
	ro.updateEntityTree();
	ro.pickEntity(entity);
}
 
Example 21
Source Project: osp   Source File: LauncherUndo.java    License: GNU General Public License v3.0 5 votes vote down vote up
public void redo() throws CannotUndoException {
  super.redo();
  launcher.postEdits = false;
  launcher.open(args);
  launcher.refreshGUI();
  launcher.postEdits = true;
}
 
Example 22
/**
 * 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);
}
 
Example 23
Source Project: JDKSourceCode1.8   Source File: DefaultStyledDocument.java    License: MIT License 5 votes vote down vote up
/**
 * 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);
}
 
Example 24
Source Project: niftyeditor   Source File: EditAttributeCommand.java    License: Apache License 2.0 5 votes vote down vote up
@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);
    }
    
}
 
Example 25
Source Project: Pixelitor   Source File: AddAnchorPointEdit.java    License: GNU General Public License v3.0 5 votes vote down vote up
@Override
public void undo() throws CannotUndoException {
    super.undo();

    subPath.deleteLast();

    comp.repaint();
}
 
Example 26
Source Project: SikuliX1   Source File: EditorUndoManager.java    License: MIT License 5 votes vote down vote up
@Override
public void undo() throws CannotUndoException {
   if (!canUndo()) {
      throw new CannotUndoException();
   }

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

   refreshControls();
}
 
Example 27
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();
    }
}
 
Example 28
Source Project: openjdk-jdk8u   Source File: GapContent.java    License: GNU General Public License v2.0 5 votes vote down vote up
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();
    }
}
 
Example 29
Source Project: gameserver   Source File: MyUndoManager.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public synchronized void undo() throws CannotUndoException {
	super.undo();
	for ( UndoRedoListener listener: list ) {
		listener.redoHappened();
	}
}
 
Example 30
/**
 * 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);
}