diff --git a/pom.xml b/pom.xml
index fcadadb0..ed9b6432 100644
--- a/pom.xml
+++ b/pom.xml
@@ -90,7 +90,7 @@
fr.igred
simple-omero-client
- 5.7.0
+ 5.14.1
diff --git a/src/main/java/gred/nucleus/autocrop/AutoCrop.java b/src/main/java/gred/nucleus/autocrop/AutoCrop.java
index 96594cef..b4ebeb48 100644
--- a/src/main/java/gred/nucleus/autocrop/AutoCrop.java
+++ b/src/main/java/gred/nucleus/autocrop/AutoCrop.java
@@ -454,6 +454,7 @@ public void cropKernelsOMERO(ImageWrapper image, Long[] outputsDat, Client clien
info.append(getSpecificImageInfo()).append(HEADERS);
for (int c = 0; c < this.channelNumbers; c++) {
DatasetWrapper dataset = client.getDataset(outputsDat[c]);
+ List rois = new ArrayList<>(this.boxes.size());
for (Map.Entry entry : new TreeMap<>(this.boxes).entrySet()) {
int i = entry.getKey().intValue();
LOGGER.info("Processing box number: {} (OMERO)", i);
@@ -481,7 +482,8 @@ public void cropKernelsOMERO(ImageWrapper image, Long[] outputsDat, Client clien
shapes.add(rectangle);
}
ROIWrapper roi = new ROIWrapper(shapes);
- image.saveROI(client, roi);
+ roi.setName(String.valueOf(i));
+ rois.add(roi);
ImagePlus croppedImage = image.toImagePlus(client, xBound, yBound, cBound, zBound, null);
Calibration cal = this.rawImg.getCalibration();
croppedImage.setCalibration(cal);
@@ -527,6 +529,7 @@ public void cropKernelsOMERO(ImageWrapper image, Long[] outputsDat, Client clien
zMax);
}
}
+ image.saveROIs(client, rois);
}
this.infoImageAnalysis += info.toString();
}
diff --git a/src/main/java/gred/nucleus/cli/CLIRunActionOMERO.java b/src/main/java/gred/nucleus/cli/CLIRunActionOMERO.java
index 1a0cfd26..483f5eb2 100644
--- a/src/main/java/gred/nucleus/cli/CLIRunActionOMERO.java
+++ b/src/main/java/gred/nucleus/cli/CLIRunActionOMERO.java
@@ -31,7 +31,7 @@ public class CLIRunActionOMERO {
Client client = new Client();
/** OMERO password connection */
- String mdp;
+ char[] mdp;
/** OMERO type of data to analyse : image data dataset tag */
String dataType;
@@ -126,11 +126,11 @@ public static void autoCropOMERO(String inputDirectory,
public void getOMEROPassword() {
if (this.cmd.hasOption("password")) {
- this.mdp = this.cmd.getOptionValue("password");
+ this.mdp = this.cmd.getOptionValue("password").toCharArray();
} else {
System.console().writer().println("Enter password: ");
Console con = System.console();
- this.mdp = String.valueOf(con.readPassword());
+ this.mdp = con.readPassword();
}
}
diff --git a/src/main/java/gred/nucleus/dialogs/AutocropDialog.java b/src/main/java/gred/nucleus/dialogs/AutocropDialog.java
index e356f137..1658eb00 100644
--- a/src/main/java/gred/nucleus/dialogs/AutocropDialog.java
+++ b/src/main/java/gred/nucleus/dialogs/AutocropDialog.java
@@ -261,8 +261,8 @@ public AutocropDialog(IDialogListener dialogListener) {
jTextFieldHostname.setText("omero.gred-clermont.fr");
jTextFieldPort.setText("4064");
- jTextFieldUsername.setText("demo");
- jPasswordField.setText("Isim@42");
+ jTextFieldUsername.setText("");
+ jPasswordField.setText("");
jTextFieldGroup.setText("553");
jComboBoxDataType.setSelectedIndex(3);
@@ -311,8 +311,8 @@ public String getUsername() {
}
- public String getPassword() {
- return String.valueOf(jPasswordField.getPassword());
+ public char[] getPassword() {
+ return jPasswordField.getPassword();
}
diff --git a/src/main/java/gred/nucleus/dialogs/CropFromCoodinateDialog.java b/src/main/java/gred/nucleus/dialogs/CropFromCoodinateDialog.java
deleted file mode 100644
index 55552fed..00000000
--- a/src/main/java/gred/nucleus/dialogs/CropFromCoodinateDialog.java
+++ /dev/null
@@ -1,204 +0,0 @@
-package gred.nucleus.dialogs;
-
-import javax.swing.*;
-import java.awt.*;
-import java.awt.event.ActionEvent;
-import java.awt.event.ActionListener;
-import java.io.File;
-
-
-public class CropFromCoodinateDialog extends JFrame implements ActionListener {
- private static final long serialVersionUID = 1L;
- private final JTextField jLinkFileChooser = new JTextField();
- private final JTextField jImageChooser = new JTextField();
- private final JTextField jCoordFileChooser = new JTextField();
- private final JFileChooser fc = new JFileChooser();
- private final String linkChooserName = "linkChooser";
- private final String imageChooserName = "imageChooser";
- private final String coordChooserName = "coordChooser";
- private boolean start = false;
- private JLabel jLabelImage;
- private JLabel jLabelCoord;
- private JButton imageButton;
- private JButton coordButton;
- private File selectedOutput;
- private File selectedConfig;
-
-
- public CropFromCoodinateDialog() {
- this.setTitle("Autocrop NucleusJ2");
- this.setSize(500, 300);
- this.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
- Container container = getContentPane();
- GridBagLayout gridBagLayout = new GridBagLayout();
- gridBagLayout.rowWeights = new double[]{0.0, 0.0, 0.0, 0.1};
- gridBagLayout.rowHeights = new int[]{60, 60, 60, 120};
- gridBagLayout.columnWeights = new double[]{0.0, 0.0};
- gridBagLayout.columnWidths = new int[]{250, 250};
- container.setLayout(gridBagLayout);
-
-
- /*/\*\
- ------------------------------ Coordinate file -----------------------------------------
- \*\/*/
-
-
- JLabel jLabelLink = new JLabel();
- container.add(jLabelLink, new GridBagConstraints(0, 0, 0, 0, 0.0, 0.0,
- GridBagConstraints.NORTHWEST, GridBagConstraints.NONE,
- new Insets(10, 10, 0, 0), 0, 0));
- jLabelLink.setText("Path to coordinate file:");
-
- container.add(jLinkFileChooser, new GridBagConstraints(0, 0, 0, 0, 0.0, 0.0,
- GridBagConstraints.NORTHWEST, GridBagConstraints.NONE,
- new Insets(30, 10, 0, 0), 0, 0));
- jLinkFileChooser.setPreferredSize(new java.awt.Dimension(300, 20));
- jLinkFileChooser.setMinimumSize(new java.awt.Dimension(300, 20));
-
- JButton linkFileButton = new JButton("...");
- container.add(linkFileButton, new GridBagConstraints(0, 0, 0, 0, 0.0, 0.0,
- GridBagConstraints.NORTHWEST, GridBagConstraints.NONE,
- new Insets(30, 330, 0, 0), 0, 0));
- linkFileButton.addActionListener(this);
- linkFileButton.setName(linkChooserName);
-
-
- /*/\*\
- ------------------------------ Image + coordinates -----------------------------------------
- \*\/*/
-
-
- /*
- JLabel imageFileLabel = new JLabel();
- container.add(imageFileLabel, new GridBagConstraints(0, 1, 0, 0, 0.0, 0.0,
- GridBagConstraints.NORTHWEST, GridBagConstraints.NONE,
- new Insets(10, 10, 0, 0), 0, 0));
- imageFileLabel.setText("Path to image:");
-
- container.add(jImageChooser, new GridBagConstraints(0, 1, 0, 0, 0.0, 0.0,
- GridBagConstraints.NORTHWEST, GridBagConstraints.NONE,
- new Insets(30, 10, 0, 0), 0, 0));
- jImageChooser.setPreferredSize(new java.awt.Dimension(300, 20));
- jImageChooser.setMinimumSize(new java.awt.Dimension(300, 20));
-
- imageButton = new JButton("...");
- container.add(linkFileButton, new GridBagConstraints(0, 1, 0, 0, 0.0, 0.0,
- GridBagConstraints.NORTHWEST, GridBagConstraints.NONE,
- new Insets(30, 330, 0, 0), 0, 0));
- imageButton.addActionListener(this);
- imageButton.setName(imageChooserName);
-
- jLabelCoord = new JLabel();
- container.add(jLabelCoord, new GridBagConstraints(0, 0, 0, 0, 0.0, 0.0,
- GridBagConstraints.NORTHWEST, GridBagConstraints.NONE,
- new Insets(10, 10, 0, 0), 0, 0));
- jLabelCoord.setText("Path to coordinates:");
-
- container.add(jCoordFileChooser, new GridBagConstraints(0, 0, 0, 0, 0.0, 0.0,
- GridBagConstraints.NORTHWEST, GridBagConstraints.NONE,
- new Insets(30, 10, 0, 0), 0, 0));
- jCoordFileChooser.setPreferredSize(new java.awt.Dimension(300, 20));
- jCoordFileChooser.setMinimumSize(new java.awt.Dimension(300, 20));
-
- coordButton = new JButton("...");
- container.add(coordButton, new GridBagConstraints(0, 0, 0, 0, 0.0, 0.0,
- GridBagConstraints.NORTHWEST, GridBagConstraints.NONE,
- new Insets(30, 330, 0, 0), 0, 0));
- coordButton.addActionListener(this);
- coordButton.setName(coordChooserName);
- */
-
- /*/\*\
- ------------------------------ Buttons -----------------------------------------
- \*\/*/
-
- JButton jButtonStart = new JButton("Start");
- container.add(jButtonStart, new GridBagConstraints(0, 3, 0, 0, 0.0, 0.0,
- GridBagConstraints.NORTHWEST, GridBagConstraints.NONE,
- new Insets(40, 80, 0, 0), 0, 0));
- jButtonStart.setPreferredSize(new java.awt.Dimension(60, 21));
- JButton jButtonQuit = new JButton("Quit");
- container.add(jButtonQuit, new GridBagConstraints(0, 3, 0, 0, 0.0, 0.0,
- GridBagConstraints.NORTHWEST, GridBagConstraints.NONE,
- new Insets(40, 10, 0, 0), 0, 0));
- jButtonQuit.setPreferredSize(new java.awt.Dimension(60, 21));
- this.setVisible(true);
-
- CropFromCoodinateDialog.QuitListener quitListener = new QuitListener(this);
- jButtonQuit.addActionListener(quitListener);
- CropFromCoodinateDialog.StartListener startListener = new CropFromCoodinateDialog.StartListener(this);
- jButtonStart.addActionListener(startListener);
- }
-
-
- public boolean isStart() {
- return start;
- }
-
-
- public String getLink() {
- return jLinkFileChooser.getText();
- }
-
-
- public String getImage() {
- return jImageChooser.getText();
- }
-
-
- public String getCoord() {
- return jCoordFileChooser.getText();
- }
-
-
- public void actionPerformed(ActionEvent e) {
- if (((JButton) e.getSource()).getName().equals(linkChooserName)) {
- fc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
- }
- fc.setAcceptAllFileFilterUsed(false);
-
- if (fc.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
- if (((JButton) e.getSource()).getName().equals(linkChooserName)) {
- File selectedInput = fc.getSelectedFile();
- jLinkFileChooser.setText(selectedInput.getPath());
- }
- }
- fc.setSelectedFile(null);
- }
-
-
- static class QuitListener implements ActionListener {
- CropFromCoodinateDialog autocropDialog;
-
-
- /** @param autocropDialog */
- public QuitListener(CropFromCoodinateDialog autocropDialog) {
- this.autocropDialog = autocropDialog;
- }
-
-
- public void actionPerformed(ActionEvent actionEvent) {
- autocropDialog.dispose();
- }
-
- }
-
- /** Classes listener to interact with the several elements of the window */
- class StartListener implements ActionListener {
- CropFromCoodinateDialog autocropDialog;
-
-
- /** @param autocropDialog */
- public StartListener(CropFromCoodinateDialog autocropDialog) {
- this.autocropDialog = autocropDialog;
- }
-
-
- public void actionPerformed(ActionEvent actionEvent) {
- start = true;
- autocropDialog.dispose();
- }
-
- }
-
-}
diff --git a/src/main/java/gred/nucleus/dialogs/CropFromCoordinatesDialog.java b/src/main/java/gred/nucleus/dialogs/CropFromCoordinatesDialog.java
new file mode 100644
index 00000000..e8129a67
--- /dev/null
+++ b/src/main/java/gred/nucleus/dialogs/CropFromCoordinatesDialog.java
@@ -0,0 +1,470 @@
+package gred.nucleus.dialogs;
+
+import ij.Prefs;
+
+import javax.swing.*;
+import javax.swing.border.Border;
+import java.awt.Color;
+import java.awt.Container;
+import java.awt.Dimension;
+import java.awt.GridBagConstraints;
+import java.awt.GridBagLayout;
+import java.awt.GridLayout;
+import java.awt.Insets;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.awt.event.ItemEvent;
+import java.awt.event.ItemListener;
+import java.io.File;
+
+
+public class CropFromCoordinatesDialog extends JFrame implements ActionListener, ItemListener {
+ private static final long serialVersionUID = -1113846613817254789L;
+ private final JTextField jImageChooser = new JTextField();
+ private final JTextField jCoordFileChooser = new JTextField();
+ private final JFileChooser fc = new JFileChooser();
+ private boolean start = false;
+ private final JRadioButton omeroYesButton = new JRadioButton("Yes");
+ private final JRadioButton omeroNoButton = new JRadioButton("No");
+ private final JPanel omeroModeLayout = new JPanel();
+ private final JPanel localModeLayout = new JPanel();
+ private final JTextField jTextFieldHostname = new JTextField();
+ private final JTextField jTextFieldPort = new JTextField();
+ private final JTextField jTextFieldUsername = new JTextField();
+ private final JPasswordField jPasswordField = new JPasswordField();
+ private final JTextField jTextFieldGroup = new JTextField();
+ private final String[] dataTypes = {"Project", "Dataset", "Tag", "Image"};
+ private final JComboBox jComboBoxDataType = new JComboBox<>(dataTypes);
+ private final JComboBox jComboBoxDataTypeToCrop = new JComboBox<>(dataTypes);
+ private final JTextField jTextFieldSourceID = new JTextField();
+ private final JTextField jTextFieldToCropID = new JTextField();
+ private final JTextField jTextFieldOutputProject = new JTextField();
+ private Container container;
+ private boolean useOMERO = false;
+ private static final String INPUT_CHOOSER = "inputChooser";
+ private static final String OUTPUT_CHOOSER = "outputChooser";
+ private final JTextField jInputFileChooser = new JTextField();
+
+
+ public CropFromCoordinatesDialog() {
+
+ String host = Prefs.get("omero.host", "");
+ long port = Prefs.getInt("omero.port", 4);
+ String username = Prefs.get("omero.user", "");
+
+
+ JButton jButtonStart = new JButton("Start");
+ jButtonStart.setBackground(new Color(0x2dce98));
+ jButtonStart.setForeground(Color.white);
+ JButton jButtonQuit = new JButton("Quit");
+ jButtonQuit.setBackground(Color.red);
+ jButtonQuit.setForeground(Color.white);
+ this.setTitle("Crop From Coordinate - NucleusJ2");
+ this.setMinimumSize(new Dimension(500, 390));
+ this.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
+
+ container = getContentPane();
+ BoxLayout mainBoxLayout = new BoxLayout(getContentPane(), BoxLayout.Y_AXIS);
+ container.setLayout(mainBoxLayout);
+
+ Border padding = BorderFactory.createEmptyBorder(10, 10, 10, 10);
+
+
+ // Use Omero ?
+ ButtonGroup bGroupOmeroMode = new ButtonGroup();
+ bGroupOmeroMode.add(omeroYesButton);
+ omeroYesButton.addItemListener(this);
+ bGroupOmeroMode.add(omeroNoButton);
+ omeroNoButton.setSelected(true);
+ omeroNoButton.addItemListener(this);
+
+ JPanel radioOmeroPanel = new JPanel();
+ radioOmeroPanel.setLayout(new BoxLayout(radioOmeroPanel, BoxLayout.X_AXIS));
+
+
+ JLabel jLabelOmero = new JLabel("Select from omero :");
+ radioOmeroPanel.add(jLabelOmero);
+ radioOmeroPanel.add(omeroYesButton);
+ radioOmeroPanel.add(omeroNoButton);
+ //radioOmeroPanel.setBorder(BorderFactory.createLineBorder(Color.black, 1));
+ container.add(radioOmeroPanel, new GridBagConstraints(0, 0, 0, 0, 0.0, 0.0,
+ GridBagConstraints.NORTHWEST, GridBagConstraints.NONE,
+ new Insets(60, 30, 0, 0), 0, 0));
+
+
+ // Local mode layout
+ localModeLayout.setLayout(new BoxLayout(localModeLayout, BoxLayout.Y_AXIS));
+
+ JPanel localPanel = new JPanel();
+ GridBagLayout localLayout = new GridBagLayout();
+ localLayout.columnWeights = new double[]{1, 5, 0.5};
+ localPanel.setLayout(localLayout);
+ GridBagConstraints c = new GridBagConstraints();
+ c.fill = GridBagConstraints.HORIZONTAL;
+
+ JLabel jLabelInput = new JLabel("Path to coordinate file:");
+ localPanel.add(jLabelInput, c);
+ c.gridx = 1;
+ c.insets = new Insets(0, 0, 0, 20);
+
+ localPanel.add(jInputFileChooser, c);
+ jInputFileChooser.setMaximumSize(new Dimension(10000, 20));
+ jInputFileChooser.setSize(new Dimension(180, 20));
+ jInputFileChooser.setText("path\\coordinate file_tab_path\\image");
+
+ JButton sourceButton = new JButton("...");
+ sourceButton.setSize(new Dimension(20, 20));
+ sourceButton.addActionListener(this);
+ sourceButton.setName(INPUT_CHOOSER);
+ c.insets = new Insets(0, 0, 0, 0);
+ c.gridx = 2;
+
+ localPanel.add(sourceButton, c);
+
+ localPanel.setBorder(padding);
+ localModeLayout.add(localPanel);
+ container.add(localModeLayout, 1);
+
+
+ // Omero mode layout
+ omeroModeLayout.setLayout(new BoxLayout(omeroModeLayout, BoxLayout.Y_AXIS));
+
+ JPanel omeroPanel = new JPanel();
+ GridBagLayout omeroLayout = new GridBagLayout();
+ omeroLayout.columnWeights = new double[]{0.1, 0.1, 2};
+ omeroPanel.setLayout(omeroLayout);
+ c = new GridBagConstraints();
+ c.fill = GridBagConstraints.HORIZONTAL;
+ c.insets = new Insets(5, 0, 5, 20);
+
+ c.gridy = 0;
+ JLabel jLabelHostname = new JLabel("Hostname :");
+ c.gridx = 0;
+ c.gridwidth = 1;
+ omeroPanel.add(jLabelHostname, c);
+ c.gridx = 1;
+ c.gridwidth = 2;
+ omeroPanel.add(jTextFieldHostname, c);
+ jTextFieldHostname.setMaximumSize(new Dimension(10000, 20));
+
+ c.gridy = 1;
+ JLabel jLabelPort = new JLabel("Port :");
+ c.gridx = 0;
+ c.gridwidth = 1;
+ omeroPanel.add(jLabelPort, c);
+ c.gridx = 1;
+ c.gridwidth = 2;
+ omeroPanel.add(jTextFieldPort, c);
+ jTextFieldPort.setMaximumSize(new Dimension(10000, 20));
+
+ c.gridy = 2;
+ JLabel jLabelUsername = new JLabel("Username :");
+ c.gridx = 0;
+ c.gridwidth = 1;
+ omeroPanel.add(jLabelUsername, c);
+ c.gridx = 1;
+ c.gridwidth = 2;
+ omeroPanel.add(jTextFieldUsername, c);
+ jTextFieldUsername.setMaximumSize(new Dimension(10000, 20));
+
+ c.gridy = 3;
+ JLabel jLabelPassword = new JLabel("Password :");
+ c.gridx = 0;
+ c.gridwidth = 1;
+ omeroPanel.add(jLabelPassword, c);
+ c.gridx = 1;
+ c.gridwidth = 2;
+ omeroPanel.add(jPasswordField, c);
+ jPasswordField.setMaximumSize(new Dimension(10000, 20));
+
+ c.gridy = 4;
+ JLabel jLabelGroup = new JLabel("Group ID :");
+ c.gridx = 0;
+ c.gridwidth = 1;
+ omeroPanel.add(jLabelGroup, c);
+ c.gridx = 1;
+ c.gridwidth = 2;
+ omeroPanel.add(jTextFieldGroup, c);
+ jTextFieldGroup.setMaximumSize(new Dimension(10000, 20));
+
+ c.gridy = 5;
+ JLabel jLabelSource = new JLabel("Image Source :");
+ c.gridx = 0;
+ c.gridwidth = 1;
+ omeroPanel.add(jLabelSource, c);
+ c.gridx = 1;
+ omeroPanel.add(jComboBoxDataType, c);
+ c.gridx = 2;
+ omeroPanel.add(jTextFieldSourceID, c);
+ jTextFieldSourceID.setMaximumSize(new Dimension(10000, 20));
+
+ c.gridy = 6;
+ JLabel jLabelToCrop = new JLabel("Image To Crop :");
+ c.gridx = 0;
+ c.gridwidth = 1;
+ omeroPanel.add(jLabelToCrop, c);
+ c.gridx = 1;
+ omeroPanel.add(jComboBoxDataTypeToCrop, c);
+ c.gridx = 2;
+ omeroPanel.add(jTextFieldToCropID, c);
+ jTextFieldToCropID.setMaximumSize(new Dimension(20000, 20));
+
+
+ c.gridy = 7;
+ JLabel jLabelOutputProject = new JLabel("Output Dataset :");
+ c.gridx = 0;
+ c.gridwidth = 1;
+ omeroPanel.add(jLabelOutputProject, c);
+ c.gridx = 1;
+ c.gridwidth = 2;
+ omeroPanel.add(jTextFieldOutputProject, c);
+ jTextFieldOutputProject.setMaximumSize(new Dimension(10000, 20));
+
+ omeroPanel.setBorder(padding);
+ omeroModeLayout.add(omeroPanel);
+
+
+ /*/\*\
+ ------------------------------ Coordinate file -----------------------------------------
+ \*\/*/
+
+ /*/\*\
+ ------------------------------ Image + coordinates -----------------------------------------
+ \*\/*/
+
+
+ /*
+ JLabel imageFileLabel = new JLabel();
+ container.add(imageFileLabel, new GridBagConstraints(0, 1, 0, 0, 0.0, 0.0,
+ GridBagConstraints.NORTHWEST, GridBagConstraints.NONE,
+ new Insets(10, 10, 0, 0), 0, 0));
+ imageFileLabel.setText("Path to image:");
+
+ container.add(jImageChooser, new GridBagConstraints(0, 1, 0, 0, 0.0, 0.0,
+ GridBagConstraints.NORTHWEST, GridBagConstraints.NONE,
+ new Insets(30, 10, 0, 0), 0, 0));
+ jImageChooser.setPreferredSize(new java.awt.Dimension(300, 20));
+ jImageChooser.setMinimumSize(new java.awt.Dimension(300, 20));
+
+ imageButton = new JButton("...");
+ container.add(linkFileButton, new GridBagConstraints(0, 1, 0, 0, 0.0, 0.0,
+ GridBagConstraints.NORTHWEST, GridBagConstraints.NONE,
+ new Insets(30, 330, 0, 0), 0, 0));
+ imageButton.addActionListener(this);
+ imageButton.setName(imageChooserName);
+
+ jLabelCoord = new JLabel();
+ container.add(jLabelCoord, new GridBagConstraints(0, 0, 0, 0, 0.0, 0.0,
+ GridBagConstraints.NORTHWEST, GridBagConstraints.NONE,
+ new Insets(10, 10, 0, 0), 0, 0));
+ jLabelCoord.setText("Path to coordinates:");
+
+ container.add(jCoordFileChooser, new GridBagConstraints(0, 0, 0, 0, 0.0, 0.0,
+ GridBagConstraints.NORTHWEST, GridBagConstraints.NONE,
+ new Insets(30, 10, 0, 0), 0, 0));
+ jCoordFileChooser.setPreferredSize(new java.awt.Dimension(300, 20));
+ jCoordFileChooser.setMinimumSize(new java.awt.Dimension(300, 20));
+
+ coordButton = new JButton("...");
+ container.add(coordButton, new GridBagConstraints(0, 0, 0, 0, 0.0, 0.0,
+ GridBagConstraints.NORTHWEST, GridBagConstraints.NONE,
+ new Insets(30, 330, 0, 0), 0, 0));
+ coordButton.addActionListener(this);
+ coordButton.setName(coordChooserName);
+ */
+
+ /*/\*\
+ ------------------------------ Buttons -----------------------------------------
+ \*\/*/
+
+ // Start/Quit buttons
+
+ Border padding2 = BorderFactory.createEmptyBorder(10, 120, 10, 120);
+
+ JPanel startQuitPanel = new JPanel();
+ startQuitPanel.setLayout(new GridLayout(1, 2, 30, 10));
+ startQuitPanel.add(jButtonStart);
+ startQuitPanel.add(jButtonQuit);
+ startQuitPanel.setBorder(padding2);
+ container.add(startQuitPanel, 2);
+
+
+ CropFromCoordinatesDialog.QuitListener quitListener = new QuitListener(this);
+ jButtonQuit.addActionListener(quitListener);
+ CropFromCoordinatesDialog.StartListener startListener = new CropFromCoordinatesDialog.StartListener(this);
+ jButtonStart.addActionListener(startListener);
+ this.setVisible(true);
+
+
+ // DEFAULT VALUES FOR TESTING :
+ jTextFieldHostname.setText(host);
+ jTextFieldPort.setText(String.valueOf(port));
+
+ jTextFieldUsername.setText(username);
+ jTextFieldGroup.setText("553");
+ jPasswordField.setText("");
+ jComboBoxDataType.setSelectedIndex(1);
+ jComboBoxDataTypeToCrop.setSelectedIndex(1);
+ jTextFieldSourceID.setText("26628");
+ jTextFieldToCropID.setText("26629");
+ jTextFieldOutputProject.setText("26401");
+ }
+
+
+ public boolean isStart() {
+ return start;
+ }
+
+
+ public String getLink() {
+ return jInputFileChooser.getText();
+ }
+
+
+ public String getImage() {
+ return jImageChooser.getText();
+ }
+
+
+ public String getCoord() {
+ return jCoordFileChooser.getText();
+ }
+
+
+ public String getInput() {
+ return jInputFileChooser.getText();
+ }
+
+
+ public boolean isOmeroEnabled() {
+ return useOMERO;
+ }
+
+
+ public String getHostname() {
+ return jTextFieldHostname.getText();
+ }
+
+
+ public String getPort() {
+ return jTextFieldPort.getText();
+ }
+
+
+ public String getSourceID() {
+ return jTextFieldSourceID.getText();
+ }
+
+ public String getToCropID() {
+ return jTextFieldToCropID.getText();
+ }
+
+
+ public String getDataType() {
+ return (String) jComboBoxDataType.getSelectedItem();
+ }
+ public String getDataTypeToCrop() {
+ return (String) jComboBoxDataTypeToCrop.getSelectedItem();
+ }
+
+
+ public String getUsername() {
+ return jTextFieldUsername.getText();
+ }
+
+
+ public String getPassword() {
+ return String.valueOf(jPasswordField.getPassword());
+ }
+
+
+ public String getGroup() {
+ return jTextFieldGroup.getText();
+ }
+
+
+ public String getOutputProject() {
+ return jTextFieldOutputProject.getText();
+ }
+
+
+ public void actionPerformed(ActionEvent e) {
+
+ if (((JButton) e.getSource()).getName().equals(INPUT_CHOOSER)) {
+ fc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
+ }
+ fc.setAcceptAllFileFilterUsed(false);
+
+ if (fc.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
+ switch (((JButton) e.getSource()).getName()) {
+ case INPUT_CHOOSER:
+ File selectedInput = fc.getSelectedFile();
+ jInputFileChooser.setText(selectedInput.getPath());
+ break;
+ case OUTPUT_CHOOSER:
+ File selectedOutput = fc.getSelectedFile();
+ jTextFieldOutputProject.setText(selectedOutput.getPath());
+ break;
+ }
+ }
+ fc.setSelectedFile(null);
+ }
+
+
+ @Override
+ public void itemStateChanged(ItemEvent e) {
+ Object source = e.getSource();
+
+ if (source == omeroNoButton) {
+ container.remove(1);
+ container.add(localModeLayout, 1);
+ useOMERO = false;
+ } else if (source == omeroYesButton) {
+ container.remove(1);
+ container.add(omeroModeLayout, 1);
+ useOMERO = true;
+ } else {
+ container.remove(3);
+ }
+
+ validate();
+ repaint();
+ }
+
+
+ static class QuitListener implements ActionListener {
+ CropFromCoordinatesDialog autocropDialog;
+
+
+ /** @param autocropDialog */
+ public QuitListener(CropFromCoordinatesDialog autocropDialog) {
+ this.autocropDialog = autocropDialog;
+ }
+
+
+ public void actionPerformed(ActionEvent actionEvent) {
+ autocropDialog.dispose();
+ }
+
+ }
+
+ /** Classes listener to interact with the several elements of the window */
+ class StartListener implements ActionListener {
+ CropFromCoordinatesDialog autocropDialog;
+
+
+ /** @param autocropDialog */
+ public StartListener(CropFromCoordinatesDialog autocropDialog) {
+ this.autocropDialog = autocropDialog;
+ }
+
+
+ public void actionPerformed(ActionEvent actionEvent) {
+ start = true;
+ autocropDialog.dispose();
+ }
+
+ }
+
+
+}
diff --git a/src/main/java/gred/nucleus/dialogs/SegmentationDialog.java b/src/main/java/gred/nucleus/dialogs/SegmentationDialog.java
index d5c000be..2c2f3cdb 100644
--- a/src/main/java/gred/nucleus/dialogs/SegmentationDialog.java
+++ b/src/main/java/gred/nucleus/dialogs/SegmentationDialog.java
@@ -260,8 +260,8 @@ public SegmentationDialog(IDialogListener dialogListener) {
jTextFieldHostname.setText("omero.gred-clermont.fr");
jTextFieldPort.setText("4064");
- jTextFieldUsername.setText("demo");
- jPasswordField.setText("Isim@42");
+ jTextFieldUsername.setText("");
+ jPasswordField.setText("");
jTextFieldGroup.setText("553");
jComboBoxDataType.setSelectedIndex(3);
@@ -310,8 +310,8 @@ public String getUsername() {
}
- public String getPassword() {
- return String.valueOf(jPasswordField.getPassword());
+ public char[] getPassword() {
+ return jPasswordField.getPassword();
}
diff --git a/src/main/java/gred/nucleus/plugins/Autocrop_.java b/src/main/java/gred/nucleus/plugins/Autocrop_.java
index 4d08c495..74814323 100644
--- a/src/main/java/gred/nucleus/plugins/Autocrop_.java
+++ b/src/main/java/gred/nucleus/plugins/Autocrop_.java
@@ -54,7 +54,7 @@ public void OnStart() {
public Client checkOMEROConnection(String hostname,
String port,
String username,
- String password,
+ char[] password,
String group) {
Client client = new Client();
@@ -78,7 +78,7 @@ private void runOmeroAutocrop() {
String hostname = autocropDialog.getHostname();
String port = autocropDialog.getPort();
String username = autocropDialog.getUsername();
- String password = autocropDialog.getPassword();
+ char[] password = autocropDialog.getPassword();
String group = autocropDialog.getGroup();
Client client = checkOMEROConnection(hostname, port, username, password, group);
diff --git a/src/main/java/gred/nucleus/plugins/CropFromCoordinates_.java b/src/main/java/gred/nucleus/plugins/CropFromCoordinates_.java
index 1dbd4adb..84491d66 100644
--- a/src/main/java/gred/nucleus/plugins/CropFromCoordinates_.java
+++ b/src/main/java/gred/nucleus/plugins/CropFromCoordinates_.java
@@ -1,20 +1,39 @@
package gred.nucleus.plugins;
+import fr.igred.omero.Client;
+import fr.igred.omero.exception.AccessException;
+import fr.igred.omero.exception.OMEROServerError;
+import fr.igred.omero.exception.ServiceException;
+import fr.igred.omero.repository.DatasetWrapper;
+import fr.igred.omero.repository.ImageWrapper;
+import fr.igred.omero.roi.ROIWrapper;
import gred.nucleus.autocrop.CropFromCoordinates;
-import gred.nucleus.dialogs.CropFromCoodinateDialog;
+import gred.nucleus.dialogs.CropFromCoordinatesDialog;
+import gred.nucleus.files.FilesNames;
import ij.IJ;
+import ij.ImagePlus;
+import ij.Prefs;
+import ij.io.FileSaver;
import ij.plugin.PlugIn;
import loci.formats.FormatException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import java.io.File;
import java.io.IOException;
import java.lang.invoke.MethodHandles;
+import java.nio.file.Files;
+import java.util.List;
+import java.util.concurrent.ExecutionException;
public class CropFromCoordinates_ implements PlugIn {
- /** Logger */
+ /**
+ * Logger
+ */
+ private DatasetWrapper toCropDataset;
private static final Logger LOGGER = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
+ CropFromCoordinatesDialog cropFromCoordinatesDialog;
public static void cropFromCoordinates(String coordinateDir) throws IOException, FormatException {
@@ -26,12 +45,11 @@ public static void cropFromCoordinates(String coordinateDir) throws IOException,
@Override
public void run(String arg) {
-
if (IJ.versionLessThan("1.32c")) {
return;
}
- CropFromCoodinateDialog cropFromCoodinateDialog = new CropFromCoodinateDialog();
- while (cropFromCoodinateDialog.isShowing()) {
+ cropFromCoordinatesDialog = new CropFromCoordinatesDialog();
+ while (cropFromCoordinatesDialog.isShowing()) {
try {
Thread.sleep(1);
} catch (InterruptedException e) {
@@ -39,22 +57,163 @@ public void run(String arg) {
}
}
- if (cropFromCoodinateDialog.isStart()) {
- String file = cropFromCoodinateDialog.getLink();
- if (file == null || file.equals("")) {
- IJ.error("Input file or directory is missing");
+ if (cropFromCoordinatesDialog.isStart()) {
+ if (cropFromCoordinatesDialog.isOmeroEnabled()) {
+
+ try {
+ runOMERO();
+ } catch (AccessException e) {
+ throw new RuntimeException(e);
+ } catch (ServiceException e) {
+ throw new RuntimeException(e);
+ } catch (ExecutionException e) {
+ throw new RuntimeException(e);
+ }
} else {
+ String file = cropFromCoordinatesDialog.getLink();
+ if (file == null || file.equals("")) {
+ IJ.error("Input file or directory is missing");
+ } else {
+ try {
+ LOGGER.info("Begin Autocrop from coordinate process ");
+
+ cropFromCoordinates(file);
+
+ LOGGER.info("Autocrop from coordinate process has ended successfully");
+ } catch (Exception e) {
+ LOGGER.info("Autocrop from coordinate process has failed");
+ LOGGER.error("An error occurred.", e);
+ }
+ }
+ }
+ }
+ }
+
+ public Client checkOMEROConnection(String hostname,
+ String port,
+ String username,
+ char[] password,
+ String group) {
+ Client client = new Client();
+ try {
+ client.connect(hostname,
+ Integer.parseInt(port),
+ username,
+ password,
+ Long.valueOf(group));
+ } catch (Exception exp) {
+ IJ.error("Invalid connection values");
+ return null;
+ }
+ return client;
+ }
+
+ private void cropImageFromOMERO(Client client, ImageWrapper image,ImageWrapper imageToCrop, DatasetWrapper outputDataset)
+ throws AccessException, ServiceException, ExecutionException, IOException, OMEROServerError {
+ List rois = image.getROIs(client);
+ for (ROIWrapper roi : rois) {
+ // Get the roi names
+ String ROIName = roi.getName();
+ // Get the name of the Image To Crop
+ String imageToCropName = imageToCrop.getName();
+ // Get the image to crop
+ ImagePlus imp = imageToCrop.toImagePlus(client, roi);
+ // Save Crop File
+ FileSaver fileSaver = new FileSaver(imp);
+ String sortie = fileSaver.toString();
+ // Save the crop as TIF
+ fileSaver.saveAsTiff(sortie);
+ // generate a temporary file
+ String resultPath = sortie;
+ File resultFile = new File(resultPath);
+ // Remove file extension
+ FilesNames outPutFilesNames = new FilesNames(imageToCropName);
+ String prefix = outPutFilesNames.prefixNameFile();
+ // Rename the temporary file same as toCrop Image name
+ File toCropNewName = new File(prefix+"_"+ROIName);
+ resultFile.renameTo(toCropNewName);
+ String toCropFile = toCropNewName.toString();
+ // Import Cropped Image to the Dataset
+ outputDataset.importImages(client, toCropFile);
+ // Delete temp file
+ Files.deleteIfExists(toCropNewName.toPath());
+ }
+ }
+
+ public void runOMERO() throws AccessException, ServiceException, ExecutionException {
+ // Check connection
+ String hostname = cropFromCoordinatesDialog.getHostname();
+ String port = cropFromCoordinatesDialog.getPort();
+ String username = cropFromCoordinatesDialog.getUsername();
+ String password = cropFromCoordinatesDialog.getPassword();
+ String group = cropFromCoordinatesDialog.getGroup();
+ String output = cropFromCoordinatesDialog.getOutputProject();
+
+ Prefs.set("omero.host", hostname);
+ Prefs.set("omero.port", port);
+ Prefs.set("omero.user", username);
+
+ Client client = checkOMEROConnection(hostname, port, username, password.toCharArray(), group);
+
+ // Handle the source according to the type given
+ String sourceDataType = cropFromCoordinatesDialog.getDataType();
+ String ToCropdataType = cropFromCoordinatesDialog.getDataType();
+ Long inputID = Long.valueOf(cropFromCoordinatesDialog.getSourceID());
+ Long inputToCropID = Long.valueOf(cropFromCoordinatesDialog.getToCropID());
+ DatasetWrapper outputds = client.getDataset(Long.parseLong(output));
+
+ try {
+ if (sourceDataType.equals("Image") && ToCropdataType.equals("Image") ) {
+ ImageWrapper image = client.getImage(inputID);
+ ImageWrapper imageToCrop = client.getImage(inputToCropID);
+
try {
LOGGER.info("Begin Autocrop from coordinate process ");
+ cropImageFromOMERO(client, image, imageToCrop, outputds); // Run cropFromCoordinates
+ LOGGER.info("Autocrop from coordinate process has ended successfully");
+ } catch (Exception e) {
+ LOGGER.info("Autocrop from coordinate process has failed");
+ LOGGER.error("An error occurred.", e);
+ }
+
+ } else {
+ List sourceImages = null;
+ List toCropImages = null;
+ String sourceImageName = "";
+ ImageWrapper sourceImage;
+ if (sourceDataType.equals("Dataset") && ToCropdataType.equals("Dataset")) {
- cropFromCoordinates(file);
+ DatasetWrapper sourceDataset = client.getDataset(inputID);
+ toCropDataset = client.getDataset(inputToCropID);
+ sourceImages = sourceDataset.getImages(client);
+ } else if (sourceDataType.equals("Tag")) {
+ sourceImages = client.getImagesTagged(inputID);
+ }
+ try {
+ LOGGER.info("Begin Autocrop from coordinate process ");
+ for (int i =0; i< sourceImages.size(); i++) {
+
+ sourceImage = sourceImages.get(i) ;
+ sourceImageName = sourceImage.getName();
+ toCropImages = toCropDataset.getImages(client,sourceImageName);
+ if(!toCropImages.isEmpty()){
+ ImageWrapper toCropImage= toCropImages.get(0);
+ cropImageFromOMERO(client, sourceImage,toCropImage, outputds); // Run cropFromCoordinates
+ }
+ }
LOGGER.info("Autocrop from coordinate process has ended successfully");
} catch (Exception e) {
LOGGER.info("Autocrop from coordinate process has failed");
LOGGER.error("An error occurred.", e);
}
}
+ } catch (ServiceException se) {
+ IJ.error("Unable to access to OMERO service");
+ } catch (AccessException ae) {
+ IJ.error("Cannot access " + sourceDataType + "with ID = " + inputID + ".");
+ } catch (Exception e) {
+ LOGGER.error("An error occurred.", e);
}
}
diff --git a/src/main/java/gred/nucleus/plugins/Segmentation_.java b/src/main/java/gred/nucleus/plugins/Segmentation_.java
index d7e88046..f52c0b5d 100644
--- a/src/main/java/gred/nucleus/plugins/Segmentation_.java
+++ b/src/main/java/gred/nucleus/plugins/Segmentation_.java
@@ -53,7 +53,7 @@ public void OnStart() {
public Client checkOMEROConnection(String hostname,
String port,
String username,
- String password,
+ char[] password,
String group) {
Client client = new Client();
try {
@@ -75,7 +75,7 @@ private void runOmeroSegmentation() {
String hostname = segmentationDialog.getHostname();
String port = segmentationDialog.getPort();
String username = segmentationDialog.getUsername();
- String password = segmentationDialog.getPassword();
+ char[] password = segmentationDialog.getPassword();
String group = segmentationDialog.getGroup();
Client client = checkOMEROConnection(hostname, port, username, password, group);