Search in sources :

Example 1 with DoubleParameter

use of net.sf.mzmine.parameters.parametertypes.DoubleParameter in project mzmine2 by mzmine.

the class GraphicsExportDialog method renewPreview.

/**
 * renew chart preview with specified size
 */
protected void renewPreview() {
    // set dimensions to chartpanel
    try {
        // update param
        updateParameterSetFromComponents();
        // 
        if (parameters.isUseOnlyWidth()) {
            double height = (ChartLogics.calcHeightToWidth(chartPanel, parameters.getWidthPixel(), false));
            DoubleParameter p = parameters.getParameter(GraphicsExportParameters.height).getEmbeddedParameter();
            DoubleComponent c = ((OptionalParameterComponent<DoubleComponent>) parametersAndComponents.get(p.getName())).getEmbeddedComponent();
            p.setValueToComponent(c, height);
            p.setValueFromComponent(c);
            chartPanel.setSize((int) parameters.getWidthPixel(), (int) parameters.getHeightPixel());
            getPnChartPreview().repaint();
        } else {
            chartPanel.setSize((int) parameters.getWidthPixel(), (int) parameters.getHeightPixel());
            chartPanel.repaint();
        }
    } catch (Exception ex) {
        ex.printStackTrace();
        LOG.log(Level.SEVERE, "Error while renewing preview of graphics export dialog ", ex);
    }
}
Also used : DoubleComponent(net.sf.mzmine.parameters.parametertypes.DoubleComponent) DoubleParameter(net.sf.mzmine.parameters.parametertypes.DoubleParameter) OptionalParameterComponent(net.sf.mzmine.parameters.parametertypes.OptionalParameterComponent)

Example 2 with DoubleParameter

use of net.sf.mzmine.parameters.parametertypes.DoubleParameter in project mzmine2 by mzmine.

the class ProjectParametersImporter method processParameterValues.

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(MZmineCore.getDesktop().getMainWindow(), "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();
            if (!st.hasMoreTokens())
                continue;
            // 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
                    mainDialog.setParameterValue(parameter, fileName, parameterValue);
                parameterIndex++;
            }
        }
    } catch (IOException ex) {
        logger.severe("Could not read file " + parameterFile);
        desktop.displayErrorMessage(MZmineCore.getDesktop().getMainWindow(), "Could not open file " + parameterFile);
        return false;
    }
    // Close reader
    try {
        parameterFileReader.close();
    } catch (IOException ex) {
        logger.severe("Could not close file " + parameterFile);
        desktop.displayErrorMessage(MZmineCore.getDesktop().getMainWindow(), "Could not close file " + parameterFile);
        return false;
    }
    return true;
}
Also used : StringTokenizer(java.util.StringTokenizer) DoubleParameter(net.sf.mzmine.parameters.parametertypes.DoubleParameter) BufferedReader(java.io.BufferedReader) FileNotFoundException(java.io.FileNotFoundException) FileReader(java.io.FileReader) IOException(java.io.IOException)

Example 3 with DoubleParameter

use of net.sf.mzmine.parameters.parametertypes.DoubleParameter in project mzmine2 by mzmine.

the class ProjectParametersImporter method processParameters.

