Пример #1
0
  private void saveDataToFile(File file) {
    try {
      PrintStream out = new PrintStream(new FileOutputStream(file));

      // Print header line
      out.print("Time");
      for (Sequence seq : seqs) {
        out.print("," + seq.name);
      }
      out.println();

      // Print data lines
      if (seqs.size() > 0 && seqs.get(0).size > 0) {
        for (int i = 0; i < seqs.get(0).size; i++) {
          double excelTime = toExcelTime(times.time(i));
          out.print(String.format(Locale.ENGLISH, "%.6f", excelTime));
          for (Sequence seq : seqs) {
            out.print("," + getFormattedValue(seq.value(i), false));
          }
          out.println();
        }
      }

      out.close();
      JOptionPane.showMessageDialog(
          this,
          Resources.format(
              Messages.FILE_CHOOSER_SAVED_FILE, file.getAbsolutePath(), file.length()));
    } catch (IOException ex) {
      String msg = ex.getLocalizedMessage();
      String path = file.getAbsolutePath();
      if (msg.startsWith(path)) {
        msg = msg.substring(path.length()).trim();
      }
      JOptionPane.showMessageDialog(
          this,
          Resources.format(Messages.FILE_CHOOSER_SAVE_FAILED_MESSAGE, path, msg),
          Messages.FILE_CHOOSER_SAVE_FAILED_TITLE,
          JOptionPane.ERROR_MESSAGE);
    }
  }
    public void applyAction(ActionEvent evt) {
      String fileStr = getArg("file");

      System.out.println("Output string " + fileStr);

      if (FormatProperties.contains(getArg("format"))) {
        if (parent instanceof AlignFrame) {
          AlignFrame af = (AlignFrame) parent;
          String outStr =
              FormatAdapter.get(getArg("format").toUpperCase(), av.getAlignment().getSequences());
          System.out.println(outStr + " " + fileStr);
          try {
            PrintStream ps =
                new PrintStream(new BufferedOutputStream(new FileOutputStream(fileStr)));
            fireStatusEvent("Saving file");

            try {
              Thread.sleep(500);
            } catch (Exception ex2) {
            }
            ps.print(outStr);
            ps.close();

            fireStatusEvent("done");

            fireJalActionEvent(new JalActionEvent(this, this, JalActionEvent.DONE));
          } catch (IOException ex) {
            fireStatusEvent("Can't open file", StatusEvent.ERROR);
            System.out.println("Exception : " + ex);
          }
        } else {
          fireStatusEvent("(Internal Error) Parent isn't Alignment Frame", StatusEvent.ERROR);
        }
      } else {
        fireStatusEvent("Format not yet supported", StatusEvent.ERROR);
      }
    }