MCPcopy Create free account
hub / github.com/AstroImageJ/astroimagej / save

Method save

ij/src/main/java/ij/io/SaveDialog.java:209–256  ·  view source on GitHub ↗
(String title, String defaultDir, String defaultName)

Source from the content-addressed store, hash-verified

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) {

Callers 1

SaveDialogMethod · 0.95

Calls 15

getInstanceMethod · 0.95
isWindowsMethod · 0.95
noExtensionMethod · 0.95
setExtensionMethod · 0.95
isMacOSXMethod · 0.95
isMacroMethod · 0.95
getFileNameMethod · 0.95
addMessageMethod · 0.95
setOKLabelMethod · 0.95
showDialogMethod · 0.95
wasCanceledMethod · 0.95
logMethod · 0.95

Tested by

no test coverage detected