Skip to content

Commit

Permalink
Merge pull request ome#4001 from jburel/mif-ij
Browse files Browse the repository at this point in the history
ij-omero round trip
  • Loading branch information
sbesson committed Jul 31, 2015
2 parents 5dd4367 + baa97fb commit fb4ef8b
Show file tree
Hide file tree
Showing 7 changed files with 194 additions and 73 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,8 @@ private boolean allowAddToQueue(List<FileElement> queue, FileObject f, long gID,
return true;
}
File file = f.getTrueFile();
//check if file is null
if (file == null) return false;
Iterator<FileElement> i = queue.iterator();
FileElement fe;
String name = file.getAbsolutePath();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
package org.openmicroscopy.shoola.agents.fsimporter.chooser;

//Java imports
import ij.IJ;
import ij.WindowManager;
import info.clearthought.layout.TableLayout;

Expand Down Expand Up @@ -1566,7 +1567,6 @@ public void addImageJFiles(List<FileObject> list,
ImportLocationSettings settings)
{
int plugin = ImporterAgent.runAsPlugin();

if (!(plugin == LookupNames.IMAGE_J_IMPORT ||
plugin == LookupNames.IMAGE_J)) return;
if (CollectionUtils.isEmpty(list)) {
Expand All @@ -1588,11 +1588,23 @@ public void addImageJFiles(List<FileObject> list,
}
list.add(f);
} else {
List<String> paths = new ArrayList<String>();
int[] values = WindowManager.getIDList();
if (values != null) {
for (int i = 0; i < values.length; i++) {
list.add(new FileObject(
WindowManager.getImage(values[i])));
//need to check if it is the same image
f = new FileObject(WindowManager.getImage(values[i]));
String path = f.getAbsolutePath();
if (!paths.contains(path)) {
paths.add(path);
list.add(f);
for (int j = 0; j < values.length; j++) {
ff = new FileObject(WindowManager.getImage(values[j]));
if (path.equals(ff.getAbsolutePath())) {
f.addAssociatedFile(ff);
}
}
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
import javax.swing.JPanel;
import javax.swing.JPopupMenu;

import ij.IJ;
import info.clearthought.layout.TableLayout;
import info.clearthought.layout.TableLayoutConstraints;
import omero.cmd.CmdCallback;
Expand Down Expand Up @@ -926,7 +927,38 @@ void setParent(FileImportComponent parent)
* @return See above.
*/
public StatusLabel getStatus() { return statusLabel; }


/**
* Returns the associated file if any.
*
* @param series See above.
* @return See above.
*/
private FileObject getAssociatedFile(int series)
{
List<FileObject> l = getFile().getAssociatedFiles();
Iterator<FileObject> i = l.iterator();
FileObject f;
while (i.hasNext()) {
f = i.next();
if (f.getIndex() == series) {
return f;
}
}
return null;
}

/**
* Returns <code>true</code> if the file has some associated files,
* <code>false</code> otherwise.
*
* @return See above.
*/
private boolean hasAssociatedFiles() {
List<FileObject> l = getFile().getAssociatedFiles();
return CollectionUtils.isNotEmpty(l);
}

/**
* Sets the result of the import.
* @param image The image.
Expand All @@ -945,16 +977,30 @@ public void setStatus(Object image)
} else if (image instanceof Set) {
//Result from the import itself
this.image = null;
Set set = (Set) image;
Iterator i = set.iterator();
FileObject f;
while (i.hasNext()) {
Object object = i.next();
if (object instanceof PixelsData) {
PixelsData pix = (PixelsData) object;
if (hasAssociatedFiles()) {
int series = pix.getImage().getSeries();
f = getAssociatedFile(series);
if (f != null) {
f.setImageID(pix.getImage().getId());
}
} else {
f = getOriginalFile();
f.setImageID(pix.getImage().getId());
}
}
}
formatResult();
} else if (image instanceof List) {
List<ThumbnailData> list = new ArrayList<ThumbnailData>((List) image);
int m = list.size();
ThumbnailData data = list.get(0);
long iid = data.getImageID();
if (data.getImage() != null) {
iid = data.getImage().getId();
}
getFile().setImageID(iid);
imageLabel.setData(data);
list.remove(0);
if (list.size() > 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -621,7 +621,9 @@ void saveROI(FileImportComponent c, List<ImageData> images)
Map<Integer, List<ROIData>> indexes =
new HashMap<Integer, List<ROIData>>();
int index;
boolean mif = false;
if (CollectionUtils.isNotEmpty(files)) {
mif = true;
Iterator<FileObject> j = files.iterator();
FileObject o;
while (j.hasNext()) {
Expand All @@ -630,6 +632,9 @@ void saveROI(FileImportComponent c, List<ImageData> images)
index = o.getIndex();
rois = reader.readImageJROI(-1, (ImagePlus) o.getFile());
indexes.put(index, rois);
if (index < 0) {
mif = false;
}
}
}
}
Expand All @@ -644,11 +649,14 @@ void saveROI(FileImportComponent c, List<ImageData> images)
id = data.getId();
index = data.getSeries();
//First check overlay
rois = null;
if (indexes.containsKey(index)) {
rois = indexes.get(index);
linkRoisToImage(id, rois);
} else {
rois = reader.readImageJROI(id, img);
if (!mif) {
rois = reader.readImageJROI(id, img);
}
}
//check roi manager
if (CollectionUtils.isEmpty(rois)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import ij.WindowManager;

import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Container;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
Expand All @@ -52,6 +51,7 @@
import org.openmicroscopy.shoola.env.data.model.ResultsObject;
import org.openmicroscopy.shoola.env.data.util.SecurityContext;
import org.openmicroscopy.shoola.env.event.SaveEvent;
import org.openmicroscopy.shoola.util.CommonsLangUtils;
import org.openmicroscopy.shoola.util.ui.MessageBox;
import org.openmicroscopy.shoola.util.ui.UIUtilities;

Expand Down Expand Up @@ -163,11 +163,23 @@ private void save()
} else {
int[] values = WindowManager.getIDList();
if (values != null) {
List<String> paths = new ArrayList<String>();
for (int i = 0; i < values.length; i++) {
plus = WindowManager.getImage(values[i]);
img = new FileObject(plus);
if (img.getOMEROID() < 0 || img.isNewImage()) {
toImport.add(img);
String path = img.getAbsolutePath();
if (!paths.contains(path)) {
paths.add(path);
toImport.add(img);
for (int j = 0; j < values.length; j++) {
FileObject ff = new FileObject(
WindowManager.getImage(values[j]));
if (path.equals(ff.getAbsolutePath())) {
img.addAssociatedFile(ff);
}
}
}
} else {
images.add(img);
}
Expand All @@ -179,7 +191,8 @@ private void save()
if (toImport.size() > 0) { //ask if they want to import the image
StringBuffer buf = new StringBuffer();
buf.append("Do you wish to import any selected images not already "
+ "saved in OMERO to the OMERO server?");
+ CommonsLangUtils.LINE_SEPARATOR+
"saved in OMERO to the OMERO server?");
MessageBox box = new MessageBox(this, "Import images", buf.toString());
if (box.centerMsgBox() == MessageBox.YES_OPTION) {
result = new ResultsObject(toImport);
Expand Down
Loading

0 comments on commit fb4ef8b

Please sign in to comment.