001package icy.sequence.edit;
002
003import icy.roi.ROI;
004import icy.sequence.Sequence;
005
006import java.util.Collection;
007
008import javax.swing.undo.CannotRedoException;
009import javax.swing.undo.CannotUndoException;
010
011/**
012 * ROI group add Sequence edit event.
013 * 
014 * @author Stephane
015 */
016public class ROIAddsSequenceEdit extends AbstractROIsSequenceEdit
017{
018    public ROIAddsSequenceEdit(Sequence sequence, Collection<ROI> rois, String name)
019    {
020        super(sequence, rois, name);
021    }
022
023    public ROIAddsSequenceEdit(Sequence sequence, Collection<ROI> rois)
024    {
025        this(sequence, rois, (rois.size() > 1) ? "ROI group added" : "ROI added");
026    }
027
028    @Override
029    public void undo() throws CannotUndoException
030    {
031        super.undo();
032
033        final Sequence sequence = getSequence();
034
035        sequence.beginUpdate();
036        try
037        {
038            for (ROI roi : getROIs())
039                sequence.removeROI(roi, false);
040        }
041        finally
042        {
043            sequence.endUpdate();
044        }
045    }
046
047    @Override
048    public void redo() throws CannotRedoException
049    {
050        super.redo();
051
052        final Sequence sequence = getSequence();
053
054        sequence.beginUpdate();
055        try
056        {
057            for (ROI roi : getROIs())
058                sequence.addROI(roi, false);
059        }
060        finally
061        {
062            sequence.endUpdate();
063        }
064    }
065}