Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

G UI quirks #17

Merged
merged 6 commits into from
Dec 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -181,13 +181,6 @@
</dependency>


<!-- https://mvnrepository.com/artifact/javax.xml.bind/jaxb-api Used for AWS library to properly parse XML files -->
<!-- <dependency>-->
<!-- <groupId>javax.xml.bind</groupId>-->
<!-- <artifactId>jaxb-api</artifactId>-->
<!-- <version>2.3.1</version>-->
<!-- </dependency>-->

<dependency>
<groupId>org.jsoup</groupId>
<artifactId>jsoup</artifactId>
Expand Down
130 changes: 111 additions & 19 deletions src/main/java/org/vcell/vcellfiji/N5ImageHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
import com.amazonaws.services.s3.AmazonS3;
import com.amazonaws.services.s3.AmazonS3ClientBuilder;
import com.amazonaws.services.s3.AmazonS3URI;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.internal.LinkedTreeMap;
import com.google.gson.reflect.TypeToken;
import ij.ImagePlus;
import ij.plugin.Duplicator;
import net.imglib2.cache.img.CachedCellImg;
Expand All @@ -18,20 +22,21 @@
import org.janelia.saalfeldlab.n5.imglib2.N5Utils;
import org.janelia.saalfeldlab.n5.s3.N5AmazonS3Reader;
import org.scijava.command.Command;
import org.scijava.log.LogService;
import org.scijava.plugin.Parameter;
import org.scijava.plugin.Plugin;
import org.janelia.saalfeldlab.n5.*;
import org.vcell.vcellfiji.UI.VCellGUI;
import org.vcell.vcellfiji.UI.N5ViewerGUI;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.lang.reflect.Type;
import java.net.URI;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.*;


