Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 50 additions & 25 deletions ij/io/Opener.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,17 +78,18 @@ public void open() {
/**
* Opens and displays the specified tiff, dicom, fits, pgm, jpeg,
* bmp, gif, lut, roi, or text file. Displays an error message if
* the file is not in a supported format.
* the file is not in a supported format and showError is true.
* @see ij.IJ#open(String)
* @see ij.IJ#openImage(String)
*/
public void open(String path) {
public void open(String path, boolean showError) {
boolean isURL = path.contains("://") || path.contains("file:/");
if (isURL && isText(path)) {
openTextURL(path);
return;
}
if (path.endsWith(".jar") || path.endsWith(".class")) {
boolean isDirectory = new File(path).isDirectory();
if (!isDirectory && (path.endsWith(".jar") || path.endsWith(".class"))) {
(new PluginInstaller()).install(path);
return;
}
Expand All @@ -101,7 +102,7 @@ public void open(String path) {
this.fileType = JAVA_OR_TEXT;
else {
useHandleExtraFileTypes = true;
imp = openImage(path);
imp = openImage(path, showError);
}
if (imp==null && isURL)
return;
Expand All @@ -112,6 +113,8 @@ public void open(String path) {
else
imp.show(getLoadRate(start,imp));
} else {
if (this.fileType != CUSTOM && isDirectory)
this.fileType = UNKNOWN;
switch (this.fileType) {
case LUT:
imp = (ImagePlus)IJ.runPlugIn("ij.plugin.LutLoader", path);
Expand Down Expand Up @@ -151,26 +154,32 @@ public void open(String path) {
IJ.runPlugIn("ij.plugin.Raw", path);
break;
case UNKNOWN:
File f = new File(path);
String msg = (f.exists()) ?
"Format not supported or reader plugin not found:"
: "File not found:";
if (path!=null) {
if (path.length()>64)
path = (new File(path)).getName();
if (path.length()<=64)
msg += " \n"+path;
if (showError) {
File f = new File(path);
String msg = (f.exists()) ?
"Format not supported or reader plugin not found:"
: "File not found:";
if (path!=null) {
if (path.length()>64)
path = (new File(path)).getName();
if (path.length()<=64)
msg += " \n"+path;
}
if (openUsingPlugins && msg.length()>20)
msg += "\n \nNOTE: The \"OpenUsingPlugins\" option is set.";
IJ.wait(IJ.isMacro()?500:100); // work around for OS X thread deadlock problem
IJ.error("Opener", msg);
}
if (openUsingPlugins && msg.length()>20)
msg += "\n \nNOTE: The \"OpenUsingPlugins\" option is set.";
IJ.wait(IJ.isMacro()?500:100); // work around for OS X thread deadlock problem
IJ.error("Opener", msg);
error = true;
break;
}
}
}

public void open(String path) {
open(path, true);
}

/** Displays a JFileChooser and then opens the tiff, dicom,
fits, pgm, jpeg, bmp, gif, lut, roi, or text files selected by
the user. Displays error messages if one or more of the selected
Expand Down Expand Up @@ -230,18 +239,22 @@ public void run() {
* @see ij.IJ#openImage
* @see #openUsingBioFormats
*/
public ImagePlus openImage(String path) {
public ImagePlus openImage(String path, boolean showError) {
if (path==null || path.equals(""))
path = getPath();
if (path==null) return null;
ImagePlus img = null;
if (path.contains("://") || path.contains("file:/")) // path is a URL
img = openURL(path);
else
img = openImage(getDir(path), getName(path));
img = openImage(getDir(path), getName(path), showError);
return img;
}

public ImagePlus openImage(String path) {
return openImage(path, true);
}

/**
* Open the nth image of the specified tiff stack.
* @see ij.IJ#openImage(String,int)
Expand Down Expand Up @@ -306,12 +319,16 @@ private boolean isText(String path) {

/** Opens the specified file and adds it to the File/Open Recent menu.
Returns true if the file was opened successfully. */
public boolean openAndAddToRecent(String path) {
open(path);
public boolean openAndAddToRecent(String path, boolean showError) {
open(path, showError);
if (!error)
Menus.addOpenRecentItem(path);
return !error;
}

public boolean openAndAddToRecent(String path) {
return openAndAddToRecent(path, true);
}

/**
* Attempts to open the specified file as a tiff, bmp, dicom, fits,
Expand All @@ -320,7 +337,7 @@ public boolean openAndAddToRecent(String path) {
* the file type is unrecognised.
* @see ij.IJ#openImage(String)
*/
public ImagePlus openImage(String directory, String name) {
public ImagePlus openImage(String directory, String name, boolean showError) {
ImagePlus imp;
FileOpener.setSilentMode(silentMode);
if (directory.length()>0 && !(directory.endsWith("/")||directory.endsWith("\\")))
Expand Down Expand Up @@ -383,12 +400,16 @@ public ImagePlus openImage(String directory, String name) {
if (imp!=null)
return imp;
else
return openUsingHandleExtraFileTypes(path);
return openUsingHandleExtraFileTypes(path, showError);
default:
return null;
}
}

public ImagePlus openImage(String directory, String name) {
return openImage(directory, name, true);
}

public ImagePlus openTempImage(String directory, String name) {
ImagePlus imp = openImage(directory, name);
if (imp!=null)
Expand All @@ -398,7 +419,7 @@ public ImagePlus openTempImage(String directory, String name) {

// Call HandleExtraFileTypes plugin to see if it can handle unknown formats
// or files in TIFF format that the built in reader is unable to open.
private ImagePlus openUsingHandleExtraFileTypes(String path) {
private ImagePlus openUsingHandleExtraFileTypes(String path, boolean showError) {
File f = new File(path);
if (!f.exists())
return null;
Expand All @@ -408,11 +429,15 @@ private ImagePlus openUsingHandleExtraFileTypes(String path) {
if (imp!=null && imp.getNChannels()>1)
imp = new CompositeImage(imp, IJ.COLOR);
this.fileType = wrap[0];
if (imp==null && (this.fileType==UNKNOWN||this.fileType==TIFF) && WindowManager.getImageCount()==nImages)
if (showError && imp==null && (this.fileType==UNKNOWN||this.fileType==TIFF) && WindowManager.getImageCount()==nImages)
IJ.error("Opener", "Unsupported format or file not found:\n"+path);
return imp;
}

private ImagePlus openUsingHandleExtraFileTypes(String path) {
return openUsingHandleExtraFileTypes(path, true);
}

String getPath() {
OpenDialog od = new OpenDialog("Open", "");
String dir = od.getDirectory();
Expand Down
41 changes: 23 additions & 18 deletions ij/plugin/DragAndDrop.java
Original file line number Diff line number Diff line change
Expand Up @@ -175,28 +175,33 @@ public void openFile(File f) {
if (null == f) return;
String path = f.getCanonicalPath();
if (f.exists()) {
if (f.isDirectory()) {
if (openAsVirtualStack)
IJ.run("Image Sequence...", "open=[" + path + "] sort use");
else
openDirectory(f, path);
if (openAsVirtualStack && !f.isDirectory() && (path.endsWith(".tif")||path.endsWith(".TIF")))
(new FileInfoVirtualStack()).run(path);
else if (openAsVirtualStack && !f.isDirectory() && (path.endsWith(".avi")||path.endsWith(".AVI")))
IJ.run("AVI...", "open=["+path+"] use");
else if (openAsVirtualStack && !f.isDirectory() && (path.endsWith(".txt"))) {
ImageProcessor ip = (new TextReader()).open(path);
if (ip!=null)
new ImagePlus(f.getName(),ip).show();
} else {
if (openAsVirtualStack && (path.endsWith(".tif")||path.endsWith(".TIF")))
(new FileInfoVirtualStack()).run(path);
else if (openAsVirtualStack && (path.endsWith(".avi")||path.endsWith(".AVI")))
IJ.run("AVI...", "open=["+path+"] use");
else if (openAsVirtualStack && (path.endsWith(".txt"))) {
ImageProcessor ip = (new TextReader()).open(path);
if (ip!=null)
new ImagePlus(f.getName(),ip).show();
} else {
if ((new Opener()).openAndAddToRecent(path, false))
Recorder.recordOpen(path);
(new Opener()).openAndAddToRecent(path);
else {
if (f.isDirectory()) {
if (openAsVirtualStack)
IJ.run("Image Sequence...", "open=[" + path + "] sort use");
else
openDirectory(f, path);
return;
} else {
IJ.error("Opener", "Unsupported format or file not found:\n"+path);
}
}
OpenDialog.setLastDirectory(f.getParent()+File.separator);
OpenDialog.setLastName(f.getName());
OpenDialog.setDefaultDirectory(f.getParent());
}

OpenDialog.setLastDirectory(f.getParent()+File.separator);
OpenDialog.setLastName(f.getName());
OpenDialog.setDefaultDirectory(f.getParent());
} else {
IJ.log("File not found: " + path);
}
Expand Down