getROIsFromOverlay(ImagePlus imp, String propert
* @param path The path to the file.
*/
private static void saveRoiFile(List extends Roi> ijRois, String path) {
- try (ZipOutputStream zos = new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(path)));
+ try (ZipOutputStream zos = new ZipOutputStream(new BufferedOutputStream(newOutputStream(Paths.get(path))));
DataOutputStream dos = new DataOutputStream(new BufferedOutputStream(zos))) {
RoiEncoder re = new RoiEncoder(dos);
for (int i = 0; i < ijRois.size(); i++) {
@@ -333,36 +297,48 @@ private static void saveRoiFile(List extends Roi> ijRois, String path) {
/**
- * Initializes the ROI manager.
+ * Adds a timestamp to the table name.
+ *
+ * @param table The table.
+ * @param name The table name.
*/
- private void initRoiManager() {
- rm = RoiManager.getInstance2();
- if (rm == null) rm = RoiManager.getRoiManager();
- rm.setVisible(false);
+ private static String renameTable(TableWrapper table, String name) {
+ String newName;
+ if (name == null || name.isEmpty()) {
+ newName = timestamp() + "_" + table.getName();
+ } else {
+ newName = timestamp() + "_" + name;
+ }
+ table.setName(newName);
+ return newName;
}
/**
- * Initializes the Bio-Formats importer options.
- *
- * @return See above.
+ * Saves a table as a text file.
*
- * @throws IOException If the importer options could not be initialized.
+ * @param table The table.
+ * @param path The path to the file.
*/
- private ImporterOptions initImporterOptions() throws IOException {
- ImporterOptions options = new ImporterOptions();
- options.setStackFormat(ImporterOptions.VIEW_HYPERSTACK);
- options.setSwapDimensions(false);
- options.setOpenAllSeries(false);
- options.setSpecifyRanges(false);
- options.setShowMetadata(false);
- options.setShowOMEXML(false);
- options.setShowROIs(loadROIs);
- options.setCrop(false);
- options.setSplitChannels(false);
- options.setSplitFocalPlanes(false);
- options.setSplitTimepoints(false);
- return options;
+ private static void saveTable(TableWrapper table, String path) {
+ try {
+ //noinspection MagicCharacter
+ table.saveAs(path, '\t');
+ } catch (FileNotFoundException | UnsupportedEncodingException e) {
+ IJ.error("Could not save table as file: " + e.getMessage());
+ }
+ }
+
+
+ /**
+ * Initializes the ROI manager.
+ */
+ private void initRoiManager() {
+ rm = RoiManager.getInstance2();
+ if (rm == null) {
+ rm = RoiManager.getRoiManager();
+ }
+ rm.setVisible(false);
}
@@ -372,7 +348,9 @@ private ImporterOptions initImporterOptions() throws IOException {
* @param text The text for the current state.
*/
private void setState(String text) {
- if (progress != null) progress.setState(text);
+ if (progress != null) {
+ progress.setState(text);
+ }
}
@@ -382,7 +360,9 @@ private void setState(String text) {
* @param text The text for the current progress.
*/
private void setProgress(String text) {
- if (progress != null) progress.setProgress(text);
+ if (progress != null) {
+ progress.setProgress(text);
+ }
}
@@ -390,15 +370,15 @@ private void setProgress(String text) {
* Signals the process is done.
*/
private void setDone() {
- if (progress != null) progress.setDone();
+ if (progress != null) {
+ progress.setDone();
+ }
}
/**
- * If this thread was constructed using a separate
- * {@code Runnable} run object, then that
- * {@code Runnable} object's {@code run} method is called;
- * otherwise, this method does nothing and returns.
+ * If this thread was constructed using a separate {@code Runnable} run object, then that {@code Runnable} object's
+ * {@code run} method is called; otherwise, this method does nothing and returns.
*
* Subclasses of {@code Thread} should override this method.
*
@@ -407,57 +387,51 @@ private void setDone() {
*/
@Override
public void run() {
- boolean finished = false;
+ boolean running = true;
if (progress instanceof ProgressDialog) {
((Component) progress).setVisible(true);
}
try {
- if (!outputOnLocal) {
+ if (!params.isOutputOnLocal()) {
setState("Temporary directory creation...");
- directoryOut = Files.createTempDirectory("Fiji_analysis").toString();
+ params.setDirectoryOut(Files.createTempDirectory("Fiji_analysis").toString());
}
- if (inputOnOMERO) {
- setState("Retrieving images from OMERO...");
- DatasetWrapper dataset = client.getDataset(inputDatasetId);
- List images = dataset.getImages(client);
- setState("Macro running...");
- runMacro(images);
- } else {
- setState("Retrieving files from input folder...");
- List files = getFilesFromDirectory(directoryIn, recursive);
- setState("Macro running...");
- runMacroOnLocalImages(files);
- }
+ setState("Macro running...");
+ runMacro();
setProgress("");
uploadTables();
- if (!outputOnLocal) {
+ if (!params.isOutputOnLocal()) {
setState("Temporary directory deletion...");
- if (!deleteTemp(directoryOut)) {
+ if (!deleteTemp(params.getDirectoryOut())) {
LOGGER.warning("Temp directory may not be deleted.");
}
}
- finished = true;
+ running = false;
setState("");
setDone();
- } catch (NoSuchElementException | IOException | ServiceException | AccessException | ExecutionException e) {
- finished = true;
+ } catch (IOException e) {
+ running = false;
setDone();
setProgress("Macro cancelled");
- if (e.getMessage() != null && "Macro cancelled".equals(e.getMessage())) {
+ if ("Macro cancelled".equals(e.getMessage())) {
IJ.run("Close");
}
IJ.error(e.getMessage());
} finally {
- if (!finished) {
+ if (running) {
setDone();
setProgress("An unexpected error occurred.");
}
- if (listener != null) listener.onThreadFinished();
- rm.setVisible(true);
- rm.close();
+ if (listener != null) {
+ listener.onThreadFinished();
+ }
+ if (rm != null) {
+ rm.setVisible(true);
+ rm.close();
+ }
}
}
@@ -471,11 +445,8 @@ private void deleteROIs(ImageWrapper image) {
setState("ROIs deletion from OMERO");
try {
List rois = image.getROIs(client);
- for (ROIWrapper roi : rois) {
- if (roi.getOwner().getId() == client.getId()) {
- client.delete(roi);
- }
- }
+ rois.removeIf(roi -> roi.getOwner().getId() != client.getId());
+ client.delete(rois);
} catch (ExecutionException | OMEROServerError | ServiceException | AccessException exception) {
LOGGER.warning(exception.getMessage());
} catch (InterruptedException e) {
@@ -494,7 +465,9 @@ private void deleteROIs(ImageWrapper image) {
*/
private List getManagedRois(ImagePlus imp) {
List ijRois = new ArrayList<>(Arrays.asList(rm.getRoisAsArray()));
- for (Roi roi : ijRois) roi.setImage(imp);
+ for (Roi roi : ijRois) {
+ roi.setImage(imp);
+ }
return ijRois;
}
@@ -519,31 +492,29 @@ private List getROIsFromManager(ImagePlus imp, String property) {
/**
- * Runs a macro on images from OMERO and saves the results.
- *
- * @param images List of images on OMERO.
+ * Runs a macro on images and saves the results.
*/
- void runMacro(List extends ImageWrapper> images) {
+ private void runMacro() {
String property = ROIWrapper.IJ_PROPERTY;
WindowManager.closeAllWindows();
+
int index = 0;
- for (ImageWrapper image : images) {
- setProgress("Image " + (index + 1) + "/" + images.size());
- long inputImageId = image.getId();
+ for (BatchImage image : images) {
+ // Initialize ROI Manager
+ initRoiManager();
- // Open image from OMERO
- ImagePlus imp = openImage(image);
+ //noinspection HardcodedFileSeparator
+ setProgress("Image " + (index + 1) + "/" + images.size());
+ setState("Opening image...");
+ ImagePlus imp = image.getImagePlus(params.getROIMode());
// If image could not be loaded, continue to next image.
if (imp != null) {
- // Initialize ROI Manager
- initRoiManager();
-
- // Load ROIs
- if (loadROIs) loadROIs(image, imp, false);
-
+ ImageWrapper imageWrapper = image.getImageWrapper();
+ Long inputImageId = imageWrapper != null ? imageWrapper.getId() : null;
imp.show();
- // Analyse the image
+ // Process the image
+ setState("Processing image...");
script.setImage(imp);
script.run();
@@ -556,89 +527,21 @@ void runMacro(List extends ImageWrapper> images) {
}
- /**
- * Runs a macro on local files and saves the results.
- *
- * @param files List of image files.
- *
- * @throws IOException A problem occurred reading a file.
- */
- void runMacroOnLocalImages(Collection files) throws IOException {
- String property = ROIWrapper.IJ_PROPERTY;
- WindowManager.closeAllWindows();
-
- ImporterOptions options = initImporterOptions();
- Map imageFiles = getImagesFromFiles(files, options);
- int nFile = 1;
- for (Map.Entry entry : imageFiles.entrySet()) {
- int n = entry.getValue();
- options.setId(entry.getKey());
- for (int i = 0; i < n; i++) {
- String msg = String.format("File %d/%d, image %d/%d", nFile, imageFiles.size(), i + 1, n);
- setProgress(msg);
- options.setSeriesOn(i, true);
- try {
- ImagePlus[] imps = BF.openImagePlus(options);
- ImagePlus imp = imps[0];
- imp.show();
-
- // Initialize ROI Manager
- initRoiManager();
-
- // Analyse the image
- script.setImage(imp);
- script.run();
-
- // Save and Close the various components
- imp.changes = false; // Prevent "Save Changes?" dialog
- save(imp, null, property);
- } catch (FormatException e) {
- IJ.error(e.getMessage());
- }
- closeWindows();
- options.setSeriesOn(i, false);
- }
- nFile++;
- }
- }
-
-
- /**
- * Opens an image from OMERO.
- *
- * @param image An OMERO image.
- *
- * @return An ImagePlus.
- */
- private ImagePlus openImage(ImageWrapper image) {
- setState("Opening image from OMERO...");
- ImagePlus imp = null;
- try {
- imp = image.toImagePlus(client);
- // Store image "annotate" permissions as a property in the ImagePlus object
- imp.setProp("Annotatable", String.valueOf(image.canAnnotate()));
- } catch (ExecutionException | ServiceException | AccessException e) {
- IJ.error("Could not load image: " + e.getMessage());
- }
- return imp;
- }
-
-
/**
* Loads ROIs from an image in OMERO into ImageJ.
*
- * @param image The OMERO image.
- * @param imp The image in ImageJ ROIs should be linked to.
- * @param toOverlay Whether the ROIs should be loaded to the ROI Manager (false) or the overlay (true).
+ * @param image The OMERO image.
+ * @param imp The image in ImageJ ROIs should be linked to.
+ * @param roiMode The mode used to load ROIs.
*/
- private void loadROIs(ImageWrapper image, ImagePlus imp, boolean toOverlay) {
+ private void loadROIs(ImageWrapper image, ImagePlus imp, ROIMode roiMode) {
List ijRois = new ArrayList<>(0);
try {
ijRois = ROIWrapper.toImageJ(image.getROIs(client));
} catch (ExecutionException | ServiceException | AccessException e) {
IJ.error("Could not load ROIs: " + e.getMessage());
}
- if (toOverlay) {
+ if (roiMode == ROIMode.OVERLAY) {
Overlay overlay = imp.getOverlay();
if (overlay != null) {
overlay.clear();
@@ -649,7 +552,7 @@ private void loadROIs(ImageWrapper image, ImagePlus imp, boolean toOverlay) {
ijRoi.setImage(imp);
overlay.add(ijRoi, ijRoi.getName());
}
- } else {
+ } else if (roiMode == ROIMode.MANAGER) {
rm.reset(); // Reset ROI manager to clear previous ROIs
for (Roi ijRoi : ijRois) {
ijRoi.setImage(imp);
@@ -672,31 +575,33 @@ private void save(ImagePlus inputImage, Long omeroInputId, String property) {
Long omeroOutputId = omeroInputId;
List outputs = getOutputImages(inputImage);
- ImagePlus outputImage = inputImage;
- if (!outputs.isEmpty()) outputImage = outputs.get(0);
+ ImagePlus outputImage = outputs.isEmpty() ? inputImage : outputs.get(0);
- // If input image is expected as output for ROIs on OMERO but is not annotable, import it.
- boolean annotable = Boolean.parseBoolean(inputImage.getProp("Annotable"));
+ boolean annotatable = Boolean.parseBoolean(inputImage.getProp("Annotatable"));
boolean outputIsNotInput = !inputImage.equals(outputImage);
- if (!outputOnOMERO || !saveROIs || annotable || outputIsNotInput) {
+ if (!params.isOutputOnOMERO() || !params.shouldSaveROIs() || annotatable || outputIsNotInput) {
outputs.removeIf(inputImage::equals);
}
- if (saveImage) {
- if (outputs.isEmpty()) LOGGER.info("Warning: there is no new image.");
- List outputIds = new ArrayList<>(outputs.size());
- outputs.forEach(imp -> outputIds.addAll(saveImage(imp, property)));
+ if (params.shouldSaveImages()) {
+ List outputIds = saveImages(outputs, property);
if (!outputIds.isEmpty() && outputIsNotInput) {
omeroOutputId = outputIds.get(0);
}
}
- if (saveROIs) {
- if (!saveImage) saveOverlay(outputImage, omeroOutputId, inputTitle, property);
+ if (params.shouldSaveROIs()) {
+ if (!params.shouldSaveImages()) {
+ saveOverlay(outputImage, omeroOutputId, inputTitle, property);
+ }
saveROIManager(outputImage, omeroOutputId, inputTitle, property);
}
- if (saveResults) saveResults(outputImage, omeroOutputId, inputTitle, property);
- if (saveLog) saveLog(omeroOutputId, inputTitle);
+ if (params.shouldSaveResults()) {
+ saveResults(outputImage, omeroOutputId, inputTitle, property);
+ }
+ if (params.shouldSaveLog()) {
+ saveLog(omeroOutputId, inputTitle);
+ }
for (ImagePlus imp : outputs) {
imp.changes = false;
@@ -705,6 +610,24 @@ private void save(ImagePlus inputImage, Long omeroInputId, String property) {
}
+ /**
+ * Saves images.
+ *
+ * @param outputs The images to save.
+ * @param property The ROI property used to group shapes in OMERO.
+ *
+ * @return The OMERO IDs of the (possibly) uploaded images.
+ */
+ private List saveImages(Collection extends ImagePlus> outputs, String property) {
+ if (outputs.isEmpty()) {
+ LOGGER.info("Warning: there is no new image.");
+ }
+ List outputIds = new ArrayList<>(outputs.size());
+ outputs.forEach(imp -> outputIds.addAll(saveImage(imp, property)));
+ return outputIds;
+ }
+
+
/**
* Saves an image.
*
@@ -716,14 +639,15 @@ private void save(ImagePlus inputImage, Long omeroInputId, String property) {
private List saveImage(ImagePlus image, String property) {
List ids = new ArrayList<>(0);
String title = removeExtension(image.getTitle());
- String path = directoryOut + File.separator + title + suffix + ".tif";
+ String path = params.getDirectoryOut() + File.separator +
+ title + params.getSuffix() + ".tif";
IJ.saveAsTiff(image, path);
- if (outputOnOMERO) {
+ if (params.isOutputOnOMERO()) {
try {
setState("Import on OMERO...");
- DatasetWrapper dataset = client.getDataset(outputDatasetId);
+ DatasetWrapper dataset = client.getDataset(params.getOutputDatasetId());
ids = dataset.importImage(client, path);
- if (saveROIs && !ids.isEmpty()) {
+ if (params.shouldSaveROIs() && !ids.isEmpty()) {
saveOverlay(image, ids.get(0), title, property);
}
} catch (AccessException | ServiceException | OMEROServerError | ExecutionException e) {
@@ -743,22 +667,24 @@ private List saveImage(ImagePlus image, String property) {
* @param property The ROI property used to group shapes on OMERO.
*/
private void saveOverlay(ImagePlus imp, Long imageId, String title, String property) {
- if (outputOnLocal) { // local save
+ if (params.isOutputOnLocal()) { // local save
setState("Saving overlay ROIs...");
- String path = directoryOut + File.separator + title + "_" + timestamp() + "_RoiSet.zip";
+ String timestamp = params.shouldClearROIs() ? "" : timestamp() + "_";
+ String path = params.getDirectoryOut() + File.separator +
+ title + "_" + timestamp + "RoiSet.zip";
List ijRois = getOverlay(imp);
saveRoiFile(ijRois, path);
}
- if (outputOnOMERO && imageId != null) { // save on Omero
+ if (params.isOutputOnOMERO() && imageId != null) { // save on Omero
List rois = getROIsFromOverlay(imp, property);
try {
ImageWrapper image = client.getImage(imageId);
- if (clearROIs) {
+ if (params.shouldClearROIs()) {
deleteROIs(image);
}
setState("Saving overlay ROIs on OMERO...");
image.saveROIs(client, rois);
- loadROIs(image, imp, true); // reload ROIs
+ loadROIs(image, imp, ROIMode.OVERLAY); // reload ROIs
} catch (ServiceException | AccessException | ExecutionException e) {
IJ.error("Could not import overlay ROIs to OMERO: " + e.getMessage());
}
@@ -775,22 +701,24 @@ private void saveOverlay(ImagePlus imp, Long imageId, String title, String prope
* @param property The ROI property used to group shapes on OMERO.
*/
private void saveROIManager(ImagePlus imp, Long imageId, String title, String property) {
- if (outputOnLocal) { // local save
+ if (params.isOutputOnLocal()) { // local save
setState("Saving ROIs...");
- String path = directoryOut + File.separator + title + "_" + timestamp() + "_RoiSet.zip";
+ String timestamp = params.shouldClearROIs() ? "" : timestamp() + "_";
+ String path = params.getDirectoryOut() + File.separator +
+ title + "_" + timestamp + "RoiSet.zip";
List ijRois = getManagedRois(imp);
saveRoiFile(ijRois, path);
}
- if (outputOnOMERO && imageId != null) { // save on Omero
+ if (params.isOutputOnOMERO() && imageId != null) { // save on Omero
List rois = getROIsFromManager(imp, property);
try {
ImageWrapper image = client.getImage(imageId);
- if (clearROIs) {
+ if (params.shouldClearROIs()) {
deleteROIs(image);
}
setState("Saving ROIs on OMERO...");
image.saveROIs(client, rois);
- loadROIs(image, imp, false); // reload ROIs
+ loadROIs(image, imp, ROIMode.MANAGER); // reload ROIs
} catch (ServiceException | AccessException | ExecutionException e) {
IJ.error("Could not import ROIs to OMERO: " + e.getMessage());
}
@@ -821,12 +749,14 @@ private void saveResults(ImagePlus imp, Long imageId, String title, String prope
if (rt != null) {
String name = rt.getTitle();
if (!Boolean.TRUE.equals(processed.get(name)) && rt.getHeadings().length > 0) {
- String path = directoryOut + File.separator + name + "_" + title + "_" + timestamp() + ".csv";
+ String path = params.getDirectoryOut() +
+ File.separator +
+ name + "_" +
+ title + "_" +
+ timestamp() + ".csv";
rt.save(path);
- if (outputOnOMERO) {
- appendTable(rt, imageId, ijRois, property);
- uploadFile(imageId, path);
- }
+ appendTable(rt, imageId, ijRois, property);
+ uploadFileToImage(imageId, path);
rt.reset();
processed.put(name, true);
}
@@ -842,10 +772,10 @@ private void saveResults(ImagePlus imp, Long imageId, String title, String prope
* @param title The image title used to name the file when saving locally.
*/
private void saveLog(Long imageId, String title) {
- String path = directoryOut + File.separator + title + "_log.txt";
+ String path = params.getDirectoryOut() + File.separator + title + "_log.txt";
IJ.selectWindow("Log");
IJ.saveAs("txt", path);
- if (outputOnOMERO) uploadFile(imageId, path);
+ uploadFileToImage(imageId, path);
}
@@ -855,16 +785,34 @@ private void saveLog(Long imageId, String title) {
* @param imageId The image ID on OMERO.
* @param path The path to the file.
*/
- private void uploadFile(Long imageId, String path) {
- if (imageId != null) {
+ private void uploadFileToImage(Long imageId, String path) {
+ if (imageId != null && params.isOutputOnOMERO()) {
+ ImageWrapper image = null;
try {
setState("Uploading results files...");
- ImageWrapper image = client.getImage(imageId);
- image.addFile(client, new File(path));
+ image = client.getImage(imageId);
} catch (ExecutionException | ServiceException | AccessException e) {
- IJ.error("Error adding file to image:" + e.getMessage());
+ IJ.error("Error retrieving image:" + e.getMessage());
+ }
+ uploadFile(image, path);
+ }
+ }
+
+
+ /**
+ * Uploads a file to an annotatable object on OMERO.
+ *
+ * @param object The object on OMERO.
+ * @param path The path to the file.
+ */
+ private void uploadFile(AnnotatableWrapper> object, String path) {
+ if (object != null && params.isOutputOnOMERO()) {
+ try {
+ object.addFile(client, new File(path));
+ } catch (ExecutionException e) {
+ IJ.error("Error adding file to object:" + e.getMessage());
} catch (InterruptedException e) {
- IJ.error("Error adding file to image:" + e.getMessage());
+ IJ.error("Error adding file to object:" + e.getMessage());
Thread.currentThread().interrupt();
}
}
@@ -879,7 +827,7 @@ private void uploadFile(Long imageId, String path) {
* @param ijRois The ROIs in ImageJ.
* @param property The ROI property used to group shapes on OMERO.
*/
- private void appendTable(ResultsTable results, Long imageId, List ijRois, String property) {
+ private void appendTable(ResultsTable results, Long imageId, List extends Roi> ijRois, String property) {
String resultsName = results.getTitle();
TableWrapper table = tables.get(resultsName);
try {
@@ -894,33 +842,45 @@ private void appendTable(ResultsTable results, Long imageId, List ijRois, S
}
+ /**
+ * Uploads a table to a project, if required.
+ *
+ * @param project The project the table belongs to.
+ * @param table The table.
+ */
+ private void uploadTable(ProjectWrapper project, TableWrapper table) {
+ if (project != null && params.isOutputOnOMERO()) {
+ try {
+ project.addTable(client, table);
+ } catch (ExecutionException | ServiceException | AccessException e) {
+ IJ.error("Could not upload table: " + e.getMessage());
+ }
+ }
+ }
+
+
/**
* Upload the tables to OMERO.
*/
private void uploadTables() {
- if (outputOnOMERO && saveResults) {
+ ProjectWrapper project = null;
+ if (params.shouldSaveResults()) {
setState("Uploading tables...");
- try {
- ProjectWrapper project = client.getProject(outputProjectId);
- for (Map.Entry entry : tables.entrySet()) {
- String name = entry.getKey();
- TableWrapper table = entry.getValue();
- String newName;
- if (name == null || name.isEmpty()) newName = timestamp() + "_" + table.getName();
- else newName = timestamp() + "_" + name;
- table.setName(newName);
- project.addTable(client, table);
- String path = directoryOut + File.separator + newName + ".csv";
- table.saveAs(path, 'c');
- project.addFile(client, new File(path));
+ if (params.isOutputOnOMERO()) {
+ try {
+ project = client.getProject(params.getOutputProjectId());
+ } catch (ExecutionException | ServiceException | AccessException e) {
+ IJ.error("Could not retrieve project: " + e.getMessage());
}
- } catch (ExecutionException | ServiceException | AccessException e) {
- IJ.error("Could not save table: " + e.getMessage());
- } catch (IOException e) {
- IJ.error("Could not save table as file: " + e.getMessage());
- } catch (InterruptedException e) {
- IJ.error("Could not upload CSV to project: " + e.getMessage());
- Thread.currentThread().interrupt();
+ }
+ for (Map.Entry entry : tables.entrySet()) {
+ String name = entry.getKey();
+ TableWrapper table = entry.getValue();
+ String newName = renameTable(table, name);
+ uploadTable(project, table);
+ String path = params.getDirectoryOut() + File.separator + newName + ".csv";
+ saveTable(table, path);
+ uploadFile(project, path);
}
}
}
@@ -940,163 +900,23 @@ private void closeWindows() {
}
+ /**
+ * Returns the client.
+ *
+ * @return See above.
+ */
public Client getClient() {
return client;
}
- public long getOutputProjectId() {
- return outputProjectId;
- }
-
-
- public void setOutputProjectId(Long outputProjectId) {
- if (outputProjectId != null) this.outputProjectId = outputProjectId;
- }
-
-
- public long getOutputDatasetId() {
- return outputDatasetId;
- }
-
-
- public void setOutputDatasetId(Long outputDatasetId) {
- if (outputDatasetId != null) this.outputDatasetId = outputDatasetId;
- }
-
-
- public long getInputDatasetId() {
- return inputDatasetId;
- }
-
-
- public void setInputDatasetId(Long inputDatasetId) {
- if (inputDatasetId != null) this.inputDatasetId = inputDatasetId;
- }
-
-
- public boolean shouldSaveROIs() {
- return saveROIs;
- }
-
-
- public void setSaveROIs(boolean saveROIs) {
- this.saveROIs = saveROIs;
- }
-
-
- public boolean shouldSaveResults() {
- return saveResults;
- }
-
-
- public void setSaveResults(boolean saveResults) {
- this.saveResults = saveResults;
- }
-
-
- public boolean isInputOnOMERO() {
- return inputOnOMERO;
- }
-
-
- public void setInputOnOMERO(boolean inputOnOMERO) {
- this.inputOnOMERO = inputOnOMERO;
- }
-
-
- public boolean shouldSaveImage() {
- return saveImage;
- }
-
-
- public void setSaveImage(boolean saveImage) {
- this.saveImage = saveImage;
- }
-
-
- public boolean shouldLoadROIs() {
- return loadROIs;
- }
-
-
- public void setLoadROIS(boolean loadROIs) {
- this.loadROIs = loadROIs;
- }
-
-
- public boolean shouldClearROIs() {
- return clearROIs;
- }
-
-
- public void setClearROIS(boolean clearROIs) {
- this.clearROIs = clearROIs;
- }
-
-
- public String getDirectoryIn() {
- return directoryIn;
- }
-
-
- public void setDirectoryIn(String directoryIn) {
- this.directoryIn = directoryIn;
- }
-
-
- public String getDirectoryOut() {
- return directoryOut;
- }
-
-
- public void setDirectoryOut(String directoryOut) {
- this.directoryOut = directoryOut;
- }
-
-
- public String getSuffix() {
- return suffix;
- }
-
-
- public void setSuffix(String suffix) {
- this.suffix = suffix;
- }
-
-
- public boolean isOutputOnOMERO() {
- return outputOnOMERO;
- }
-
-
- public void setOutputOnOMERO(boolean outputOnOMERO) {
- this.outputOnOMERO = outputOnOMERO;
- }
-
-
- public boolean isOutputOnLocal() {
- return outputOnLocal;
- }
-
-
- public void setOutputOnLocal(boolean outputOnLocal) {
- this.outputOnLocal = outputOnLocal;
- }
-
-
- public void setSaveLog(boolean saveLog) {
- this.saveLog = saveLog;
- }
-
-
+ /**
+ * Sets the listener.
+ *
+ * @param listener The listener.
+ */
public void setListener(BatchListener listener) {
this.listener = listener;
}
-
- public void setRecursive(boolean recursive) {
- this.recursive = recursive;
- }
-
}
diff --git a/src/main/java/fr/igred/ij/macro/ProgressLog.java b/src/main/java/fr/igred/ij/macro/ProgressLog.java
index 5544b86..4424855 100644
--- a/src/main/java/fr/igred/ij/macro/ProgressLog.java
+++ b/src/main/java/fr/igred/ij/macro/ProgressLog.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2021-2022 MICA & GReD
+ * Copyright (C) 2021-2023 MICA & GReD
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
@@ -16,9 +16,11 @@
*/
package fr.igred.ij.macro;
+
import java.util.logging.Level;
import java.util.logging.Logger;
+
/**
* Logs the progress of the batch process.
*/
diff --git a/src/main/java/fr/igred/ij/macro/ProgressMonitor.java b/src/main/java/fr/igred/ij/macro/ProgressMonitor.java
index ce9f5f0..6844c34 100644
--- a/src/main/java/fr/igred/ij/macro/ProgressMonitor.java
+++ b/src/main/java/fr/igred/ij/macro/ProgressMonitor.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2021-2022 MICA & GReD
+ * Copyright (C) 2021-2023 MICA & GReD
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
@@ -16,6 +16,7 @@
*/
package fr.igred.ij.macro;
+
/**
* Monitors the batch process progress.
*/
@@ -28,6 +29,7 @@ public interface ProgressMonitor {
*/
void setProgress(String text);
+
/**
* Sets the current state.
*
@@ -35,6 +37,7 @@ public interface ProgressMonitor {
*/
void setState(String text);
+
/**
* Signals the process is done.
*/
diff --git a/src/main/java/fr/igred/ij/macro/ScriptRunner.java b/src/main/java/fr/igred/ij/macro/ScriptRunner.java
index b993002..18aff0f 100644
--- a/src/main/java/fr/igred/ij/macro/ScriptRunner.java
+++ b/src/main/java/fr/igred/ij/macro/ScriptRunner.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2021-2022 MICA & GReD
+ * Copyright (C) 2021-2023 MICA & GReD
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
@@ -16,16 +16,20 @@
*/
package fr.igred.ij.macro;
+
import ij.IJ;
import ij.ImagePlus;
import ij.gui.GenericDialog;
+
/**
* Runs an ImageJ macro.
*/
public class ScriptRunner {
+ /** The path to the macro. */
private final String path;
+ /** The arguments for the macro. */
private String arguments = "";
@@ -69,8 +73,11 @@ private static boolean isSciJavaLoaded() {
* @return A new ScriptRunner object.
*/
public static ScriptRunner createScriptRunner(String path) {
- if (isSciJavaLoaded()) return new ScriptRunner2(path);
- else return new ScriptRunner(path);
+ if (isSciJavaLoaded()) {
+ return new ScriptRunner2(path);
+ } else {
+ return new ScriptRunner(path);
+ }
}
@@ -109,6 +116,7 @@ public void setArguments(String arguments) {
*
* @return See above.
*/
+ @SuppressWarnings("MagicCharacter")
public String getLanguage() {
return path.substring(path.lastIndexOf('.'));
}
diff --git a/src/main/java/fr/igred/ij/macro/ScriptRunner2.java b/src/main/java/fr/igred/ij/macro/ScriptRunner2.java
index 75b428f..d232f37 100644
--- a/src/main/java/fr/igred/ij/macro/ScriptRunner2.java
+++ b/src/main/java/fr/igred/ij/macro/ScriptRunner2.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2021-2022 MICA & GReD
+ * Copyright (C) 2021-2023 MICA & GReD
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
@@ -16,6 +16,7 @@
*/
package fr.igred.ij.macro;
+
import ij.IJ;
import ij.ImagePlus;
import ij.gui.Overlay;
@@ -40,14 +41,19 @@
import java.util.Map;
import java.util.stream.Collectors;
+
/**
* Runs an ImageJ2 script.
*/
public class ScriptRunner2 extends ScriptRunner {
+ /** Whether inputs were detected. */
private final boolean detectedInputs;
+ /** The inputs. */
protected Map inputs;
+ /** The script. */
private ScriptModule script;
+ /** The script language. */
private String language = "";
@@ -265,10 +271,12 @@ private void addInputs() {
ModuleItem newInput = new DefaultMutableModuleItem<>(scriptInfo, input.getKey(), Long.class);
scriptInfo.registerInput(newInput);
} else if (value.getClass().equals(Double.class)) {
- ModuleItem newInput = new DefaultMutableModuleItem<>(scriptInfo, input.getKey(), Double.class);
+ ModuleItem newInput = new DefaultMutableModuleItem<>(scriptInfo, input.getKey(),
+ Double.class);
scriptInfo.registerInput(newInput);
} else {
- ModuleItem newInput = new DefaultMutableModuleItem<>(scriptInfo, input.getKey(), String.class);
+ ModuleItem newInput = new DefaultMutableModuleItem<>(scriptInfo, input.getKey(),
+ String.class);
scriptInfo.registerInput(newInput);
}
}
diff --git a/src/main/java/fr/igred/ij/macro/package-info.java b/src/main/java/fr/igred/ij/macro/package-info.java
index 821d0a7..d0189b7 100644
--- a/src/main/java/fr/igred/ij/macro/package-info.java
+++ b/src/main/java/fr/igred/ij/macro/package-info.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2021-2022 MICA & GReD
+ * Copyright (C) 2021-2023 MICA & GReD
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
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 e6f8792..ed111c1 100644
--- a/src/main/java/fr/igred/ij/plugin/frame/OMEROBatchPlugin.java
+++ b/src/main/java/fr/igred/ij/plugin/frame/OMEROBatchPlugin.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2021-2022 MICA & GReD
+ * Copyright (C) 2021-2023 MICA & GReD
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
@@ -16,9 +16,13 @@
*/
package fr.igred.ij.plugin.frame;
+
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;
import fr.igred.ij.macro.ScriptRunner;
import fr.igred.omero.Client;
@@ -58,90 +62,123 @@
import java.util.logging.Logger;
import java.util.stream.Collectors;
+import static fr.igred.ij.io.LocalBatchImage.listImages;
+import static fr.igred.ij.io.OMEROBatchImage.listImages;
import static javax.swing.JOptionPane.showMessageDialog;
+
/**
* Main window for the OMERO batch plugin.
*/
public class OMEROBatchPlugin extends PlugInFrame implements BatchListener {
+ /** The logger. */
private static final Logger LOGGER = Logger.getLogger(MethodHandles.lookup().lookupClass().getName());
+ /** The format used to display OMERO objects. */
private static final String FORMAT = "%%-%ds (ID:%%%dd)";
- // minimum window size
+ /** The minimum window size */
private final Dimension minimumSize = new Dimension(640, 480);
// connection management
+ /** The connection status. */
private final JLabel connectionStatus = new JLabel("Disconnected");
+ /** The connection button. */
private final JButton connect = new JButton("Connect");
+ /** The disconnection button. */
private final JButton disconnect = new JButton("Disconnect");
// source selection
+ /** The OMERO input button. */
private final JRadioButton omero = new JRadioButton("OMERO");
+ /** The local input button. */
private final JRadioButton local = new JRadioButton("Local");
- // 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 input2 = new JPanel();
-
// group and user selection
+ /** The list of groups. */
private final JComboBox groupList = new JComboBox<>();
+ /** The list of users. */
private final JComboBox userList = new JComboBox<>();
// choice of the dataSet
+ /** The list of projects. */
private final JComboBox projectListIn = new JComboBox<>();
+ /** The list of datasets. */
private final JComboBox datasetListIn = new JComboBox<>();
- private final JCheckBox checkDelROIs = new JCheckBox(" Clear ROIs each time ");
- private final JCheckBox checkLoadROIs = new JCheckBox(" Load ROIs ");
+ /** The checkbox to delete ROIs. */
+ private final JCheckBox checkDelROIs = new JCheckBox("Clear ROIs each time");
+ /** The list of possible output projects. */
+ private final JComboBox roiMode = new JComboBox<>(ROIMode.values());
// choice of the record
+ /** The input folder. */
private final JTextField inputFolder = new JTextField(20);
+ /** The checkbox to analyse subfolders. */
private final JCheckBox recursive = new JCheckBox("Recursive");
+ /** The macro file. */
private final JTextField macro = new JTextField(20);
+ /** The macro language label. */
private final JLabel labelLanguage = new JLabel();
+ /** The macro arguments label. */
private final JLabel labelArguments = new JLabel();
+ /** The checkbox to save images. */
private final JCheckBox checkImage = new JCheckBox("New image(s)");
+ /** The checkbox to save results. */
private final JCheckBox checkResults = new JCheckBox("Results table(s)");
+ /** The checkbox to save ROIs. */
private final JCheckBox checkROIs = new JCheckBox("ROIs");
+ /** The checkbox to save the log. */
private final JCheckBox checkLog = new JCheckBox("Log file");
- private final JPanel output2 = new JPanel();
+ /** The suffix of the output files. */
private final JTextField suffix = new JTextField(10);
// Omero or local => checkbox
+ /** The checkbox to save to OMERO. */
private final JCheckBox onlineOutput = new JCheckBox("OMERO");
+ /** The checkbox to save locally. */
private final JCheckBox localOutput = new JCheckBox("Local");
- // existing dataset
- private final JPanel output3a = new JPanel();
+ /** The list of possible output projects. */
private final JComboBox projectListOut = new JComboBox<>();
+ /** The list of possible output datasets. */
private final JComboBox datasetListOut = new JComboBox<>();
- private final JButton newDatasetBtn = new JButton("New");
- // local
- private final JPanel output3b = new JPanel();
+ /** The output folder. */
private final JTextField outputFolder = new JTextField(20);
- // start button
+ /** The start button. */
private final JButton start = new JButton("Start");
//variables to keep
+ /** The OMERO client. */
private transient Client client;
+ /** The script runner. */
private transient ScriptRunner script;
+ /** The groups. */
private transient List groups;
+ /** The group projects. */
private transient List groupProjects;
+ /** The selected user's projects. */
private transient List userProjects;
+ /** The datasets. */
private transient List datasets;
+ /** The current user's projects. */
private transient List myProjects;
+ /** The current user's datasets. */
private transient List myDatasets;
+ /** The users. */
private transient List users;
+ /** The current user. */
private transient ExperimenterWrapper exp;
+ /** The output directory. */
private String directoryOut = null;
+ /** The input directory. */
private String directoryIn = null;
+ /** The output dataset ID. */
private Long outputDatasetId = null;
+ /** The output project ID. */
private Long outputProjectId = null;
@@ -152,8 +189,8 @@ public OMEROBatchPlugin() {
super("OMERO Batch Plugin");
super.setMinimumSize(minimumSize);
- final String projectName = "Project Name: ";
- final String datasetName = "Dataset Name: ";
+ final String projectName = "Project: ";
+ final String datasetName = "Dataset: ";
final String browse = "Browse";
final Font nameFont = new Font("Arial", Font.ITALIC, 10);
@@ -205,8 +242,9 @@ public OMEROBatchPlugin() {
source.setBorder(BorderFactory.createTitledBorder("Source"));
super.add(source);
- JLabel labelGroup = new JLabel("Group Name: ");
- JLabel labelUser = new JLabel("User Name: ");
+ JPanel input1a = new JPanel();
+ JLabel labelGroup = new JLabel("Group: ");
+ JLabel labelUser = new JLabel("User: ");
labelGroup.setLabelFor(groupList);
labelUser.setLabelFor(userList);
input1a.add(labelGroup);
@@ -219,6 +257,7 @@ public OMEROBatchPlugin() {
groupList.setFont(listFont);
userList.setFont(listFont);
+ JPanel input1b = new JPanel();
JLabel labelProjectIn = new JLabel(projectName);
JLabel labelDatasetIn = new JLabel(datasetName);
JButton preview = new JButton("Preview");
@@ -237,9 +276,7 @@ public OMEROBatchPlugin() {
projectListIn.setFont(listFont);
datasetListIn.setFont(listFont);
- input1c.add(checkLoadROIs);
- input1c.add(checkDelROIs);
-
+ JPanel input2 = new JPanel();
JLabel inputFolderLabel = new JLabel("Images folder: ");
JButton inputFolderBtn = new JButton(browse);
inputFolderLabel.setLabelFor(inputFolder);
@@ -251,11 +288,18 @@ public OMEROBatchPlugin() {
input2.add(recursive);
inputFolderBtn.addActionListener(e -> chooseDirectory(inputFolder));
+ JPanel input3 = new JPanel();
+ JLabel labelROIMode = new JLabel("Load ROIs: ");
+ labelROIMode.setLabelFor(roiMode);
+ 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);
@@ -320,29 +364,34 @@ public OMEROBatchPlugin() {
onlineOutput.addActionListener(this::updateOutput);
localOutput.addActionListener(this::updateOutput);
+ JPanel output2 = new JPanel();
JLabel labelExtension = new JLabel("Suffix of output files:");
labelExtension.setLabelFor(suffix);
suffix.setText("_macro");
output2.add(labelExtension);
output2.add(suffix);
+ JPanel output3a = new JPanel();
+ JPanel output3a1 = new JPanel();
+ JButton newDatasetBtn = new JButton("New");
JLabel labelProjectOut = new JLabel(projectName);
JLabel labelDatasetOut = new JLabel(datasetName);
labelProjectOut.setLabelFor(projectListOut);
labelDatasetOut.setLabelFor(datasetListOut);
output3a.add(labelProjectOut);
output3a.add(projectListOut);
- output3a.add(Box.createRigidArea(smallHorizontal));
- output3a.add(labelDatasetOut);
- output3a.add(datasetListOut);
- output3a.add(Box.createRigidArea(smallHorizontal));
- output3a.add(newDatasetBtn);
+ output3a1.add(labelDatasetOut);
+ output3a1.add(datasetListOut);
+ output3a1.add(Box.createRigidArea(smallHorizontal));
+ output3a1.add(newDatasetBtn);
+ output3a.add(output3a1);
projectListOut.addItemListener(this::updateOutputProject);
datasetListOut.addItemListener(this::updateOutputDataset);
newDatasetBtn.addActionListener(this::createNewDataset);
projectListOut.setFont(listFont);
datasetListOut.setFont(listFont);
+ JPanel output3b = new JPanel();
JLabel outputFolderLabel = new JLabel("Output folder: ");
JButton directoryBtn = new JButton(browse);
outputFolderLabel.setLabelFor(outputFolder);
@@ -355,8 +404,8 @@ public OMEROBatchPlugin() {
// choice of output
JPanel panelOutput = new JPanel();
- panelOutput.add(output2);
panelOutput.add(output1);
+ panelOutput.add(output2);
panelOutput.add(output3a);
panelOutput.add(output3b);
panelOutput.setLayout(new BoxLayout(panelOutput, BoxLayout.PAGE_AXIS));
@@ -373,12 +422,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);
@@ -470,9 +519,13 @@ public static void errorWindow(String message) {
*/
private static void chooseDirectory(JTextField textField) {
String pref = textField.getName();
- if (pref.isEmpty()) pref = "omero.batch." + Prefs.DIR_IMAGE;
+ if (pref.isEmpty()) {
+ pref = "omero.batch." + Prefs.DIR_IMAGE;
+ }
String previousDir = textField.getText();
- if (previousDir.isEmpty()) previousDir = Prefs.get(pref, previousDir);
+ if (previousDir.isEmpty()) {
+ previousDir = Prefs.get(pref, previousDir);
+ }
JFileChooser outputChoice = new JFileChooser(previousDir);
outputChoice.setDialogTitle("Choose the directory");
@@ -511,7 +564,7 @@ public void run(String arg) {
* @param username The OMERO user.
* @param userId The user ID.
*/
- public void userProjectsAndDatasets(String username, long userId) {
+ private void userProjects(String username, long userId) {
if ("All members".equals(username)) {
userProjects = groupProjects;
} else {
@@ -555,7 +608,9 @@ private void updateInputProject(ItemEvent e) {
for (DatasetWrapper d : this.datasets) {
datasetListIn.addItem(format(d.getName(), d.getId(), padName, padId));
}
- if (!this.datasets.isEmpty()) datasetListIn.setSelectedIndex(0);
+ if (!this.datasets.isEmpty()) {
+ datasetListIn.setSelectedIndex(0);
+ }
}
}
}
@@ -590,7 +645,9 @@ private void updateOutputProject(ItemEvent e) {
for (DatasetWrapper d : this.myDatasets) {
datasetListOut.addItem(format(d.getName(), d.getId(), padName, padId));
}
- if (!this.datasets.isEmpty()) datasetListOut.setSelectedIndex(0);
+ if (!this.datasets.isEmpty()) {
+ datasetListOut.setSelectedIndex(0);
+ }
}
}
}
@@ -612,7 +669,9 @@ private void createNewDataset(ActionEvent e) {
null,
null,
null);
- if (name == null) return;
+ if (name == null) {
+ return;
+ }
try {
DatasetWrapper newDataset = project.addDataset(client, name, "");
id = newDataset.getId();
@@ -654,8 +713,10 @@ private void updateUser(ItemEvent e) {
int index = userList.getSelectedIndex();
String username = userList.getItemAt(index);
long userId = -1;
- if (index >= 1) userId = users.get(index - 1).getId();
- userProjectsAndDatasets(username, userId);
+ if (index >= 1) {
+ userId = users.get(index - 1).getId();
+ }
+ userProjects(username, userId);
projectListIn.removeAllItems();
projectListOut.removeAllItems();
datasetListIn.removeAllItems();
@@ -670,8 +731,12 @@ private void updateUser(ItemEvent e) {
for (ProjectWrapper project : myProjects) {
projectListOut.addItem(format(project.getName(), project.getId(), padMyName, padMyId));
}
- if (!userProjects.isEmpty()) projectListIn.setSelectedIndex(0);
- if (!myProjects.isEmpty()) projectListOut.setSelectedIndex(0);
+ if (!userProjects.isEmpty()) {
+ projectListIn.setSelectedIndex(0);
+ }
+ if (!myProjects.isEmpty()) {
+ projectListOut.setSelectedIndex(0);
+ }
}
}
@@ -732,20 +797,16 @@ private void updateInput(ItemEvent e) {
connected = connect();
}
if (connected) {
- input1a.setVisible(true);
- input1b.setVisible(true);
- input1c.setVisible(true);
- input2.setVisible(false);
+ groupList.getParent().setVisible(true);
+ projectListIn.getParent().setVisible(true);
+ inputFolder.getParent().setVisible(false);
} else {
local.setSelected(true);
}
} else { //local.isSelected()
- input2.setVisible(true);
- checkDelROIs.setSelected(false);
- checkLoadROIs.setSelected(false);
- input1c.setVisible(false);
- input1b.setVisible(false);
- input1a.setVisible(false);
+ inputFolder.getParent().setVisible(true);
+ projectListIn.getParent().setVisible(false);
+ groupList.getParent().setVisible(false);
}
this.repack();
}
@@ -813,7 +874,9 @@ public void onThreadFinished() {
private boolean connect() {
final Color green = new Color(0, 153, 0);
boolean connected = false;
- if (client == null) client = new Client();
+ if (client == null) {
+ client = new Client();
+ }
OMEROConnectDialog connectDialog = new OMEROConnectDialog();
connectDialog.connect(client);
if (!connectDialog.wasCancelled()) {
@@ -845,7 +908,9 @@ private boolean connect() {
int index = -1;
for (int i = 0; index < 0 && i < groups.size(); i++) {
- if (groups.get(i).getId() == groupId) index = i;
+ if (groups.get(i).getId() == groupId) {
+ index = i;
+ }
}
groupList.setSelectedIndex(-1);
groupList.setSelectedIndex(index);
@@ -920,57 +985,62 @@ private void previewDataset() {
*/
public void start(ActionEvent e) {
ProgressDialog progress = new ProgressDialog();
- OMEROBatchRunner runner = new OMEROBatchRunner(script, client, progress);
- runner.setListener(this);
+ BatchParameters params = new BatchParameters();
- // initiation of success variables
- boolean checkInput;
- boolean checkMacro = getMacro();
- boolean checkOutput = getOutput();
+ // initialization of success variables
+ boolean badInput;
+ boolean badMacro = !getMacro();
+ boolean badOutput = !getOutput();
// input data
- if (omero.isSelected()) {
- runner.setInputOnOMERO(true);
- int index = datasetListIn.getSelectedIndex();
- DatasetWrapper dataset = datasets.get(index);
- long inputDatasetId = dataset.getId();
- runner.setInputDatasetId(inputDatasetId);
- runner.setOutputDatasetId(inputDatasetId);
- checkInput = true;
- } else { // local.isSelected()
- runner.setInputOnOMERO(false);
- checkInput = getLocalInput();
- runner.setDirectoryIn(directoryIn);
- runner.setRecursive(recursive.isSelected());
+ params.setSuffix(suffix.getText());
+ params.setROIMode(roiMode.getItemAt(roiMode.getSelectedIndex()));
+ params.setClearROIS(checkDelROIs.isSelected());
+ params.setSaveImages(checkImage.isSelected());
+ params.setSaveResults(checkResults.isSelected());
+ params.setSaveROIs(checkROIs.isSelected());
+ params.setSaveLog(checkLog.isSelected());
+
+ List images;
+ long inputDatasetId = -1L;
+ try {
+ if (omero.isSelected()) {
+ int index = datasetListIn.getSelectedIndex();
+ DatasetWrapper dataset = datasets.get(index);
+ inputDatasetId = dataset.getId();
+ List imageWrappers = dataset.getImages(client);
+ images = listImages(client, imageWrappers);
+ badInput = false;
+ } else { // local.isSelected()
+ badInput = !getLocalInput();
+ images = listImages(directoryIn, recursive.isSelected());
+ }
+ params.setOutputDatasetId(inputDatasetId);
+ } catch (ServiceException | AccessException | ExecutionException | IOException exception) {
+ IJ.error(exception.getMessage());
+ return;
}
- if (!checkInput || !checkMacro || !checkOutput) {
+ if (badInput || badMacro || badOutput) {
return;
}
- // suffix
- runner.setSuffix(suffix.getText());
-
- runner.setLoadROIS(checkLoadROIs.isSelected());
- runner.setClearROIS(checkDelROIs.isSelected());
- runner.setSaveImage(checkImage.isSelected());
- runner.setSaveResults(checkResults.isSelected());
- runner.setSaveROIs(checkROIs.isSelected());
- runner.setSaveLog(checkLog.isSelected());
if (onlineOutput.isSelected()) {
- runner.setOutputOnOMERO(true);
+ params.setOutputOnOMERO(true);
if (checkResults.isSelected()) {
- runner.setOutputProjectId(outputProjectId);
+ params.setOutputProjectId(outputProjectId);
}
if (checkImage.isSelected()) {
- runner.setOutputDatasetId(outputDatasetId);
+ params.setOutputDatasetId(outputDatasetId);
}
}
if (localOutput.isSelected()) {
- runner.setOutputOnLocal(true);
- runner.setDirectoryOut(directoryOut);
+ params.setOutputOnLocal(true);
+ params.setDirectoryOut(directoryOut);
}
+ OMEROBatchRunner runner = new OMEROBatchRunner(script, images, params, client, progress);
+ runner.setListener(this);
start.setEnabled(false);
try {
runner.start();
@@ -996,14 +1066,13 @@ private void updateOutput(ActionEvent e) {
onlineOutput.setSelected(outputOnline);
}
- output2.setVisible(outputImage);
- output3a.setVisible(outputOnline && (outputImage || outputResults));
- datasetListOut.setVisible(outputOnline && outputImage);
- newDatasetBtn.setVisible(outputOnline && outputImage);
+ suffix.getParent().setVisible(outputImage);
+ projectListOut.getParent().setVisible(outputOnline && (outputImage || outputResults));
+ datasetListOut.getParent().setVisible(outputOnline && outputImage);
if (outputOnline && userProjects.equals(myProjects)) {
projectListOut.setSelectedIndex(projectListIn.getSelectedIndex());
}
- output3b.setVisible(outputLocal);
+ outputFolder.getParent().setVisible(outputLocal);
repack();
}
@@ -1113,8 +1182,8 @@ private boolean getLocalOutput() {
*/
private boolean checkDeleteROIs() {
boolean check = true;
- if (checkDelROIs.isSelected() && (!onlineOutput.isSelected() || !checkROIs.isSelected())) {
- errorWindow(String.format("ROIs:%nYou can't clear ROIs if you don't save ROIs on OMERO"));
+ if (checkDelROIs.isSelected() && !checkROIs.isSelected()) {
+ errorWindow(String.format("ROIs:%nYou can't clear ROIs if you don't save ROIs"));
check = false;
}
return check;
@@ -1129,7 +1198,8 @@ private boolean checkDeleteROIs() {
private boolean checkUploadLocalInput() {
boolean check = true;
if (local.isSelected() && onlineOutput.isSelected() && !checkImage.isSelected()) {
- errorWindow(String.format("Output:%nYou can't upload results file or ROIs on OMERO if your image isn't in OMERO"));
+ errorWindow(String.format(
+ "Output:%nYou can't upload results file or ROIs on OMERO if your image isn't in OMERO"));
check = false;
}
return check;
@@ -1189,11 +1259,12 @@ private void repack() {
this.pack();
this.setMinimumSize(bestSize);
- Container inputPanel = input1b.getParent();
+ Container inputPanel = projectListIn.getParent().getParent();
inputPanel.setMinimumSize(inputPanel.getPreferredSize());
- inputPanel.setMaximumSize(new Dimension(inputPanel.getMaximumSize().width, inputPanel.getPreferredSize().height));
+ inputPanel.setMaximumSize(
+ new Dimension(inputPanel.getMaximumSize().width, inputPanel.getPreferredSize().height));
- Container outputPanel = output2.getParent();
+ Container outputPanel = onlineOutput.getParent().getParent();
outputPanel.setMinimumSize(outputPanel.getPreferredSize());
outputPanel.setMaximumSize(new Dimension(outputPanel.getMaximumSize().width, outputPanel.getHeight()));
}
@@ -1201,16 +1272,16 @@ private void repack() {
private class ClientDisconnector extends WindowAdapter {
- ClientDisconnector() {
- super();
- }
+ ClientDisconnector() {}
@Override
public void windowClosing(WindowEvent e) {
super.windowClosing(e);
Client c = client;
- if (c != null) c.disconnect();
+ if (c != null) {
+ c.disconnect();
+ }
}
}
diff --git a/src/main/java/fr/igred/ij/plugin/frame/package-info.java b/src/main/java/fr/igred/ij/plugin/frame/package-info.java
index fe5949d..f0c7ee6 100644
--- a/src/main/java/fr/igred/ij/plugin/frame/package-info.java
+++ b/src/main/java/fr/igred/ij/plugin/frame/package-info.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2021-2022 MICA & GReD
+ * Copyright (C) 2021-2023 MICA & GReD
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
diff --git a/src/test/java/fr/igred/ij/plugin/frame/OMEROBatchPluginTest.java b/src/test/java/fr/igred/ij/plugin/frame/OMEROBatchPluginTest.java
index 1c20d2e..6869f83 100644
--- a/src/test/java/fr/igred/ij/plugin/frame/OMEROBatchPluginTest.java
+++ b/src/test/java/fr/igred/ij/plugin/frame/OMEROBatchPluginTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2021-2022 MICA & GReD
+ * Copyright (C) 2021-2023 MICA & GReD
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software