annotate flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/DistanceOnlySelect.java @ 5649:066f3a2f34d6

Minor refactoring.
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Wed, 10 Apr 2013 13:11:45 +0200
parents 53be73133104
children
rev   line source
1625
c45e8d6b99a2 #315 Added new state for entering a kilometer range without step width.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
1 package de.intevation.flys.artifacts.states;
c45e8d6b99a2 #315 Added new state for entering a kilometer range without step width.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
2
c45e8d6b99a2 #315 Added new state for entering a kilometer range without step width.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
3 import org.apache.log4j.Logger;
c45e8d6b99a2 #315 Added new state for entering a kilometer range without step width.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
4
1630
cafd8af6734a Improved bounds validation for distance only states.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1625
diff changeset
5 import de.intevation.artifacts.Artifact;
cafd8af6734a Improved bounds validation for distance only states.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1625
diff changeset
6
4865
1358d0c8481c RangeState and descendants: Use RangeAccess, resolve direct ld_* usage.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1630
diff changeset
7 import de.intevation.flys.artifacts.access.RangeAccess;
1630
cafd8af6734a Improved bounds validation for distance only states.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1625
diff changeset
8 import de.intevation.flys.artifacts.FLYSArtifact;
cafd8af6734a Improved bounds validation for distance only states.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1625
diff changeset
9
1625
c45e8d6b99a2 #315 Added new state for entering a kilometer range without step width.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
10
c45e8d6b99a2 #315 Added new state for entering a kilometer range without step width.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
11 public class DistanceOnlySelect extends DistanceSelect {
c45e8d6b99a2 #315 Added new state for entering a kilometer range without step width.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
12
c45e8d6b99a2 #315 Added new state for entering a kilometer range without step width.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
13 private static Logger logger = Logger.getLogger(DistanceOnlySelect.class);
c45e8d6b99a2 #315 Added new state for entering a kilometer range without step width.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
14
c45e8d6b99a2 #315 Added new state for entering a kilometer range without step width.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
15 @Override
c45e8d6b99a2 #315 Added new state for entering a kilometer range without step width.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
16 protected String getUIProvider() {
c45e8d6b99a2 #315 Added new state for entering a kilometer range without step width.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
17 return "distance_only_panel";
c45e8d6b99a2 #315 Added new state for entering a kilometer range without step width.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
18 }
1630
cafd8af6734a Improved bounds validation for distance only states.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1625
diff changeset
19
cafd8af6734a Improved bounds validation for distance only states.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1625
diff changeset
20
cafd8af6734a Improved bounds validation for distance only states.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1625
diff changeset
21 @Override
cafd8af6734a Improved bounds validation for distance only states.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1625
diff changeset
22 public boolean validate(Artifact artifact)
cafd8af6734a Improved bounds validation for distance only states.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1625
diff changeset
23 throws IllegalArgumentException
cafd8af6734a Improved bounds validation for distance only states.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1625
diff changeset
24 {
4865
1358d0c8481c RangeState and descendants: Use RangeAccess, resolve direct ld_* usage.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1630
diff changeset
25 // TODO think about better hierarchy wrt RangeState#validate.
1630
cafd8af6734a Improved bounds validation for distance only states.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1625
diff changeset
26 FLYSArtifact flys = (FLYSArtifact) artifact;
cafd8af6734a Improved bounds validation for distance only states.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1625
diff changeset
27
cafd8af6734a Improved bounds validation for distance only states.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1625
diff changeset
28 try {
4865
1358d0c8481c RangeState and descendants: Use RangeAccess, resolve direct ld_* usage.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1630
diff changeset
29 RangeAccess rangeAccess = new RangeAccess(flys, null);
1358d0c8481c RangeState and descendants: Use RangeAccess, resolve direct ld_* usage.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1630
diff changeset
30 double from = rangeAccess.getFrom();
1358d0c8481c RangeState and descendants: Use RangeAccess, resolve direct ld_* usage.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1630
diff changeset
31 double to = rangeAccess.getTo();
1630
cafd8af6734a Improved bounds validation for distance only states.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1625
diff changeset
32
cafd8af6734a Improved bounds validation for distance only states.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1625
diff changeset
33 double[] minmax = getMinMax(flys);
cafd8af6734a Improved bounds validation for distance only states.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1625
diff changeset
34
cafd8af6734a Improved bounds validation for distance only states.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1625
diff changeset
35 return validateBounds(minmax[0], minmax[1], from, to);
cafd8af6734a Improved bounds validation for distance only states.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1625
diff changeset
36 }
cafd8af6734a Improved bounds validation for distance only states.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1625
diff changeset
37 catch (NumberFormatException nfe) {
cafd8af6734a Improved bounds validation for distance only states.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1625
diff changeset
38 throw new IllegalArgumentException("error_invalid_double_value");
cafd8af6734a Improved bounds validation for distance only states.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1625
diff changeset
39 }
4865
1358d0c8481c RangeState and descendants: Use RangeAccess, resolve direct ld_* usage.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1630
diff changeset
40 catch (NullPointerException npe) {
1358d0c8481c RangeState and descendants: Use RangeAccess, resolve direct ld_* usage.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1630
diff changeset
41 throw new IllegalArgumentException("error_empty_state");
1358d0c8481c RangeState and descendants: Use RangeAccess, resolve direct ld_* usage.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1630
diff changeset
42 }
1630
cafd8af6734a Improved bounds validation for distance only states.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1625
diff changeset
43 }
1625
c45e8d6b99a2 #315 Added new state for entering a kilometer range without step width.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
44 }
c45e8d6b99a2 #315 Added new state for entering a kilometer range without step width.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
45 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :

http://dive4elements.wald.intevation.org