Example #1
0
 private void addDocument(NodeBoxDocument doc) {
   doc.setVisible(true);
   doc.requestFocus();
   doc.focusNetworkView();
   doc.setActiveNetwork("/");
   documents.add(doc);
   currentDocument = doc;
 }
Example #2
0
  public boolean openDocument(File file) {
    // Check if the document is already open.
    String path;
    try {
      path = file.getCanonicalPath();
      for (NodeBoxDocument doc : Application.getInstance().getDocuments()) {
        try {
          if (doc.getDocumentFile() == null) continue;
          if (doc.getDocumentFile().getCanonicalPath().equals(path)) {
            // The document is already open. Bring it to the front.
            doc.toFront();
            doc.requestFocus();
            NodeBoxMenuBar.addRecentFile(file);
            return true;
          }
        } catch (IOException e) {
          logger.log(
              Level.WARNING,
              "The document " + doc.getDocumentFile() + " refers to path with errors",
              e);
        }
      }
    } catch (IOException e) {
      logger.log(Level.WARNING, "The document " + file + " refers to path with errors", e);
    }

    try {
      NodeBoxDocument doc = NodeBoxDocument.load(file);
      addDocument(doc);
      NodeBoxMenuBar.addRecentFile(file);
      return true;
    } catch (RuntimeException e) {
      logger.log(Level.SEVERE, "Error while loading " + file, e);
      ExceptionDialog d = new ExceptionDialog(null, e);
      d.setVisible(true);
      return false;
    }
  }