コード例 #1
0
 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);
   }
 }
コード例 #2
0
  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);
    }
  }
コード例 #3
0
 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();
   }
 }
コード例 #4
0
  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;
      }
    }
  }
コード例 #5
0
  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);
      }
    }
  }
コード例 #6
0
  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;
  }
コード例 #7
0
  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);
  }
コード例 #8
0
 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());
 }
コード例 #9
0
 public DefaultFileManager(AbstractWorkspace workspace) {
   this.workspace = workspace;
   if (AbstractWorkspace.isApp()) {
     setPrefix(System.getProperty("user.home"));
   }
 }