Skip to content

Commit

Permalink
Merge pull request #54 from virtualcell/stronger-indication-of-loadin…
Browse files Browse the repository at this point in the history
…g-image

Stronger indication of loading image
  • Loading branch information
AvocadoMoon authored Oct 4, 2024
2 parents 2ca44e8 + fac12ae commit 9e74f37
Show file tree
Hide file tree
Showing 14 changed files with 742 additions and 509 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,13 @@
import org.scijava.log.slf4j.SLF4JLogService;
import org.scijava.plugin.Parameter;
import org.scijava.plugin.Plugin;
import org.vcell.N5.UI.MainPanel;
import org.vcell.N5.UI.N5ExportTable;
import org.vcell.N5.retrieving.LoadingFactory;
import org.vcell.N5.retrieving.SimResultsLoader;

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 @@ -32,17 +31,18 @@ public class N5ImageHandler implements Command {
public static final String formatName = "N5";
@Parameter
public static LogService logService;
public static N5ExportTable exportTable;
public static MainPanel exportTable;
public static String exportedMetaDataPath = System.getProperty("user.home") + "/.vcell/exportMetaData.json";
private static ExportDataRepresentation.FormatExportDataRepresentation exampleJSONData;
public static LoadingFactory loadingFactory;

@Override
public void run() {
exportTable = new N5ExportTable();
initializeLogService();
loadingFactory = new LoadingFactory();
exportTable = new MainPanel();
setExampleJSONData();
// N5ImageHandler.logService.setLevel(LogService.DEBUG);
exportTable.displayExportTable();
Thread thread = new Thread(() -> {
// For some reason getting a standard client takes three seconds.
// So create one upon initialization, while the user is focused on the GUI
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,203 @@
package org.vcell.N5.UI;

import org.vcell.N5.N5ImageHandler;

import javax.swing.*;
import javax.swing.border.Border;
import javax.swing.border.EtchedBorder;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.time.LocalDateTime;
import java.util.Enumeration;

public class ControlButtonsPanel extends JPanel implements ActionListener {

private static JButton openOrCancel;
// private final JButton openLocal = new JButton("Open N5 Local");
private final JButton copyLink;
private final JButton useN5Link;
private final JButton questionMark;
private final JButton openInMemory;
private final JCheckBox includeExampleExports;
private final JCheckBox todayInterval;
private final JCheckBox monthInterval;
private final JCheckBox yearlyInterval;
private final JCheckBox anyInterval;
private final JPanel timeFilter;

private N5ExportTable n5ExportTable;
private RemoteFileSelection remoteFileSelection;

public ControlButtonsPanel(){
openOrCancel = new JButton("Open");
copyLink = new JButton("Copy Link");
useN5Link = new JButton("Use N5 Link");
questionMark = new JButton("?");
questionMark.setPreferredSize(new Dimension(20, 20));
openInMemory = new JButton("Open In Memory");
openInMemory.setSelected(false);
includeExampleExports = new JCheckBox("Show Example Exports");
includeExampleExports.setSelected(!N5ImageHandler.exportedDataExists());

GridBagConstraints gridBagConstraints = new GridBagConstraints();

JPanel topRow = new JPanel(new GridBagLayout());
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 0;
topRow.add(openOrCancel, gridBagConstraints);
gridBagConstraints.gridwidth = 1;

gridBagConstraints.gridx = 1;
gridBagConstraints.gridy = 0;
topRow.add(openInMemory, gridBagConstraints);
gridBagConstraints.gridx = 2;

JPanel bottomRow = new JPanel(new GridBagLayout());
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 0;
bottomRow.add(copyLink, gridBagConstraints);
gridBagConstraints.gridx = 1;
bottomRow.add(useN5Link, gridBagConstraints);
bottomRow.add(questionMark);


JPanel userButtonsPanel = new JPanel(new GridBagLayout());
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 0;
userButtonsPanel.add(topRow, gridBagConstraints);
gridBagConstraints.gridy = 1;
userButtonsPanel.add(bottomRow, gridBagConstraints);

// buttonsPanel.add(questionMark);


todayInterval = new JCheckBox("Past 24 Hours");
monthInterval = new JCheckBox("Past Month");
yearlyInterval = new JCheckBox("Past Year");
anyInterval = new JCheckBox("Any Time");
anyInterval.setSelected(true);

ButtonGroup buttonGroup = new ButtonGroup();
buttonGroup.add(todayInterval);
buttonGroup.add(monthInterval);
buttonGroup.add(yearlyInterval);
buttonGroup.add(anyInterval);

JPanel filters = new JPanel();
filters.setLayout(new BorderLayout());
timeFilter = new JPanel(new GridBagLayout());
timeFilter.add(anyInterval);
timeFilter.add(todayInterval);
timeFilter.add(monthInterval);
timeFilter.add(yearlyInterval);
// timeFilter.setBorder(BorderFactory.createTitledBorder(lowerEtchedBorder, " Time "));
filters.add(timeFilter, BorderLayout.NORTH);
filters.add(includeExampleExports, BorderLayout.SOUTH);
Border lowerEtchedBorder = BorderFactory.createEtchedBorder(EtchedBorder.LOWERED);
filters.setBorder(BorderFactory.createTitledBorder(lowerEtchedBorder, " Filters "));


int paneWidth = 800;
this.setPreferredSize(new Dimension(paneWidth, 100));
this.setLayout(new BorderLayout());
// topBar.add(openLocal);
this.add(userButtonsPanel, BorderLayout.EAST);
this.add(filters, BorderLayout.WEST);
this.setBorder(BorderFactory.createTitledBorder(lowerEtchedBorder, " User Options "));


openOrCancel.addActionListener(this);
copyLink.addActionListener(this);
questionMark.addActionListener(this);
useN5Link.addActionListener(this);
includeExampleExports.addActionListener(this);
// openLocal.addActionListener(this);
openInMemory.addActionListener(this);

Enumeration<AbstractButton> b = buttonGroup.getElements();
while (b.hasMoreElements()){
b.nextElement().addActionListener(this);
}

openOrCancel.setEnabled(false);
copyLink.setEnabled(false);
openInMemory.setEnabled(false);
}

public void initialize(N5ExportTable n5ExportTable, RemoteFileSelection remoteFileSelection){
this.n5ExportTable = n5ExportTable;
this.remoteFileSelection = remoteFileSelection;
}

@Override
public void actionPerformed(ActionEvent e) {
if(e.getSource().equals(openOrCancel) || e.getSource().equals(openInMemory)){
if (openOrCancel.getText().equals("Cancel")){
n5ExportTable.removeFromLoadingRows();
} else {
n5ExportTable.openSelectedRows(e.getSource().equals(openInMemory));
}
} else if (e.getSource().equals(copyLink)) {
n5ExportTable.copySelectedRowLink();
} else if (e.getSource().equals(questionMark)) {
new HelpExplanation().displayHelpMenu();
} else if (e.getSource().equals(useN5Link)) {
remoteFileSelection.setVisible(true);
} else if (e.getSource().equals(includeExampleExports)){
if(includeExampleExports.isSelected()){
n5ExportTable.updateExampleExportsToTable();
return;
}
n5ExportTable.updateTableData();
} else if (e.getSource().equals(anyInterval) || e.getSource().equals(todayInterval)
|| e.getSource().equals(monthInterval) || e.getSource().equals(yearlyInterval)) {
if(includeExampleExports.isSelected()){
n5ExportTable.updateExampleExportsToTable();
return;
}
n5ExportTable.updateTableData();
}
}

public LocalDateTime oldestTimeAllowed(){
LocalDateTime pastTime = LocalDateTime.now();
if (todayInterval.isSelected()){
pastTime = pastTime.minusDays(1);
} else if (monthInterval.isSelected()) {
pastTime = pastTime.minusMonths(1);
} else if (yearlyInterval.isSelected()) {
pastTime = pastTime.minusYears(1);
} else {
pastTime = pastTime.minusYears(10); //Max date back is 10 years
}
return pastTime;
}

public void allowCancel(boolean allow){
openOrCancel.setEnabled(true);
copyLink.setEnabled(true);
openInMemory.setEnabled(!allow);
useN5Link.setEnabled(true);
remoteFileSelection.submitS3Info.setEnabled(true);
if (allow){
openOrCancel.setText("Cancel");
} else {
openOrCancel.setText("Open");
}
}

public void enableRowContextDependentButtons(boolean enable){
openOrCancel.setEnabled(enable);
copyLink.setEnabled(enable);
openInMemory.setEnabled(enable);
}

public void enableCriticalButtons(boolean enable){
useN5Link.setEnabled(enable);
openOrCancel.setEnabled(enable);
copyLink.setEnabled(enable);
remoteFileSelection.submitS3Info.setEnabled(enable);
openInMemory.setEnabled(enable);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
package org.vcell.N5.UI;

import javax.swing.*;
import javax.swing.border.Border;
import javax.swing.border.EtchedBorder;
import javax.swing.table.AbstractTableModel;
import java.awt.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

public class ExportDetailsPanel extends JSplitPane {
private final JTextPane variableTextPanel;
private final Border lowerEtchedBorder = BorderFactory.createEtchedBorder(EtchedBorder.LOWERED);
private final ParameterTableModel parameterTableModel;
private final JTable parameterTable;


public ExportDetailsPanel(){
super(JSplitPane.HORIZONTAL_SPLIT);
variableTextPanel = new JTextPane();
parameterTableModel = new ParameterTableModel();
parameterTable = new JTable(parameterTableModel);
JScrollPane parameterTableScrollPane = new JScrollPane(parameterTable);
int paneWidth = 800;
parameterTableScrollPane.setPreferredSize(new Dimension(paneWidth / 2, 80));
parameterTableScrollPane.setBorder(BorderFactory.createTitledBorder(lowerEtchedBorder, " Parameter Values "));
// jTextPane.setSize(800, 200);
variableTextPanel.setEditable(false);
JScrollPane jtextScrollPane = new JScrollPane(variableTextPanel);
jtextScrollPane.setPreferredSize(new Dimension(paneWidth / 2, 80));
jtextScrollPane.setBorder(BorderFactory.createTitledBorder(lowerEtchedBorder, " Variables "));

this.add(jtextScrollPane);
this.add(parameterTableScrollPane);
// exportDetails = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, jtextScrollPane, parameterTableScrollPane);
this.setBorder(BorderFactory.createTitledBorder(lowerEtchedBorder, " Export Details "));
this.setResizeWeight(0.5);
this.setContinuousLayout(true);

MainPanel.setEnableParentAndChild(this, false);
// return exportDetails;
}

public void resetExportDetails(){
parameterTableModel.resetTableData();
variableTextPanel.setText("");
MainPanel.setEnableParentAndChild(this, false);
}

public void addExportDetailEntries(String variableText, ArrayList<String> parameters){
variableTextPanel.setText(variableText);
for(String parameterValues : parameters){
String[] tokens = parameterValues.split(":");
parameterTableModel.addRowData(tokens[0], tokens[1], tokens[2]);
}
variableTextPanel.updateUI();
parameterTable.updateUI();
}


static class ParameterTableModel extends AbstractTableModel {

private final static String parameterHeader = "Parameter";
private final static String defaultValueHeader = "Default Value";
private final static String newValueHeader = "New Value";


private List<HashMap<String, String>> tableData = new ArrayList<>();
private final ArrayList<String> headers = new ArrayList<String>(){{
add(parameterHeader);
add(defaultValueHeader);
add(newValueHeader);
}};
@Override
public String getColumnName(int column) {
return headers.get(column);
}

@Override
public int getRowCount() {
return tableData.size();
}

@Override
public int getColumnCount() {
return headers.size();
}

@Override
public Object getValueAt(int rowIndex, int columnIndex) {
HashMap<String, String> rowData = tableData.get(rowIndex);
if(columnIndex == headers.indexOf(parameterHeader)){
return rowData.get(parameterHeader);
} else if (columnIndex == headers.indexOf(defaultValueHeader)) {
return rowData.get(defaultValueHeader);
} else if (columnIndex == headers.indexOf(newValueHeader)) {
return rowData.get(newValueHeader);
}
return null;
}

public void addRowData(String parameterName, String defaultValue, String newValue){
HashMap<String, String> data = new HashMap<String, String>(){{
put(parameterHeader, parameterName);
put(defaultValueHeader, defaultValue);
put(newValueHeader, newValue);
}};
tableData.add(data);
}

public void resetTableData(){
tableData = new ArrayList<>();
}

}
}
Loading

0 comments on commit 9e74f37

Please sign in to comment.