Returns the path to the specified directory if title is "home" ("user.home"), "downloads", "startup", "imagej" (ImageJ directory), "plugins", "macros", "luts", "temp", "current", "default", "image" (directory active image was loaded from), "file" (directory most recently used
(String title)
| 1959 | dialog box. Also aborts the macro if the user cancels the |
| 1960 | dialog box.*/ |
| 1961 | public static String getDirectory(String title) { |
| 1962 | String dir = null; |
| 1963 | String title2 = title.toLowerCase(Locale.US); |
| 1964 | if (title2.equals("plugins")) |
| 1965 | dir = Menus.getPlugInsPath(); |
| 1966 | else if (title2.equals("macros")) |
| 1967 | dir = Menus.getMacrosPath(); |
| 1968 | else if (title2.equals("luts")) { |
| 1969 | String ijdir = Prefs.getImageJDir(); |
| 1970 | if (ijdir!=null) |
| 1971 | dir = ijdir + "luts" + File.separator; |
| 1972 | else |
| 1973 | dir = null; |
| 1974 | } else if (title2.equals("home")) |
| 1975 | dir = System.getProperty("user.home"); |
| 1976 | else if (title2.equals("downloads")) |
| 1977 | dir = System.getProperty("user.home")+File.separator+"Downloads"; |
| 1978 | else if (title2.equals("startup")) |
| 1979 | dir = Prefs.getImageJDir(); |
| 1980 | else if (title2.equals("imagej")) |
| 1981 | dir = Prefs.getImageJDir(); |
| 1982 | else if (title2.equals("current") || title2.equals("default")) |
| 1983 | dir = OpenDialog.getDefaultDirectory(); |
| 1984 | else if (title2.equals("preferences")) |
| 1985 | dir = Prefs.getPrefsDir(); |
| 1986 | else if (title2.equals("temp")) { |
| 1987 | dir = System.getProperty("java.io.tmpdir"); |
| 1988 | if (isMacintosh()) dir = "/tmp/"; |
| 1989 | } else if (title2.equals("image")) { |
| 1990 | ImagePlus imp = WindowManager.getCurrentImage(); |
| 1991 | FileInfo fi = imp!=null?imp.getOriginalFileInfo():null; |
| 1992 | if (fi!=null && fi.directory!=null) { |
| 1993 | dir = fi.directory; |
| 1994 | } else |
| 1995 | dir = null; |
| 1996 | } else if (title2.equals("file")) |
| 1997 | dir = OpenDialog.getLastDirectory(); |
| 1998 | else if (title2.equals("cwd")) |
| 1999 | dir = System.getProperty("user.dir"); |
| 2000 | else { |
| 2001 | String defaultDir = OpenDialog.getDefaultDirectory(); |
| 2002 | DirectoryChooser dc = new DirectoryChooser(title); |
| 2003 | dir = dc.getDirectory(); |
| 2004 | OpenDialog.setDefaultDirectory(defaultDir); |
| 2005 | if (dir==null) Macro.abort(); |
| 2006 | } |
| 2007 | dir = addSeparator(dir); |
| 2008 | return dir; |
| 2009 | } |
| 2010 | |
| 2011 | public static String addSeparator(String path) { |
| 2012 | if (path==null) |
no test coverage detected