001/** 002 * 003 */ 004package icy.roi.edit; 005 006import icy.painter.Anchor3D; 007import icy.roi.ROI3D; 008import icy.type.point.Point3D; 009 010import javax.swing.undo.CannotRedoException; 011import javax.swing.undo.CannotUndoException; 012import javax.swing.undo.UndoableEdit; 013 014import plugins.kernel.roi.roi3d.ROI3DPolyLine; 015 016/** 017 * 3D control point added implementation for ROI undoable edition. 018 * 019 * @author Stephane 020 */ 021public class Point3DAddedROIEdit extends AbstractPoint3DROIEdit 022{ 023 Point3D position; 024 final int index; 025 026 public Point3DAddedROIEdit(ROI3D roi, Anchor3D point) 027 { 028 super(roi, point, "ROI point added"); 029 030 position = point.getPosition(); 031 032 if (roi instanceof ROI3DPolyLine) 033 index = ((ROI3DPolyLine) roi).getControlPoints().indexOf(point); 034 else 035 throw new IllegalArgumentException("Point3DAddedROIEdit: " + roi.getClassName() + " class not supported !"); 036 } 037 038 @Override 039 public void undo() throws CannotUndoException 040 { 041 super.undo(); 042 043 // undo 044 if (getROI3D() instanceof ROI3DPolyLine) 045 { 046 final ROI3DPolyLine roi = (ROI3DPolyLine) getROI3D(); 047 roi.removePoint(point); 048 } 049 } 050 051 @Override 052 public void redo() throws CannotRedoException 053 { 054 super.redo(); 055 056 // redo 057 point.setPosition(position); 058 if (getROI3D() instanceof ROI3DPolyLine) 059 { 060 final ROI3DPolyLine roi = (ROI3DPolyLine) getROI3D(); 061 roi.addPoint(point, Math.min(index, roi.getControlPoints().size())); 062 } 063 } 064 065 @Override 066 public boolean addEdit(UndoableEdit edit) 067 { 068 // don't collapse here 069 return false; 070 } 071 072 @Override 073 public void die() 074 { 075 super.die(); 076 077 position = null; 078 } 079}