Skip to content

Commit

Permalink
Merge pull request #42 from virtualcell/41-forever-loading
Browse files Browse the repository at this point in the history
41 forever loading
  • Loading branch information
AvocadoMoon authored May 6, 2024
2 parents 1b69322 + 6a99f31 commit ce32916
Show file tree
Hide file tree
Showing 7 changed files with 255 additions and 463 deletions.
45 changes: 21 additions & 24 deletions view-simulation-results/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -130,42 +130,21 @@
<dependency>
<groupId>org.janelia.saalfeldlab</groupId>
<artifactId>n5</artifactId>
<version>3.1.2</version>
<version>3.2.0</version>
</dependency>

<!-- https://mvnrepository.com/artifact/org.janelia.saalfeldlab/n5-imglib2 -->
<dependency>
<groupId>org.janelia.saalfeldlab</groupId>
<artifactId>n5-imglib2</artifactId>
<version>6.0.0</version>
<version>7.0.0</version>
</dependency>

<!-- https://mvnrepository.com/artifact/org.janelia.saalfeldlab/n5-aws-s3 -->
<dependency>
<groupId>org.janelia.saalfeldlab</groupId>
<artifactId>n5-aws-s3</artifactId>
<version>4.0.0</version>
</dependency>

<!-- https://mvnrepository.com/artifact/org.janelia.saalfeldlab/n5-universe -->
<dependency>
<groupId>org.janelia.saalfeldlab</groupId>
<artifactId>n5-universe</artifactId>
<version>1.3.1</version>
</dependency>

<!-- https://mvnrepository.com/artifact/org.janelia.saalfeldlab/n5-zarr -->
<dependency>
<groupId>org.janelia.saalfeldlab</groupId>
<artifactId>n5-zarr</artifactId>
<version>1.2.0</version>
</dependency>

<!-- https://mvnrepository.com/artifact/org.janelia.saalfeldlab/n5-ij -->
<dependency>
<groupId>org.janelia.saalfeldlab</groupId>
<artifactId>n5-ij</artifactId>
<version>4.0.0</version>
<version>4.1.1</version>
</dependency>


Expand All @@ -182,6 +161,24 @@
<artifactId>scijava-log-slf4j</artifactId>
<version>1.0.6</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-simple -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
</dependency>

<!-- https://mvnrepository.com/artifact/com.google.code.gson/gson -->
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.10.1</version>
</dependency>



</dependencies>

Expand Down
165 changes: 64 additions & 101 deletions view-simulation-results/src/main/java/org/vcell/N5/N5ImageHandler.java
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
package org.vcell.N5;


import org.scijava.log.slf4j.SLF4JLogService;
import org.vcell.N5.UI.N5ExportTable;
import org.vcell.N5.UI.N5ViewerGUI;
import ij.ImagePlus;
import ij.plugin.Duplicator;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import org.scijava.command.Command;
import org.scijava.log.LogService;
import org.scijava.log.Logger;
import org.scijava.log.slf4j.SLF4JLogService;
import org.scijava.plugin.Parameter;
import org.scijava.plugin.Plugin;
import org.vcell.N5.UI.N5ExportTable;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;
import java.io.*;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.Stack;


/*
Expand All @@ -27,117 +27,80 @@
*/

