Open a file. If it's a directory, ask to open all images as a sequence in a stack or individually.
(File f)
| 199 | |
| 200 | /** Open a file. If it's a directory, ask to open all images as a sequence in a stack or individually. */ |
| 201 | @AstroImageJ(reason = "Skip Folder Opener dialog in some cases; Set FolderOpener directory", modified = true) |
| 202 | public void openFile(File f) { |
| 203 | if (IJ.debugMode) IJ.log("DragAndDrop.openFile: "+f); |
| 204 | try { |
| 205 | if (null == f) return; |
| 206 | String path = f.getCanonicalPath(); |
| 207 | if (f.exists()) { |
| 208 | if (f.isDirectory()) { |
| 209 | if (openAsVirtualStack) |
| 210 | IJ.run("Image Sequence...", "open=[" + path + "] sort use"); |
| 211 | else |
| 212 | openDirectory(f, path); |
| 213 | } else { |
| 214 | if (openAsVirtualStack && (path.endsWith(".tif")||path.endsWith(".TIF")||path.endsWith(".tiff"))) |
| 215 | (new FileInfoVirtualStack()).run(path); |
| 216 | else if (openAsVirtualStack && (path.endsWith(".avi")||path.endsWith(".AVI"))) |
| 217 | IJ.run("AVI...", "open=["+path+"] use"); |
| 218 | else if (openAsVirtualStack && (path.endsWith(".txt"))) { |
| 219 | ImageProcessor ip = (new TextReader()).open(path); |
| 220 | if (ip!=null) |
| 221 | new ImagePlus(f.getName(),ip).show(); |
| 222 | } else { |
| 223 | Recorder.recordOpen(path); |
| 224 | (new Opener(openOptions)).openAndAddToRecent(path); |
| 225 | } |
| 226 | OpenDialog.setLastDirectory(f.getParent()+File.separator); |
| 227 | OpenDialog.setLastName(f.getName()); |
| 228 | OpenDialog.setDefaultDirectory(f.getParent()); |
| 229 | Prefs.set("import.sequence.dir", f.getParent()); |
| 230 | } |
| 231 | } else { |
| 232 | IJ.log("File not found: " + path); |
| 233 | } |
| 234 | } catch (Throwable e) { |
| 235 | if (!Macro.MACRO_CANCELED.equals(e.getMessage())) |
| 236 | IJ.handleException(e); |
| 237 | } |
| 238 | } |
| 239 | |
| 240 | @AstroImageJ(reason = "Show warning and abort if folder has no images; Add option for skipping dialog", modified = true) |
| 241 | private void openDirectory(File f, String path) { |
no test coverage detected