
/**
 * PumpProbePanel.java
 * Displays pump-probe data files
 * 
 * Created: Jan 29, 2004
 *
 * @author Nathan Stevens
 * @version 0.25 3/10/2006 
 */
 
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.border.*;
import java.util.*;
import java.io.*;

public class PumpProbePanel extends JPanel implements ActionListener,
  ListSelectionListener, ItemListener, ExperimentPanel {
  private InstruView instruView = null;
  private ExperimentData experimentData = null;
  private String[] meta = new String[5];
  private NoteBookDialog noteBookDialog = null;
  private JList dataList = null;
  private JPanel cardPanel = null;
  private final static String DATAINFO = "datainfo";
  private final static String METADATAINFO= "metadatainfo";
  private final static String SDLINFO= "sdlinfo";
  private JLabel filenameLB, org1LB, org2LB, lab1LB, lab2LB;
  private JLabel owner1LB, owner2LB, em1LB, em2LB, instLB;
  private JLabel sdcLabel, minLabel, maxLabel, dpLabel, delayLabel, unit1LB, unit2LB, unit3LB;
  private JLabel itimeLabel, savgLabel;
  private JTextField dateTF, sdldateTF, pageTF, laserTF, celltypeTF, notesTF;
  private JTextArea sdlnotesTA = null;
  private JCheckBox sdlSCB = null;
  private int[] selectedData = null;
  private SpectraData currentData = null;
  private String type = "pump-probe";
  private File file = null;
  private boolean saved = true;
  
  // The main constructor
  public PumpProbePanel(InstruView instruView) {
    this.instruView = instruView;
    
    // set the main layout
		setLayout(new BorderLayout());
    
    // Some gui components
		JButton button;
		JLabel label;
		TitledBorder title1, title2;
    
    // Add the spectra data list
    JPanel dataListPanel, dataListPanel_A, dataListPanel_B;
    
    dataListPanel = new JPanel();
		dataListPanel.setLayout(new BoxLayout(dataListPanel, BoxLayout.Y_AXIS));
    title1 = BorderFactory.createTitledBorder("Spectra Data List");
    dataListPanel.setBorder(title1);
    
    dataList = new JList();
		dataList.addListSelectionListener(this);
		JScrollPane listScrollPane = new JScrollPane(dataList);
		listScrollPane.setPreferredSize(new Dimension(200, 320));
    dataListPanel.add(listScrollPane);
    
    dataListPanel.add(Box.createRigidArea(new Dimension(0, 5)));
    
    // add the add, remove buttons and so on
    dataListPanel_A = new JPanel();
    dataListPanel_A.setLayout(new GridLayout(2, 2));
    
    button = new JButton("Select All");
		button.addActionListener(this);
		button.setActionCommand("selectall");
		dataListPanel_A.add(button);
		
		button = new JButton("UnSelect");
		button.addActionListener(this);
		button.setActionCommand("unselect");
		dataListPanel_A.add(button);
    
		button = new JButton("Remove");
		button.addActionListener(this);
		button.setActionCommand("remove");
		dataListPanel_A.add(button);
    
		button = new JButton("Add");
		button.addActionListener(this);
		button.setActionCommand("add");
    dataListPanel_A.add(button);
    
    dataListPanel.add(dataListPanel_A);
    
    // Add the buttons to lets the user select which data they want to view
    dataListPanel_B = new JPanel();
    dataListPanel_B.setLayout(new FlowLayout(FlowLayout.CENTER));
    
    Insets insets = new Insets(2, 5, 2, 5);
    
    button = new JButton("SDL ?");
		button.addActionListener(this);
		button.setActionCommand("sdlinfo");
		button.setMargin(insets);
    dataListPanel_B.add(button);
    
    button = new JButton("Data ?");
		button.addActionListener(this);
		button.setActionCommand("datainfo");
		button.setMargin(insets);
    dataListPanel_B.add(button);
    
    button = new JButton("Meta ?");
		button.addActionListener(this);
		button.setActionCommand("metainfo");
		button.setMargin(insets);
    dataListPanel_B.add(button);
    
    button = new JButton("Sort");
		button.addActionListener(this);
		button.setActionCommand("sort");
		button.setMargin(insets);
    dataListPanel_B.add(button);
    
    dataListPanel.add(dataListPanel_B);
    
    add(dataListPanel, "Center");
    
    // Add the information panel data list
    cardPanel = new JPanel();
		cardPanel.setLayout(new CardLayout());
    title2 = BorderFactory.createTitledBorder("Data Information");
    cardPanel.setBorder(title2);
    
    cardPanel.add(getDataInfoPanel(), DATAINFO);
    cardPanel.add(getMetaDataInfoPanel(), METADATAINFO);
    cardPanel.add(getSDLInfoPanel(), SDLINFO);
    
    add(cardPanel, "East");
    
    // initialize some thing
    meta[0] = InstruView.getProperty("organization");
    meta[1] = InstruView.getProperty("laboratory");
    meta[2] = InstruView.getProperty("owner");
    meta[3] = InstruView.getProperty("email");
    meta[4] = "mm-dd-yyyy";
    experimentData  = new ExperimentData("pump-probe", meta);
  }
  
  // Method to return the data info panel
  private JPanel getDataInfoPanel() {
    // Add the information panel data list
    JPanel infoPanel, cpanel, ip1, ip2, ip3, ip4, ip5, ip6, ip7;
    JButton button;
    JLabel label;
    
    infoPanel = new JPanel();
		infoPanel.setLayout(new BoxLayout(infoPanel, BoxLayout.Y_AXIS));
    
    // add the panel that contains data counts
    cpanel = new JPanel();
    cpanel.setLayout(new FlowLayout(FlowLayout.LEFT));
    
    label = new JLabel("Spectra Data Count : ");
    cpanel.add(label);
    
    sdcLabel = new JLabel("0");
    sdcLabel.setForeground(Color.red);
    cpanel.add(sdcLabel);
    
    cpanel.add(Box.createRigidArea(new Dimension(10,0)));
    
    button = new JButton("Notebook");
		button.addActionListener(this);
		button.setActionCommand("notebook");
    cpanel.add(button);
    
    infoPanel.add(cpanel);
    
    // add the first panel
    ip1 = new JPanel();
    ip1.setLayout(new FlowLayout(FlowLayout.LEFT));
    
    label = new JLabel("Data Range ");
    ip1.add(label);
    
    minLabel = new JLabel("0");
    minLabel.setForeground(Color.blue);
    ip1.add(minLabel);
    
    label = new JLabel(" To ");
    ip1.add(label);
    
    maxLabel = new JLabel("1000");
    maxLabel.setForeground(Color.blue);
    ip1.add(maxLabel);
    
    unit1LB = new JLabel(" nm");
    ip1.add(unit1LB);
    
    infoPanel.add(ip1);
    
    // Add the second panel
    ip2 = new JPanel();
    ip2.setLayout(new FlowLayout(FlowLayout.LEFT));
    
    label = new JLabel("Data Points ");
    ip2.add(label);
    
    dpLabel = new JLabel("0");
    dpLabel.setForeground(Color.blue);
    ip2.add(dpLabel);
    
    unit2LB = new JLabel(" Delay ");
    ip2.add(unit2LB);
    
    delayLabel = new JLabel("0");
    delayLabel.setForeground(Color.blue);
    ip2.add(delayLabel);
    
    unit3LB = new JLabel(" fs");
    ip2.add(unit3LB);
    
    infoPanel.add(ip2);
    
    // Add the third panel
    ip3 = new JPanel();
    ip3.setLayout(new FlowLayout(FlowLayout.LEFT));
    
    label = new JLabel("Int. Time ");
    ip3.add(label);
    
    itimeLabel = new JLabel("2.0");
    itimeLabel.setForeground(Color.blue);
    ip3.add(itimeLabel);
    
    label = new JLabel(" msec Spectra Avg.");
    ip3.add(label);
    
    savgLabel = new JLabel("1");
    savgLabel.setForeground(Color.blue);
    ip3.add(savgLabel);
    
    infoPanel.add(ip3);
    
    // Add the fourth panel
    ip4 = new JPanel();
    ip4.setLayout(new FlowLayout(FlowLayout.LEFT));
    
    label = new JLabel("Pump Wavelength ");
    ip4.add(label);
    
    laserTF = new JTextField("500.0", 6);
    laserTF.addActionListener(this);
    laserTF.setActionCommand("updatecurrent");
    ip4.add(laserTF);
    
    label = new JLabel(" nm");
    ip4.add(label);
    
    infoPanel.add(ip4);
    
    // Add the fifth panel
    ip5 = new JPanel();
    ip5.setLayout(new FlowLayout(FlowLayout.LEFT));
    
    label = new JLabel("Cell Type ");
    ip5.add(label);
    
    celltypeTF = new JTextField("Unknown", 18);
    ip5.add(celltypeTF);
    
    infoPanel.add(ip5);
    
    // Add the sixth panel
    ip6 = new JPanel();
    ip6.setLayout(new FlowLayout(FlowLayout.LEFT));
    
    label = new JLabel("Notes ");
    ip6.add(label);
    
    notesTF = new JTextField("None", 20);
    ip6.add(notesTF);
    
    infoPanel.add(ip6);
    
    // Add the seventh panel
    ip7 = new JPanel();
    ip7.setLayout(new FlowLayout(FlowLayout.LEFT));
    
    label = new JLabel("Update");
    ip7.add(label);
    
    button = new JButton("Current");
		button.addActionListener(this);
		button.setActionCommand("updatecurrent");
		ip7.add(button);
		
		button = new JButton("Selected");
		button.addActionListener(this);
		button.setActionCommand("updateselected");
		ip7.add(button);
		
		button = new JButton("All");
		button.addActionListener(this);
		button.setActionCommand("updateall");
		ip7.add(button);
    
    infoPanel.add(ip7);
    
    return infoPanel;
  }
  
  // Method to return the data info panel
  private JPanel getMetaDataInfoPanel() {
    // Some Gui components
    JPanel infoPanel, panel;
    JButton button;
    JLabel label;
    
    infoPanel = new JPanel();
		infoPanel.setLayout(new BoxLayout(infoPanel, BoxLayout.Y_AXIS));
    
    // add the first panel
    panel = new JPanel();
    panel.setLayout(new FlowLayout(FlowLayout.LEFT));
    
    label = new JLabel("Organization : ");
    panel.add(label);
    
    org1LB = new JLabel(InstruView.getProperty("organization"));
    org1LB.setForeground(Color.blue);
    panel.add(org1LB);
    
    infoPanel.add(panel);
    
    // Add the second panel
    panel = new JPanel();
    panel.setLayout(new FlowLayout(FlowLayout.LEFT));
    
    label = new JLabel("Laboratory : ");
    panel.add(label);
    
    lab1LB = new JLabel(InstruView.getProperty("laboratory"));
    lab1LB.setForeground(Color.blue);
    panel.add(lab1LB);
    
    infoPanel.add(panel);
    
    // Add the third panel
    panel = new JPanel();
    panel.setLayout(new FlowLayout(FlowLayout.LEFT));
    
    label = new JLabel("Instrument : ");
    panel.add(label);
    
    instLB = new JLabel(InstruView.getProperty("instrument.pump-probe"));
    instLB.setForeground(Color.blue);
    panel.add(instLB);
    
    infoPanel.add(panel);
    
    // Add the forth panel
    panel = new JPanel();
    panel.setLayout(new FlowLayout(FlowLayout.LEFT));
    
    label = new JLabel("Owner : ");
    panel.add(label);
    
    owner1LB = new JLabel(InstruView.getProperty("owner"));
    owner1LB.setForeground(Color.blue);
    panel.add(owner1LB);
    
    infoPanel.add(panel);
    
    // add the fifth panel now
    panel = new JPanel();
    panel.setLayout(new FlowLayout(FlowLayout.LEFT));
    
    label = new JLabel("Email : ");
    panel.add(label);
    
    em1LB = new JLabel(InstruView.getProperty("email"));
    em1LB.setForeground(Color.blue);
    panel.add(em1LB);
    
    infoPanel.add(panel);
    
    // Add the sixth panel
    panel = new JPanel();
    panel.setLayout(new FlowLayout(FlowLayout.LEFT));
    
    label = new JLabel("Date : ");
    panel.add(label);
    
    dateTF = new JTextField("dd-mm-yyyy", 8);
    dateTF.addActionListener(this);
    dateTF.setActionCommand("m-updatecurrent");
    panel.add(dateTF);
    
    label = new JLabel("Page : ");
    panel.add(label);
    
    pageTF = new JTextField("10", 4);
    pageTF.addActionListener(this);
    pageTF.setActionCommand("m-updatecurrent");
    panel.add(pageTF);
    
    infoPanel.add(panel);
    
    // add the seventh panel now
    panel = new JPanel();
    panel.setLayout(new FlowLayout(FlowLayout.LEFT));
    
    button = new JButton("Attachments");
		button.addActionListener(this);
		button.setActionCommand("attachments");
		panel.add(button);
    
    infoPanel.add(panel);
    
    // add some spacing
    infoPanel.add(Box.createRigidArea(new Dimension(0, 15)));
    
    // Add the eigth panel now
    panel = new JPanel();
    panel.setLayout(new FlowLayout(FlowLayout.LEFT));
    
    label = new JLabel("Update");
    panel.add(label);
    
    button = new JButton("Current");
		button.addActionListener(this);
		button.setActionCommand("m-updatecurrent");
		panel.add(button);
		
		button = new JButton("Selected");
		button.addActionListener(this);
		button.setActionCommand("m-updateselected");
		panel.add(button);
		
		button = new JButton("All");
		button.addActionListener(this);
		button.setActionCommand("m-updateall");
		panel.add(button);
    
    infoPanel.add(panel);
    
    return infoPanel;
  }
  
  // Method to get the SDL info panel
  private JPanel getSDLInfoPanel() {
    // Some Gui components
    JPanel infoPanel, panel;
    JButton button;
    JLabel label;
    
    infoPanel = new JPanel();
		infoPanel.setLayout(new BoxLayout(infoPanel, BoxLayout.Y_AXIS));
    
    // add the file name panel
    panel = new JPanel();
    panel.setLayout(new FlowLayout(FlowLayout.LEFT));
    
    label = new JLabel("File Name : ");
    panel.add(label);
    
    filenameLB = new JLabel("not set");
    filenameLB.setForeground(Color.blue);
    panel.add(filenameLB);
    
    infoPanel.add(panel);
    
    // add the first panel
    panel = new JPanel();
    panel.setLayout(new FlowLayout(FlowLayout.LEFT));
    
    label = new JLabel("Organization : ");
    panel.add(label);
    
    org2LB = new JLabel(InstruView.getProperty("organization"));
    org2LB.setForeground(Color.blue);
    panel.add(org2LB);
    
    infoPanel.add(panel);
    
    // Add the second panel
    panel = new JPanel();
    panel.setLayout(new FlowLayout(FlowLayout.LEFT));
    
    label = new JLabel("Laboratory : ");
    panel.add(label);
    
    lab2LB = new JLabel(InstruView.getProperty("laboratory"));
    lab2LB.setForeground(Color.blue);
    panel.add(lab2LB);
    
    infoPanel.add(panel);
    
    // Add the third panel
    panel = new JPanel();
    panel.setLayout(new FlowLayout(FlowLayout.LEFT));
    
    label = new JLabel("Owner : ");
    panel.add(label);
    
    owner2LB = new JLabel(InstruView.getProperty("owner"));
    owner2LB.setForeground(Color.blue);
    panel.add(owner2LB);
    
    infoPanel.add(panel);
    
    // Add the fourth panel
    panel = new JPanel();
    panel.setLayout(new FlowLayout(FlowLayout.LEFT));
    
    label = new JLabel("Email : ");
    panel.add(label);
    
    em2LB = new JLabel(InstruView.getProperty("email"));
    em2LB.setForeground(Color.blue);
    panel.add(em2LB);
    
    infoPanel.add(panel);
    
    // add the fifth panel
    panel = new JPanel();
    panel.setLayout(new FlowLayout(FlowLayout.LEFT));
    
    label = new JLabel("Date : ");
    panel.add(label);
    
    sdldateTF = new JTextField("mm-dd-yyyy", 8);
    panel.add(sdldateTF);
    
    infoPanel.add(panel);
    
    // add the six panel now
    panel = new JPanel();
    panel.setLayout(new FlowLayout(FlowLayout.LEFT));
    
    sdlnotesTA = new JTextArea("notes go here");
    sdlnotesTA.setFont(new Font("Serif", Font.PLAIN, 12));
    sdlnotesTA.setLineWrap(true);
    sdlnotesTA.setWrapStyleWord(true);
    
    JScrollPane scrollPane = new JScrollPane(sdlnotesTA);
    scrollPane.setPreferredSize(new Dimension(275, 80));
    
    panel.add(scrollPane);
    
    infoPanel.add(panel);
    
    // Add the sixth panel now
    panel = new JPanel();
    panel.setLayout(new BoxLayout(panel, BoxLayout.X_AXIS));
    
    sdlSCB = new JCheckBox("Shared");
    sdlSCB.addItemListener(this);
    panel.add(sdlSCB);
    
    button = new JButton("Attachments");
		button.addActionListener(this);
		button.setActionCommand("sdl-attachments");
		panel.add(button);
    
    panel.add(Box.createHorizontalGlue());
    
		button = new JButton("Update");
		button.addActionListener(this);
		button.setActionCommand("sdl-update");
		panel.add(button);
    
    infoPanel.add(panel);
    
    return infoPanel;
  }
  
  // Method to handel action events
	public void actionPerformed(ActionEvent ae) {
    String cmd = ae.getActionCommand();
		
		if(cmd.equals("selectall")) {
			selectAllData();
		}
		else if(cmd.equals("unselect")) {
			dataList.clearSelection();
			selectedData = null;
		}
    else if(cmd.equals("remove")) {
      removeData();
    }
    else if(cmd.equals("add")) {
      addData();
    }
    else if(cmd.equals("datainfo")) {
      CardLayout cl = (CardLayout)(cardPanel.getLayout());
      cl.show(cardPanel, DATAINFO);
    }
    else if(cmd.equals("metainfo")) {
      CardLayout cl = (CardLayout)(cardPanel.getLayout());
      cl.show(cardPanel, METADATAINFO);
    }
    else if(cmd.equals("sdlinfo")) {
      CardLayout cl = (CardLayout)(cardPanel.getLayout());
      cl.show(cardPanel, SDLINFO);
    }
    else if(cmd.equals("sort")) {
      instruView.showDataSortDialog();
    }
    else if(cmd.equals("notebook")) {
      showNoteBookDialog();
    }
    else if(cmd.equals("updatecurrent") && currentData !=null) {
      updateCurrentDataInfo();
      updateInfoPanel();
    }
    else if(cmd.equals("updateselected")  && currentData !=null) {
      updateSelectedDataInfo();
      updateInfoPanel();
    }
    else if(cmd.equals("updateall")  && experimentData.getDataCount() != 0) {
      updateAllDataInfo();
    }
    else if(cmd.equals("m-updatecurrent") && currentData !=null) {
      updateCurrentMetaInfo();
      updateInfoPanel();
    }
    else if(cmd.equals("m-updateselected")  && currentData !=null) {
      updateSelectedMetaInfo();
      updateInfoPanel();
    }
    else if(cmd.equals("m-updateall")  && experimentData.getDataCount() != 0) {
      updateAllMetaInfo();
    }
    else if(cmd.equals("sdl-update")) {
      updateSDLInfo();
    }
    else {
			System.err.println("Action event not handeled in PumpProbePanel");
			System.err.println("Event is " + cmd);
		}
  }
  
  // Method to handel list selection events
	public void valueChanged(ListSelectionEvent e) {
    if (e.getValueIsAdjusting()) {
      return;
		}
		
    JList theList = (JList)e.getSource();
    if (!theList.isSelectionEmpty()) {
			selectedData = theList.getSelectedIndices();
		}
    
    if(experimentData.getDataCount() > 0 && selectedData != null) {
      currentData = experimentData.getData(selectedData[0]);
      updateInfoPanel();
    }
	}
  
  // Method to listen to item state changes
  public void itemStateChanged(ItemEvent e) {
    Object source = e.getItemSelectable();
    if(source == sdlSCB) {
      if (e.getStateChange() == ItemEvent.SELECTED) {
        experimentData.setShared(true);
      }
      else {
        experimentData.setShared(false);
      }
    }
  }
  
  // Method to update the displayed information
  private void updateInfoPanel() {
    type = currentData.getType();
    String[] header = currentData.getHeader();
    String[] dmeta = currentData.getMetaInfo();
    
    minLabel.setText(header[0]);
    maxLabel.setText(header[1]);
    dpLabel.setText(header[2]);
    delayLabel.setText(header[3]);
    itimeLabel.setText(header[4]);
    savgLabel.setText(header[5]);
    laserTF.setText(header[6]);
    celltypeTF.setText(header[7]); 
    notesTF.setText(header[8]);
    
    //get the profile direction if 1 update the units labels
    int pd = currentData.getProfileDirection();
    if(pd == 0) {
      unit1LB.setText(" nm");
      unit2LB.setText(" Delay");
      unit3LB.setText(" fs");
    }
    else {
      unit1LB.setText(" fs");
      unit2LB.setText(" Wavelength");
      unit3LB.setText(" nm");
    }
    
    // update the meta information now
    org1LB.setText(dmeta[0]);
    lab1LB.setText(dmeta[1]);
    instLB.setText(dmeta[4]);
    owner1LB.setText(dmeta[2]);
    em1LB.setText(dmeta[3]);
    dateTF.setText(dmeta[5]);
    pageTF.setText(dmeta[6]);
  }
  
  // Method to add the experiment data list
  public void setExperimentData(ExperimentData edata) {
    experimentData = edata;
    dataList.clearSelection();
    updateSpectraDataListView();
    saved = true;
    file = null;
    selectedData = null;
    
    // display the sdl meta information now
    String[] meta = edata.getMetaInfo();
    org2LB.setText(meta[0]);
    lab2LB.setText(meta[1]);
    owner2LB.setText(meta[2]);
    em2LB.setText(meta[3]);
    sdldateTF.setText(meta[4]);
    sdlnotesTA.setText(edata.getNotes());
    
    sdlSCB.setSelected(edata.isShared());
  }
  
  // Method to get the spectra data list
  public ExperimentData getExperimentData() {
    return experimentData;
  }
  
  // Method to add a single Spectra Data Object
  public void addSpectraData(SpectraData sda) {
    experimentData.addData(sda);
    updateSpectraDataListView();
    saved = false;
  }
  
  // Method to add a single Spectra Data Object
  public void addSpectraData(SpectraData[] sda) {
    for(int i = 0; i < sda.length; i++) {
      experimentData.addData(sda[i]);
    }
    updateSpectraDataListView();
    saved = false;
  }
  
  // Method to update the data int the SpectraData objects
  public void updateSpectraData(SpectraData[] sda) {
    for(int i = 0; i < sda.length; i++) {
      String[] na = sda[i].getName().split("-");
      float[][] data = sda[i].getData();
      String[] header = sda[i].getMetaInfo();
      
      // create the name to check
      String name = "";
      if(na.length == 2) {
        name = na[0];
      }
      else {
        name = na[0] + "-" + na[1];
      }
      
      for(int j = 0; j < experimentData.getDataCount(); j++) {
        SpectraData sd = experimentData.getData(j);
        String sdname = sd.getName();
        if(name.equals(sdname)) {
          sd.setData(data);
          saved = false;
          break;
        }
      }
    }
  }
  
  // Method to get the selected Index
  public SpectraData[] getSelectedSpectraData() {
    SpectraData[] sda = null;
    
    if(selectedData != null && experimentData !=null) {
      int dcount = selectedData.length;
      sda = new SpectraData[dcount];
      
      for(int i= 0; i < dcount; i++) {
        sda[i] = experimentData.getData(selectedData[i]);
      }
    }
    return sda;
  }
  
  // Method to set the file to save data in
  public void setSpectraDataListFile(File file) {
    this.file = file;
    
    //update the file name label now
    filenameLB.setText(file.getName());
  }
  
  // Method to set the file to save data in
  public File getSpectraDataListFile() {
    return file;
  }
  
  // Method to get the save status
  public boolean isSaved() {
    return saved;
  }
  
  //Method to set saved
  public void setSaved(boolean b) {
    saved = b;
  }
  
  // Method to print a massage to the dialog
  public void print(String text) {
    instruView.console.print(text);
    instruView.console.setVisible(true);
  }
  
  // Method to set the mouse listener
  public void setMouseListener(MouseListener listener) {
    dataList.addMouseListener(listener);
  }
  
  // Method to return the name of the experiment panel
  public String getName() {
    return "pump-probe";
  }
  
  // Method to select all the data in the list
	private void selectAllData() {
		if(experimentData !=null) {
			int[] indices = new int[experimentData.getDataCount()];
			for(int i = 0; i < indices.length; i++) {
				indices[i] = i;
			}
			dataList.setSelectedIndices(indices);
		}
	}
  
  // Method to remove data
  public void removeData() {
    if(selectedData != null && experimentData.getDataCount() != 0) {
      
      for(int i= 0; i < selectedData.length; i++) {
        int index = selectedData[i] - i;
        experimentData.remove(index);
      }
      
      selectedData = null;
      updateSpectraDataListView();
      saved = false;
      selectedData = null;
    }
  }
  
  // method to clear the data
	private void RemoveAllData() {
    selectedData = null;
    experimentData = new ExperimentData("pump-probe", meta);
		updateSpectraDataListView();
    saved = true;
	}
  
  // Method to add a data file
  private void addData() {
    instruView.showAddSpectraDataDialog();
  }
  
  // Method to update the data list view in this case a JList
  public void updateSpectraDataListView() {
    Vector v = experimentData.getData();
    Enumeration e = v.elements();
    
    int size = v.size();
    String[] sd_names = new String[size];
    
    int i = 0;
    while (e.hasMoreElements()) {
      SpectraData sd = (SpectraData)e.nextElement();
      sd_names[i] = sd.toString();
      i++;
    }
    
    // update the JList now
    dataList.setListData(sd_names);
    sdcLabel.setText(size+ "");
  }
  
  // Method to update the current spectra data information
  private void updateCurrentDataInfo() {
    String[] header = currentData.getHeader();
    
    header[6] = laserTF.getText();
    header[7] = celltypeTF.getText();
    header[8] = notesTF.getText();
    
    saved = false;
  }
  
  // Method to update the selected data info
  private void updateSelectedDataInfo() {
    int dcount = selectedData.length;
    
    for(int i= 0; i < dcount; i++) {
      currentData = experimentData.getData(selectedData[i]);
      updateCurrentDataInfo();
    }
    currentData = experimentData.getData(selectedData[0]);
  }
  
  // Method to update all data info
  private void updateAllDataInfo() {
    Vector expData = experimentData.getData();
    Enumeration theData = expData.elements();
    
    while(theData.hasMoreElements()) {
      currentData = (SpectraData)theData.nextElement();
      updateCurrentDataInfo();
    }
  }
  
  // Method to update the current spectra data information
  private void updateCurrentMetaInfo() {
    String[] dmeta = currentData.getMetaInfo();
    dmeta[5] = dateTF.getText();
    dmeta[6] = pageTF.getText();
    saved = false;
  }
  
  // Method to update the selected data info
  private void updateSelectedMetaInfo() {
    int dcount = selectedData.length;
    
    for(int i= 0; i < dcount; i++) {
      currentData = experimentData.getData(selectedData[i]);
      updateCurrentMetaInfo();
    }
    currentData = experimentData.getData(selectedData[0]);
  }
  
  // Method to update all data info
  private void updateAllMetaInfo() {
    Vector expData = experimentData.getData();
    Enumeration theData = expData.elements();
    
    while(theData.hasMoreElements()) {
      currentData = (SpectraData)theData.nextElement();
      updateCurrentMetaInfo();
    }
  }
  
  // Method to update the sdl information
  private void updateSDLInfo() {
    String[] meta = experimentData.getMetaInfo();
    meta[4] = sdldateTF.getText();
    experimentData.setNotes(sdlnotesTA.getText());
    saved = false;
  }
  
  // Method to show the NoteBookDialog
  private void showNoteBookDialog() {
    if(experimentData.getDataCount() > 0) {
      noteBookDialog = new NoteBookDialog("Pump-Probe Data Notebook", this);
      noteBookDialog.setSize(800, 700);
      noteBookDialog.setVisible(true);
    }
  }
} // --end class PumpProbePanel
