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 if (!_sources.isEmpty()) {
55 _sources.remove(_sources.size()-1);
60 * @return the number of files loaded
62 public int getNumFiles()
64 return _sources.size();
69 * @return The source name, if a single file
71 public String getFilename()
73 if (getNumFiles() == 1) {
74 return _sources.get(0).getName();
80 * @return The source names
82 public ArrayList<String> getFilenames()
84 ArrayList<String> filenames = new ArrayList<String>();
85 for (SourceInfo source : _sources)
87 filenames.add(source.getName());
93 * @param inIndex index number, starting from zero
94 * @return source info object
96 public SourceInfo getSource(int inIndex)
98 return _sources.get(inIndex);
102 * Get the SourceInfo object (if any) for the given point
103 * @param inPoint point object
104 * @return SourceInfo object if there is one, otherwise null
106 public SourceInfo getSourceForPoint(DataPoint inPoint)
108 for (SourceInfo source : _sources)
110 if (source.getIndex(inPoint) >= 0) {
118 * @return the info about the last file loaded, if any
120 public SourceInfo getLastFileInfo()
122 if (getNumFiles() == 0)
126 return getSource(getNumFiles()-1);
130 * @return the most recent file title loaded, if any
132 public String getLastFileTitle()
134 final int numFiles = getNumFiles();
139 for (int i=(numFiles-1); i>=0; i--)
141 SourceInfo info = getSource(i);
144 String title = info.getFileTitle();
145 if (title != null && !title.equals(""))
155 * Clone contents of file info
157 @SuppressWarnings("unchecked")
158 public FileInfo clone()
161 ArrayList<SourceInfo> copy = (ArrayList<SourceInfo>) _sources.clone();
162 return new FileInfo(copy);