
/**
 * SpectraData.java
 * This is stores the data and file information from a spectra data file.
 * Created: Dec 27, 2003
 *
 * @author Nathan Stevens
 * @version 0.14 4/21/06
 */
import java.io.*;
import java.util.*;

public class SpectraData implements SpectraDataFormat_1, Serializable {
  private String name; // The name of the spectroscopy data
  private String displayname; // the name that is returned by the toString method
  private String type;  // The experiement type
  private Vector attachmentURL; // location of any attachments
  private Vector keywords; //keywords used for searching purposes
  private String[] header; // The header information
  private String[] metaInfo; // the meta information for the data
  private float[][] data;  // The data in the file
  private float[][] rdata; // The reference data, if any.
  private String units = "nm"; // The units of data within
  private String xlabel, ylabel; // The x and y column labels
  private String delay = "0"; // Used to pump-probe
  private boolean exportX = true; // Export X data or not.
  private boolean hasref = false; // whether this has reference data or not
  private boolean is3D = false; // is this 3D data or 2D data?
  private int direction = 0; // 0 is horizontal, and 1 is vertical
  private boolean isProfile = false; // is this data profile data.
  private String password; // password to view data object
  private boolean shared; // whether data is to be shared
  private final int VERSION = 1; // what format version is this
  
  // default constructor
  public SpectraData() { }
  
  // The main constructor
  public SpectraData(String name, String type, String[] header, String[] metaInfo, 
                                   float[][] data, float[][] rdata) {
    this.name = name;
    this.type = type;
    this.header = header;
    this.metaInfo = metaInfo;
    this.data = data;
    this.rdata = rdata;
    
    // set the x and y labels based on the name
    xlabel = name + "-wl";
    ylabel = name + "-int";
    
    if(type.equals("macro") || type.equals("micro") || type.equals("FT")) {
      units = "cm-1";
    }
    else if (type.equals("pump-probeTP")) {
      units = "fs";
      this.type = "pump-probe";
    }
    
    // set has reference
    if(rdata != null) {
      hasref = true;
    }
    
    // set the display name variable
    displayname = name + " (" + header[0] + "-" + header[1] + units + ")";
  }
  
  // Method to get the name of the data object
  public String getName() {
    return name;
  }
  
  // Method to set the name
  public void setName(String name) {
    this.name = name;
    
    xlabel = name + "-wl";
    ylabel = name + "-int";
    
    displayname = name + " (" + header[0] + "-" + header[1] + units + ")";
  }
  
  // Method to get the data header
  public String[] getHeader() {
    return header;
  }
  
  // Method to set the header informations
  public void setHeader(String[] header) {
    this.header = header;
    displayname = name + " (" + header[0] + "-" + header[1] + units + ")";
  }
  
  // Method to get and the Meta information about the data
  public String[] getMetaInfo() {
    return metaInfo;
  }
  
  // Method to set Meta information about the data
  public void setMetaInfo(String[] mi) {
    metaInfo = mi;
  }
  
  // Method to get the data from the file
  public float[][] getData() {
    return data;
  }
  
  // Method to set the data
  public void setData(float[][] data) {
    this.data = data;
    if(is3D) {
      header[0] = "" + data[0][1];
      header[1] = "" + data[0][data[0].length-1];
      header[2] = "" + data[1][0];
      header[3] = "" + data[data.length -1][0];
      header[4] = "" + (data.length * data[0].length);
    }
    else if(type.equals("streak") && direction == 0) {
      header[0] = "" + data[0][0];
      header[1] = "" + data[data.length-1][0];
      header[4] = "" + data.length;
    }
    else if(type.equals("streak") && direction == 1) {
      header[2] = "" + data[0][0];
      header[3] = "" + data[data.length-1][0];
      header[4] = "" + data.length;
    }
    else {
      header[0] = "" + data[0][0];
      header[1] = "" + data[data.length-1][0];
      header[2] = "" + data.length;
    }
  }
  
  // Method to get the data from the file
  public float[][] getReferenceData() {
    return rdata;
  }
  
  // Method set the reference data
  public void setReferenceData(float[][] rdata) {
    this.rdata = rdata;
    if(rdata != null) {
      hasref = true;
    }
  }
  
  // Method to see if data has a reference data
  public boolean hasRef() {
    return hasref;
  }
  
  // Method to return the type of this data object
  public String getType() {
    return type;
  }
  
  // Method to set the type
  public void setType(String type) {
    this.type = type;
  }
  
  // Method to get the column labels
  public String[] getColumnLabels() {
    String[] xylabel = {xlabel, ylabel};
    return xylabel;
  }
  
  // Method to set the Column labels
  public void setColumnLabels(String xlabel, String ylabel) {
    this.xlabel = xlabel;
    this.ylabel = ylabel;
  }
  
  // Method to return whether to export x or not
  public boolean exportX() {
    return exportX;
  }
  
  // Method to set whether or not to export the xlabel, and column.
  // used when generating work sheets containing multiple data
  public void setExportX(boolean b) {
    exportX = b;
  }
  
  // Method to see if data is 3D or not
  public boolean is3D() {
    return is3D;
  }
  
  // Method to set whether the data is 2D or 3D
  public void set3D(boolean b) {
    is3D = b;
  }
  
  // set whether the data is a profile from 3D data
  public boolean isProfile() {
    return isProfile;
  }
  
  // Method to set whether the data is 2D or 3D
  public void setProfile(boolean b) {
    isProfile = b;
  }
  
  // Method to set the direction the profile.  time or wavelength
  public int getProfileDirection() {
    return direction;
  }
  
  // Method to set the direction of the data vertical or horizontal
  public void setProfileDirection(int d) {
    direction = d;
  }
  
  // Method to return the delay
  public String getDelay() {
    return delay;
  }
  
  // Method to set the delay string and hence the name
  public void setDelay(String delay) {
    this.delay = delay;
    displayname = name + "-" + delay + " (" + header[0] + "-" + header[1] + units + ")";
  }
  
  // Method to return the size of the data array
  public int size() {
    if(data != null) {
      return data.length;
    }
    else {
      return 0;
    }
  }
  
  // Method to get the attachment URL list
  public Vector getAttachmentURL() {
    return attachmentURL;
  }
  
  // Method to set the attachment URL list
  public void setAttachmentURL(Vector urls) {
    attachmentURL = urls;
  }
  
  // Method to get the list of keywords for seaching purposes
  public Vector getKeywords() {
    return keywords;
  }
  
  // Method to set the list of keyowrds
  public void setKeywords(Vector keywords) {
    this.keywords = keywords;
  }
  
  // Method to see if data should be shared
  public boolean isShared() {
    return shared;
  }
  
  // Method to set the shared variable
  public void setShared(boolean b) {
    shared = b;
  }
  
  // Method to get the password
  public String getPassword() {
    return password;
  }
  
  // Method to set the password
  public void setPassword(String pw) {
    password = pw;
  }
  
  // get the version of this file
  public int getVersion() {
    return VERSION;
  }
  
  // Method to return the name of this object
  public String toString() {
    return displayname;
  }
} // --end class SpectraData
