Ejemplo n.º 1
0
  private void doExportTimeTree() {
    FileDialog dialog = new FileDialog(this, "Export Time Tree File...", FileDialog.SAVE);

    dialog.setVisible(true);
    if (dialog.getFile() != null) {
      File file = new File(dialog.getDirectory(), dialog.getFile());

      PrintStream ps = null;
      try {
        ps = new PrintStream(file);
        writeTimeTreeFile(ps);
        ps.close();
      } catch (IOException ioe) {
        JOptionPane.showMessageDialog(
            this,
            "Error writing tree file: " + ioe.getMessage(),
            "Export Error",
            JOptionPane.ERROR_MESSAGE);
      }
    }
  }
Ejemplo n.º 2
0
  protected void doExportData() {
    FileDialog dialog = new FileDialog(this, "Export Data File...", FileDialog.SAVE);

    dialog.setVisible(true);
    if (dialog.getFile() != null) {
      File file = new File(dialog.getDirectory(), dialog.getFile());

      Writer writer = null;
      try {
        writer = new PrintWriter(file);
        treesPanel.writeDataFile(writer);
        writer.close();
      } catch (IOException ioe) {
        JOptionPane.showMessageDialog(
            this,
            "Error writing data file: " + ioe.getMessage(),
            "Export Error",
            JOptionPane.ERROR_MESSAGE);
      }
    }
  }
Ejemplo n.º 3
0
  protected boolean readFromFile(File file) throws IOException {
    Reader reader = new FileReader(file);

    BufferedReader bufferedReader = new BufferedReader(reader);
    String line = bufferedReader.readLine();
    while (line != null && line.length() == 0) {
      line = bufferedReader.readLine();
    }

    boolean isNexus = (line != null && line.toUpperCase().contains("#NEXUS"));

    reader = new FileReader(file);

    Tree tree = null;
    try {
      if (isNexus) {
        NexusImporter importer = new NexusImporter(reader);
        tree = importer.importTree(taxa);
      } else {
        NewickImporter importer = new NewickImporter(reader);
        tree = importer.importTree(taxa);
      }

    } catch (Importer.ImportException ime) {
      JOptionPane.showMessageDialog(
          this,
          "Error parsing imported file: " + ime,
          "Error reading file",
          JOptionPane.ERROR_MESSAGE);
      ime.printStackTrace();
      return false;
    } catch (IOException ioex) {
      JOptionPane.showMessageDialog(
          this, "File I/O Error: " + ioex, "File I/O Error", JOptionPane.ERROR_MESSAGE);
      ioex.printStackTrace();
      return false;
    } catch (Exception ex) {
      JOptionPane.showMessageDialog(
          this, "Fatal exception: " + ex, "Error reading file", JOptionPane.ERROR_MESSAGE);
      ex.printStackTrace();
      return false;
    }

    if (tree == null) {
      JOptionPane.showMessageDialog(
          this,
          "The file is not in a suitable format or contains no trees.",
          "Error reading file",
          JOptionPane.ERROR_MESSAGE);
      return false;
    }

    FlexibleTree binaryTree = new FlexibleTree(tree, true);
    binaryTree.resolveTree();
    trees.add(binaryTree);
    if (taxa == null) {
      taxa = binaryTree;
    }

    getExportTreeAction().setEnabled(true);
    getExportDataAction().setEnabled(true);

    return true;
  }