MCPcopy Create free account
hub / github.com/OpenSourcePhysics/osp / saveAs

Method saveAs

src/org/opensourcephysics/tools/DataTool.java:2404–2430  ·  view source on GitHub ↗

Saves the current tab to a file selected with a chooser. @return the name of the saved file, or null if not saved

()

Source from the content-addressed store, hash-verified

2402 * @return the name of the saved file, or null if not saved
2403 */
2404 protected String saveAs() {
2405 int result = OSPRuntime.getChooser().showSaveDialog(this);
2406 if (result == JFileChooser.APPROVE_OPTION) {
2407 OSPRuntime.chooserDir = OSPRuntime.getChooser().getCurrentDirectory().toString();
2408 File file = OSPRuntime.getChooser().getSelectedFile();
2409 // check to see if file already exists
2410 if (file.exists()) {
2411 int selected = JOptionPane.showConfirmDialog(null,
2412 ToolsRes.getString("Tool.Dialog.ReplaceFile.Message") + " " + file.getName() + "?", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
2413 ToolsRes.getString("Tool.Dialog.ReplaceFile.Title"), //$NON-NLS-1$
2414 JOptionPane.YES_NO_CANCEL_OPTION);
2415 if (selected != JOptionPane.YES_OPTION) {
2416 return null;
2417 }
2418 }
2419 String fileName = file.getAbsolutePath();
2420 if ((fileName == null) || fileName.trim().equals("")) { //$NON-NLS-1$
2421 return null;
2422 }
2423 // add .xml extension if none but don't require it
2424 if (XML.getExtension(fileName) == null) {
2425 fileName += ".xml"; //$NON-NLS-1$
2426 }
2427 return save(XML.getRelativePath(fileName));
2428 }
2429 return null;
2430 }
2431
2432 /**
2433 * Returns the index of the tab containing the specified Data object.

Callers 4

saveMethod · 0.95
actionPerformedMethod · 0.95
saveMethod · 0.45
saveChangesMethod · 0.45

Calls 13

getChooserMethod · 0.95
getStringMethod · 0.95
getExtensionMethod · 0.95
saveMethod · 0.95
getRelativePathMethod · 0.95
existsMethod · 0.80
showConfirmDialogMethod · 0.80
getNameMethod · 0.65
equalsMethod · 0.65
showSaveDialogMethod · 0.45
toStringMethod · 0.45
getAbsolutePathMethod · 0.45

Tested by

no test coverage detected