Java Code Examples for ij.io.OpenDialog#getDefaultDirectory()
The following examples show how to use
ij.io.OpenDialog#getDefaultDirectory() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Loader.java From TrakEM2 with GNU General Public License v3.0 | 5 votes |
/** Ask for the user to provide a template XML file to extract a root TemplateThing. */ public TemplateThing askForXMLTemplate(final Project project) { // ask for an .xml file or a .dtd file //fd.setFilenameFilter(new XMLFileFilter(XMLFileFilter.BOTH)); final OpenDialog od = new OpenDialog("Select XML Template", OpenDialog.getDefaultDirectory(), null); final String filename = od.getFileName(); if (null == filename || filename.toLowerCase().startsWith("null")) return null; // if there is a path, read it out if possible String dir = od.getDirectory(); if (null == dir) return null; if (IJ.isWindows()) dir = dir.replace('\\', '/'); if (!dir.endsWith("/")) dir += "/"; TemplateThing[] roots; try { roots = DTDParser.extractTemplate(dir + filename); } catch (final Exception e) { IJError.print(e); return null; } if (null == roots || roots.length < 1) return null; if (roots.length > 1) { Utils.showMessage("Found more than one root.\nUsing first root only."); } return roots[0]; }
Example 2
Source File: Commander.java From Scripts with GNU General Public License v3.0 | 4 votes |
/** * Executes console commands. Outputs one of the following exit status: * <p> * "0": Executed a a self-contained command that need no follow-up. null: * Failed to retrieve a path. non-null string: A successfully retrieved path * * @see #interpretCommand */ String execCommand(final String cmd) { // Case "0": Self-contained commands that need no follow-up String exitStatus = String.valueOf(0); if (cmd.startsWith("quit")) { quit(); return exitStatus; } else if (cmd.startsWith("help")) { new ij.gui.HTMLDialog("Commander Help", helpMessage(), false); return exitStatus; } else if (cmd.startsWith("ls")) { printList(); return exitStatus; } else if (cmd.equals("options")) { showOptionsDialog(); return exitStatus; } else if (cmd.startsWith("refresh")) { freezeStatusBar = false; return exitStatus; } else if (cmd.startsWith("..")) { selectParentDirectory(path); return exitStatus; } else if (cmd.equals("bookmark")) { addBookmark(); return exitStatus; } else if (cmd.equals("cd")) { cdToDirectory(path); return exitStatus; } else if (cmd.startsWith("info")) { showInfo(); return exitStatus; } // Remaining cases: Commands that only retrieve paths exitStatus = null; if (cmd.startsWith("goto")) { exitStatus = IJ.getDirectory("Choose new directory"); } else if (cmd.startsWith("~")) { exitStatus = IJ.getDirectory("home"); } else if (cmd.startsWith("imp")) { exitStatus = IJ.getDirectory("image"); } else if (cmd.equals("luts")) { exitStatus = IJ.getDirectory(cmd); } else if (cmd.equals("macros")) { exitStatus = IJ.getDirectory(cmd); } else if (cmd.equals("plugins")) { exitStatus = IJ.getDirectory(cmd); } else if (cmd.startsWith("pwd")) { exitStatus = OpenDialog.getDefaultDirectory(); } else if (cmd.equals("ij")) { exitStatus = IJ.getDirectory("imagej"); } else if (cmd.startsWith("tmp")) { exitStatus = IJ.getDirectory("temp"); } else if (cmd.equals("myr")) { exitStatus = Utils.getMyRoutinesDir(); } else if (cmd.equals("lib")) { exitStatus = Utils.getLibDir(); } else if (cmd.equals("samples")) { exitStatus = IJ.getDirectory("imagej") + cmd; } else if (cmd.equals("scripts")) { exitStatus = IJ.getDirectory("imagej") + cmd; } if (exitStatus != null && exitStatus.isEmpty()) exitStatus = null; return exitStatus; }
Example 3
Source File: Render.java From TrakEM2 with GNU General Public License v3.0 | 4 votes |
static public void exportSVG(ProjectThing thing, double z_scale) { StringBuffer data = new StringBuffer(); data.append("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n") .append("<svg\n") .append("\txmlns:dc=\"http://purl.org/dc/elements/1.1/\"\n") .append("\txmlns:cc=\"http://web.resource.org/cc/\"\n") .append("\txmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\"\n") .append("\txmlns:svg=\"http://www.w3.org/2000/svg\"\n") .append("\txmlns=\"http://www.w3.org/2000/svg\"\n") //.append("\twidth=\"1500\"\n") //.append("\theight=\"1000\"\n") .append("\tid=\"").append(thing.getProject().toString()).append("\">\n") ; // traverse the tree at node 'thing' thing.exportSVG(data, z_scale, "\t"); data.append("</svg>"); // save the file final SaveDialog sd = new SaveDialog("Save .svg", OpenDialog.getDefaultDirectory(), "svg"); String dir = sd.getDirectory(); if (null == dir) return; if (IJ.isWindows()) dir = dir.replace('\\', '/'); if (!dir.endsWith("/")) dir += "/"; String file_name = sd.getFileName(); String file_path = dir + file_name; File f = new File(file_path); if (f.exists()) { YesNoCancelDialog d = new YesNoCancelDialog(IJ.getInstance(), "Overwrite?", "File " + file_name + " exists! Overwrite?"); if (!d.yesPressed()) { return; } } String contents = data.toString(); try { DataOutputStream dos = new DataOutputStream(new BufferedOutputStream(new FileOutputStream(f), data.length())); dos.writeBytes(contents); dos.flush(); } catch (Exception e) { IJError.print(e); Utils.log("ERROR: Most likely did NOT save your file."); } }
Example 4
Source File: Loader.java From TrakEM2 with GNU General Public License v3.0 | 4 votes |
/** A dialog to open a stack, making sure there is enough memory for it. */ synchronized public ImagePlus openStack() { final OpenDialog od = new OpenDialog("Select stack", OpenDialog.getDefaultDirectory(), null); final String file_name = od.getFileName(); if (null == file_name || file_name.toLowerCase().startsWith("null")) return null; String dir = od.getDirectory().replace('\\', '/'); if (!dir.endsWith("/")) dir += "/"; final File f = new File(dir + file_name); if (!f.exists()) { Utils.showMessage("File " + dir + file_name + " does not exist."); return null; } // avoid opening trakem2 projects if (file_name.toLowerCase().endsWith(".xml")) { Utils.showMessage("Cannot import " + file_name + " as a stack."); return null; } // estimate file size: assumes an uncompressed tif, or a zipped tif with an average compression ratio of 2.5 long size = f.length() / 1024; // in megabytes if (file_name.length() -4 == file_name.toLowerCase().lastIndexOf(".zip")) { size = (long)(size * 2.5); // 2.5 is a reasonable compression ratio estimate based on my experience } releaseToFit(size); ImagePlus imp_stack = null; try { IJ.redirectErrorMessages(); imp_stack = openImagePlus(f.getCanonicalPath()); } catch (final Exception e) { IJError.print(e); return null; } if (null == imp_stack) { Utils.showMessage("Can't open the stack."); return null; } else if (1 == imp_stack.getStackSize()) { Utils.showMessage("Not a stack!"); return null; } return imp_stack; // the open... command }