Skip to content

Commit 3f01ebb

Browse files
ROI Manager For ROI Source
Instead of asking users to select files. Use the ROI manager to load the ROI's preemptively, and select them continuously so long as ImageJ is open.
1 parent 7b5c239 commit 3f01ebb

File tree

2 files changed

+93
-2
lines changed

2 files changed

+93
-2
lines changed
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
package org.vcell.N5.reduction.GUI;
2+
3+
import ij.gui.Roi;
4+
import ij.plugin.frame.RoiManager;
5+
6+
import javax.swing.*;
7+
import javax.swing.table.DefaultTableModel;
8+
import java.awt.event.ActionEvent;
9+
import java.awt.event.ActionListener;
10+
import java.util.ArrayList;
11+
import java.util.Arrays;
12+
13+
public class AvailableROIs extends JDialog implements ActionListener {
14+
private final JButton okayButton = new JButton("Okay");
15+
private final JButton cancelButton = new JButton("Cancel");
16+
private final ROIDataModel roiDataModel = new ROIDataModel();
17+
private final JTable table = new JTable(roiDataModel);
18+
private int[] selectedRows = new int[0];
19+
20+
public AvailableROIs(){
21+
JScrollPane scrollPane = new JScrollPane(table);
22+
23+
JPanel buttonPanel = new JPanel();
24+
okayButton.addActionListener(this);
25+
cancelButton.addActionListener(this);
26+
buttonPanel.add(okayButton);
27+
buttonPanel.add(cancelButton);
28+
29+
this.setLayout(new BoxLayout(this.getContentPane(), BoxLayout.Y_AXIS));
30+
31+
this.add(scrollPane);
32+
this.add(buttonPanel);
33+
this.setSize(300, 300);
34+
this.setModal(true);
35+
this.setVisible(true);
36+
37+
38+
}
39+
40+
public ArrayList<Roi> getSelectedRows(){
41+
ArrayList<Roi> selectedRois = new ArrayList<>();
42+
for (int selectedRow : selectedRows){
43+
selectedRois.add(roiDataModel.rois.get(selectedRow));
44+
}
45+
return selectedRois;
46+
}
47+
48+
@Override
49+
public void actionPerformed(ActionEvent e) {
50+
if (e.getSource().equals(okayButton)){
51+
selectedRows = table.getSelectedRows();
52+
this.dispose();
53+
} else if (e.getSource().equals(cancelButton)){
54+
this.dispose();
55+
}
56+
}
57+
58+
private static class ROIDataModel extends DefaultTableModel{
59+
private final ArrayList<Roi> rois;
60+
public ROIDataModel(){
61+
rois = new ArrayList<>();
62+
rois.addAll(Arrays.asList(RoiManager.getRoiManager().getRoisAsArray()));
63+
}
64+
65+
@Override
66+
public int getRowCount() {
67+
if (rois == null){
68+
return 0;
69+
}
70+
return rois.size();
71+
}
72+
73+
@Override
74+
public String getColumnName(int column) {
75+
return "Available ROI's From ROI Manager";
76+
}
77+
78+
@Override
79+
public int getColumnCount() {
80+
return 1;
81+
}
82+
83+
@Override
84+
public Object getValueAt(int rowIndex, int columnIndex) {
85+
return rois.get(rowIndex).getName();
86+
}
87+
}
88+
89+
}

view-simulation-results/src/main/java/org/vcell/N5/reduction/GUI/RoiSelection.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import ij.gui.Roi;
44
import ij.io.RoiDecoder;
5+
import ij.plugin.frame.RoiManager;
56

67
import javax.swing.*;
78
import java.awt.*;
@@ -25,7 +26,7 @@ public RoiSelection(DataReductionGUI parentGUI){
2526
JList<String> simROITable = new JList<>(simTableModel);
2627
JFileChooser simROIFileChooser = new JFileChooser();
2728
this.add(createROIInput(simROITable, simTableModel, simROIFileChooser, "Sim"));
28-
this.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), "Apply 2D ROI Files"));
29+
this.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), "Apply ROI"));
2930
this.parentGUI = parentGUI;
3031
}
3132

@@ -41,7 +42,8 @@ private JPanel createROIInput(JList<String> jList, ROIDataModel roiDataModel,
4142
addButton.addActionListener(new ActionListener() {
4243
@Override
4344
public void actionPerformed(ActionEvent e) {
44-
ArrayList<Roi> roiList = fillROIList(fileChooser);
45+
AvailableROIs availableROIs = new AvailableROIs();
46+
ArrayList<Roi> roiList = availableROIs.getSelectedRows();
4547
for (Roi roi : roiList){
4648
roiDataModel.addRow(roi);
4749
}

0 commit comments

Comments
 (0)