From b6fea45e198be42351460e97511b4b0c41d0d93a Mon Sep 17 00:00:00 2001 From: Ezequiel Valencia Date: Fri, 25 Oct 2024 10:27:56 -0400 Subject: [PATCH] Data Reduction GUI Update Have the data reduction GUI be more coherent, and select range only be available for "Open In Memory" --- .../org/vcell/N5/UI/AdvancedFeatures.java | 22 ++- .../org/vcell/N5/UI/ControlButtonsPanel.java | 46 +++--- .../main/java/org/vcell/N5/UI/MainPanel.java | 2 +- .../java/org/vcell/N5/UI/N5ExportTable.java | 6 +- .../org/vcell/N5/UI/RemoteFileSelection.java | 2 +- .../vcell/N5/analysis/DataReductionGUI.java | 156 ++++++++++++++---- .../vcell/N5/retrieving/LoadingManager.java | 5 +- 7 files changed, 169 insertions(+), 70 deletions(-) diff --git a/view-simulation-results/src/main/java/org/vcell/N5/UI/AdvancedFeatures.java b/view-simulation-results/src/main/java/org/vcell/N5/UI/AdvancedFeatures.java index 31d1834..f2d6884 100644 --- a/view-simulation-results/src/main/java/org/vcell/N5/UI/AdvancedFeatures.java +++ b/view-simulation-results/src/main/java/org/vcell/N5/UI/AdvancedFeatures.java @@ -3,23 +3,33 @@ import javax.swing.*; import javax.swing.border.Border; import javax.swing.border.EtchedBorder; +import java.awt.*; public class AdvancedFeatures extends JPanel { public final JCheckBox inMemory; public final JCheckBox dataReduction; - public final JCheckBox rangeSelection; + public final JButton copyLink; + public final JButton useN5Link; public AdvancedFeatures(){ Border lowerEtchedBorder = BorderFactory.createEtchedBorder(EtchedBorder.LOWERED); + inMemory = new JCheckBox("Open In Memory"); - dataReduction = new JCheckBox("Data Reduction"); - rangeSelection = new JCheckBox("Select Range"); + dataReduction = new JCheckBox("Run Measurement Script"); + JPanel checkBoxPanel = new JPanel(); + checkBoxPanel.add(dataReduction); + + JPanel buttonPanel = new JPanel(); + copyLink = new JButton("Copy Link"); + useN5Link = new JButton("Use N5 Link"); + buttonPanel.add(copyLink); + buttonPanel.add(useN5Link); - add(inMemory); - add(dataReduction); - add(rangeSelection); + setLayout(new BorderLayout()); + add(buttonPanel, BorderLayout.NORTH); + add(checkBoxPanel, BorderLayout.SOUTH); this.setBorder(BorderFactory.createTitledBorder(lowerEtchedBorder, " Advanced Features ")); } diff --git a/view-simulation-results/src/main/java/org/vcell/N5/UI/ControlButtonsPanel.java b/view-simulation-results/src/main/java/org/vcell/N5/UI/ControlButtonsPanel.java index 83b2d52..2f3f872 100644 --- a/view-simulation-results/src/main/java/org/vcell/N5/UI/ControlButtonsPanel.java +++ b/view-simulation-results/src/main/java/org/vcell/N5/UI/ControlButtonsPanel.java @@ -12,9 +12,8 @@ public class ControlButtonsPanel extends JPanel implements ActionListener { private static JButton openOrCancel; + private JButton openInMemory; // private final JButton openLocal = new JButton("Open N5 Local"); - private final JButton copyLink; - private final JButton useN5Link; private final JButton questionMark; public final JCheckBox includeExampleExports; @@ -30,9 +29,8 @@ public ControlButtonsPanel(){ displayAdvancedFeatures = new JCheckBox("Advanced Features"); - openOrCancel = new JButton("Open"); - copyLink = new JButton("Copy Link"); - useN5Link = new JButton("Use N5 Link"); + openOrCancel = new JButton("Open Virtually"); + openInMemory = new JButton("Open In Memory"); questionMark = new JButton("?"); questionMark.setPreferredSize(new Dimension(20, 20)); @@ -44,12 +42,9 @@ public ControlButtonsPanel(){ topRow.add(openOrCancel, gridBagConstraints); gridBagConstraints.gridx = 1; - topRow.add(copyLink, gridBagConstraints); + topRow.add(openInMemory, gridBagConstraints); gridBagConstraints.gridx = 2; - topRow.add(useN5Link, gridBagConstraints); - - gridBagConstraints.gridx = 3; topRow.add(questionMark); JPanel bottomRow = new JPanel(new GridBagLayout()); @@ -72,7 +67,7 @@ public ControlButtonsPanel(){ int paneWidth = 800; - this.setPreferredSize(new Dimension(paneWidth, 80)); + this.setPreferredSize(new Dimension(paneWidth, 110)); this.setLayout(new BorderLayout()); // topBar.add(openLocal); Border lowerEtchedBorder = BorderFactory.createEtchedBorder(EtchedBorder.LOWERED); @@ -84,16 +79,18 @@ public ControlButtonsPanel(){ openOrCancel.addActionListener(this); - copyLink.addActionListener(this); + advancedFeatures.copyLink.addActionListener(this); questionMark.addActionListener(this); - useN5Link.addActionListener(this); + advancedFeatures.useN5Link.addActionListener(this); // openLocal.addActionListener(this); includeExampleExports.addActionListener(this); displayAdvancedFeatures.addActionListener(this); + openInMemory.addActionListener(this); openOrCancel.setEnabled(false); - copyLink.setEnabled(false); + openInMemory.setEnabled(false); + advancedFeatures.copyLink.setEnabled(false); } public void initialize(N5ExportTable n5ExportTable, RemoteFileSelection remoteFileSelection){ @@ -103,17 +100,17 @@ public void initialize(N5ExportTable n5ExportTable, RemoteFileSelection remoteFi @Override public void actionPerformed(ActionEvent e) { - if(e.getSource().equals(openOrCancel)){ + if(e.getSource().equals(openOrCancel) || e.getSource().equals(openInMemory)){ if (openOrCancel.getText().equals("Cancel")){ n5ExportTable.removeFromLoadingRows(); } else { - n5ExportTable.openSelectedRows(); + n5ExportTable.openSelectedRows(e.getSource().equals(openInMemory)); } - } else if (e.getSource().equals(copyLink)) { + } else if (e.getSource().equals(advancedFeatures.copyLink)) { n5ExportTable.copySelectedRowLink(); } else if (e.getSource().equals(questionMark)) { new HelpExplanation().displayHelpMenu(); - } else if (e.getSource().equals(useN5Link)) { + } else if (e.getSource().equals(advancedFeatures.useN5Link)) { remoteFileSelection.setVisible(true); } else if (e.getSource().equals(includeExampleExports)){ n5ExportTable.updateTableData(); @@ -124,25 +121,28 @@ public void actionPerformed(ActionEvent e) { public void allowCancel(boolean allow){ openOrCancel.setEnabled(true); - copyLink.setEnabled(true); - useN5Link.setEnabled(true); + advancedFeatures.copyLink.setEnabled(true); + advancedFeatures.useN5Link.setEnabled(true); remoteFileSelection.submitS3Info.setEnabled(true); + openInMemory.setEnabled(!allow); if (allow){ openOrCancel.setText("Cancel"); } else { - openOrCancel.setText("Open"); + openOrCancel.setText("Open Virtually"); } } public void enableRowContextDependentButtons(boolean enable){ openOrCancel.setEnabled(enable); - copyLink.setEnabled(enable); + advancedFeatures.copyLink.setEnabled(enable); + openInMemory.setEnabled(enable); } public void enableCriticalButtons(boolean enable){ - useN5Link.setEnabled(enable); + advancedFeatures.useN5Link.setEnabled(enable); openOrCancel.setEnabled(enable); - copyLink.setEnabled(enable); + advancedFeatures.copyLink.setEnabled(enable); remoteFileSelection.submitS3Info.setEnabled(enable); + openInMemory.setEnabled(enable); } } diff --git a/view-simulation-results/src/main/java/org/vcell/N5/UI/MainPanel.java b/view-simulation-results/src/main/java/org/vcell/N5/UI/MainPanel.java index 6a05bb6..8f82d9f 100644 --- a/view-simulation-results/src/main/java/org/vcell/N5/UI/MainPanel.java +++ b/view-simulation-results/src/main/java/org/vcell/N5/UI/MainPanel.java @@ -45,7 +45,7 @@ public MainPanel(){ filters.add(searchBar, BorderLayout.SOUTH); parentPanel.add(filters, BorderLayout.SOUTH); - parentPanel.setPreferredSize(new Dimension(paneWidth, 650)); + parentPanel.setPreferredSize(new Dimension(paneWidth, 750)); JOptionPane pane = new JOptionPane(parentPanel, JOptionPane.PLAIN_MESSAGE, 0, null, new Object[]{"Close"}); exportTableDialog = pane.createDialog("VCell Exports"); exportTableDialog.setModal(false); 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 cf21e7f..27ad19a 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 @@ -155,7 +155,7 @@ private void automaticRefresh(){ refreshTableThread.start(); } - public void openSelectedRows(){ + public void openSelectedRows(boolean openInMemory){ ArrayList filesToOpen = new ArrayList<>(); for(int row: exportListTable.getSelectedRows()){ String uri = n5ExportTableModel.getRowData(row).uri; @@ -164,8 +164,8 @@ public void openSelectedRows(){ filesToOpen.add(simResultsLoader); } AdvancedFeatures advancedFeatures = MainPanel.controlButtonsPanel.advancedFeatures; - N5ImageHandler.loadingManager.openN5FileDataset(filesToOpen, advancedFeatures.inMemory.isSelected(), - advancedFeatures.rangeSelection.isSelected(), advancedFeatures.dataReduction.isSelected()); + N5ImageHandler.loadingManager.openN5FileDataset(filesToOpen, openInMemory, + advancedFeatures.dataReduction.isSelected()); } public void copySelectedRowLink(){ 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 374adae..fbe16b9 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 @@ -98,7 +98,7 @@ public void actionPerformed(ActionEvent e) { SimResultsLoader simResultsLoader = new SimResultsLoader(getS3URL(), "", -1, ""); AdvancedFeatures advancedFeatures = MainPanel.controlButtonsPanel.advancedFeatures; N5ImageHandler.loadingManager.openN5FileDataset(new ArrayList(){{add(simResultsLoader);}}, - advancedFeatures.inMemory.isSelected(), advancedFeatures.rangeSelection.isSelected(), + advancedFeatures.inMemory.isSelected(), advancedFeatures.dataReduction.isSelected()); this.setVisible(false); } diff --git a/view-simulation-results/src/main/java/org/vcell/N5/analysis/DataReductionGUI.java b/view-simulation-results/src/main/java/org/vcell/N5/analysis/DataReductionGUI.java index 9ea4a93..4f1dedd 100644 --- a/view-simulation-results/src/main/java/org/vcell/N5/analysis/DataReductionGUI.java +++ b/view-simulation-results/src/main/java/org/vcell/N5/analysis/DataReductionGUI.java @@ -7,6 +7,7 @@ import org.vcell.N5.N5ImageHandler; import javax.swing.*; +import javax.swing.table.AbstractTableModel; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; @@ -29,11 +30,8 @@ public class DataReductionGUI extends JPanel implements ActionListener { private String notInMemoryWarning; - private final JFileChooser imageROIFileChooser = new JFileChooser(); - private final JFileChooser simROIFileChooser = new JFileChooser(); - - private ArrayList imageROIList; private ArrayList simROIList; + private ArrayList imageROIList; private final JDialog jDialog; private final JOptionPane pane; @@ -73,12 +71,11 @@ public DataReductionSubmission(){ public DataReductionGUI(int numSimsToOpen){ this.numSimsToOpen = numSimsToOpen; - setLayout(new GridLayout(4, 1)); + setLayout(new BorderLayout()); - add(imageAndAnalysisType()); - add(roisSelectedGUI()); - add(normalizeGUI()); - setSize(400, 400); + add(imageAndAnalysisType(), BorderLayout.NORTH); + add(new ROISelection(), BorderLayout.CENTER); + add(normalizeGUI(), BorderLayout.SOUTH); setVisible(true); pane = new JOptionPane(this, JOptionPane.PLAIN_MESSAGE, JOptionPane.OK_CANCEL_OPTION); @@ -124,7 +121,8 @@ private JPanel normalizeGUI(){ fromSim.add(new JLabel("to")); fromSim.add(createNormFromSimEnd); - entireImageFramesJPanel = new JPanel(new GridLayout(2, 1)); + entireImageFramesJPanel = new JPanel(new GridLayout(3, 1)); + entireImageFramesJPanel.add(explainInput); entireImageFramesJPanel.add(fromImage); entireImageFramesJPanel.add(fromSim); entireImageFramesJPanel.setVisible(false); @@ -134,40 +132,34 @@ private JPanel normalizeGUI(){ return jPanel; } - private JPanel roisSelectedGUI(){ - JPanel jPanel = new JPanel(new BorderLayout()); - imageROIFileButton = new JButton("ROI's For Image"); - simROIFileButton = new JButton("ROI's For Simulation"); - - imageROIFileButton.addActionListener(this); - simROIFileButton.addActionListener(this); - - jPanel.add(imageROIFileButton, BorderLayout.WEST); - jPanel.add(simROIFileButton, BorderLayout.EAST); - return jPanel; - } - private JPanel imageAndAnalysisType(){ - JPanel jPanel = new JPanel(new BorderLayout()); + JPanel jPanel = new JPanel(new GridLayout(2,4)); + GridBagConstraints gridBagConstraints = new GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 0; + jPanel.add(new JLabel("Select Experimental Image"), gridBagConstraints); + gridBagConstraints.gridy = 1; chosenImage = new JComboBox<>(WindowManager.getImageTitles()); - chosenMeasurement = new JComboBox<>(new String[]{AvailableMeasurements.MEDIAN.publicName}); + jPanel.add(chosenImage, gridBagConstraints); + gridBagConstraints.gridy = 2; + jPanel.add(new JLabel("Measurement Type"), gridBagConstraints); + gridBagConstraints.gridy = 3; + chosenMeasurement = new JComboBox<>(new String[]{AvailableMeasurements.AVERAGE.publicName}); + jPanel.add(chosenMeasurement, gridBagConstraints); chosenMeasurement.addActionListener(this); chosenImage.addActionListener(this); - jPanel.add(chosenImage, BorderLayout.NORTH); - jPanel.add(chosenMeasurement, BorderLayout.SOUTH); + return jPanel; } + + @Override public void actionPerformed(ActionEvent e) { - if (e.getSource().equals(imageROIFileButton)){ - imageROIList = fillROIList(imageROIFileChooser); - } else if (e.getSource().equals(simROIFileButton)) { - simROIList = fillROIList(simROIFileChooser); - } else if (e.getSource().equals(normalizeMeasurement)) { + if (e.getSource().equals(normalizeMeasurement)) { entireImageFramesJPanel.setVisible(normalizeMeasurement.isSelected()); } } @@ -185,7 +177,7 @@ private ArrayList fillROIList(JFileChooser fileChooser){ } enum AvailableMeasurements{ - MEDIAN("Median"); + AVERAGE("Average"); public final String publicName; AvailableMeasurements(String publicName){ @@ -197,6 +189,104 @@ public static void main(String[] args) { DataReductionGUI dataReductionGUI = new DataReductionGUI(0); dataReductionGUI.displayGUI(); } + + class ROISelection extends JPanel implements ActionListener{ + private final JFileChooser imageROIFileChooser = new JFileChooser(); + private final ROIDataModel imageTableModel = new ROIDataModel(); + private final JTable imageROITable = new JTable(imageTableModel); + + private final JFileChooser simROIFileChooser = new JFileChooser(); + private final ROIDataModel simTableModel = new ROIDataModel(); + private final JTable simROITable = new JTable(simTableModel); + public ROISelection(){ + JPanel roisForImage = new JPanel(new GridBagLayout()); + JPanel roisForSims = new JPanel(new GridBagLayout()); + Dimension tableDimensions = new Dimension(100, 70); + imageROITable.getTableHeader().setBackground(Color.WHITE); + imageROITable.setEnabled(false); + simROITable.getTableHeader().setBackground(Color.WHITE); + simROITable.setEnabled(false); + + imageROIFileButton = new JButton("ROI's For Image"); + JScrollPane displayImageROIList = new JScrollPane(imageROITable); + displayImageROIList.setPreferredSize(tableDimensions); + setROIPanelSettings(roisForImage, imageROIFileButton, displayImageROIList); + + simROIFileButton = new JButton("ROI's For Simulation"); + JScrollPane displaySimROIList = new JScrollPane(simROITable); + displaySimROIList.setPreferredSize(tableDimensions); + setROIPanelSettings(roisForSims, simROIFileButton, displaySimROIList); + + imageROIFileButton.addActionListener(this); + simROIFileButton.addActionListener(this); + + this.setLayout(new BorderLayout()); + this.add(roisForImage, BorderLayout.WEST); + this.add(roisForSims, BorderLayout.EAST); + } + + public void setROIPanelSettings(JPanel jPanel, JButton button, JScrollPane jScrollPane){ + GridBagConstraints gridBagConstraints = new GridBagConstraints(); + gridBagConstraints.gridy = 0; + gridBagConstraints.gridx = 0; + gridBagConstraints.fill = GridBagConstraints.BOTH; + gridBagConstraints.insets = new Insets(5, 5, 5, 5); + jPanel.add(button, gridBagConstraints); + gridBagConstraints.gridy = 1; + jPanel.add(jScrollPane, gridBagConstraints); + } + + @Override + public void actionPerformed(ActionEvent e) { + if (e.getSource().equals(imageROIFileButton)){ + imageROIList = fillROIList(imageROIFileChooser); + imageTableModel.clear(); + for (Roi roi : imageROIList){ + imageTableModel.addRow(roi.getName()); + } + imageROITable.updateUI(); + } else if (e.getSource().equals(simROIFileButton)) { + simROIList = fillROIList(simROIFileChooser); + simTableModel.clear(); + for (Roi roi : simROIList){ + simTableModel.addRow(roi.getName()); + } + simROITable.updateUI(); + } + } + + class ROIDataModel extends AbstractTableModel { + private final ArrayList data = new ArrayList<>(); + private final String[] headers = new String[]{"ROI's Selected"}; + @Override + public int getRowCount() { + return data.size(); + } + + @Override + public int getColumnCount() { + return headers.length; + } + + @Override + public String getColumnName(int column) { + return headers[column]; + } + + @Override + public Object getValueAt(int rowIndex, int columnIndex) { + return data.get(rowIndex); + } + + public void addRow(String roiName){ + data.add(roiName); + } + + public void clear(){ + data.clear(); + } + } + } } diff --git a/view-simulation-results/src/main/java/org/vcell/N5/retrieving/LoadingManager.java b/view-simulation-results/src/main/java/org/vcell/N5/retrieving/LoadingManager.java index 8e83d88..9aa3cab 100644 --- a/view-simulation-results/src/main/java/org/vcell/N5/retrieving/LoadingManager.java +++ b/view-simulation-results/src/main/java/org/vcell/N5/retrieving/LoadingManager.java @@ -29,10 +29,9 @@ public class LoadingManager implements SimLoadingEventCreator { private static final Logger logger = N5ImageHandler.getLogger(RangeSelector.class); - public void openN5FileDataset(ArrayList filesToOpen, boolean openInMemory, - boolean selectRange, boolean dataReduction){ + public void openN5FileDataset(ArrayList filesToOpen, boolean openInMemory, boolean dataReduction){ RangeSelector rangeSelector = new RangeSelector(); - if (selectRange){ + if (openInMemory){ SimResultsLoader firstSim = filesToOpen.get(0); firstSim.createS3ClientAndReader(); ArrayList dimensions = firstSim.getN5Dimensions();