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.menu.tools; 020 021import icy.gui.dialog.MessageDialog; 022import icy.gui.viewer.Viewer; 023import icy.main.Icy; 024import icy.roi.ROI; 025import icy.sequence.Sequence; 026import icy.sequence.SequenceUtil; 027import icy.system.thread.ThreadUtil; 028 029import java.util.List; 030 031/** 032 * @deprecated Use {@link SequenceUtil#getSubSequence(Sequence, ROI)} instead. 033 */ 034@Deprecated 035public class SequenceCropper 036{ 037 private SequenceCropper() 038 { 039 super(); 040 } 041 042 /** 043 * @deprecated Use {@link SequenceUtil#getSubSequence(Sequence, ROI)} instead. 044 */ 045 @Deprecated 046 public static boolean doRoiCrop() 047 { 048 final Viewer viewer = Icy.getMainInterface().getActiveViewer(); 049 if (viewer == null) 050 return false; 051 052 final Sequence seq = viewer.getSequence(); 053 if (seq == null) 054 return false; 055 056 List<ROI> rois = seq.getROIs(); 057 int size = rois.size(); 058 059 if (size == 0) 060 { 061 MessageDialog.showDialog("There is no ROI in the current sequence.\nCrop operation need a ROI.", 062 MessageDialog.INFORMATION_MESSAGE); 063 return false; 064 } 065 else if (size > 1) 066 { 067 rois = seq.getSelectedROIs(); 068 size = rois.size(); 069 070 if (size == 0) 071 { 072 MessageDialog.showDialog("You need to select a ROI to do the crop operation.", 073 MessageDialog.INFORMATION_MESSAGE); 074 return false; 075 } 076 else if (size > 1) 077 { 078 MessageDialog.showDialog("You must have only one selected ROI to do the crop operation.", 079 MessageDialog.INFORMATION_MESSAGE); 080 return false; 081 } 082 } 083 084 return doRoiCrop(viewer, rois.get(0)); 085 } 086 087 /** 088 * @deprecated Use {@link SequenceUtil#getSubSequence(Sequence, ROI)} instead. 089 */ 090 @Deprecated 091 public static boolean doRoiCrop(final Viewer viewer, final ROI roi) 092 { 093 final Sequence seq = viewer.getSequence(); 094 if (seq == null) 095 return false; 096 097 ThreadUtil.bgRun(new Runnable() 098 { 099 @Override 100 public void run() 101 { 102 103 // create output sequence 104 final Sequence out = SequenceUtil.getSubSequence(seq, roi); 105 106 ThreadUtil.invokeLater(new Runnable() 107 { 108 @Override 109 public void run() 110 { 111 // get output viewer 112 final Viewer vout = new Viewer(out); 113 // copy colormap from input viewer 114 vout.getLut().copyFrom(viewer.getLut()); 115 } 116 }); 117 } 118 }); 119 120 return true; 121 } 122}