From 951ff7bce1ace9df7a2df81dbebb072a63c96823 Mon Sep 17 00:00:00 2001 From: Pierre Pouchin Date: Sun, 5 Nov 2023 11:56:04 +0100 Subject: [PATCH] Add choice to load ROIs to ROI Manager or Overlay --- .../java/fr/igred/ij/io/LocalBatchImage.java | 2 +- src/main/java/fr/igred/ij/io/ROIMode.java | 6 ++-- .../fr/igred/ij/macro/BatchParameters.java | 19 +++++++----- .../fr/igred/ij/macro/OMEROBatchRunner.java | 8 ++--- .../ij/plugin/frame/OMEROBatchPlugin.java | 29 ++++++++++--------- 5 files changed, 32 insertions(+), 32 deletions(-) diff --git a/src/main/java/fr/igred/ij/io/LocalBatchImage.java b/src/main/java/fr/igred/ij/io/LocalBatchImage.java index 6aa3c40..f6e8b26 100644 --- a/src/main/java/fr/igred/ij/io/LocalBatchImage.java +++ b/src/main/java/fr/igred/ij/io/LocalBatchImage.java @@ -173,7 +173,7 @@ public ImageWrapper getImageWrapper() { @Override public ImagePlus getImagePlus(ROIMode mode) { ImagePlus imp = null; - boolean loadROIs = !mode.toString().isEmpty(); + boolean loadROIs = mode != ROIMode.DO_NOT_LOAD; try { ImporterOptions options = initImporterOptions(); options.setShowROIs(loadROIs); diff --git a/src/main/java/fr/igred/ij/io/ROIMode.java b/src/main/java/fr/igred/ij/io/ROIMode.java index c97a470..573dc97 100644 --- a/src/main/java/fr/igred/ij/io/ROIMode.java +++ b/src/main/java/fr/igred/ij/io/ROIMode.java @@ -25,9 +25,9 @@ */ public enum ROIMode { /** - * Do not load ROIs (empty String for ImporterOptions). + * Do not load ROIs. */ - DO_NOT_LOAD(""), + DO_NOT_LOAD("No"), /** * Load ROIs in the ROI Manager. */ @@ -38,7 +38,7 @@ public enum ROIMode { OVERLAY(ImporterOptions.ROIS_MODE_OVERLAY); /** - * ROI mode String value for ImporterOptions. + * ROI mode String value for ImporterOptions and user selection. */ private final String value; diff --git a/src/main/java/fr/igred/ij/macro/BatchParameters.java b/src/main/java/fr/igred/ij/macro/BatchParameters.java index 44b7feb..6090671 100644 --- a/src/main/java/fr/igred/ij/macro/BatchParameters.java +++ b/src/main/java/fr/igred/ij/macro/BatchParameters.java @@ -17,12 +17,15 @@ package fr.igred.ij.macro; +import fr.igred.ij.io.ROIMode; + + /** * Holds the parameters to batch run scripts. */ public class BatchParameters { - private boolean loadROIs; + private ROIMode roiMode; private boolean saveImages; private boolean saveROIs; private boolean saveResults; @@ -40,7 +43,7 @@ public class BatchParameters { * Default constructor. */ public BatchParameters() { - this.loadROIs = false; + this.roiMode = ROIMode.DO_NOT_LOAD; this.saveImages = false; this.saveROIs = false; this.saveResults = false; @@ -61,7 +64,7 @@ public BatchParameters() { * @param parameters The parameters to copy. */ public BatchParameters(BatchParameters parameters) { - this.loadROIs = parameters.loadROIs; + this.roiMode = parameters.roiMode; this.saveImages = parameters.saveImages; this.saveROIs = parameters.saveROIs; this.saveResults = parameters.saveResults; @@ -185,18 +188,18 @@ public void setSaveImages(boolean saveImages) { * * @return See above. */ - public boolean shouldLoadROIs() { - return loadROIs; + public ROIMode getROIMode() { + return roiMode; } /** * Sets whether the ROIs should be loaded or not. * - * @param loadROIs See above. + * @param roiMode See above. */ - public void setLoadROIS(boolean loadROIs) { - this.loadROIs = loadROIs; + public void setROIMode(ROIMode roiMode) { + this.roiMode = roiMode; } diff --git a/src/main/java/fr/igred/ij/macro/OMEROBatchRunner.java b/src/main/java/fr/igred/ij/macro/OMEROBatchRunner.java index c4135a0..223d622 100644 --- a/src/main/java/fr/igred/ij/macro/OMEROBatchRunner.java +++ b/src/main/java/fr/igred/ij/macro/OMEROBatchRunner.java @@ -494,23 +494,19 @@ private List getROIsFromManager(ImagePlus imp, String property) { /** * Runs a macro on images and saves the results. */ - void runMacro() { + private void runMacro() { String property = ROIWrapper.IJ_PROPERTY; WindowManager.closeAllWindows(); // Initialize ROI Manager initRoiManager(); - ROIMode roiMode = ROIMode.DO_NOT_LOAD; - if (params.shouldLoadROIs()) { - roiMode = ROIMode.MANAGER; - } int index = 0; for (BatchImage image : images) { //noinspection HardcodedFileSeparator setProgress("Image " + (index + 1) + "/" + images.size()); setState("Opening image..."); - ImagePlus imp = image.getImagePlus(roiMode); + ImagePlus imp = image.getImagePlus(params.getROIMode()); // If image could not be loaded, continue to next image. if (imp != null) { ImageWrapper imageWrapper = image.getImageWrapper(); diff --git a/src/main/java/fr/igred/ij/plugin/frame/OMEROBatchPlugin.java b/src/main/java/fr/igred/ij/plugin/frame/OMEROBatchPlugin.java index e62a27c..3def198 100644 --- a/src/main/java/fr/igred/ij/plugin/frame/OMEROBatchPlugin.java +++ b/src/main/java/fr/igred/ij/plugin/frame/OMEROBatchPlugin.java @@ -20,6 +20,7 @@ import fr.igred.ij.gui.OMEROConnectDialog; import fr.igred.ij.gui.ProgressDialog; import fr.igred.ij.io.BatchImage; +import fr.igred.ij.io.ROIMode; import fr.igred.ij.macro.BatchListener; import fr.igred.ij.macro.BatchParameters; import fr.igred.ij.macro.OMEROBatchRunner; @@ -97,7 +98,7 @@ public class OMEROBatchPlugin extends PlugInFrame implements BatchListener { // choices of input images private final JPanel input1a = new JPanel(); private final JPanel input1b = new JPanel(); - private final JPanel input1c = new JPanel(); + private final JPanel input3 = new JPanel(); private final JPanel input2 = new JPanel(); // group and user selection @@ -113,8 +114,8 @@ public class OMEROBatchPlugin extends PlugInFrame implements BatchListener { private final JComboBox datasetListIn = new JComboBox<>(); /** The checkbox to delete ROIs. */ private final JCheckBox checkDelROIs = new JCheckBox("Clear ROIs each time"); - /** The checkbox to load ROIs. */ - private final JCheckBox checkLoadROIs = new JCheckBox("Load ROIs"); + /** The list of possible output projects. */ + private final JComboBox roiMode = new JComboBox<>(ROIMode.values()); // choice of the record /** The input folder. */ @@ -286,9 +287,6 @@ public OMEROBatchPlugin() { projectListIn.setFont(listFont); datasetListIn.setFont(listFont); - input1c.add(checkLoadROIs); - input1c.add(checkDelROIs); - JLabel inputFolderLabel = new JLabel("Images folder: "); JButton inputFolderBtn = new JButton(browse); inputFolderLabel.setLabelFor(inputFolder); @@ -300,11 +298,16 @@ public OMEROBatchPlugin() { input2.add(recursive); inputFolderBtn.addActionListener(e -> chooseDirectory(inputFolder)); + JLabel labelROIMode = new JLabel("Load ROIs: "); + input3.add(labelROIMode); + input3.add(roiMode); + input3.add(checkDelROIs); + JPanel panelInput = new JPanel(); panelInput.add(input1a); panelInput.add(input1b); - panelInput.add(input1c); panelInput.add(input2); + panelInput.add(input3); panelInput.setLayout(new BoxLayout(panelInput, BoxLayout.PAGE_AXIS)); panelInput.setBorder(BorderFactory.createTitledBorder("Input")); super.add(panelInput); @@ -422,12 +425,12 @@ public OMEROBatchPlugin() { input2.setVisible(false); input1a.setVisible(true); input1b.setVisible(true); - input1c.setVisible(true); + input3.setVisible(true); super.pack(); input1a.setMaximumSize(new Dimension(input1a.getMaximumSize().width, input1a.getHeight())); input1b.setMaximumSize(new Dimension(input1b.getMaximumSize().width, input1b.getHeight())); - input1c.setMaximumSize(new Dimension(input1c.getMaximumSize().width, input1c.getHeight())); + input3.setMaximumSize(new Dimension(input3.getMaximumSize().width, input3.getHeight())); local.setSelected(true); @@ -799,17 +802,15 @@ private void updateInput(ItemEvent e) { if (connected) { input1a.setVisible(true); input1b.setVisible(true); - input1c.setVisible(true); - input1c.add(checkLoadROIs); input2.setVisible(false); + checkDelROIs.setVisible(true); } else { local.setSelected(true); } } else { //local.isSelected() input2.setVisible(true); - input2.add(checkLoadROIs); checkDelROIs.setSelected(false); - input1c.setVisible(false); + checkDelROIs.setVisible(false); input1b.setVisible(false); input1a.setVisible(false); } @@ -999,7 +1000,7 @@ public void start(ActionEvent e) { // input data params.setSuffix(suffix.getText()); - params.setLoadROIS(checkLoadROIs.isSelected()); + params.setROIMode(roiMode.getItemAt(roiMode.getSelectedIndex())); params.setClearROIS(checkDelROIs.isSelected()); params.setSaveImages(checkImage.isSelected()); params.setSaveResults(checkResults.isSelected());