(String title, String defaultDir, String defaultName)
| 207 | |
| 208 | // Save using FileDialog |
| 209 | void save(String title, String defaultDir, String defaultName) { |
| 210 | ImageJ ij = IJ.getInstance(); |
| 211 | Frame parent = ij!=null?ij:new Frame(); |
| 212 | FileDialog fd = new FileDialog(parent, title, FileDialog.SAVE); |
| 213 | if (defaultName!=null) |
| 214 | fd.setFile(defaultName); |
| 215 | if (defaultDir!=null) { |
| 216 | if (IJ.isWindows() && defaultDir.contains("/")) { |
| 217 | File f = new File(defaultDir); |
| 218 | if (f.isDirectory()) |
| 219 | try { |
| 220 | defaultDir = f.getCanonicalPath(); |
| 221 | } catch (IOException e) {} |
| 222 | } |
| 223 | fd.setDirectory(defaultDir); |
| 224 | } |
| 225 | fd.show(); |
| 226 | name = fd.getFile(); |
| 227 | String origName = name; |
| 228 | if (noExtension(name)) { |
| 229 | if (".raw".equals(ext)) |
| 230 | ext = null; |
| 231 | name = setExtension(name, ext); |
| 232 | boolean dialog = name!=null && !name.equals(origName) && IJ.isMacOSX() && !IJ.isMacro(); |
| 233 | if (dialog) { |
| 234 | File f = new File( fd.getDirectory()+getFileName()); |
| 235 | if (!f.exists()) dialog = false; |
| 236 | } |
| 237 | if (dialog) { |
| 238 | Font font = new Font("SansSerif", Font.BOLD, 12); |
| 239 | GenericDialog gd = new GenericDialog("Replace File?"); |
| 240 | gd.addMessage("\""+name+"\" already exists.\nDo you want to replace it?", font); |
| 241 | gd.addMessage("To avoid this dialog, enable" |
| 242 | +"\n\"Show all filename extensions\"\nin Finder Preferences."); |
| 243 | gd.setOKLabel("Replace"); |
| 244 | gd.showDialog(); |
| 245 | if (gd.wasCanceled()) |
| 246 | name = null; |
| 247 | } |
| 248 | } |
| 249 | if (IJ.debugMode) IJ.log(origName+"->"+name); |
| 250 | dir = fd.getDirectory(); |
| 251 | if (name==null) |
| 252 | Macro.abort(); |
| 253 | fd.dispose(); |
| 254 | if (ij==null) |
| 255 | parent.dispose(); |
| 256 | } |
| 257 | |
| 258 | @AstroImageJ(reason = "Increase condition from 5 to 10", modified = true) |
| 259 | private boolean noExtension(String name) { |
no test coverage detected