Mercurial > dive4elements > river
comparison gwt-client/src/main/java/org/dive4elements/river/client/client/ui/chart/MinMaxStepNaviChartStepper.java @ 9263:abf14917be32
Moved stepping behaviour of NaviOutputChart into an exchangeable strategy.
Allows for distinct values stepping of sinfo flood duration.
author | gernotbelger |
---|---|
date | Tue, 17 Jul 2018 19:48:18 +0200 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
9262:fee5fa18361c | 9263:abf14917be32 |
---|---|
1 /** Copyright (C) 2017 by Bundesanstalt für Gewässerkunde | |
2 * Software engineering by | |
3 * Björnsen Beratende Ingenieure GmbH | |
4 * Dr. Schumacher Ingenieurbüro für Wasser und Umwelt | |
5 * | |
6 * This file is Free Software under the GNU AGPL (>=v3) | |
7 * and comes with ABSOLUTELY NO WARRANTY! Check out the | |
8 * documentation coming with Dive4Elements River for details. | |
9 */ | |
10 package org.dive4elements.river.client.client.ui.chart; | |
11 | |
12 /** | |
13 * 'Old' stepping behaviour of the navi chart, as used by WINFO and Fixierungsanalyse. | |
14 * | |
15 * @author Gernot Belger | |
16 */ | |
17 public class MinMaxStepNaviChartStepper implements INaviChartStepper { | |
18 | |
19 private double currentKm; | |
20 private final double minKm; | |
21 private final double maxKm; | |
22 private final double step; | |
23 | |
24 public MinMaxStepNaviChartStepper(final double minKm, final double maxKm, final double step) { | |
25 this.minKm = minKm; | |
26 this.maxKm = maxKm; | |
27 this.step = step; | |
28 | |
29 this.currentKm = minKm; | |
30 } | |
31 | |
32 @Override | |
33 public double getCurrentKm() { | |
34 return this.currentKm; | |
35 } | |
36 | |
37 @Override | |
38 public double stepForward() { | |
39 | |
40 if (this.currentKm >= this.maxKm) | |
41 this.currentKm = this.maxKm; | |
42 else { | |
43 // Why this math? | |
44 double newVal = this.currentKm * 100; | |
45 newVal += this.step / 10; | |
46 this.currentKm = (double) Math.round(newVal) / 100; | |
47 } | |
48 | |
49 return this.currentKm; | |
50 } | |
51 | |
52 @Override | |
53 public double stepBackward() { | |
54 | |
55 if (this.currentKm <= this.minKm) | |
56 this.currentKm = this.minKm; | |
57 else { | |
58 // Why this math? | |
59 double newVal = this.currentKm * 100; | |
60 newVal -= this.step / 10; | |
61 | |
62 this.currentKm = ((double) Math.round(newVal) / 100); | |
63 } | |
64 | |
65 return this.currentKm; | |
66 } | |
67 | |
68 @Override | |
69 public double setValidCurrentKm(final double userInput) { | |
70 | |
71 if (userInput > this.maxKm) | |
72 this.currentKm = this.maxKm; | |
73 else if (userInput < this.minKm) | |
74 this.currentKm = this.minKm; | |
75 else | |
76 this.currentKm = userInput; | |
77 | |
78 return this.currentKm; | |
79 } | |
80 } |