Skip to content

Commit

Permalink
Example Table Available To Users
Browse files Browse the repository at this point in the history
  • Loading branch information
AvocadoMoon committed Apr 26, 2024
1 parent 521f753 commit b38d604
Show file tree
Hide file tree
Showing 4 changed files with 114 additions and 53 deletions.
8 changes: 8 additions & 0 deletions view-simulation-results/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,14 @@
<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
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package org.vcell.N5;


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;
Expand All @@ -9,6 +11,13 @@
import org.scijava.plugin.Plugin;
import org.vcell.N5.UI.N5ExportTable;

import java.io.*;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.Stack;


/*
Able to open N5 files locally, display the datasets that can be chosen from it, and open the datasets within ImageJ.
Expand All @@ -23,6 +32,7 @@ public class N5ImageHandler implements Command {
@Parameter
public static LogService logService;
public static N5ExportTable exportTable;
public static String exportedMetaDataPath = System.getProperty("user.home") + "/.vcell/exportMetaData.json";

@Override
public void run() {
Expand All @@ -49,4 +59,48 @@ public static void main(String[] args) {
n5ImageHandler.run();
}

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;
}

public static boolean exportedDataExists(){
File jsonFile = new File(exportedMetaDataPath);
return jsonFile.exists();
}

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;

}

// 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);
}
}



}
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ public ImagePlus getImgPlusFromLocalN5File() throws IOException {

public ImagePlus getImgPlusFromN5File() throws IOException {
AmazonS3KeyValueAccess amazonS3KeyValueAccess = new AmazonS3KeyValueAccess(s3Client, bucketName, false);
N5KeyValueReader n5AmazonS3Reader = new N5KeyValueReader(amazonS3KeyValueAccess, s3ObjectKey, new GsonBuilder(), true);
N5KeyValueReader n5AmazonS3Reader = new N5KeyValueReader(amazonS3KeyValueAccess, s3ObjectKey, new GsonBuilder(), false);

// N5AmazonS3Reader n5AmazonS3Reader = new N5AmazonS3Reader(s3Client, bucketName, "/" + s3ObjectKey);
long start = System.currentTimeMillis();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
package org.vcell.N5.UI;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import ij.ImagePlus;
import ij.plugin.Duplicator;
import org.scijava.log.Logger;
import org.vcell.N5.ExportDataRepresentation;
import org.vcell.N5.N5ImageHandler;
Expand All @@ -20,10 +16,7 @@
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.io.FileReader;
import java.io.IOException;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
Expand All @@ -37,13 +30,19 @@ public class N5ExportTable implements ActionListener, ListSelectionListener {
private ParameterTableModel parameterTableModel;
private JTable parameterTable;
private JTable exportListTable;
private JScrollPane tableScrollPane;

private static JButton open;
private static JButton copyLink;
private static JButton refreshButton;
private static JButton useN5Link;
private static JButton questionMark;
public static JCheckBox openInMemory;
private static JButton switchMainTableContext;
private final String optionForExampleTableButtonText = "Show Export Examples";
private final String optionForPersonalTableButtonText = "Show My Exports";
private final String exampleTableLabelText = " Example Export Table ";
private final String personalTableLabelText = " Personal Export Table ";
private JCheckBox todayInterval;
private JCheckBox monthInterval;
private JCheckBox yearlyInterval;
Expand All @@ -63,7 +62,7 @@ public void initalizeTableData(){
ExportDataRepresentation jsonData = null;
n5ExportTableModel.resetData();
try {
jsonData = getJsonData();
jsonData = switchMainTableContext.getText().equals(optionForPersonalTableButtonText) ? N5ImageHandler.getExampleJSONData() : N5ImageHandler.getJsonData();
if (jsonData != null){
LocalDateTime pastTime = LocalDateTime.now();
if (todayInterval.isSelected()){
Expand All @@ -89,6 +88,8 @@ public void initalizeTableData(){
}
}
n5ExportTableModel.fireTableDataChanged();
tableScrollPane.setBorder(BorderFactory.createTitledBorder(lowerEtchedBorder, switchMainTableContext.getText().equals(optionForPersonalTableButtonText) ? exampleTableLabelText : personalTableLabelText));
tableScrollPane.updateUI();
} catch (FileNotFoundException e) {
throw new RuntimeException(e);
}
Expand Down Expand Up @@ -149,11 +150,11 @@ private JSplitPane exportDetailsPanel(){
private JScrollPane tablePanel(){
n5ExportTableModel = new N5ExportTableModel();
exportListTable = new JTable(n5ExportTableModel);
JScrollPane jScrollPane = new JScrollPane(exportListTable);
tableScrollPane = new JScrollPane(exportListTable);

jScrollPane.setPreferredSize(new Dimension(500, 400));
jScrollPane.setBorder(BorderFactory.createTitledBorder(lowerEtchedBorder, " Export Table "));
return jScrollPane;
tableScrollPane.setPreferredSize(new Dimension(500, 400));
tableScrollPane.setBorder(BorderFactory.createTitledBorder(lowerEtchedBorder, switchMainTableContext.getText().equals(optionForExampleTableButtonText) ? personalTableLabelText : exampleTableLabelText));
return tableScrollPane;
}

private JPanel topPanel(){
Expand All @@ -163,36 +164,51 @@ private JPanel topPanel(){
useN5Link = new JButton("Use N5 Link");
questionMark = new JButton("?");
openInMemory = new JCheckBox("Open In Memory");
switchMainTableContext = new JButton(N5ImageHandler.exportedDataExists() ? optionForExampleTableButtonText : optionForPersonalTableButtonText);
openInMemory.setSelected(true);


JPanel userButtonsPanel = new JPanel(new GridBagLayout());
GridBagConstraints gridBagConstraints = new GridBagConstraints();
Insets buttonMargin = new Insets(2, 5, 2, 5);
gridBagConstraints.insets = buttonMargin;

JPanel topRow = new JPanel(new GridBagLayout());
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 0;
open.setMargin(buttonMargin);
userButtonsPanel.add(open, gridBagConstraints);
topRow.add(open, gridBagConstraints);
gridBagConstraints.gridx = 1;
gridBagConstraints.gridy = 0;
refreshButton.setMargin(buttonMargin);
userButtonsPanel.add(refreshButton, gridBagConstraints);
topRow.add(refreshButton, gridBagConstraints);
gridBagConstraints.gridx = 2;
gridBagConstraints.gridy = 0;
copyLink.setMargin(buttonMargin);
userButtonsPanel.add(copyLink, gridBagConstraints);
topRow.add(copyLink, gridBagConstraints);

JPanel midRow = new JPanel(new GridBagLayout());
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 1;
useN5Link.setMargin(buttonMargin);
userButtonsPanel.add(useN5Link, gridBagConstraints);
gridBagConstraints.gridy = 0;
midRow.add(useN5Link, gridBagConstraints);
// gridBagConstraints.gridx = 1;
// gridBagConstraints.gridy = 2;
gridBagConstraints.gridx = 1;
gridBagConstraints.gridy = 0;
midRow.add(switchMainTableContext, gridBagConstraints);

JPanel bottomRow = new JPanel(new GridBagLayout());
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 0;
bottomRow.add(openInMemory, gridBagConstraints);


JPanel userButtonsPanel = new JPanel(new GridBagLayout());
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 0;
userButtonsPanel.add(topRow, gridBagConstraints);
gridBagConstraints.gridy = 1;
userButtonsPanel.add(midRow, gridBagConstraints);
gridBagConstraints.gridy = 2;
questionMark.setMargin(buttonMargin);
userButtonsPanel.add(bottomRow, gridBagConstraints);



// buttonsPanel.add(questionMark);
gridBagConstraints.gridx = 2;
gridBagConstraints.gridy = 1;
userButtonsPanel.add(openInMemory, gridBagConstraints);


todayInterval = new JCheckBox("Past 24 Hours");
monthInterval = new JCheckBox("Past Month");
Expand Down Expand Up @@ -225,7 +241,7 @@ private JPanel topPanel(){
copyLink.addActionListener(this);
questionMark.addActionListener(this);
useN5Link.addActionListener(this);
remoteFileSelection.submitS3Info.addActionListener(this);
switchMainTableContext.addActionListener(this);

return topBar;
}
Expand All @@ -236,6 +252,7 @@ public static void enableCriticalButtons(boolean enable){
refreshButton.setEnabled(enable);
copyLink.setEnabled(enable);
remoteFileSelection.submitS3Info.setEnabled(enable);
switchMainTableContext.setEnabled(enable);
}

@Override
Expand All @@ -258,6 +275,10 @@ public void actionPerformed(ActionEvent e) {
new HelpExplanation().displayHelpMenu();
} else if (e.getSource().equals(useN5Link)) {
remoteFileSelection.setVisible(true);
} else if (e.getSource().equals(switchMainTableContext)){
String currentState = switchMainTableContext.getText();
switchMainTableContext.setText(currentState.equals(optionForExampleTableButtonText) ? optionForPersonalTableButtonText : optionForExampleTableButtonText);
initalizeTableData();
}
}

Expand All @@ -281,29 +302,7 @@ public void valueChanged(ListSelectionEvent e) {
parameterTable.updateUI();
}

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;
}

public static ExportDataRepresentation getJsonData() throws FileNotFoundException {
File jsonFile = new File(System.getProperty("user.home") + "/.vcell", "exportMetaData.json");
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;

}
static class ParameterTableModel extends AbstractTableModel{

private final static String parameterHeader = "Parameter";
Expand Down

0 comments on commit b38d604

Please sign in to comment.