private UserParameter<?, ?>[] processParameters(File parameterFile) {
    ArrayList<UserParameter<?, ?>> parameters = new ArrayList<UserParameter<?, ?>>();
    // Open reader
    BufferedReader parameterFileReader;
    try {
        parameterFileReader = new BufferedReader(new FileReader(parameterFile));
        // Read column headers which are used as parameter names
        String firstRow = parameterFileReader.readLine();
        StringTokenizer st = new StringTokenizer(firstRow, ",");
        // Assume first column contains file names
        st.nextToken();
        ArrayList<String> parameterNames = new ArrayList<String>();
        Hashtable<String, ArrayList<String>> parameterValues = new Hashtable<String, ArrayList<String>>();
        while (st.hasMoreTokens()) {
            String paramName = st.nextToken();
            if (parameterValues.containsKey(paramName)) {
                logger.severe("Did not import parameters because of a non-unique parameter name: " + paramName);
                desktop.displayErrorMessage(MZmineCore.getDesktop().getMainWindow(), "Could not open file " + parameterFile);
                parameterFileReader.close();
                return null;
            }
            parameterNames.add(paramName);
            parameterValues.put(paramName, new ArrayList<String>());
        }
        // 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();
        int rowNumber = 2;
        while (nextRow != null) {
            st = new StringTokenizer(nextRow, ",");
            // Skip first column (File name)
            if (st.hasMoreTokens())
                st.nextToken();
            Iterator<String> parameterNameIterator = parameterNames.iterator();
            while (st.hasMoreTokens()) {
                if (st.hasMoreTokens() ^ parameterNameIterator.hasNext()) {
                    logger.severe("Incorrect number of parameter values on row " + rowNumber);
                    desktop.displayErrorMessage(MZmineCore.getDesktop().getMainWindow(), "Incorrect number of parameter values on row " + rowNumber);
                    parameterFileReader.close();
                    return null;
                }
                parameterValues.get(parameterNameIterator.next()).add(st.nextToken());
            }
            nextRow = parameterFileReader.readLine();
            rowNumber++;
        }
        // Decide parameter types (all numeric => Double, all unique string
        // => String, at least one duplicate string => Object with possible
        // values
        Iterator<String> parameterNameIterator = parameterNames.iterator();
        while (parameterNameIterator.hasNext()) {
            String name = parameterNameIterator.next();
            ArrayList<String> vals = parameterValues.get(name);
            // Test for all numeric
            Iterator<String> valIterator = vals.iterator();
            boolean isAllNumeric = true;
            while (valIterator.hasNext()) {
                try {
                    Double.valueOf(valIterator.next());
                } catch (NumberFormatException ex) {
                    isAllNumeric = false;
                    break;
                }
            }
            if (isAllNumeric) {
                parameters.add(new DoubleParameter(name, null));
                continue;
            }
            // Test for "set of values"
            ArrayList<String> uniqueValues = new ArrayList<String>();
            valIterator = vals.iterator();
            while (valIterator.hasNext()) {
                String val = valIterator.next();
                if (!uniqueValues.contains(val))
                    uniqueValues.add(val);
            }
            if (uniqueValues.size() < vals.size()) {
                parameters.add(new ComboParameter<String>(name, null, uniqueValues.toArray(new String[0])));
                continue;
            }
            // Otherwise it is a free text parameter
            parameters.add(new StringParameter(name, null));
        }
        // Close reader
        parameterFileReader.close();
    } catch (IOException ex) {
        logger.severe("Could not read file " + parameterFile);
        desktop.displayErrorMessage(MZmineCore.getDesktop().getMainWindow(), "Could not open file " + parameterFile);
        return null;
    }
    return parameters.toArray(new UserParameter[0]);
}
Also used : StringParameter(net.sf.mzmine.parameters.parametertypes.StringParameter) DoubleParameter(net.sf.mzmine.parameters.parametertypes.DoubleParameter) Hashtable(java.util.Hashtable) ArrayList(java.util.ArrayList) IOException(java.io.IOException) UserParameter(net.sf.mzmine.parameters.UserParameter) StringTokenizer(java.util.StringTokenizer) BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader)

Example 4 with DoubleParameter

use of net.sf.mzmine.parameters.parametertypes.DoubleParameter in project mzmine2 by mzmine.

the class ProjectParametersSetupDialog method copyParameterValuesToRawDataFiles.

private void copyParameterValuesToRawDataFiles() {
    MZmineProject currentProject = MZmineCore.getProjectManager().getCurrentProject();
    // Remove all previous parameters from project
    UserParameter<?, ?>[] parameters = currentProject.getParameters();
    for (UserParameter<?, ?> parameter : parameters) {
        currentProject.removeParameter(parameter);
    }
    // Add new parameters
    parameters = parameterValues.keySet().toArray(new UserParameter[0]);
    for (UserParameter<?, ?> parameter : parameters) {
        currentProject.addParameter(parameter);
    }
    // Set values for new parameters
    for (int columnIndex = 0; columnIndex < parameterValues.keySet().size(); columnIndex++) {
        UserParameter<?, ?> parameter = tablemodelParameterValues.getParameter(columnIndex + 1);
        for (int dataFileIndex = 0; dataFileIndex < dataFiles.length; dataFileIndex++) {
            RawDataFile file = dataFiles[dataFileIndex];
            Object value = tablemodelParameterValues.getValueAt(dataFileIndex, columnIndex + 1);
            if (parameter instanceof DoubleParameter) {
                Double doubleValue = null;
                if (value instanceof Double)
                    doubleValue = (Double) value;
                if (value instanceof String)
                    doubleValue = Double.parseDouble((String) value);
                currentProject.setParameterValue(parameter, file, doubleValue);
            }
            if (parameter instanceof StringParameter) {
                if (value == null)
                    value = "";
                currentProject.setParameterValue(parameter, file, (String) value);
            }
            if (parameter instanceof ComboParameter) {
                if (value == null)
                    value = "";
                currentProject.setParameterValue(parameter, file, (String) value);
            }
        }
    }
}
Also used : UserParameter(net.sf.mzmine.parameters.UserParameter) StringParameter(net.sf.mzmine.parameters.parametertypes.StringParameter) DoubleParameter(net.sf.mzmine.parameters.parametertypes.DoubleParameter) RawDataFile(net.sf.mzmine.datamodel.RawDataFile) MZmineProject(net.sf.mzmine.datamodel.MZmineProject) ComboParameter(net.sf.mzmine.parameters.parametertypes.ComboParameter)

