view gwt-client/src/main/java/org/dive4elements/river/client/client/ui/chart/MinMaxStepNaviChartStepper.java @ 9390:f575ff573cbb

"Name der Peilung" columname minfo.
author gernotbelger
date Thu, 09 Aug 2018 15:22:31 +0200
parents abf14917be32
children
line wrap: on
line source
/** Copyright (C) 2017 by Bundesanstalt für Gewässerkunde
 * Software engineering by
 *  Björnsen Beratende Ingenieure GmbH
 *  Dr. Schumacher Ingenieurbüro für Wasser und Umwelt
 *
 * This file is Free Software under the GNU AGPL (>=v3)
 * and comes with ABSOLUTELY NO WARRANTY! Check out the
 * documentation coming with Dive4Elements River for details.
 */
package org.dive4elements.river.client.client.ui.chart;

/**
 * 'Old' stepping behaviour of the navi chart, as used by WINFO and Fixierungsanalyse.
 *
 * @author Gernot Belger
 */
public class MinMaxStepNaviChartStepper implements INaviChartStepper {

    private double currentKm;
    private final double minKm;
    private final double maxKm;
    private final double step;

    public MinMaxStepNaviChartStepper(final double minKm, final double maxKm, final double step) {
        this.minKm = minKm;
        this.maxKm = maxKm;
        this.step = step;

        this.currentKm = minKm;
    }

    @Override
    public double getCurrentKm() {
        return this.currentKm;
    }

    @Override
    public double stepForward() {

        if (this.currentKm >= this.maxKm)
            this.currentKm = this.maxKm;
        else {
            // Why this math?
            double newVal = this.currentKm * 100;
            newVal += this.step / 10;
            this.currentKm = (double) Math.round(newVal) / 100;
        }

        return this.currentKm;
    }

    @Override
    public double stepBackward() {

        if (this.currentKm <= this.minKm)
            this.currentKm = this.minKm;
        else {
            // Why this math?
            double newVal = this.currentKm * 100;
            newVal -= this.step / 10;

            this.currentKm = ((double) Math.round(newVal) / 100);
        }

        return this.currentKm;
    }

    @Override
    public double setValidCurrentKm(final double userInput) {

        if (userInput > this.maxKm)
            this.currentKm = this.maxKm;
        else if (userInput < this.minKm)
            this.currentKm = this.minKm;
        else
            this.currentKm = userInput;

        return this.currentKm;
    }
}

http://dive4elements.wald.intevation.org