Package ij.plugin

Source Code of ij.plugin.MeasurementsWriter

package ij.plugin;
import ij.*;
import ij.text.*;
import ij.measure.ResultsTable;
import ij.io.*;
import java.io.*;
import java.awt.Frame;

/** Writes measurements to a csv or tab-delimited text file. */
public class MeasurementsWriter implements PlugIn {

  public void run(String path) {
    save(path);
  }
 
  public boolean save(String path) {
    Frame frame = WindowManager.getFrontWindow();
    if (frame!=null && (frame instanceof TextWindow)) {
      TextWindow tw = (TextWindow)frame;
      if (tw.getTextPanel().getResultsTable()==null) {
        IJ.error("Save As>Results", "\""+tw.getTitle()+"\" is not a results table");
        return false;
      }
      return tw.getTextPanel().saveAs(path);
    } else if (IJ.isResultsWindow()) {
      TextPanel tp = IJ.getTextPanel();
      if (tp!=null) {
        if (!tp.saveAs(path))
          return false;
      }
    } else {
      ResultsTable rt = ResultsTable.getResultsTable();
      if (rt==null || rt.getCounter()==0)
        return false;
      if (path.equals("")) {
        SaveDialog sd = new SaveDialog("Save as Text", "Results", Prefs.get("options.ext", ".xls"));
        String file = sd.getFileName();
        if (file == null) return false;
        path = sd.getDirectory() + file;
      }
      try {
        rt.saveAs(path);
      } catch (IOException e) {
        IJ.error(""+e);
      }
    }
    return true;
  }

}
TOP

Related Classes of ij.plugin.MeasurementsWriter

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.