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

Method doRunEjs

src/org/opensourcephysics/tools/EjsTool.java:244–468  ·  view source on GitHub ↗

Extracts an EJS model (and its resource files) from the given source and then runs EJS with that model. The example is extracted in the source directory of the users' EJS. The user will be warned before overwriting any file. @return boolean

(String _model, java.util.Set<String> _resources, Class<?> _ejsClass,
			final String _password)

Source from the content-addressed store, hash-verified

242 * @return boolean
243 */
244 static private boolean doRunEjs(String _model, java.util.Set<String> _resources, Class<?> _ejsClass,
245 final String _password) {
246 String ejsRootDirPath = null;
247 // String console_options = null;
248 String sourceDirPath = null;
249 String version = null;
250 File ejsRootDirectory = null;
251 java.awt.Component parentComponent = null;
252 try {
253 String filename = System.getProperty("user.home").replace('\\', '/'); //$NON-NLS-1$
254 if (!filename.endsWith("/")) { //$NON-NLS-1$
255 filename = filename + "/"; //$NON-NLS-1$
256 }
257 Reader reader = new FileReader(filename + INFO_FILE);
258 LineNumberReader l = new LineNumberReader(reader);
259 String sl = l.readLine();
260 while (sl != null) {
261 if (sl.startsWith("ejs_root_directory = ")) { //$NON-NLS-1$
262 ejsRootDirPath = sl.substring("ejs_root_directory = ".length()).trim(); //$NON-NLS-1$
263 // else if (sl.startsWith("console_options = ")) console_options =
264 // sl.substring("console_options = ".length()).trim();
265 } else if (sl.startsWith("source_directory = ")) { //$NON-NLS-1$
266 sourceDirPath = sl.substring("source_directory = ".length()).trim(); //$NON-NLS-1$
267 } else if (sl.startsWith("version = ")) { //$NON-NLS-1$
268 version = sl.substring("version = ".length()).trim(); //$NON-NLS-1$
269 }
270 sl = l.readLine();
271 }
272 reader.close();
273 int major = 3;
274 if (version != null) {
275 int index = version.indexOf('.');
276 if (index >= 0) {
277 major = Integer.parseInt(version.substring(0, index));
278 }
279 }
280 if (major < 4) { // Incorrect version, update to 4.0
281 JOptionPane.showMessageDialog(parentComponent,
282 version + " " + res.getString("EjsTool.IncorrectVersion"), //$NON-NLS-1$ //$NON-NLS-2$
283 res.getString("EjsTool.Error"), JOptionPane.ERROR_MESSAGE); //$NON-NLS-1$
284 return false;
285 }
286 // See if EjsConsole.jar is there
287 ejsRootDirectory = new File(ejsRootDirPath);
288 if (!new File(ejsRootDirectory, "EjsConsole.jar").exists()) { //$NON-NLS-1$
289 ejsRootDirectory = null;
290 }
291 } catch (Exception exc) {
292 exc.printStackTrace();
293 ejsRootDirectory = null;
294 }
295 if (ejsRootDirectory == null) {
296 // Create a chooser
297 JFileChooser chooser = OSPRuntime.createChooser("", new String[] {}); //$NON-NLS-1$
298 chooser.setDialogTitle(res.getString("EjsTool.EjsNotFound")); //$NON-NLS-1$
299 chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
300 chooser.setMultiSelectionEnabled(false);
301 // The message

Callers 1

runEjsMethod · 0.95

Calls 15

createChooserMethod · 0.95
ejsConfirmListMethod · 0.95
getPathMethod · 0.95
extractFilesMethod · 0.95
lengthMethod · 0.80
showMessageDialogMethod · 0.80
existsMethod · 0.80
setBorderMethod · 0.80
getPropertyMethod · 0.65
closeMethod · 0.65
getStringMethod · 0.65
setFontMethod · 0.65

Tested by

no test coverage detected