/*
Expand All @@ -43,11 +48,13 @@

@Plugin(type = Command.class, menuPath = "Plugins>VCell>N5 Dataset Viewer")
public class N5ImageHandler implements Command, ActionListener {
private VCellGUI vGui;
private N5ViewerGUI vGui;
private File selectedLocalFile;
private AmazonS3 s3Client;
private String bucketName;
private String s3ObjectKey;
@Parameter
private LogService logService;
private SwingWorker<ArrayList<String>, ArrayList<String>> n5DatasetListUpdater;
@Override
public void actionPerformed(ActionEvent e) {
Expand All @@ -66,6 +73,14 @@ protected ArrayList<String> doInBackground() throws Exception {
@Override
protected void done() {
enableCriticalButtons(true);
try{
if(vGui.jFileChooserResult == JFileChooser.APPROVE_OPTION){
get();
}
}
catch (Exception exception){
logService.error(exception);
}
}

@Override
Expand All @@ -80,18 +95,19 @@ else if (e.getSource() == vGui.okayButton) {
SwingWorker swingWorker = new SwingWorker() {
@Override
protected Object doInBackground() throws Exception {
try{
loadN5Dataset(vGui.datasetList.getSelectedValue());
return null;
}
catch (IOException ex){
return null;
}
loadN5Dataset(vGui.datasetList.getSelectedValue());
return null;
}

@Override
protected void done() {
enableCriticalButtons(true);
try{
get();
}
catch (Exception exception){
logService.error(exception);
}
}
};
swingWorker.execute();
Expand All @@ -112,6 +128,56 @@ protected ArrayList<String> doInBackground() throws Exception {
@Override
protected void done() {
enableCriticalButtons(true);
try{
get();
vGui.remoteFileSelection.dispose();
}
catch (Exception exception){
logService.error(exception);
}
}

@Override
protected void process(List<ArrayList<String>> chunks) {
displayN5Results(chunks.get(0));
}
};
n5DatasetListUpdater.execute();
n5DatasetListUpdater.getState();
} else if (e.getSource() == vGui.mostRecentExport) {
n5DatasetListUpdater= new SwingWorker<ArrayList<String>, ArrayList<String>>() {
@Override
protected ArrayList<String> doInBackground(){
HashMap <String, Object> jsonData = getJsonData();
if (jsonData != null){
List<String> set = (ArrayList<String>) jsonData.get("jobIDs");
LinkedTreeMap<String, String> lastElement = null;
for(int i = set.size() - 1; i > -1; i--){
lastElement = (LinkedTreeMap<String, String>) jsonData.get(set.get(i));
if(lastElement != null && lastElement.get("format").equalsIgnoreCase("n5")){
break;
}
lastElement = null;
}
if(lastElement != null){
String url = lastElement.get("uri");
createS3Client(url);
ArrayList<String> list = getS3N5DatasetList();
publish(list);
}
}
return null;
}

@Override
protected void done() {
enableCriticalButtons(true);
try{
get();
}
catch (Exception exception){
logService.error(exception);
}
}

@Override
Expand All @@ -120,24 +186,27 @@ protected void process(List<ArrayList<String>> chunks) {
}
};
n5DatasetListUpdater.execute();
n5DatasetListUpdater.getState();
}
}

private void enableCriticalButtons(boolean enable) {
vGui.remoteFileSelection.submitS3Info.setEnabled(enable);
vGui.okayButton.setEnabled(enable);
vGui.LocalFiles.setEnabled(enable);
vGui.localFiles.setEnabled(enable);
vGui.remoteFiles.setEnabled(enable);
vGui.mostRecentExport.setEnabled(enable);
}

@Override
public void run() {
this.vGui = new VCellGUI();
this.vGui = new N5ViewerGUI();
this.vGui.localFileDialog.addActionListener(this);

this.vGui.okayButton.addActionListener(this);

this.vGui.remoteFileSelection.submitS3Info.addActionListener(this);
this.vGui.mostRecentExport.addActionListener(this);
}

public ArrayList<String> getN5DatasetList(){
Expand Down Expand Up @@ -189,13 +258,13 @@ public ImagePlus getImgPlusFromN5File(String selectedDataset, N5Reader n5Reader)


private void displayN5Dataset(ImagePlus imagePlus){
if (this.vGui.openVirtualCheckBox.isSelected()){
imagePlus.show();
}
else{
if (this.vGui.openMemoryCheckBox.isSelected()){
ImagePlus memoryImagePlus = new Duplicator().run(imagePlus);
memoryImagePlus.show();
}
else{
imagePlus.show();
}
}

public N5AmazonS3Reader getN5AmazonS3Reader(){
Expand Down Expand Up @@ -227,6 +296,11 @@ public void loadN5Dataset(String selectedDataset) throws IOException {
}

//When creating client's try to make one for an Amazon link, otherwise use our custom url scheme

public void createS3Client(String url){
createS3Client(url, null, null);
}

public void createS3Client(String url, HashMap<String, String> credentials, HashMap<String, String> endpoint){
AmazonS3ClientBuilder s3ClientBuilder = AmazonS3ClientBuilder.standard();
URI uri = URI.create(url);
Expand Down Expand Up @@ -296,4 +370,22 @@ public static void main(String[] args) {
N5ImageHandler n5ImageHandler = new N5ImageHandler();
n5ImageHandler.run();
}

public HashMap<String, Object> getJsonData(){
try{
File jsonFile = new File(System.getProperty("user.home") + "/.vcell", "exportMetaData.json");
if (jsonFile.exists() && jsonFile.length() != 0){
HashMap<String, Object> jsonHashMap;
Gson gson = new GsonBuilder().setPrettyPrinting().create();
Type type = new TypeToken<HashMap<String, Object>>() {}.getType();
jsonHashMap = gson.fromJson(new FileReader(jsonFile.getAbsolutePath()), type);
return jsonHashMap;
}
return null;
}
catch (Exception e){
logService.error("Failed to read export metadata JSON:", e);
return null;
}
}
}
141 changes: 141 additions & 0 deletions src/main/java/org/vcell/vcellfiji/UI/N5ViewerGUI.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
package org.vcell.vcellfiji.UI;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;

public class N5ViewerGUI extends JFrame implements ActionListener {
public JButton localFiles;
public JPanel mainPanel;
private JFrame thisJFrame;
public JFileChooser localFileDialog;
private JToolBar menuBar;
public JList<String> datasetList;
private JScrollPane resultsScrollPane;
public JButton remoteFiles;
public JButton okayButton;
public JCheckBox openMemoryCheckBox;
private JPanel datasetListPanel;
private JLabel datasetLabel;
private JLabel openInMemory;
public int jFileChooserResult;

public JButton mostRecentExport;

public RemoteFileSelection remoteFileSelection;

public N5ViewerGUI() {
thisJFrame = this;
localFileDialog = new JFileChooser();
mainPanel = new JPanel();
datasetListPanel = new JPanel();
mainPanel.setLayout(new GridBagLayout());
datasetListPanel.setLayout(new GridBagLayout());
datasetList = new JList<>();
datasetList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

GridBagConstraints mainPanelConstraints = new GridBagConstraints();
mainPanelConstraints.gridx = 0;
mainPanelConstraints.gridy = 0;
localFiles = new JButton();
localFiles.setText("Local Files");
mainPanel.add(localFiles, mainPanelConstraints);

mainPanelConstraints.gridy = 0;
mainPanelConstraints.gridx = 1;
remoteFiles = new JButton();
remoteFiles.setText("Remote Files");
mainPanel.add(remoteFiles, mainPanelConstraints);

mainPanelConstraints.gridy = 0;
mainPanelConstraints.gridx = 2;
mostRecentExport = new JButton();
mostRecentExport.setText("Recent Export");
mainPanel.add(mostRecentExport, mainPanelConstraints);

mainPanelConstraints.gridy = 0;
mainPanelConstraints.gridx = 3;
openInMemory = new JLabel();
openInMemory.setText("Open Image in Memory");
mainPanel.add(openInMemory, mainPanelConstraints);

mainPanelConstraints.gridy = 0;
mainPanelConstraints.gridx = 4;
openMemoryCheckBox = new JCheckBox();
mainPanel.add(openMemoryCheckBox, mainPanelConstraints);


GridBagConstraints datasetConstraints = new GridBagConstraints();
datasetConstraints.gridx = 0;
datasetConstraints.gridy = 0;
datasetLabel = new JLabel();
datasetLabel.setText("Dataset List");
datasetListPanel.add(datasetLabel, datasetConstraints);

datasetConstraints.gridx = 0;
datasetConstraints.gridy = 1;
datasetConstraints.gridwidth = 1;
datasetConstraints.ipady = 70;
datasetConstraints.ipadx = 100;
resultsScrollPane = new JScrollPane(datasetList);
datasetListPanel.add(resultsScrollPane, datasetConstraints);

mainPanelConstraints.gridwidth = 4;
mainPanelConstraints.gridy = 1;
mainPanelConstraints.ipady = 40;
mainPanelConstraints.gridx = 0;
mainPanelConstraints.fill = GridBagConstraints.BOTH;
mainPanelConstraints.anchor = GridBagConstraints.CENTER;
mainPanel.add(datasetListPanel, mainPanelConstraints);


mainPanelConstraints = new GridBagConstraints();
mainPanelConstraints.gridy = 2;
mainPanelConstraints.gridx = 0;
mainPanelConstraints.gridwidth = 4;
okayButton = new JButton();
okayButton.setText("Open Dataset");
mainPanel.add(okayButton, mainPanelConstraints);


localFiles.addActionListener(this);

remoteFiles.addActionListener(this);

// listener for if credentials or endpoint is used

this.setTitle("VCell Manager");
this.setContentPane(this.mainPanel);
this.setSize(600, 400);
this.setVisible(true);
this.remoteFileSelection = new RemoteFileSelection(thisJFrame);


}

public void updateDatasetList(ArrayList<String> arrayList){
DefaultListModel<String> listModel = new DefaultListModel<>();
for (String s: arrayList){
listModel.addElement(s);
}
this.datasetList.setModel(listModel);
this.datasetList.updateUI();
}

private void createUIComponents() {
// TODO: place custom component creation code here
}

@Override
public void actionPerformed(ActionEvent e) {
if (e.getSource() == localFiles){
localFileDialog.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
jFileChooserResult = localFileDialog.showOpenDialog(thisJFrame);
} else if (e.getSource() == remoteFiles) {
remoteFileSelection.setVisible(true);
}
}
}

Loading
Loading