diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..3d47f986c41db29ec6dc0d5036bf760b3a1cf366 --- /dev/null +++ b/.gitignore @@ -0,0 +1,6 @@ +.idea/ +target/ +.settings/ +*.iml +.project +.classpath \ No newline at end of file diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000000000000000000000000000000000000..08aa7c1470853736820fea96ea3a09061c959117 --- /dev/null +++ b/pom.xml @@ -0,0 +1,89 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + + <!-- Inherited Icy Parent POM --> + <parent> + <groupId>org.bioimageanalysis.icy</groupId> + <artifactId>parent-pom-plugin</artifactId> + <version>1.0.3</version> + </parent> + + <!-- Project Information --> + <artifactId>track-processor-excel-export</artifactId> + <version>1.2.1</version> + + <packaging>jar</packaging> + + <name>Track Processor Export Track to Excel</name> + <description>This processor exports the tracks in an xls file (compatible with Protocols) </description> + <url>http://icy.bioimageanalysis.org/plugin/track-processor-export-track-to-excel/</url> + <inceptionYear>2020</inceptionYear> + + <organization> + <name>Institut Pasteur</name> + <url>https://pasteur.fr</url> + </organization> + + <licenses> + <license> + <name>GNU GPLv3</name> + <url>https://www.gnu.org/licenses/gpl-3.0.en.html</url> + <distribution>repo</distribution> + </license> + </licenses> + + <developers> + <developer> + <id>sdallongeville</id> + <name>Stéphane Dallongeville</name> + <url>https://research.pasteur.fr/fr/member/stephane-dallongeville/</url> + <roles> + <role>founder</role> + <role>lead</role> + <role>architect</role> + <role>developer</role> + <role>debugger</role> + <role>tester</role> + <role>maintainer</role> + <role>support</role> + </roles> + </developer> + </developers> + + <!-- Project properties --> + <properties> + + </properties> + + <!-- Project build configuration --> + <build> + + </build> + + <!-- List of project's dependencies --> + <dependencies> + <!-- The core of Icy --> + <dependency> + <groupId>org.bioimageanalysis.icy</groupId> + <artifactId>icy-kernel</artifactId> + </dependency> + + <dependency> + <groupId>org.bioimageanalysis.icy</groupId> + <artifactId>track-manager</artifactId> + <version>1.4.6</version> + </dependency> + </dependencies> + + <!-- Icy Maven repository (to find parent POM) --> + <repositories> + <repository> + <id>icy</id> + <name>Icy's Nexus</name> + <url>https://icy-nexus.pasteur.fr/repository/Icy/</url> + </repository> + </repositories> +</project> diff --git a/src/main/java/plugins/fab/trackmanager/processors/TrackProcessorExportTrackToXLS.java b/src/main/java/plugins/fab/trackmanager/processors/TrackProcessorExportTrackToXLS.java new file mode 100644 index 0000000000000000000000000000000000000000..d83f27395ab3f8cd9567ef8133c053efc54340fb --- /dev/null +++ b/src/main/java/plugins/fab/trackmanager/processors/TrackProcessorExportTrackToXLS.java @@ -0,0 +1,128 @@ +package plugins.fab.trackmanager.processors; + +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.io.File; +import java.util.ArrayList; +import java.util.List; + +import javax.swing.BoxLayout; +import javax.swing.JButton; +import javax.swing.JFileChooser; + +import icy.gui.dialog.MessageDialog; +import icy.gui.util.GuiUtil; +import icy.main.Icy; +import icy.system.IcyExceptionHandler; +import icy.util.XLSUtil; +import jxl.write.WritableSheet; +import jxl.write.WritableWorkbook; +import plugins.fab.trackmanager.PluginTrackManagerProcessor; +import plugins.fab.trackmanager.TrackSegment; +import plugins.nchenouard.spot.Detection; + +public class TrackProcessorExportTrackToXLS extends PluginTrackManagerProcessor implements ActionListener +{ + public TrackProcessorExportTrackToXLS() + { + JButton exportTracksToXLSButton = new JButton("export tracks to excel"); + setName("Export Tracks to XLS"); + + panel.setLayout(new BoxLayout(panel, BoxLayout.PAGE_AXIS)); + panel.add(GuiUtil.createLineBoxPanel(exportTracksToXLSButton)); + exportTracksToXLSButton.addActionListener(this); + } + + @Override + public void Close() + { + // + } + + @Override + public void Compute() + { + // + } + + @Override + public void displaySequenceChanged() + { + // + } + + @Override + public void actionPerformed(ActionEvent e) + { + exportToXLS(new ArrayList<TrackSegment>(trackPool.getTrackSegmentList())); + } + + private static void exportToXLS(List<TrackSegment> tracks) + { + JFileChooser chooser = new JFileChooser(); + chooser.setDialogTitle("Select xls file."); + + int returnVal = chooser.showOpenDialog(null); + if (returnVal != JFileChooser.APPROVE_OPTION) + return; + + exportToXLS(tracks, chooser.getSelectedFile()); + } + + public static boolean exportToXLS(List<TrackSegment> trackSegmentList, File file) + { + try + { + final WritableWorkbook doc = XLSUtil.loadWorkbookForWrite(file); + final WritableSheet sh = XLSUtil.createNewPage(doc, "Tracks"); + int cursorY = 0; + + for (TrackSegment ts : trackSegmentList) + { + cursorY++; + XLSUtil.setCellString(sh, 0, cursorY, "track #"); + XLSUtil.setCellNumber(sh, 1, cursorY, trackSegmentList.indexOf(ts)); + cursorY++; + + XLSUtil.setCellString(sh, 2, cursorY, "t"); + XLSUtil.setCellString(sh, 3, cursorY, "x"); + XLSUtil.setCellString(sh, 4, cursorY, "y"); + XLSUtil.setCellString(sh, 5, cursorY, "z"); + XLSUtil.setCellString(sh, 6, cursorY, "virtual"); + cursorY++; + + ArrayList<Detection> detectionList = ts.getDetectionList(); + + for (int i = 0; i < detectionList.size(); i++) + { + final Detection d = detectionList.get(i); + + if (d.isEnabled()) + { + XLSUtil.setCellNumber(sh, 2, cursorY, d.getT()); + XLSUtil.setCellNumber(sh, 3, cursorY, d.getX()); + XLSUtil.setCellNumber(sh, 4, cursorY, d.getY()); + XLSUtil.setCellNumber(sh, 5, cursorY, d.getZ()); + XLSUtil.setCellNumber(sh, 6, cursorY, + (d.getDetectionType() == Detection.DETECTIONTYPE_VIRTUAL_DETECTION) ? 1 : 0); + + cursorY++; + } + } + } + + XLSUtil.saveAndClose(doc); + } + catch (Exception e) + { + if (Icy.getMainInterface().isHeadLess()) + IcyExceptionHandler.showErrorMessage(e, true); + else + MessageDialog.showDialog("Cannot open file.", MessageDialog.ERROR_MESSAGE); + + return false; + } + + return true; + } +} diff --git a/src/main/java/plugins/fab/trackmanager/processors/TrackXLSExport.java b/src/main/java/plugins/fab/trackmanager/processors/TrackXLSExport.java new file mode 100644 index 0000000000000000000000000000000000000000..703ada81cc4a70012eea92259d1ab7b6e07ba7e9 --- /dev/null +++ b/src/main/java/plugins/fab/trackmanager/processors/TrackXLSExport.java @@ -0,0 +1,79 @@ +/** + * + */ +package plugins.fab.trackmanager.processors; + +import icy.plugin.abstract_.Plugin; +import icy.plugin.interface_.PluginBundled; + +import java.io.File; + +import plugins.adufour.blocks.lang.Block; +import plugins.adufour.blocks.util.VarList; +import plugins.adufour.vars.lang.Var; +import plugins.adufour.vars.lang.VarMutable; +import plugins.fab.trackmanager.TrackGroup; + +/** + * Block (Protocols) to export Tracks (TrackGroup) in XLS format. + * + * @author Stephane + */ +public class TrackXLSExport extends Plugin implements Block, PluginBundled +{ + public final VarMutable file; + public final Var<TrackGroup> tracks; + + public TrackXLSExport() + { + super(); + + file = new VarMutable("Output file", null) + { + @Override + public boolean isAssignableFrom(@SuppressWarnings("rawtypes") Var source) + { + return (String.class == source.getType()) || (File.class == source.getType()); + } + }; + tracks = new Var<TrackGroup>("TrackGroup", new TrackGroup(null)); + } + + @Override + public void declareInput(VarList inputMap) + { + inputMap.add("tracks", tracks); + inputMap.add("file", file); + } + + @Override + public void declareOutput(VarList outputMap) + { + // + } + + @Override + public void run() + { + final Object obj = file.getValue(); + final TrackGroup tg = tracks.getValue(); + + if ((obj != null) && (tg != null)) + { + final File f; + + if (obj instanceof String) + f = new File((String) obj); + else + f = (File) obj; + + TrackProcessorExportTrackToXLS.exportToXLS(tg.getTrackSegmentList(), f); + } + } + + @Override + public String getMainPluginClassName() + { + return TrackProcessorExportTrackToXLS.class.getName(); + } +}