001/**
002 * 
003 */
004package plugins.tutorial.training;
005
006import icy.canvas.IcyCanvas;
007import icy.gui.dialog.MessageDialog;
008import icy.painter.Overlay;
009import icy.plugin.abstract_.PluginActionable;
010import icy.sequence.Sequence;
011import icy.type.point.Point5D;
012
013import java.awt.BasicStroke;
014import java.awt.Color;
015import java.awt.Graphics2D;
016import java.awt.event.MouseEvent;
017
018/**
019 * @author Stephane
020 */
021public class OverlayPlugin1 extends PluginActionable
022{
023    public class SimpleCrossOverlay extends Overlay
024    {
025        public SimpleCrossOverlay()
026        {
027            super("Simple cross");
028        }
029
030        @Override
031        public void paint(Graphics2D g, Sequence sequence, IcyCanvas canvas)
032        {
033            if (g != null)
034            {
035                // paint a yellow cross all over the image
036                g.setColor(Color.YELLOW);
037                g.setStroke(new BasicStroke(5));
038                g.drawLine(0, 0, sequence.getWidth(), sequence.getHeight());
039                g.drawLine(0, sequence.getHeight(), sequence.getWidth(), 0);
040            }
041        }
042
043        @Override
044        public void mouseClick(MouseEvent e, Point5D.Double point, IcyCanvas canvas)
045        {
046            // remove the overlay when the user clicks on the image
047            remove();
048        }
049    }
050
051    @Override
052    public void run()
053    {// get the current sequence having focus.
054        Sequence sequence = getActiveSequence();
055
056        // check if a sequence is opened
057        if (sequence == null)
058        {
059            MessageDialog.showDialog("Please open a sequence to use this plugin.", MessageDialog.WARNING_MESSAGE);
060            return;
061        }
062
063        sequence.addOverlay(new SimpleCrossOverlay());
064    }
065}