Skip to content

Commit

Permalink
Update Reduction GUI and ROI File Selection
Browse files Browse the repository at this point in the history
  • Loading branch information
AvocadoMoon committed Nov 6, 2024
1 parent 2a6f095 commit 78f1621
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 88 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
import ij.ImagePlus;
import ij.WindowManager;
import ij.gui.Roi;
import org.vcell.N5.N5ImageHandler;
import org.vcell.N5.UI.MainPanel;
import org.vcell.N5.retrieving.SimResultsLoader;

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;
Expand All @@ -23,7 +25,7 @@ public class DataReductionGUI extends JPanel implements ActionListener {
private final JOptionPane pane;
private File chosenFile;

private final int numSimsToOpen;
private final ArrayList<SimResultsLoader> filesToOpen;

public int mainGUIReturnValue;
public int fileChooserReturnValue;
Expand All @@ -32,8 +34,10 @@ public class DataReductionGUI extends JPanel implements ActionListener {
private final RoiSelection roiSelection;
private final NormalizeGUI normalizeGUI;

public DataReductionGUI(int numSimsToOpen, double simCSize, double simZSize, double simTSize){
this.numSimsToOpen = numSimsToOpen;
private final Border lowerEtchedBorder = BorderFactory.createEtchedBorder(EtchedBorder.LOWERED);

public DataReductionGUI(ArrayList<SimResultsLoader> filesToOpen, double simCSize, double simZSize, double simTSize){
this.filesToOpen = filesToOpen;
setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));

pane = new JOptionPane(this, JOptionPane.PLAIN_MESSAGE, JOptionPane.OK_CANCEL_OPTION);
Expand All @@ -44,9 +48,15 @@ public DataReductionGUI(int numSimsToOpen, double simCSize, double simZSize, dou
roiSelection = new RoiSelection();
normalizeGUI = new NormalizeGUI(jDialog, simTSize);

add(imageSelectionPanel());
add(new SelectMeasurements());
JPanel imagesToMeasurePanel = new JPanel();
imagesToMeasurePanel.setLayout(new BoxLayout(imagesToMeasurePanel, BoxLayout.Y_AXIS));
imagesToMeasurePanel.setBorder(BorderFactory.createTitledBorder(lowerEtchedBorder, "Images To Measure"));
imagesToMeasurePanel.add(imageSelectionPanel());
imagesToMeasurePanel.add(selectedImagesToOpenPanel());

add(imagesToMeasurePanel);
add(roiSelection);
add(new SelectMeasurements());
add(displayOptionsPanel());
add(normalizeGUI);
add(selectSimRange);
Expand Down Expand Up @@ -82,18 +92,34 @@ private DataReductionSubmission createSubmission(){
return new DataReductionSubmission(normalizeMeasurement.isSelected(),
roiSelection.getSimROIList(), roiSelection.getImageROIList(),
WindowManager.getImage((String) chosenImage.getSelectedItem()),
simRange[0], simRange[1], labRange[0], labRange[1], numSimsToOpen, chosenFile,
simRange[0], simRange[1], labRange[0], labRange[1], filesToOpen.size(), chosenFile,
selectSimRange.getRangeOfSim());
}

private JPanel imageSelectionPanel(){
JPanel jPanel = new JPanel(new GridLayout(1, 2));
jPanel.add(new JLabel("Select Experimental Image"));
jPanel.add(new JLabel("Experimental"));
chosenImage = new JComboBox<>(WindowManager.getImageTitles());
jPanel.add(chosenImage);
return jPanel;
}

private JPanel selectedImagesToOpenPanel(){
JPanel jPanel = new JPanel();
String[] namesOfImagesToOpen = new String[filesToOpen.size()];
for (int i = 0; i < filesToOpen.size(); i++){
namesOfImagesToOpen[i] = filesToOpen.get(i).userSetFileName;
}
JList<String> selectedImagesToOpen = new JList<>(namesOfImagesToOpen);
selectedImagesToOpen.setEnabled(false);
selectedImagesToOpen.setVisibleRowCount(4);
JScrollPane jScrollPane = new JScrollPane(selectedImagesToOpen);
jPanel.add(new JLabel("Selected Simulations"));
jPanel.add(jScrollPane);
jPanel.setLayout(new GridLayout(1, 2));
return jPanel;
}

private JPanel displayOptionsPanel(){
JPanel jPanel = new JPanel();
jPanel.setLayout(new BoxLayout(jPanel, BoxLayout.X_AXIS));
Expand Down Expand Up @@ -161,7 +187,7 @@ public DataReductionSubmission(boolean normalizeMeasurementsBool, ArrayList<Roi>
}

public static void main(String[] args) {
DataReductionGUI dataReductionGUI = new DataReductionGUI(0, 0, 0, 0);
DataReductionGUI dataReductionGUI = new DataReductionGUI(new ArrayList<>(), 0, 0, 0);
dataReductionGUI.displayGUI();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,54 +11,67 @@
import java.io.File;
import java.util.ArrayList;

class RoiSelection extends JPanel implements ActionListener {
private final JFileChooser imageROIFileChooser = new JFileChooser();
class RoiSelection extends JPanel {
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);

private final JButton imageROIFileButton;
private final JButton simROIFileButton;
public RoiSelection(){
this.setLayout(new BoxLayout(this, BoxLayout.X_AXIS));

private ArrayList<Roi> imageROIList;
private ArrayList<Roi> simROIList;
JList<String> imageROITable = new JList<>(imageTableModel);
JFileChooser imageROIFileChooser = new JFileChooser();
this.add(createROIInput(imageROITable, imageTableModel, imageROIFileChooser, "Experimental"));

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);
JList<String> simROITable = new JList<>(simTableModel);
JFileChooser simROIFileChooser = new JFileChooser();
this.add(createROIInput(simROITable, simTableModel, simROIFileChooser, "Sim"));
this.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), "ROI Files"));
}

private JPanel createROIInput(JList<String> jList, ROIDataModel roiDataModel,
JFileChooser fileChooser, String label){
JPanel jPanel = new JPanel();
jPanel.setLayout(new BoxLayout(jPanel, BoxLayout.Y_AXIS));
jList.setVisibleRowCount(4);
JScrollPane jScrollPane = new JScrollPane(jList);
jPanel.add(jScrollPane);

JButton addButton = new JButton("+");
addButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
ArrayList<Roi> roiList = fillROIList(fileChooser);
for (Roi roi : roiList){
roiDataModel.addRow(roi);
}
jList.updateUI();
}
});
JButton minusButton = new JButton("-");
minusButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
for (int roiIndex: jList.getSelectedIndices()){
roiDataModel.removeRow(roiIndex);
}
jList.updateUI();
}
});
JPanel buttonPanel = new JPanel(new GridLayout(1, 2));
buttonPanel.add(addButton);
buttonPanel.add(minusButton);
jPanel.add(buttonPanel);
jPanel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEmptyBorder(), label));

