mirror of
https://github.com/paulscherrerinstitute/ch.psi.imagej.hdf5.git
synced 2025-04-21 05:30:02 +02:00
externalized Panel for dialog
This commit is contained in:
parent
be80fb446a
commit
d7f6602944
@ -284,34 +284,7 @@ public class HDF5Reader implements PlugIn {
|
||||
GenericDialog gd = new GenericDialog("Variable Name Selection");
|
||||
gd.addMessage("Please select variables to be loaded.\n");
|
||||
|
||||
// Filter datasets that are not potential images / that cannot be displayed
|
||||
List<Dataset> fdatasets = new ArrayList<Dataset>();
|
||||
for(Dataset d: datasets){
|
||||
if(d.getRank()>=2 && d.getRank()<=5){
|
||||
fdatasets.add(d);
|
||||
}
|
||||
}
|
||||
|
||||
JList<Dataset> list = new JList<>(fdatasets.toArray(new Dataset[fdatasets.size()]));
|
||||
list.setCellRenderer(new DefaultListCellRenderer() {
|
||||
private static final long serialVersionUID = 1L;
|
||||
public Component getListCellRendererComponent(JList<?> list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
|
||||
JLabel label = (JLabel) super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
|
||||
final Dataset d = ((Dataset) value);
|
||||
label.setText(d.getFullName()+" ("+d.getRank()+"D)");
|
||||
return label;
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
JScrollPane scroll = new JScrollPane(list);
|
||||
scroll.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
|
||||
|
||||
JPanel panel = new JPanel();
|
||||
panel.setLayout(new BoxLayout(panel,BoxLayout.Y_AXIS));
|
||||
panel.add(scroll);
|
||||
JCheckBox checkbox = new JCheckBox("Group Datasets (2D datasets only)");
|
||||
panel.add(checkbox);
|
||||
SelectionPanel panel = new SelectionPanel(datasets);
|
||||
|
||||
gd = new GenericDialog("Variable Name Selection");
|
||||
gd.add(panel);
|
||||
@ -321,8 +294,8 @@ public class HDF5Reader implements PlugIn {
|
||||
|
||||
SelectedDatasets selectedDatasets = new SelectedDatasets();
|
||||
if (!gd.wasCanceled()) {
|
||||
selectedDatasets.setDatasets(list.getSelectedValuesList());
|
||||
selectedDatasets.setGroup(checkbox.isSelected());
|
||||
selectedDatasets.setDatasets(panel.getSelectedValues());
|
||||
selectedDatasets.setGroup(panel.groupValues());
|
||||
}
|
||||
|
||||
return selectedDatasets;
|
||||
|
90
src/main/java/ch/psi/imagej/hdf5/SelectionPanel.java
Normal file
90
src/main/java/ch/psi/imagej/hdf5/SelectionPanel.java
Normal file
@ -0,0 +1,90 @@
|
||||
package ch.psi.imagej.hdf5;
|
||||
|
||||
import java.awt.Component;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.swing.BoxLayout;
|
||||
import javax.swing.DefaultListCellRenderer;
|
||||
import javax.swing.DefaultListModel;
|
||||
import javax.swing.JCheckBox;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JList;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JScrollPane;
|
||||
import javax.swing.ScrollPaneConstants;
|
||||
|
||||
import ncsa.hdf.object.Dataset;
|
||||
import javax.swing.JTextField;
|
||||
import javax.swing.JSpinner;
|
||||
import java.awt.FlowLayout;
|
||||
|
||||
public class SelectionPanel extends JPanel {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private final JList<Dataset> list;
|
||||
private JCheckBox checkbox;
|
||||
private JCheckBox chckbxNewCheckBox;
|
||||
private JLabel lblSlice;
|
||||
private JPanel panel;
|
||||
private JTextField textField;
|
||||
|
||||
public SelectionPanel(){
|
||||
this(new ArrayList<Dataset>());
|
||||
}
|
||||
|
||||
public SelectionPanel(List<Dataset> datasets){
|
||||
// Filter datasets that are not potential images / that cannot be displayed
|
||||
List<Dataset> fdatasets = new ArrayList<Dataset>();
|
||||
for(Dataset d: datasets){
|
||||
if(d.getRank()>=2 && d.getRank()<=5){
|
||||
fdatasets.add(d);
|
||||
}
|
||||
}
|
||||
|
||||
list = new JList<>(new DefaultListModel<Dataset>());
|
||||
list.setListData(fdatasets.toArray(new Dataset[fdatasets.size()]));
|
||||
list.setCellRenderer(new DefaultListCellRenderer() {
|
||||
private static final long serialVersionUID = 1L;
|
||||
public Component getListCellRendererComponent(JList<?> list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
|
||||
JLabel label = (JLabel) super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
|
||||
final Dataset d = ((Dataset) value);
|
||||
label.setText(d.getFullName()+" ("+d.getRank()+"D)");
|
||||
return label;
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
JScrollPane scroll = new JScrollPane(list);
|
||||
scroll.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
|
||||
|
||||
setLayout(new BoxLayout(this,BoxLayout.Y_AXIS));
|
||||
add(scroll);
|
||||
checkbox = new JCheckBox("Group Datasets (2D datasets only)");
|
||||
add(checkbox);
|
||||
|
||||
chckbxNewCheckBox = new JCheckBox("Virtual Stack");
|
||||
add(chckbxNewCheckBox);
|
||||
|
||||
panel = new JPanel();
|
||||
FlowLayout flowLayout = (FlowLayout) panel.getLayout();
|
||||
flowLayout.setAlignment(FlowLayout.LEFT);
|
||||
add(panel);
|
||||
|
||||
lblSlice = new JLabel("Slice:");
|
||||
panel.add(lblSlice);
|
||||
|
||||
textField = new JTextField();
|
||||
panel.add(textField);
|
||||
textField.setColumns(10);
|
||||
}
|
||||
|
||||
public List<Dataset> getSelectedValues(){
|
||||
return list.getSelectedValuesList();
|
||||
}
|
||||
|
||||
public boolean groupValues(){
|
||||
return checkbox.isSelected();
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user