001/*
002 * Copyright 2010-2015 Institut Pasteur.
003 * 
004 * This file is part of Icy.
005 * 
006 * Icy is free software: you can redistribute it and/or modify
007 * it under the terms of the GNU General Public License as published by
008 * the Free Software Foundation, either version 3 of the License, or
009 * (at your option) any later version.
010 * 
011 * Icy is distributed in the hope that it will be useful,
012 * but WITHOUT ANY WARRANTY; without even the implied warranty of
013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
014 * GNU General Public License for more details.
015 * 
016 * You should have received a copy of the GNU General Public License
017 * along with Icy. If not, see <http://www.gnu.org/licenses/>.
018 */
019package icy.roi;
020
021import icy.painter.Anchor2D;
022import icy.util.ShapeUtil;
023import icy.util.ShapeUtil.BooleanOperator;
024import icy.util.ShapeUtil.ShapeOperation;
025
026import java.awt.Shape;
027import java.awt.geom.Point2D;
028import java.util.ArrayList;
029import java.util.Arrays;
030import java.util.List;
031
032/**
033 * @deprecated Use {@link plugins.kernel.roi.roi2d.ROI2DShape} instead.
034 */
035@Deprecated
036public abstract class ROI2DShape extends plugins.kernel.roi.roi2d.ROI2DShape
037{
038    /**
039     * @deprecated Use {@link ROIUtil#merge(List, BooleanOperator)} instead.
040     */
041    @Deprecated
042    public static ROI2DPath merge(ROI2DShape[] rois, ShapeOperation operation)
043    {
044        return merge(Arrays.asList(rois), operation.getBooleanOperator());
045    }
046
047    /**
048     * @deprecated Use {@link ROIUtil#merge(List, BooleanOperator)} instead.
049     */
050    @Deprecated
051    public static ROI2DPath merge(List<ROI2DShape> rois, BooleanOperator operator)
052    {
053        final List<Shape> shapes = new ArrayList<Shape>(rois.size());
054
055        for (ROI2DShape roi : rois)
056            shapes.add(roi.getShape());
057
058        final ROI2DPath result = new ROI2DPath(ShapeUtil.merge(shapes, operator));
059
060        switch (operator)
061        {
062            case OR:
063                result.setName("Union");
064                break;
065            case AND:
066                result.setName("Intersection");
067                break;
068            case XOR:
069                result.setName("Exclusive union");
070                break;
071            default:
072                result.setName("Merge");
073                break;
074        }
075
076        return result;
077    }
078
079    /**
080     * @deprecated Use {@link ROI#getSubtraction(ROI)} instead.
081     */
082    @Deprecated
083    public static ROI2DPath subtract(ROI2DShape roi1, ROI2DShape roi2)
084    {
085        final ROI2DPath result = new ROI2DPath(ShapeUtil.subtract(roi1, roi2));
086
087        result.setName("Substraction");
088
089        return result;
090    }
091
092    /**
093     * @deprecated Use {@link ROI#getSubtraction(ROI)} instead.
094     */
095    @Deprecated
096    public static ROI2DPath substract(ROI2DShape roi1, ROI2DShape roi2)
097    {
098        return subtract(roi1, roi2);
099    }
100
101    /**
102     * @deprecated Use {@link plugins.kernel.roi.roi2d.ROI2DShape.ROI2DShapePainter} instead.
103     */
104    @Deprecated
105    protected class ROI2DShapePainter extends plugins.kernel.roi.roi2d.ROI2DShape.ROI2DShapePainter
106    {
107        public ROI2DShapePainter()
108        {
109            super();
110        }
111    }
112
113    public ROI2DShape(Shape shape)
114    {
115        super(shape);
116    }
117
118    @Override
119    protected ROI2DShapePainter createPainter()
120    {
121        return new ROI2DShapePainter();
122    }
123
124    @Override
125    protected Anchor2D createAnchor(Point2D pos)
126    {
127        return new Anchor2D(pos.getX(), pos.getY(), getColor(), getFocusedColor());
128    }
129
130    @Override
131    protected Anchor2D createAnchor(double x, double y)
132    {
133        return createAnchor(new Point2D.Double(x, y));
134    }
135}