@Plugin(type = Command.class, menuPath = "Plugins>VCell>VCell Simulation Results Viewer")
public class N5ImageHandler implements Command, ActionListener {
private N5ViewerGUI vGui;
public class N5ImageHandler implements Command {
public static final String formatName = "N5";
private SimResultsLoader simResultsLoader;
@Parameter
public static LogService logService;
public static N5ExportTable exportTable;
public static String exportedMetaDataPath = System.getProperty("user.home") + "/.vcell/exportMetaData.json";

@Override
public void actionPerformed(ActionEvent e) {
enableCriticalButtons(false);

// generate dataset list
if (e.getSource() == vGui.remoteFileSelection.submitS3Info || e.getSource() == vGui.mostRecentExport){
simResultsLoader = new SimResultsLoader();
SwingWorker n5DatasetListUpdater = new SwingWorker() {
@Override
protected Object doInBackground() throws Exception {
vGui.setCursor(new Cursor(Cursor.WAIT_CURSOR));
String uri = "";
if (e.getSource() == vGui.remoteFileSelection.submitS3Info) {
vGui.remoteFileSelection.setCursor(new Cursor(Cursor.WAIT_CURSOR));
uri = vGui.remoteFileSelection.getS3URL();
} else if (e.getSource() == vGui.mostRecentExport) {
ExportDataRepresentation.SimulationExportDataRepresentation lastElement = N5ExportTable.getLastJSONElement();
if (lastElement != null) {
uri = lastElement.uri;
simResultsLoader.setDataSetChosen(lastElement.savedFileName);
}
}
simResultsLoader.setURI(URI.create(uri));
simResultsLoader.createS3Client();
displayN5Dataset(simResultsLoader.getImgPlusFromN5File());

return null;
}

@Override
protected void done() {
vGui.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
enableCriticalButtons(true);
try {
if (e.getSource() == vGui.remoteFileSelection.submitS3Info) {
vGui.remoteFileSelection.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
vGui.remoteFileSelection.dispose();
}
} catch (Exception exception) {
logService.error(exception);
}
}
};
N5ImageHandler.logService.debug("Generating Dataset List");
n5DatasetListUpdater.execute();
}
// https://stackoverflow.com/questions/16937997/java-swingworker-thread-to-update-main-gui
// Why swing updating does not work
public void run() {
exportTable = new N5ExportTable();
initializeLogService();
// N5ImageHandler.logService.setLevel(LogService.DEBUG);
exportTable.displayExportTable();
}

public static Logger getLogger(Class classToLog){
return logService.subLogger(classToLog.getCanonicalName(), LogService.DEBUG);
}

public static void initializeLogService(){
if (N5ImageHandler.logService == null){
N5ImageHandler.logService = new SLF4JLogService();
N5ImageHandler.logService.initialize();
}
}

public void enableCriticalButtons(boolean enable) {
logService.debug("Disabling Critical Buttons");
vGui.remoteFileSelection.submitS3Info.setEnabled(enable);
vGui.okayButton.setEnabled(enable);
vGui.localFiles.setEnabled(enable);
vGui.remoteFiles.setEnabled(enable);
vGui.mostRecentExport.setEnabled(enable);
vGui.exportTableButton.setEnabled(enable);
logService.debug("Enabling Critical Buttons");
logService.error("Test Error");
public static void main(String[] args) {
N5ImageHandler n5ImageHandler = new N5ImageHandler();
initializeLogService();
n5ImageHandler.run();
}

static {
public static ExportDataRepresentation.SimulationExportDataRepresentation getLastJSONElement() throws FileNotFoundException {
ExportDataRepresentation jsonData = getJsonData();
if (jsonData != null && jsonData.formatData.containsKey(N5ImageHandler.formatName)) {
ExportDataRepresentation.FormatExportDataRepresentation formatExportDataRepresentation = jsonData.formatData.get(N5ImageHandler.formatName);
Stack<String> formatJobIDs = formatExportDataRepresentation.formatJobIDs;
String jobID = formatJobIDs.isEmpty() ? null : formatJobIDs.peek();

return jobID == null ? null : formatExportDataRepresentation.simulationDataMap.get(jobID);
}
return null;
}

@Override
public void run() {
// this.vGui = new N5ViewerGUI(this);
// this.vGui.localFileDialog.addActionListener(this);
// this.vGui.okayButton.addActionListener(this);
//// this.vGui.exportTableButton.addActionListener(this);
//
// this.vGui.remoteFileSelection.submitS3Info.addActionListener(this);
// this.vGui.mostRecentExport.addActionListener(this);
N5ExportTable exportTable = new N5ExportTable(this);
if(N5ImageHandler.logService == null){
N5ImageHandler.logService = new SLF4JLogService();
}
N5ImageHandler.logService.setLevel(LogService.DEBUG);
exportTable.displayExportTable();
public static boolean exportedDataExists(){
File jsonFile = new File(exportedMetaDataPath);
return jsonFile.exists();
}

public void displayN5Dataset(ImagePlus imagePlus) throws IOException {
if (this.vGui.openMemoryCheckBox.isSelected()){
ImagePlus memoryImagePlus = new Duplicator().run(imagePlus);
memoryImagePlus.show();
}
else{
imagePlus.show();
public static ExportDataRepresentation getJsonData() throws FileNotFoundException {
File jsonFile = new File(exportedMetaDataPath);
if (jsonFile.exists() && jsonFile.length() != 0){
ExportDataRepresentation jsonHashMap;
Gson gson = new GsonBuilder().setPrettyPrinting().create();
jsonHashMap = gson.fromJson(new FileReader(jsonFile.getAbsolutePath()), ExportDataRepresentation.class);
return jsonHashMap;
}
return null;

}

public static LogService getLogger(){
if (logService == null){
logService = new SLF4JLogService();
// https://www.npoint.io/docs/b85bb21076bf422a7d93
public static ExportDataRepresentation getExampleJSONData() throws FileNotFoundException {
try(BufferedInputStream remoteJSONFile = new BufferedInputStream(new URL("https://api.npoint.io/b85bb21076bf422a7d93").openStream())){
InputStreamReader remoteJSONFileReader = new InputStreamReader(remoteJSONFile);
ExportDataRepresentation jsonHashMap;
Gson gson = new GsonBuilder().setPrettyPrinting().create();
jsonHashMap = gson.fromJson(remoteJSONFileReader, ExportDataRepresentation.class);
return jsonHashMap;
} catch (IOException e) {
throw new RuntimeException(e);
}
return logService;
}

public static void main(String[] args) {
N5ImageHandler n5ImageHandler = new N5ImageHandler();
n5ImageHandler.run();
}


}
Loading

0 comments on commit ce32916

Please sign in to comment.