1 package tim.prune.data;
3 import java.util.ArrayList;
6 * Class to hold the information about the file(s)
7 * from which the data was loaded from / saved to
11 /** List of sources */
12 private ArrayList<SourceInfo> _sources = new ArrayList<SourceInfo>();
22 * Private constructor for creating clone
23 * @param inList list of sources
25 private FileInfo(ArrayList<SourceInfo> inList)
31 * Add a data source to the list
32 * @param inInfo info object to add
34 public void addSource(SourceInfo inInfo)
40 * Replace the list of data sources with the given source
41 * @param inInfo new source
43 public void replaceSource(SourceInfo inInfo)
50 * remove the last source added
52 public void removeSource()
54 _sources.remove(_sources.size()-1);
58 * @return the number of files loaded
60 public int getNumFiles()
62 return _sources.size();
67 * @return The source name, if a single file
69 public String getFilename()
71 if (getNumFiles() == 1) {
72 return _sources.get(0).getName();
78 * @param inIndex index number, starting from zero
79 * @return source info object
81 public SourceInfo getSource(int inIndex)
83 return _sources.get(inIndex);
87 * Get the SourceInfo object (if any) for the given point
88 * @param inPoint point object
89 * @return SourceInfo object if there is one, otherwise null
91 public SourceInfo getSourceForPoint(DataPoint inPoint)
93 for (SourceInfo source : _sources)
95 if (source.getIndex(inPoint) >= 0) {
103 * @return the info about the last file loaded, if any
105 public SourceInfo getLastFileInfo()
107 if (getNumFiles() == 0)
111 return getSource(getNumFiles()-1);
115 * @return the most recent file title loaded, if any
117 public String getLastFileTitle()
119 final int numFiles = getNumFiles();
124 for (int i=(numFiles-1); i>=0; i--)
126 SourceInfo info = getSource(i);
129 String title = info.getFileTitle();
130 if (title != null && !title.equals(""))
140 * Clone contents of file info
142 @SuppressWarnings("unchecked")
143 public FileInfo clone()
146 ArrayList<SourceInfo> copy = (ArrayList<SourceInfo>) _sources.clone();
147 return new FileInfo(copy);