private boolean processParameterValues(File parameterFile,
UserParameter[] parameters) {
// Warn user if main dialog already contains a parameter with same name
for (UserParameter parameter : parameters) {
UserParameter p = mainDialog.getParameter(parameter.getName());
if (p != null) {
int res = JOptionPane.showConfirmDialog(mainDialog,
"Overwrite previous parameter(s) with same name?",
"Overwrite?", JOptionPane.OK_CANCEL_OPTION);
if (res == JOptionPane.CANCEL_OPTION)
return false;
else
break;
}
}
// Remove parameters with same name
for (UserParameter parameter : parameters) {
UserParameter p = mainDialog.getParameter(parameter.getName());
if (p != null) {
mainDialog.removeParameter(p);
}
}
// Add new parameters to the main dialog
for (UserParameter parameter : parameters) {
mainDialog.addParameter(parameter);
}
// Open reader
BufferedReader parameterFileReader;
try {
parameterFileReader = new BufferedReader(new FileReader(
parameterFile));
} catch (FileNotFoundException ex) {
logger.severe("Could not open file " + parameterFile);
desktop.displayErrorMessage("Could not open file " + parameterFile);
return false;
}
try {
// Skip first row
parameterFileReader.readLine();
// Read rest of the rows which contain file name in the first column
// and parameter values in the rest of the columns
String nextRow = parameterFileReader.readLine();
while (nextRow != null) {
StringTokenizer st = new StringTokenizer(nextRow, ",");
nextRow = parameterFileReader.readLine();
// Get raw data file for this row
String fileName = st.nextToken();
// Set parameter values to project
int parameterIndex = 0;
while (st.hasMoreTokens()) {
String parameterValue = st.nextToken();
UserParameter parameter = parameters[parameterIndex];
if (parameter instanceof DoubleParameter)
mainDialog.setParameterValue(parameter, fileName,
Double.parseDouble(parameterValue));
else