Commit e6d35d70 authored by Radek Ošlejšek's avatar Radek Ošlejšek
Browse files

Merge branch '105-adjust-hd-control-panel' into 'master'

Plus/minus buttons

See merge request grp-fidentis/analyst2!114
parents 49b0fabb 14d7ce92
Loading
Loading
Loading
Loading
+28 −11
Original line number Diff line number Diff line
@@ -22,7 +22,8 @@ import java.util.stream.Collector;
 */
public class WeightedAverageCollector<T> implements Collector<T, IntemediateResults, Double> {

    private final ToDoubleFunction<? super T> valueFunction, weightFunction;
    private final ToDoubleFunction<? super T> valueFunction;
    private final ToDoubleFunction<? super T> weightFunction;
    
    /**
     * Constructor.
@@ -48,7 +49,7 @@ public class WeightedAverageCollector<T> implements Collector<T, IntemediateResu
    public static <T> Collector<T, ?, Double> toWeightedAverage(
            ToDoubleFunction<? super T> valueFunction,
            ToDoubleFunction<? super T> weightFunction) {
        return new WeightedAverageCollector(valueFunction, weightFunction);
        return new WeightedAverageCollector<>(valueFunction, weightFunction);
    }
    
    /**
@@ -69,9 +70,9 @@ public class WeightedAverageCollector<T> implements Collector<T, IntemediateResu
    @Override
    public BiConsumer<IntemediateResults, T> accumulator() {
        return (iResult, streamElement) -> {
            iResult.weightedValSum += valueFunction.applyAsDouble(streamElement)
                    * weightFunction.applyAsDouble(streamElement);
            iResult.weightSum += weightFunction.applyAsDouble(streamElement);
            iResult.addWeightedValSum(valueFunction.applyAsDouble(streamElement)
                    * weightFunction.applyAsDouble(streamElement));
            iResult.addWeightSum(weightFunction.applyAsDouble(streamElement));
        };
    }
    
@@ -86,8 +87,8 @@ public class WeightedAverageCollector<T> implements Collector<T, IntemediateResu
    @Override
    public BinaryOperator<IntemediateResults> combiner() {
        return (iResult1, iResult2) -> {
            iResult1.weightedValSum += iResult2.weightedValSum;
            iResult1.weightSum += iResult2.weightSum;
            iResult1.addWeightedValSum(iResult2.getWeightedValSum());
            iResult1.addWeightSum(iResult2.getWeightSum());
            
            return iResult1;
        };
@@ -108,7 +109,7 @@ public class WeightedAverageCollector<T> implements Collector<T, IntemediateResu
     */
    @Override
    public Function<IntemediateResults, Double> finisher() {
        return iResult -> iResult.weightedValSum / iResult.weightSum;
        return iResult -> iResult.getWeightedValSum() / iResult.getWeightSum();
    }
    
    /**
@@ -130,6 +131,22 @@ public class WeightedAverageCollector<T> implements Collector<T, IntemediateResu
 * @author Daniel Schramm
 */
class IntemediateResults {
    double weightedValSum = 0;
    double weightSum = 0;
    private double weightedValSum = 0;
    private double weightSum = 0;

    public double getWeightedValSum() {
        return weightedValSum;
    }

    public double getWeightSum() {
        return weightSum;
    }

    public void addWeightedValSum(double weightedValSum) {
        this.weightedValSum += weightedValSum;
    }

    public void addWeightSum(double weightSum) {
        this.weightSum += weightSum;
    }
}
+253 −67

File changed.

Preview size limit exceeded, changes collapsed.

+45 −0
Original line number Diff line number Diff line
package cz.fidentis.analyst.core;

/**
 * Class holding the upper and lower bounds of an interval.
 * 
 * @author Daniel Schramm
 */
public class IntValueRange {
    
    private final int minimum, maximum;

    /**
     * Constructor.
     * 
     * @param minimum The lower bound of the interval
     * @param maximum The upper bound of the interval
     * @throws IllegalArgumentException if the {@code minimum} is greater than the {@code maximum}
     */
    public IntValueRange(int minimum, int maximum) {
        if (minimum > maximum) {
            throw new IllegalArgumentException("Minimum value must be less or equal to maximum value");
        }
        
        this.minimum = minimum;
        this.maximum = maximum;
    }

    /**
     * Returns the lower bound of the interval.
     * 
     * @return Lower bound of the interval
     */
    public int getMinimum() {
        return minimum;
    }

    /**
     * Returns the upper bound of the interval.
     * 
     * @return Upper bound of the interval
     */
    public int getMaximum() {
        return maximum;
    }
}
+16 −1
Original line number Diff line number Diff line
@@ -138,9 +138,24 @@ public class DistancePanel extends ControlPanel {
            });
            featurePointCheckBoxes.add(checkBox);

            final JTextField sliderInput = fpBuilder.addSliderOptionLine(null, null, 100, null);
            final JTextField sliderInput = fpBuilder.addSliderButtonedWithVal(100, 1, null);
            sliderInput.setText(ControlPanelBuilder.doubleToStringLocale(DrawableFeaturePoints.DEFAULT_SIZE));
            sliderInput.postActionEvent(); // Set correct position of slider
            sliderInput.addActionListener((ActionEvent ae) -> {
                if (!checkBox.isSelected()) {
                    return; // Recompute only if the feature point is selected
                }
                
                if (ControlPanelBuilder.TEXT_FIELD_BUTTON_PRESSED_MINUS.equals(ae.getActionCommand())
                        || ControlPanelBuilder.TEXT_FIELD_BUTTON_PRESSED_PLUS.equals(ae.getActionCommand())) {
                    // Plus/minus button was pressed -> recompute
                    action.actionPerformed(new ActionEvent(
                            ae.getSource(),
                            ActionEvent.ACTION_PERFORMED,
                            ACTION_COMMAND_DISTANCE_RECOMPUTE
                    ));
                }
            });
            sliderInput.addActionListener(createListener(action, ACTION_COMMAND_FEATURE_POINT_RESIZE, i));
            // Modify listener of the ENTER key press
            final Object enterKeyAction = sliderInput.getInputMap()