public void handleModelChange() { if (workspace.getModelDir() != null) { setPrefix(workspace.getModelDir()); } else if (AbstractWorkspace.isApp()) { setPrefix(System.getProperty("user.home")); } try { closeAllFiles(); } catch (java.io.IOException ex) { throw new IllegalStateException(ex); } }
public org.nlogo.api.File getFile(String fileName) { if (AbstractWorkspace.isApplet()) { return new org.nlogo.api.RemoteFile(fileName); } else { return new org.nlogo.api.LocalFile(fileName); } }
public boolean fileExists(String filePath) { if (AbstractWorkspace.isApplet()) { try { return org.nlogo.api.RemoteFile.exists(attachPrefix(filePath)); } catch (java.net.MalformedURLException ex) { return false; } } else { return new java.io.File(filePath).exists(); } }
public void setPrefix(String newPrefix) { if (AbstractWorkspace.isApplet()) { return; } // Ensure a slash so it isAbsolute() won't get mixed up with getModelDir() if (newPrefix.charAt(newPrefix.length() - 1) != java.io.File.separatorChar) { newPrefix += java.io.File.separatorChar; } if (new java.io.File(newPrefix).isAbsolute()) { prefix = newPrefix; } else { prefix = relativeToAbsolute(newPrefix); if (prefix.charAt(prefix.length() - 1) != java.io.File.separatorChar) { prefix += java.io.File.separatorChar; } } }
public String attachPrefix(String filename) throws java.net.MalformedURLException { if (AbstractWorkspace.isApplet()) { try { return new java.net.URL(new java.net.URL(prefix), filename).toString(); } catch (java.net.MalformedURLException ex) { throw new IllegalStateException(ex); } } else { // Check to see if we were given an absolute File Path java.io.File fileForm = new java.io.File(filename); if (fileForm.isAbsolute() || prefix == null) { return filename; } else { return relativeToAbsolute(filename); } } }
public org.nlogo.api.File findOpenFile(String fileName) { if (AbstractWorkspace.isApplet()) { for (org.nlogo.api.File nextFile : openFiles) { if (fileName.equals(nextFile.getPath())) { return nextFile; } } } else { java.io.File newFile = new java.io.File(fileName); Iterator<org.nlogo.api.File> files = openFiles.iterator(); while (files.hasNext()) { org.nlogo.api.File nextFile = files.next(); if (newFile.getAbsolutePath().equals(nextFile.getAbsolutePath())) { return nextFile; } } } return null; }
public void openFile(String newFileName) throws java.io.IOException { // Check to see if we already opened the file String fullFileName = attachPrefix(newFileName); if (fullFileName == null) { throw new java.io.IOException("This filename is illegal, " + newFileName); } org.nlogo.api.File newFile = findOpenFile(fullFileName); if (newFile == null) { if (AbstractWorkspace.isApplet()) { newFile = new org.nlogo.api.RemoteFile(fullFileName); } else { newFile = new org.nlogo.api.LocalFile(fullFileName); } openFiles.add(newFile); } setCurrentFile(newFile); }
public Object read(org.nlogo.agent.World world) throws java.io.IOException { if (eof()) { throw new java.io.EOFException(); } return workspace.compiler().readFromFile(currentFile, world, workspace.getExtensionManager()); }
public DefaultFileManager(AbstractWorkspace workspace) { this.workspace = workspace; if (AbstractWorkspace.isApp()) { setPrefix(System.getProperty("user.home")); } }