Example 5 with DoubleParameter

use of net.sf.mzmine.parameters.parametertypes.DoubleParameter in project mzmine2 by mzmine.

the class UserParameterOpenHandler_2_3 method endElement.

/**
 * @see org.xml.sax.helpers.DefaultHandler#endElement(java.lang.String, java.lang.String,
 *      java.lang.String)
 */
@SuppressWarnings("unchecked")
public void endElement(String namespaceURI, String sName, String qName) throws SAXException {
    if (canceled)
        throw new SAXException("Parsing canceled");
    // <OPTION>
    if (qName.equals(UserParameterElementName_2_3.OPTION.getElementName())) {
        String optionValue = getTextOfElement();
        currentOptions.add(optionValue);
    }
    // <VALUE>
    if (qName.equals(UserParameterElementName_2_3.VALUE.getElementName())) {
        RawDataFile currentDataFile = dataFilesIDMap.get(currentDataFileID);
        String valueString = getTextOfElement();
        Object value;
        if (currentParameter instanceof DoubleParameter) {
            value = new Double(valueString);
        } else
            value = valueString;
        currentValues.put(currentDataFile, value);
    }
    // <PARAMETER>
    if (qName.equals(UserParameterElementName_2_3.PARAMETER.getElementName())) {
        if (currentParameter instanceof ComboParameter) {
            String[] newChoices = currentOptions.toArray(new String[0]);
            ((ComboParameter<String>) currentParameter).setChoices(newChoices);
        }
        newProject.addParameter(currentParameter);
        for (RawDataFile dataFile : currentValues.keySet()) {
            Object value = currentValues.get(dataFile);
            newProject.setParameterValue(currentParameter, dataFile, value);
        }
        parsedParams++;
    }
}
Also used : DoubleParameter(net.sf.mzmine.parameters.parametertypes.DoubleParameter) RawDataFile(net.sf.mzmine.datamodel.RawDataFile) SAXException(org.xml.sax.SAXException) ComboParameter(net.sf.mzmine.parameters.parametertypes.ComboParameter)

Aggregations

DoubleParameter (net.sf.mzmine.parameters.parametertypes.DoubleParameter)10 ComboParameter (net.sf.mzmine.parameters.parametertypes.ComboParameter)6 StringParameter (net.sf.mzmine.parameters.parametertypes.StringParameter)5 SAXException (org.xml.sax.SAXException)4 RawDataFile (net.sf.mzmine.datamodel.RawDataFile)3 BufferedReader (java.io.BufferedReader)2 FileReader (java.io.FileReader)2 IOException (java.io.IOException)2 StringTokenizer (java.util.StringTokenizer)2 UserParameter (net.sf.mzmine.parameters.UserParameter)2 Color (java.awt.Color)1 FileNotFoundException (java.io.FileNotFoundException)1 ArrayList (java.util.ArrayList)1 Hashtable (java.util.Hashtable)1 DefaultListModel (javax.swing.DefaultListModel)1 MZmineProject (net.sf.mzmine.datamodel.MZmineProject)1 Desktop (net.sf.mzmine.desktop.Desktop)1 CursorPosition (net.sf.mzmine.modules.visualization.tic.CursorPosition)1 Parameter (net.sf.mzmine.parameters.Parameter)1 ParameterSet (net.sf.mzmine.parameters.ParameterSet)1