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 SequenceCanvasResizeFrame extends ActionDialog 037{ 038 /** 039 * 040 */ 041 private static final long serialVersionUID = -430346980166539623L; 042 043 final SequenceCanvasResizePanel resizePanel; 044 045 public SequenceCanvasResizeFrame(Sequence sequence) 046 { 047 super("Canvas size"); 048 049 resizePanel = new SequenceCanvasResizePanel(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 Icy.getMainInterface().addSequence( 069 SequenceUtil.scale(resizePanel.getSequence(), resizePanel.getNewWidth(), 070 resizePanel.getNewHeight(), resizePanel.getResizeContent(), 071 resizePanel.getXAlign(), resizePanel.getYAlign(), 072 resizePanel.getFilterType())); 073 } 074 finally 075 { 076 pf.close(); 077 } 078 } 079 }); 080 } 081 }); 082 083 setSize(420, 520); 084 ComponentUtil.center(this); 085 086 setVisible(true); 087 } 088}