001/*
002 * Copyright 2010, 2011 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 plugins.tutorial.painter;
020
021import icy.canvas.IcyCanvas;
022import icy.canvas.IcyCanvas2D;
023import icy.gui.dialog.MessageDialog;
024import icy.gui.frame.progress.AnnounceFrame;
025import icy.painter.Overlay;
026import icy.plugin.abstract_.PluginActionable;
027import icy.sequence.Sequence;
028import icy.type.point.Point5D;
029
030import java.awt.event.MouseEvent;
031
032/**
033 * This tutorial displays a fancy marked animation at each click.
034 * 
035 * @author Fabrice de Chaumont
036 * @author Stephane Dallongeville
037 */
038public class AnimatedOverlayTutorial extends PluginActionable
039{
040    @Override
041    public void run()
042    {
043        // Get the current sequence focused. Stored to remove
044        Sequence sequence = getActiveSequence();
045
046        if (sequence == null) // no sequence has been found.
047        {
048            MessageDialog.showDialog("This example needs a sequence to start. Please load an image file.",
049                    MessageDialog.INFORMATION_MESSAGE);
050            return;
051        }
052
053        new AnnounceFrame("Click over image to put marks");
054
055        // we add a painter which will listen to mouse click and create the OneMarkPainter objects.
056        sequence.addOverlay(new ListeningClickOverlay());
057    }
058
059    /**
060     * This inner class is designed to listen to click event on a sequence, and place a
061     * OneMarkPainter on it.
062     */
063    class ListeningClickOverlay extends Overlay
064    {
065        public ListeningClickOverlay()
066        {
067            super("Click test overlay");
068        }
069
070        @Override
071        public void mouseClick(MouseEvent e, Point5D.Double imagePoint, IcyCanvas canvas)
072        {
073            // check if we are dealing with a 2D canvas and we have a valid image position
074            if ((canvas instanceof IcyCanvas2D) && (imagePoint != null))
075            {
076                // get all sequence where the overlay is attached
077                for (Sequence sequence : getSequences())
078                    sequence.addOverlay(new AnimatedOverlay(imagePoint.toPoint2D()));
079            }
080        }
081    }
082}