annotate artifacts/src/main/java/org/dive4elements/river/exports/process/ManualPointsProcessor.java @ 8472:3f505fba522f

(issue1772) Use 0.001km tolarance instead of 0.1 to find matching km. There is no sense to use a define here. I will not write static final double NULLPOINTNULLNULLONE=0.001 if i just want to use that value and not any other value which may make sense in some other place. Using hardcoded values can have its merits and makes the code easier to read.
author Andre Heinecke <andre.heinecke@intevation.de>
date Tue, 18 Nov 2014 15:24:40 +0100
parents e4606eae8ea5
children 5e38e2924c07
rev   line source
7097
c64c04d0796e Move manual point handling into a Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
1 /* Copyright (C) 2013 by Bundesanstalt für Gewässerkunde
c64c04d0796e Move manual point handling into a Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
2 * Software engineering by Intevation GmbH
c64c04d0796e Move manual point handling into a Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
3 *
c64c04d0796e Move manual point handling into a Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
4 * This file is Free Software under the GNU AGPL (>=v3)
c64c04d0796e Move manual point handling into a Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
5 * and comes with ABSOLUTELY NO WARRANTY! Check out the
c64c04d0796e Move manual point handling into a Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
6 * documentation coming with Dive4Elements River for details.
c64c04d0796e Move manual point handling into a Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
7 */
c64c04d0796e Move manual point handling into a Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
8
c64c04d0796e Move manual point handling into a Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
9
c64c04d0796e Move manual point handling into a Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
10 package org.dive4elements.river.exports.process;
c64c04d0796e Move manual point handling into a Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
11
c64c04d0796e Move manual point handling into a Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
12 import org.apache.log4j.Logger;
c64c04d0796e Move manual point handling into a Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
13
c64c04d0796e Move manual point handling into a Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
14 import java.util.List;
c64c04d0796e Move manual point handling into a Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
15 import java.util.ArrayList;
c64c04d0796e Move manual point handling into a Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
16
c64c04d0796e Move manual point handling into a Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
17 import org.json.JSONArray;
c64c04d0796e Move manual point handling into a Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
18 import org.json.JSONException;
c64c04d0796e Move manual point handling into a Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
19
c64c04d0796e Move manual point handling into a Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
20 import org.jfree.data.xy.XYSeries;
c64c04d0796e Move manual point handling into a Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
21 import org.jfree.chart.annotations.XYTextAnnotation;
c64c04d0796e Move manual point handling into a Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
22
c64c04d0796e Move manual point handling into a Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
23 import org.dive4elements.artifactdatabase.state.ArtifactAndFacet;
c64c04d0796e Move manual point handling into a Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
24 import org.dive4elements.artifacts.CallContext;
c64c04d0796e Move manual point handling into a Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
25 import org.dive4elements.river.artifacts.model.FacetTypes;
c64c04d0796e Move manual point handling into a Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
26 import org.dive4elements.river.exports.DiagramGenerator;
c64c04d0796e Move manual point handling into a Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
27 import org.dive4elements.river.jfree.RiverAnnotation;
c64c04d0796e Move manual point handling into a Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
28 import org.dive4elements.river.jfree.CollisionFreeXYTextAnnotation;
c64c04d0796e Move manual point handling into a Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
29 import org.dive4elements.river.jfree.StyledXYSeries;
c64c04d0796e Move manual point handling into a Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
30 import org.dive4elements.river.themes.ThemeDocument;
c64c04d0796e Move manual point handling into a Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
31
c64c04d0796e Move manual point handling into a Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
32 public class ManualPointsProcessor extends DefaultProcessor {
c64c04d0796e Move manual point handling into a Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
33
8202
e4606eae8ea5 sed src/**/*.java 's/logger/log/g'
Sascha L. Teichmann <teichmann@intevation.de>
parents: 7097
diff changeset
34 private static final Logger log = Logger.getLogger(ManualPointsProcessor.class);
7097
c64c04d0796e Move manual point handling into a Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
35
c64c04d0796e Move manual point handling into a Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
36 @Override
c64c04d0796e Move manual point handling into a Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
37 public void doOut(
c64c04d0796e Move manual point handling into a Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
38 DiagramGenerator generator,
c64c04d0796e Move manual point handling into a Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
39 ArtifactAndFacet bundle,
c64c04d0796e Move manual point handling into a Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
40 ThemeDocument theme,
c64c04d0796e Move manual point handling into a Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
41 boolean visible) {
c64c04d0796e Move manual point handling into a Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
42 CallContext context = generator.getCallContext();
c64c04d0796e Move manual point handling into a Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
43 String seriesName = bundle.getFacetDescription();
c64c04d0796e Move manual point handling into a Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
44 XYSeries series = new StyledXYSeries(seriesName, theme);
c64c04d0796e Move manual point handling into a Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
45 String jsonData = (String) bundle.getData(context);
c64c04d0796e Move manual point handling into a Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
46
c64c04d0796e Move manual point handling into a Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
47 // Add text annotations for single points.
c64c04d0796e Move manual point handling into a Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
48 List<XYTextAnnotation> xy = new ArrayList<XYTextAnnotation>();
c64c04d0796e Move manual point handling into a Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
49
c64c04d0796e Move manual point handling into a Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
50 try {
c64c04d0796e Move manual point handling into a Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
51 JSONArray points = new JSONArray(jsonData);
c64c04d0796e Move manual point handling into a Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
52 for (int i = 0, P = points.length(); i < P; i++) {
c64c04d0796e Move manual point handling into a Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
53 JSONArray array = points.getJSONArray(i);
c64c04d0796e Move manual point handling into a Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
54 double x = array.getDouble(0);
c64c04d0796e Move manual point handling into a Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
55 double y = array.getDouble(1);
c64c04d0796e Move manual point handling into a Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
56 String name = array.getString(2);
c64c04d0796e Move manual point handling into a Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
57 boolean act = array.getBoolean(3);
c64c04d0796e Move manual point handling into a Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
58 if (!act) {
c64c04d0796e Move manual point handling into a Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
59 continue;
c64c04d0796e Move manual point handling into a Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
60 }
8202
e4606eae8ea5 sed src/**/*.java 's/logger/log/g'
Sascha L. Teichmann <teichmann@intevation.de>
parents: 7097
diff changeset
61 //log.debug(" x " + x + " y " + y );
7097
c64c04d0796e Move manual point handling into a Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
62 series.add(x, y, false);
c64c04d0796e Move manual point handling into a Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
63 xy.add(new CollisionFreeXYTextAnnotation(name, x, y));
c64c04d0796e Move manual point handling into a Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
64 }
c64c04d0796e Move manual point handling into a Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
65 }
c64c04d0796e Move manual point handling into a Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
66 catch(JSONException e){
8202
e4606eae8ea5 sed src/**/*.java 's/logger/log/g'
Sascha L. Teichmann <teichmann@intevation.de>
parents: 7097
diff changeset
67 log.error("Could not decode json.");
7097
c64c04d0796e Move manual point handling into a Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
68 }
c64c04d0796e Move manual point handling into a Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
69
c64c04d0796e Move manual point handling into a Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
70 RiverAnnotation annotation = new RiverAnnotation(null, null, null, theme);
c64c04d0796e Move manual point handling into a Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
71 annotation.setTextAnnotations(xy);
c64c04d0796e Move manual point handling into a Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
72
c64c04d0796e Move manual point handling into a Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
73 if (visible) {
c64c04d0796e Move manual point handling into a Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
74 generator.addAnnotations(annotation);
c64c04d0796e Move manual point handling into a Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
75 }
c64c04d0796e Move manual point handling into a Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
76
c64c04d0796e Move manual point handling into a Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
77 generator.addAxisSeries(series, axisName, visible);
c64c04d0796e Move manual point handling into a Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
78 }
c64c04d0796e Move manual point handling into a Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
79
c64c04d0796e Move manual point handling into a Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
80 @Override
c64c04d0796e Move manual point handling into a Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
81 public boolean canHandle(String facetType) {
c64c04d0796e Move manual point handling into a Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
82 if (facetType == null) {
c64c04d0796e Move manual point handling into a Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
83 return false;
c64c04d0796e Move manual point handling into a Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
84 }
c64c04d0796e Move manual point handling into a Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
85 return FacetTypes.IS.MANUALPOINTS(facetType);
c64c04d0796e Move manual point handling into a Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
86 }
c64c04d0796e Move manual point handling into a Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
87 }

http://dive4elements.wald.intevation.org