gt: 		StatRecord stat = _stats[0];
context: /***
   * Copyright (c) 2008, Endless Loop Software, Inc.
   * 
   * This file is part of EgoNet.
   * 
   * EgoNet is free software; you can redistribute it and/or modify
   * it under the terms of the GNU General Public License as published by
   * the Free Software Foundation; either version 3 of the License, or
   * (at your option) any later version.
   * 
   * EgoNet is distributed in the hope that it will be useful,
   * but WITHOUT ANY WARRANTY; without even the implied warranty of
   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   * GNU General Public License for more details.
   * 
   * You should have received a copy of the GNU General Public License
   * along with this program.  If not, see <http://www.gnu.org/licenses/>.
   */
  package org.egonet.gui.interview;
  import java.awt.GridBagConstraints;
  import java.awt.GridBagLayout;
  import java.awt.Insets;
  import java.awt.event.ActionEvent;
  import java.io.File;
  import java.io.IOException;
  import java.text.DecimalFormat;
  import java.util.ArrayList;
  import java.util.HashSet;
  import java.util.Iterator;
  import java.util.List;
  import java.util.Set;
  
  import javax.swing.JButton;
  import javax.swing.JPanel;
  import javax.swing.JTable;
  import javax.swing.ProgressMonitor;
  
  import org.egonet.exceptions.CorruptedInterviewException;
  import org.egonet.gui.EgoStore;
  import org.egonet.io.InterviewReader;
  import org.egonet.io.StatisticsFileReader;
  import org.egonet.statistics.StatRecord;
  import org.egonet.statistics.StatTableModel;
  import org.egonet.statistics.StatisticsArrayPanel;
  import org.slf4j.Logger;
  import org.slf4j.LoggerFactory;
  
  import au.com.bytecode.opencsv.CSVWriter;
  
  public class SummaryPanel extends JPanel
  {
  	
  	final private static Logger logger = LoggerFactory.getLogger(SummaryPanel.class);
  	
  	private final    JButton 		_finishedButton = new JButton("Finished");
  	private          JPanel 			_summaryPanel;
  
  	private          StatRecord[] 	_stats          = new StatRecord[0];
  	private          int 				_recordCount    = 0;
  	private EgoClient egoClient;
  
  	
     public SummaryPanel(EgoClient egoClient, StatRecord[] stats)
     {
  	   this.egoClient = egoClient;
        setLayout(new GridBagLayout());
  
        /* Get data to display */
        _stats         = stats;
        _recordCount   = stats.length;
  
        /* Load table */
        _summaryPanel = new StatisticsArrayPanel(new SummaryModel(this));
  
        add(_summaryPanel,
           new GridBagConstraints( 0, 0, 1, 1, 1.0, 1.0,
                                   GridBagConstraints.CENTER, GridBagConstraints.BOTH,
                                   new Insets(0, 0, 0, 0), 0, 0));
        add(_finishedButton,
           new GridBagConstraints( 0, 1, 1, 1, 0.0, 0.0,
                                   GridBagConstraints.EAST, GridBagConstraints.NONE,
                                   new Insets(5, 5, 5, 5), 0, 0));
  
        _finishedButton.addActionListener(new java.awt.event.ActionListener()
        {
           public void actionPerformed(ActionEvent e)
           {
              finishedButton_actionPerformed(e);
           }
        });
     }
  
  	public SummaryPanel(EgoClient egoClient, ProgressMonitor progress)
  	{
  		this.egoClient = egoClient;
  		setLayout(new GridBagLayout());
  
  		/* Get data to display */
  		loadInterviewArray(progress);
  
  		/* Load table */
  		_summaryPanel = new StatisticsArrayPanel(new SummaryModel(this));
  
  		add(_summaryPanel,
  			new GridBagConstraints(	0, 0, 1, 1, 1.0, 1.0,
  											GridBagConstraints.CENTER, GridBagConstraints.BOTH,
  											new Insets(0, 0, 0, 0), 0, 0));
  		add(_finishedButton,
  			new GridBagConstraints( 0, 1, 1, 1, 0.0, 0.0,
  											GridBagConstraints.EAST, GridBagConstraints.NONE,
  											new Insets(5, 5, 5, 5), 0, 0));
  
  		_finishedButton.addActionListener(new java.awt.event.ActionListener()
  		{
  			public void actionPerformed(ActionEvent e)
  			{
  				finishedButton_actionPerformed(e);
  			}
  		});
  	}
  
  	private void finishedButton_actionPerformed(ActionEvent e)
  	{
  	    egoClient.getFrame().gotoSourceSelectPanel();
  	}
  
  	private void loadInterviewArray(ProgressMonitor progress)
  	{
  		File intPath = new File(egoClient.getStorage().getStudyFile().getParent(), "/Interviews/");
  		File istPath = new File(egoClient.getStorage().getStudyFile().getParent(), "/Statistics/");
  		
  		if(intPath == null || !intPath.exists()) {
  			throw new IllegalArgumentException(intPath.getPath() + " does not seem to exist");
  		}
  		else if(istPath == null || !istPath.exists()) {
  			throw new IllegalArgumentException(istPath.getPath() + " does not seem to exist");
  		}
  		
  		String[] intFiles = intPath.list();
  		Set<File> istFileSet = new HashSet<File>();
  		int i = 0, p = 0;
  
  		istPath.mkdir();
  		
  		progress.setMinimum(0);
  		progress.setMaximum(intFiles.length * 2);
  
  		logger.info("Files available for loading in "+intPath.getAbsolutePath()+": " + intFiles.length);
  		for (i = 0; (i < intFiles.length) && !progress.isCanceled(); i++)
  		{
  			
  			progress.setProgress(++p);
  
  			String thisIntFileName = intFiles[i];
  			logger.info("Loading file " + thisIntFileName);
  			
  			File intFile = new File(intPath, thisIntFileName);
  
  			try {
  				// Check that this has the correct Study Id
  				String istPathString = istPath.getCanonicalPath();
  	
  				EgoStore store = egoClient.getStorage();
  				File thisIstFile = store.interviewStatisticsFile(istPathString, intFiles[i]);
  				
  				InterviewReader ir = new InterviewReader(egoClient.getStudy(), intFile);
  				ir.getInterview();
  				store.generateStatisticsFile(intFile);
  				istFileSet.add(thisIstFile);
  			} catch (CorruptedInterviewException ex)
  			{
  				// no match, eat silently
  				logger.info("Skipped "+thisIntFileName+", interview was corrupted or study ID didn't match");
  			} catch (IOException ex)
  			{
  				logger.info("Failed to read " + thisIntFileName,ex);
  			} catch(Exception ex) {
  				throw new RuntimeException(
  						"Failed to generate statistics for "+intFile.getName(), ex);
  			}
  		
  			
  		}
  
  		_stats = new StatRecord[istFileSet.size()];
  
  		progress.setMaximum(intFiles.length + istFileSet.size());
  		for (Iterator<File> it = istFileSet.iterator(); it.hasNext() && !progress.isCanceled();)
  		{
  			progress.setProgress(++p);
  
  			try
  			{
  				StatisticsFileReader sfr = new StatisticsFileReader(it.next());
  				StatRecord rec = sfr.readStatRecord();
  
  				if (rec != null)
  				{
  					_stats[_recordCount++] = rec;
  				}
  			}
  			catch (Exception ignored)
  			{
  				ignored.printStackTrace();
  			}
  		}
  	}
  
  	public void writeStudySummary(CSVWriter w)
  	{
  		Iterator it;
  