/*
 * Copyright 2006 The MZmine Development Team
 *
 * This file is part of MZmine.
 *
 * MZmine 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 2 of the License, or (at your option) any later
 * version.
 *
 * MZmine 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
 * MZmine; if not, write to the Free Software Foundation, Inc., 51 Franklin St,
 * Fifth Floor, Boston, MA 02110-1301 USA
 */

package net.sf.mzmine.io;

import java.io.File;
import java.util.Hashtable;
import java.util.Vector;

import net.sf.mzmine.methods.Method;
import net.sf.mzmine.methods.MethodParameters;
import net.sf.mzmine.methods.alignment.AlignmentResult;
import net.sf.mzmine.methods.peakpicking.PeakList;
import net.sf.mzmine.userinterface.mainwindow.MainWindow;

/**
 * This class represents a MZmine project.
 * That includes raw data files, processed raw data files,
 * peak lists, alignment results.... 
 */
public class MZmineProject {

    private static MZmineProject currentProject;
    private Vector<RawDataFile> projectFiles;
    
    class Operation {
        File previousFileName;
        Method processsingMethod;
        MethodParameters parameters;
    }
    
    /* we have to index by File, not by RawDataFile - that would 
     * cause keeping all previous RawDataFile objects in memory */
    private Hashtable<File, Operation> fileHistory;
    
    public MZmineProject() {
        projectFiles = new Vector<RawDataFile>();
        fileHistory = new Hashtable<File, Operation>();
        currentProject = this;
    }
    
    public static MZmineProject getCurrentProject() {
        assert currentProject != null;
        return currentProject;
    }
    
    void addFile(RawDataFile newFile) {
        projectFiles.add(newFile);
        MainWindow.getInstance().getItemSelector().addRawData(newFile);
    }
    
    public void removeFile(RawDataFile file) {
        projectFiles.remove(file);
        fileHistory.remove(file.getFileName());
        MainWindow.getInstance().getItemSelector().removeRawData(file);
    }
    
    /**
     */
    public void updateFile(RawDataFile oldFile, RawDataFile newFile, Method processingMethod, MethodParameters methodParameters) {
        Operation op = new Operation();
        op.previousFileName = oldFile.getFileName();
        op.processsingMethod = processingMethod;
        op.parameters = methodParameters;
        projectFiles.setElementAt(newFile, projectFiles.indexOf(oldFile));
        fileHistory.put(newFile.getFileName(), op);
        // TODO: notify visualizers? 
    }
    
    
    
}

@@ -1269,17 +1269,16 @@
 ults....
- 
 %0A */%0Apub
@@ -1399,20 +1399,16 @@
 tFiles;%0A
-    
 %0A    cla
@@ -1526,28 +1526,24 @@
 ters;%0A    %7D%0A
-    
 %0A    /* we h
@@ -1595,17 +1595,16 @@
 at would
- 
 %0A     * 
@@ -1715,20 +1715,16 @@
 istory;%0A
-    
 %0A    pub
@@ -1880,36 +1880,32 @@
 t = this;%0A    %7D%0A
-    
 %0A    public stat
@@ -2015,28 +2015,24 @@
 ject;%0A    %7D%0A
-    
 %0A    void ad
@@ -2169,28 +2169,24 @@
 ile);%0A    %7D%0A
-    
 %0A    public 
@@ -2291,23 +2291,26 @@
 file.get
-FileNam
+CurrentFil
 e());%0A  
@@ -2381,28 +2381,24 @@
 ile);%0A    %7D%0A
-    
 %0A    /**%0A   
@@ -2614,23 +2614,26 @@
 File.get
-FileNam
+CurrentFil
 e();%0A   
@@ -2834,22 +2834,110 @@
 .get
-FileName(), op
+CurrentFile(), op);%0A        MainWindow.getInstance().getItemSelector().replaceRawData(oldFile, newFile
 );%0A 
@@ -2975,29 +2975,16 @@
 ers?
- 
 %0A    %7D%0A
-    %0A    %0A    
+%0A%0A
 %0A%7D%0A

Update file also updates item selector