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;
020
021import icy.gui.dialog.ActionDialog;
022import icy.gui.dialog.MessageDialog;
023import icy.main.Icy;
024import icy.math.UnitUtil;
025import icy.math.UnitUtil.UnitPrefix;
026import icy.sequence.Sequence;
027
028import java.awt.BorderLayout;
029import java.awt.event.ActionEvent;
030import java.awt.event.ActionListener;
031
032/**
033 * @author Stephane
034 */
035public class SequencePropertiesDialog extends ActionDialog
036{
037    /**
038     * 
039     */
040    private static final long serialVersionUID = 5696186054980120411L;
041
042    SequencePropertiesPanel panel;
043
044    public SequencePropertiesDialog(final Sequence sequence)
045    {
046        super("Sequence Properties");
047
048        initialize();
049
050        panel.setSequence(sequence);
051        // don't close automatically
052        setCloseAfterAction(false);
053
054        setOkAction(new ActionListener()
055        {
056            @Override
057            public void actionPerformed(ActionEvent e)
058            {
059                final double sx, sy, sz, st;
060
061                sx = panel.getPixelSizeXFieldValue();
062                sy = panel.getPixelSizeYFieldValue();
063                sz = panel.getPixelSizeZFieldValue();
064                st = panel.getTimeIntervalFieldValue();
065
066                if ((sx <= 0d) || (sy <= 0d) || (sz <= 0d))
067                {
068                    MessageDialog.showDialog("Pixel size values should be > 0 !", MessageDialog.WARNING_MESSAGE);
069                    return;
070                }
071
072                sequence.setName(panel.getNameFieldValue());
073                sequence.setPixelSizeX(UnitUtil.getValueInUnit(sx, panel.getPixelSizeXUnit(), UnitPrefix.MICRO));
074                sequence.setPixelSizeY(UnitUtil.getValueInUnit(sy, panel.getPixelSizeYUnit(), UnitPrefix.MICRO));
075                sequence.setPixelSizeZ(UnitUtil.getValueInUnit(sz, panel.getPixelSizeZUnit(), UnitPrefix.MICRO));
076
077                double valueInSec = st;
078
079                switch (panel.getTimeIntervalUnit())
080                {
081                    case 0:
082                        valueInSec *= 60d;
083                    case 1:
084                        valueInSec *= 60d;
085                        break;
086                    case 3:
087                        valueInSec /= 1000d;
088                        break;
089                }
090
091                // time interval
092                sequence.setTimeInterval(valueInSec);
093
094                // position
095                sequence.setPositionX(UnitUtil.getValueInUnit(panel.getPositionXValue(), panel.getPositionXUnit(),
096                        UnitPrefix.MICRO));
097                sequence.setPositionY(UnitUtil.getValueInUnit(panel.getPositionYValue(), panel.getPositionYUnit(),
098                        UnitPrefix.MICRO));
099                sequence.setPositionZ(UnitUtil.getValueInUnit(panel.getPositionZValue(), panel.getPositionZUnit(),
100                        UnitPrefix.MICRO));
101
102                // channel name
103                for (int c = 0; c < sequence.getSizeC(); c++)
104                    sequence.setChannelName(c, panel.getChannelNameFieldValue(c));
105
106                dispose();
107            }
108        });
109
110        pack();
111        setLocationRelativeTo(Icy.getMainInterface().getMainFrame());
112        setVisible(true);
113    }
114
115    private void initialize()
116    {
117        panel = new SequencePropertiesPanel();
118
119        mainPanel.setLayout(new BorderLayout());
120        mainPanel.add(panel, BorderLayout.CENTER);
121        mainPanel.validate();
122    }
123}