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.gui.sequence.tools;
020
021import icy.gui.dialog.ActionDialog;
022import icy.gui.frame.progress.ProgressFrame;
023import icy.gui.util.ComponentUtil;
024import icy.main.Icy;
025import icy.sequence.Sequence;
026import icy.sequence.SequenceUtil;
027import icy.system.thread.ThreadUtil;
028
029import java.awt.BorderLayout;
030import java.awt.event.ActionEvent;
031import java.awt.event.ActionListener;
032
033/**
034 * @author Stephane
035 */
036public class SequenceResizeFrame extends ActionDialog
037{
038    /**
039     * 
040     */
041    private static final long serialVersionUID = -8638672567750415881L;
042
043    final SequenceResizePanel resizePanel;
044
045    public SequenceResizeFrame(Sequence sequence)
046    {
047        super("Image size");
048
049        resizePanel = new SequenceResizePanel(sequence);
050        getMainPanel().add(resizePanel, BorderLayout.CENTER);
051        validate();
052
053        // action
054        setOkAction(new ActionListener()
055        {
056            @Override
057            public void actionPerformed(ActionEvent e)
058            {
059                // launch in background as it can take sometime
060                ThreadUtil.bgRun(new Runnable()
061                {
062                    @Override
063                    public void run()
064                    {
065                        final ProgressFrame pf = new ProgressFrame("Resizing sequence...");
066                        try
067                        {
068                            final Sequence seqOut = SequenceUtil.scale(resizePanel.getSequence(),
069                                    resizePanel.getNewWidth(), resizePanel.getNewHeight(),
070                                    resizePanel.getResizeContent(), resizePanel.getXAlign(), resizePanel.getYAlign(),
071                                    resizePanel.getFilterType());
072
073                            Icy.getMainInterface().addSequence(seqOut);
074                        }
075                        finally
076                        {
077                            pf.close();
078                        }
079                    }
080                });
081            }
082        });
083
084        setSize(420, 520);
085        ComponentUtil.center(this);
086
087        setVisible(true);
088    }
089}