diff --git a/ij/io/Opener.java b/ij/io/Opener.java index 1ccdbacdf..8c5ab3b77 100644 --- a/ij/io/Opener.java +++ b/ij/io/Opener.java @@ -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; } @@ -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; @@ -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); @@ -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 @@ -230,7 +239,7 @@ 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; @@ -238,10 +247,14 @@ public ImagePlus openImage(String path) { 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) @@ -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, @@ -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("\\"))) @@ -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) @@ -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; @@ -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(); diff --git a/ij/plugin/DragAndDrop.java b/ij/plugin/DragAndDrop.java index e374748c9..df87d3b01 100644 --- a/ij/plugin/DragAndDrop.java +++ b/ij/plugin/DragAndDrop.java @@ -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); }