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

Method canWrite

src/org/opensourcephysics/media/core/VideoIO.java:1045–1073  ·  view source on GitHub ↗

Determines if a file can be written. If the file exists, the user is prompted for approval to overwrite. @param file the file to check @return true if the file can be written

(File file)

Source from the content-addressed store, hash-verified

1043 * @return true if the file can be written
1044 */
1045 public static boolean canWrite(File file) {
1046 if (OSPRuntime.isJS)
1047 return true;
1048 // refuse filenames containing "&"
1049 if (file.getName().contains("&")) {
1050 new AsyncDialog().showMessageDialog(null,
1051 MediaRes.getString("VideoIO.Dialog.BadFileName.Message") + " \n\"&\"" , //$NON-NLS-1$ //$NON-NLS-2$
1052 MediaRes.getString("VideoIO.Dialog.BadFileName.Title"), //$NON-NLS-1$
1053 JOptionPane.WARNING_MESSAGE, (ev) -> {
1054 });
1055 return false;
1056 }
1057 if (file.exists() && !file.canWrite()) {
1058 JOptionPane.showMessageDialog(null, ControlsRes.getString("Dialog.ReadOnly.Message"), //$NON-NLS-1$
1059 ControlsRes.getString("Dialog.ReadOnly.Title"), //$NON-NLS-1$
1060 JOptionPane.PLAIN_MESSAGE);
1061 return false;
1062 }
1063 if (file.exists()) {
1064 int selected = JOptionPane.showConfirmDialog(null, "\"" + file.getName() + "\" " //$NON-NLS-1$ //$NON-NLS-2$
1065 + MediaRes.getString("VideoIO.Dialog.FileExists.Message"), //$NON-NLS-1$
1066 MediaRes.getString("VideoIO.Dialog.FileExists.Title"), //$NON-NLS-1$
1067 JOptionPane.YES_NO_OPTION);
1068 if (selected != JOptionPane.YES_OPTION) {
1069 return false;
1070 }
1071 }
1072 return true;
1073 }
1074
1075// /**
1076// * A Stop-gap method to allow Java-only functionality.

Callers 15

getChooserFilesAsyncMethod · 0.95
saveMethod · 0.95
defineZipFilePathMethod · 0.95
isTabSetWritableMethod · 0.80
isNodeWritableMethod · 0.80
writeMethod · 0.80
getFileIconMethod · 0.80
getIconMethod · 0.80
setOSPCacheMethod · 0.80
clearOSPCacheMethod · 0.80
clearOSPCacheHostMethod · 0.80
saveMethod · 0.80

Calls 7

getStringMethod · 0.95
getStringMethod · 0.95
showMessageDialogMethod · 0.80
existsMethod · 0.80
showConfirmDialogMethod · 0.80
containsMethod · 0.65
getNameMethod · 0.65

Tested by 1

defineZipFilePathMethod · 0.76