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.gui;
020
021import icy.gui.dialog.MessageDialog;
022import icy.gui.frame.sequence.SequenceActionFrame;
023import icy.plugin.abstract_.PluginActionable;
024import icy.sequence.Sequence;
025
026import java.awt.event.ActionEvent;
027import java.awt.event.ActionListener;
028
029import javax.swing.JLabel;
030
031/**
032 * This example demonstrates a simple use of the SequenceActionFrame object
033 * 
034 * @author Stephane
035 * @author Fab
036 */
037public class SequenceActionFrameExample extends PluginActionable
038{
039    @Override
040    public void run()
041    {
042        // build a default action frame
043        final SequenceActionFrame mainFrame = new SequenceActionFrame("Example", true);
044
045        // define action to do when OK button is pressed
046        mainFrame.setOkAction(new ActionListener()
047        {
048            @Override
049            public void actionPerformed(ActionEvent e)
050            {
051                // get selected sequence
052                final Sequence sequence = mainFrame.getSequence();
053
054                // no sequence
055                if (sequence == null)
056                    MessageDialog.showDialog("No sequence selected");
057                else
058                    MessageDialog.showDialog("You have selected : " + sequence.getName());
059            }
060        });
061
062        // define if the frame should be closed after OK action is done (default = true)
063        mainFrame.setCloseAfterAction(true);
064
065        // build your GUI here
066        mainFrame.getMainPanel().add(new JLabel("Set whatever you want here"));
067
068        // add the frame to the interface
069        addIcyFrame(mainFrame);
070        // center frame
071        mainFrame.center();
072        // make it visible
073        mainFrame.setVisible(true);
074        // and get focus
075        mainFrame.requestFocus();
076    }
077}