return jPanel;
}

public ArrayList<Roi> getImageROIList(){
return imageROIList;
return imageTableModel.data;
}

public ArrayList<Roi> getSimROIList(){
return simROIList;
return simTableModel.data;
}

private void setROIPanelSettings(JPanel jPanel, JButton button, JScrollPane jScrollPane){
Expand All @@ -72,24 +85,6 @@ private void setROIPanelSettings(JPanel jPanel, JButton button, JScrollPane jScr
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();
}
}
private ArrayList<Roi> fillROIList(JFileChooser fileChooser){
fileChooser.setMultiSelectionEnabled(true);
int choice = fileChooser.showDialog(this, "Open ROI's");
Expand All @@ -102,35 +97,21 @@ private ArrayList<Roi> fillROIList(JFileChooser fileChooser){
return roiList;
}

class ROIDataModel extends AbstractTableModel {
private final ArrayList<String> 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;
static class ROIDataModel extends AbstractListModel<String> {
private final ArrayList<Roi> data = new ArrayList<>();
public void addRow(Roi roi){
data.add(roi);
}
public void removeRow(int index){data.remove(index);}

@Override
public String getColumnName(int column) {
return headers[column];
public int getSize() {
return data.size();
}

@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();
public String getElementAt(int index) {
return data.get(index).getName();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public void openN5FileDataset(ArrayList<SimResultsLoader> filesToOpen, boolean o
firstSim.createS3ClientAndReader();
ArrayList<Double> dimensions = firstSim.getN5Dimensions();
if (dataReduction){
dataReductionGUI = new DataReductionGUI(filesToOpen.size(), dimensions.get(2), dimensions.get(3), dimensions.get(4));
dataReductionGUI = new DataReductionGUI(filesToOpen, dimensions.get(2), dimensions.get(3), dimensions.get(4));
dataReductionGUI.displayGUI();
} else {
rangeSelector.displayRangeMenu(dimensions.get(2), dimensions.get(3), dimensions.get(4));
Expand Down

0 comments on commit 78f1621

Please sign in to comment.