Search in sources :

Example 1 with NumericParameter

use of qupath.lib.plugins.parameters.NumericParameter in project qupath by qupath.

the class ParameterPanelFX method setNumericParameterValueRange.

/**
 * Set the minimum and maximum value for a numeric parameter.
 *
 * If the parameter is being displayed with a slider, the slider range will also be updated accordingly.
 *
 * @param key
 * @param minValue
 * @param maxValue
 * @return
 */
public boolean setNumericParameterValueRange(final String key, double minValue, double maxValue) {
    // Try to get a component to set
    Parameter<?> parameterOrig = params.getParameters().get(key);
    if (parameterOrig == null || !(parameterOrig instanceof NumericParameter)) {
        logger.warn("Unable to set range for {} - no numeric parameter found with that key", key);
        return false;
    }
    NumericParameter<?> parameter = (NumericParameter<?>) parameterOrig;
    // Occurs with hidden parameters
    try {
        parameter.setRange(minValue, maxValue);
        Node component = map.get(parameter);
        if (component instanceof Parent) {
            for (Node comp : ((Parent) component).getChildrenUnmodifiable()) {
                if (comp instanceof Slider) {
                    // Only change the text if necessary
                    Slider slider = (Slider) comp;
                    slider.setMin(minValue);
                    slider.setMax(maxValue);
                    return true;
                }
            }
        }
    } catch (Exception e) {
        logger.warn("Unable to set range for {}: {}", parameter, e.getLocalizedMessage());
    }
    return false;
}
Also used : Slider(javafx.scene.control.Slider) Parent(javafx.scene.Parent) NumericParameter(qupath.lib.plugins.parameters.NumericParameter) Node(javafx.scene.Node)

Example 2 with NumericParameter

use of qupath.lib.plugins.parameters.NumericParameter in project qupath by qupath.

the class ParameterPanelFX method setNumericParameterValue.

/**
 * Set a numeric parameter value (either int or double).
 *
 * The reason for using this method rather than setting the parameter value directly is that it ensures that
 * any displayed components (text fields, sliders...) are updated accordingly.
 *
 * @param key
 * @param value
 * @return
 */
public boolean setNumericParameterValue(final String key, Number value) {
    // Try to get a component to set
    Parameter<?> parameterOrig = params.getParameters().get(key);
    if (parameterOrig == null || !(parameterOrig instanceof NumericParameter)) {
        logger.warn("Unable to set parameter {} with value {} - no numeric parameter found with that key", key, value);
        return false;
    }
    NumericParameter<?> parameter = (NumericParameter<?>) parameterOrig;
    Node component = map.get(parameter);
    // Occurs with hidden parameters
    if (component == null) {
        parameter.setDoubleLastValue(value.doubleValue());
        return true;
    }
    if (component instanceof Parent) {
        for (Node comp : ((Parent) component).getChildrenUnmodifiable()) {
            if (comp instanceof TextField) {
                // Only change the text if necessary
                TextField textField = (TextField) comp;
                setTextFieldFromNumber(textField, value, parameter.getUnit());
                return true;
            }
        }
    }
    logger.warn("Unable to set parameter {} with value {} - no component found", key, value);
    return false;
}
Also used : Parent(javafx.scene.Parent) NumericParameter(qupath.lib.plugins.parameters.NumericParameter) Node(javafx.scene.Node) TextField(javafx.scene.control.TextField)

Aggregations

Node (javafx.scene.Node)2 Parent (javafx.scene.Parent)2 NumericParameter (qupath.lib.plugins.parameters.NumericParameter)2 Slider (javafx.scene.control.Slider)1 TextField (javafx.scene.control.TextField)1