diff --git a/view-simulation-results/src/main/java/org/vcell/N5/LoadingFactory.java b/view-simulation-results/src/main/java/org/vcell/N5/LoadingFactory.java new file mode 100644 index 0000000..23a9247 --- /dev/null +++ b/view-simulation-results/src/main/java/org/vcell/N5/LoadingFactory.java @@ -0,0 +1,107 @@ +package org.vcell.N5; + +import ij.ImagePlus; +import org.vcell.N5.UI.ImageIntoMemory; +import org.vcell.N5.UI.N5ExportTable; +import org.vcell.N5.UI.SimLoadingEventCreator; +import org.vcell.N5.UI.SimLoadingListener; + +import javax.swing.*; +import javax.swing.event.EventListenerList; +import java.awt.*; +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; + +public class LoadingFactory implements SimLoadingEventCreator{ + private static final EventListenerList eventListenerList = new EventListenerList(); + + public void openN5FileDataset(ArrayList filesToOpen, boolean openInMemory){ + N5ExportTable.enableCriticalButtons(false); + N5ExportTable.exportTableDialog.setCursor(new Cursor(Cursor.WAIT_CURSOR)); + Thread openN5FileDataset = new Thread(() -> { + try{ + for(SimResultsLoader simResultsLoader: filesToOpen){ + simResultsLoader.createS3ClientAndReader(); + ImageIntoMemory imageIntoMemory; + if (openInMemory){ + ArrayList dimensions = simResultsLoader.getN5Dimensions(); + imageIntoMemory = new ImageIntoMemory(dimensions.get(2), dimensions.get(3), dimensions.get(4), simResultsLoader); + imageIntoMemory.displayRangeMenu(); + } else{ + ImagePlus imagePlus = simResultsLoader.getImgPlusFromN5File(); + imagePlus.show(); + } + + } + } catch (Exception ex) { + N5ExportTable.exportTableDialog.setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); + N5ExportTable.enableCriticalButtons(true); + throw new RuntimeException(ex); + } finally { + SwingUtilities.invokeLater(new Runnable() { + @Override + public void run() { + if (!openInMemory) { + N5ExportTable.exportTableDialog.setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); + N5ExportTable.enableCriticalButtons(true); + } + } + }); + } + }); + openN5FileDataset.setName("Open N5 File"); + openN5FileDataset.start(); + } + + public void openLocalN5FS(ArrayList filesToOpen){ + N5ExportTable.enableCriticalButtons(true); + JFileChooser fileChooser = new JFileChooser(); + fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); + fileChooser.setAcceptAllFileFilterUsed(false); + int result = fileChooser.showOpenDialog(null); + if (result == JFileChooser.APPROVE_OPTION){ + File file = fileChooser.getSelectedFile(); + N5ExportTable.exportTableDialog.setCursor(new Cursor(Cursor.WAIT_CURSOR)); + Thread openN5FileDataset = new Thread(() -> { + try{ + for(SimResultsLoader simResultsLoader: filesToOpen){ + simResultsLoader.setSelectedLocalFile(file); + ImagePlus imagePlus = simResultsLoader.getImgPlusFromLocalN5File(); + imagePlus.show(); + } + } catch (IOException ex) { + throw new RuntimeException(ex); + } finally { + SwingUtilities.invokeLater(new Runnable() { + @Override + public void run() { + N5ExportTable.exportTableDialog.setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); + N5ExportTable.enableCriticalButtons(true); + } + }); + } + }); + openN5FileDataset.start(); + } + } + + @Override + public void addSimLoadingListener(SimLoadingListener simLoadingListener) { + eventListenerList.add(SimLoadingListener.class, simLoadingListener); + } + + @Override + public void notifySimIsLoading(SimResultsLoader simResultsLoader) { + for (SimLoadingListener simLoadingListener: eventListenerList.getListeners(SimLoadingListener.class)){ + simLoadingListener.simIsLoading(simResultsLoader.rowNumber); + } + } + + @Override + public void notifySimIsDoneLoading(SimResultsLoader simResultsLoader) { + for (SimLoadingListener simLoadingListener: eventListenerList.getListeners(SimLoadingListener.class)){ + simLoadingListener.simFinishedLoading(simResultsLoader.rowNumber); + } + } +} diff --git a/view-simulation-results/src/main/java/org/vcell/N5/N5ImageHandler.java b/view-simulation-results/src/main/java/org/vcell/N5/N5ImageHandler.java index 3a9a14e..e69e1cf 100644 --- a/view-simulation-results/src/main/java/org/vcell/N5/N5ImageHandler.java +++ b/view-simulation-results/src/main/java/org/vcell/N5/N5ImageHandler.java @@ -35,6 +35,7 @@ public class N5ImageHandler implements Command { public static N5ExportTable exportTable; public static String exportedMetaDataPath = System.getProperty("user.home") + "/.vcell/exportMetaData.json"; private static ExportDataRepresentation.FormatExportDataRepresentation exampleJSONData; + public final static LoadingFactory loadingFactory = new LoadingFactory(); @Override public void run() { diff --git a/view-simulation-results/src/main/java/org/vcell/N5/SimResultsLoader.java b/view-simulation-results/src/main/java/org/vcell/N5/SimResultsLoader.java index bcebbaf..890ef62 100644 --- a/view-simulation-results/src/main/java/org/vcell/N5/SimResultsLoader.java +++ b/view-simulation-results/src/main/java/org/vcell/N5/SimResultsLoader.java @@ -10,7 +10,6 @@ import com.google.gson.GsonBuilder; import ij.ImagePlus; import ij.plugin.ContrastEnhancer; -import ij.plugin.frame.ContrastAdjuster; import net.imglib2.cache.img.CachedCellImg; import net.imglib2.img.display.imagej.ImageJFunctions; import net.imglib2.type.numeric.real.DoubleType; @@ -24,14 +23,10 @@ import org.janelia.saalfeldlab.n5.imglib2.N5Utils; import org.janelia.saalfeldlab.n5.s3.N5AmazonS3Reader; import org.scijava.log.Logger; -import org.vcell.N5.UI.N5ExportTable; -import org.vcell.N5.UI.ImageIntoMemory; import javax.net.ssl.HostnameVerifier; import javax.net.ssl.SSLContext; import javax.net.ssl.SSLSession; -import javax.swing.*; -import java.awt.*; import java.io.File; import java.io.IOException; import java.io.UnsupportedEncodingException; @@ -57,9 +52,14 @@ public class SimResultsLoader { private static final Logger logger = N5ImageHandler.getLogger(SimResultsLoader.class); public static AmazonS3ClientBuilder s3ClientBuilder; + public int rowNumber; public SimResultsLoader(){ + } + public SimResultsLoader(String stringURI, String userSetFileName, int rowNumber){ + this(stringURI, userSetFileName); + this.rowNumber = rowNumber; } public SimResultsLoader(String stringURI, String userSetFileName){ uri = URI.create(stringURI); @@ -164,77 +164,6 @@ public ArrayList getN5Dimensions(){ return n5AmazonS3Reader.getAttribute(dataSetChosen, "dimensions", ArrayList.class); } - - public static void openN5FileDataset(ArrayList filesToOpen, boolean openInMemory){ - N5ExportTable.enableCriticalButtons(false); - N5ExportTable.exportTableDialog.setCursor(new Cursor(Cursor.WAIT_CURSOR)); - Thread openN5FileDataset = new Thread(() -> { - try{ - for(SimResultsLoader simResultsLoader: filesToOpen){ - simResultsLoader.createS3ClientAndReader(); - ImageIntoMemory imageIntoMemory; - if (openInMemory){ - ArrayList dimensions = simResultsLoader.getN5Dimensions(); - imageIntoMemory = new ImageIntoMemory(dimensions.get(2), dimensions.get(3), dimensions.get(4), simResultsLoader); - imageIntoMemory.displayRangeMenu(); - } else{ - ImagePlus imagePlus = simResultsLoader.getImgPlusFromN5File(); - imagePlus.show(); - } - - } - } catch (Exception ex) { - N5ExportTable.exportTableDialog.setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); - N5ExportTable.enableCriticalButtons(true); - throw new RuntimeException(ex); - } finally { - SwingUtilities.invokeLater(new Runnable() { - @Override - public void run() { - if (!openInMemory) { - N5ExportTable.exportTableDialog.setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); - N5ExportTable.enableCriticalButtons(true); - } - } - }); - } - }); - openN5FileDataset.setName("Open N5 File"); - openN5FileDataset.start(); - } - - public static void openLocalN5FS(ArrayList filesToOpen){ - N5ExportTable.enableCriticalButtons(true); - JFileChooser fileChooser = new JFileChooser(); - fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); - fileChooser.setAcceptAllFileFilterUsed(false); - int result = fileChooser.showOpenDialog(null); - if (result == JFileChooser.APPROVE_OPTION){ - File file = fileChooser.getSelectedFile(); - N5ExportTable.exportTableDialog.setCursor(new Cursor(Cursor.WAIT_CURSOR)); - Thread openN5FileDataset = new Thread(() -> { - try{ - for(SimResultsLoader simResultsLoader: filesToOpen){ - simResultsLoader.setSelectedLocalFile(file); - ImagePlus imagePlus = simResultsLoader.getImgPlusFromLocalN5File(); - imagePlus.show(); - } - } catch (IOException ex) { - throw new RuntimeException(ex); - } finally { - SwingUtilities.invokeLater(new Runnable() { - @Override - public void run() { - N5ExportTable.exportTableDialog.setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); - N5ExportTable.enableCriticalButtons(true); - } - }); - } - }); - openN5FileDataset.start(); - } - } - void setDataSetChosen(String dataSetChosen) { this.dataSetChosen = dataSetChosen; } diff --git a/view-simulation-results/src/main/java/org/vcell/N5/UI/ImageIntoMemory.java b/view-simulation-results/src/main/java/org/vcell/N5/UI/ImageIntoMemory.java index 3735deb..f89a327 100644 --- a/view-simulation-results/src/main/java/org/vcell/N5/UI/ImageIntoMemory.java +++ b/view-simulation-results/src/main/java/org/vcell/N5/UI/ImageIntoMemory.java @@ -15,7 +15,7 @@ import java.awt.event.FocusEvent; import java.io.IOException; -public class ImageIntoMemory extends EventListenerList implements ActionListener { +public class ImageIntoMemory implements ActionListener { public int startC; public int endC; public int startT; diff --git a/view-simulation-results/src/main/java/org/vcell/N5/UI/N5ExportTable.java b/view-simulation-results/src/main/java/org/vcell/N5/UI/N5ExportTable.java index 08d8dbf..8348bf5 100644 --- a/view-simulation-results/src/main/java/org/vcell/N5/UI/N5ExportTable.java +++ b/view-simulation-results/src/main/java/org/vcell/N5/UI/N5ExportTable.java @@ -1,14 +1,8 @@ package org.vcell.N5.UI; -import ij.ImagePlus; -import net.imglib2.cache.img.CachedCellImg; -import net.imglib2.img.display.imagej.ImageJFunctions; -import net.imglib2.type.numeric.real.DoubleType; -import org.janelia.saalfeldlab.n5.N5FSReader; import org.scijava.log.Logger; import org.vcell.N5.ExportDataRepresentation; import org.vcell.N5.N5ImageHandler; -import org.vcell.N5.SimCacheLoader; import org.vcell.N5.SimResultsLoader; import javax.swing.*; @@ -24,7 +18,6 @@ import java.awt.datatransfer.StringSelection; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; -import java.io.File; import java.io.FileNotFoundException; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; @@ -32,7 +25,7 @@ import java.util.*; import java.util.concurrent.TimeUnit; -public class N5ExportTable implements ActionListener, ListSelectionListener { +public class N5ExportTable implements ActionListener, ListSelectionListener, SimLoadingListener { public static JDialog exportTableDialog; private N5ExportTableModel n5ExportTableModel; private ParameterTableModel parameterTableModel; @@ -363,7 +356,7 @@ public void actionPerformed(ActionEvent e) { SimResultsLoader simResultsLoader = new SimResultsLoader(uri, n5ExportTableModel.getRowData(row).savedFileName); filesToOpen.add(simResultsLoader); } - SimResultsLoader.openN5FileDataset(filesToOpen, e.getSource().equals(openInMemory)); + N5ImageHandler.loadingFactory.openN5FileDataset(filesToOpen, e.getSource().equals(openInMemory)); } else if (e.getSource().equals(copyLink)) { ExportDataRepresentation.SimulationExportDataRepresentation selectedRow = n5ExportTableModel.getRowData(exportListTable.getSelectedRow()); Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); @@ -381,7 +374,7 @@ public void actionPerformed(ActionEvent e) { SimResultsLoader simResultsLoader = new SimResultsLoader(uri, n5ExportTableModel.getRowData(row).savedFileName); filesToOpen.add(simResultsLoader); } - SimResultsLoader.openLocalN5FS(filesToOpen); + N5ImageHandler.loadingFactory.openLocalN5FS(filesToOpen); } else if (e.getSource().equals(includeExampleExports)){ if(includeExampleExports.isSelected()){ @@ -429,6 +422,16 @@ public void valueChanged(ListSelectionEvent e) { parameterTable.updateUI(); } + @Override + public void simIsLoading(int itemRow) { + + } + + @Override + public void simFinishedLoading(int itemRow) { + + } + static class ParameterTableModel extends AbstractTableModel{ diff --git a/view-simulation-results/src/main/java/org/vcell/N5/UI/RemoteFileSelection.java b/view-simulation-results/src/main/java/org/vcell/N5/UI/RemoteFileSelection.java index be90e61..84823c5 100644 --- a/view-simulation-results/src/main/java/org/vcell/N5/UI/RemoteFileSelection.java +++ b/view-simulation-results/src/main/java/org/vcell/N5/UI/RemoteFileSelection.java @@ -1,5 +1,6 @@ package org.vcell.N5.UI; +import org.vcell.N5.N5ImageHandler; import org.vcell.N5.SimResultsLoader; import javax.swing.*; @@ -95,7 +96,7 @@ public String getS3URL(){ @Override public void actionPerformed(ActionEvent e) { SimResultsLoader simResultsLoader = new SimResultsLoader(getS3URL(), ""); - SimResultsLoader.openN5FileDataset(new ArrayList(){{add(simResultsLoader);}}, N5ExportTable.openInMemory.isSelected()); + N5ImageHandler.loadingFactory.openN5FileDataset(new ArrayList(){{add(simResultsLoader);}}, N5ExportTable.openInMemory.isSelected()); this.setVisible(false); } } diff --git a/view-simulation-results/src/main/java/org/vcell/N5/UI/SimLoadingEventCreator.java b/view-simulation-results/src/main/java/org/vcell/N5/UI/SimLoadingEventCreator.java new file mode 100644 index 0000000..fcb6538 --- /dev/null +++ b/view-simulation-results/src/main/java/org/vcell/N5/UI/SimLoadingEventCreator.java @@ -0,0 +1,14 @@ +package org.vcell.N5.UI; + +import org.vcell.N5.SimResultsLoader; + +import javax.swing.event.EventListenerList; + +public interface SimLoadingEventCreator { + public void addSimLoadingListener(SimLoadingListener simLoadingListener); + + public void notifySimIsLoading(SimResultsLoader simResultsLoader); + + public void notifySimIsDoneLoading(SimResultsLoader simResultsLoader); + +} diff --git a/view-simulation-results/src/main/java/org/vcell/N5/UI/SimLoadingListener.java b/view-simulation-results/src/main/java/org/vcell/N5/UI/SimLoadingListener.java new file mode 100644 index 0000000..c5a0ea7 --- /dev/null +++ b/view-simulation-results/src/main/java/org/vcell/N5/UI/SimLoadingListener.java @@ -0,0 +1,11 @@ +package org.vcell.N5.UI; + +import java.util.EventListener; + +public interface SimLoadingListener extends EventListener { + + public void simIsLoading(int itemRow); + + public void simFinishedLoading(int itemRow); + +}