annotate artifacts/src/main/java/org/dive4elements/river/exports/process/ManualPointsProcessor.java @ 9556:9b8e8fc1f408

Use facetName in all processors as themeType for legend aggregation.
author gernotbelger
date Tue, 23 Oct 2018 16:26:58 +0200
parents 1cc7653ca84f
children
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
8856
5e38e2924c07 Fix code style.
Tom Gottfried <tom@intevation.de>
parents: 8202
diff changeset
34 private static final Logger log = Logger.getLogger(
5e38e2924c07 Fix code style.
Tom Gottfried <tom@intevation.de>
parents: 8202
diff changeset
35 ManualPointsProcessor.class);
7097
c64c04d0796e Move manual point handling into a Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
36
c64c04d0796e Move manual point handling into a Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
37 @Override
c64c04d0796e Move manual point handling into a Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
38 public void doOut(
c64c04d0796e Move manual point handling into a Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
39 DiagramGenerator generator,
c64c04d0796e Move manual point handling into a Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
40 ArtifactAndFacet bundle,
c64c04d0796e Move manual point handling into a Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
41 ThemeDocument theme,
c64c04d0796e Move manual point handling into a Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
42 boolean visible) {
9123
1cc7653ca84f Cleanup of ChartGenerator and ChartGenerator2 code. Put some of the copy/pasted code into a common abstraction.
gernotbelger
parents: 8856
diff changeset
43 CallContext context = generator.getContext();
7097
c64c04d0796e Move manual point handling into a Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
44 String seriesName = bundle.getFacetDescription();
9556
9b8e8fc1f408 Use facetName in all processors as themeType for legend aggregation.
gernotbelger
parents: 9123
diff changeset
45 XYSeries series = new StyledXYSeries(bundle.getFacetName(), seriesName, theme);
7097
c64c04d0796e Move manual point handling into a Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
46 String jsonData = (String) bundle.getData(context);
c64c04d0796e Move manual point handling into a Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
47
c64c04d0796e Move manual point handling into a Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
48 // Add text annotations for single points.
c64c04d0796e Move manual point handling into a Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
49 List<XYTextAnnotation> xy = new ArrayList<XYTextAnnotation>();
c64c04d0796e Move manual point handling into a Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
50
c64c04d0796e Move manual point handling into a Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
51 try {
c64c04d0796e Move manual point handling into a Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
52 JSONArray points = new JSONArray(jsonData);
c64c04d0796e Move manual point handling into a Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
53 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
54 JSONArray array = points.getJSONArray(i);
c64c04d0796e Move manual point handling into a Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
55 double x = array.getDouble(0);
c64c04d0796e Move manual point handling into a Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
56 double y = array.getDouble(1);
c64c04d0796e Move manual point handling into a Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
57 String name = array.getString(2);
c64c04d0796e Move manual point handling into a Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
58 boolean act = array.getBoolean(3);
c64c04d0796e Move manual point handling into a Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
59 if (!act) {
c64c04d0796e Move manual point handling into a Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
60 continue;
c64c04d0796e Move manual point handling into a Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
61 }
8202
e4606eae8ea5 sed src/**/*.java 's/logger/log/g'
Sascha L. Teichmann <teichmann@intevation.de>
parents: 7097
diff changeset
62 //log.debug(" x " + x + " y " + y );
7097
c64c04d0796e Move manual point handling into a Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
63 series.add(x, y, false);
c64c04d0796e Move manual point handling into a Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
64 xy.add(new CollisionFreeXYTextAnnotation(name, x, y));
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 }
c64c04d0796e Move manual point handling into a Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
67 catch(JSONException e){
8202
e4606eae8ea5 sed src/**/*.java 's/logger/log/g'
Sascha L. Teichmann <teichmann@intevation.de>
parents: 7097
diff changeset
68 log.error("Could not decode json.");
7097
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
8856
5e38e2924c07 Fix code style.
Tom Gottfried <tom@intevation.de>
parents: 8202
diff changeset
71 RiverAnnotation annotation = new RiverAnnotation(
5e38e2924c07 Fix code style.
Tom Gottfried <tom@intevation.de>
parents: 8202
diff changeset
72 null, null, null, theme);
7097
c64c04d0796e Move manual point handling into a Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
73 annotation.setTextAnnotations(xy);
c64c04d0796e Move manual point handling into a Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
74
c64c04d0796e Move manual point handling into a Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
75 if (visible) {
c64c04d0796e Move manual point handling into a Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
76 generator.addAnnotations(annotation);
c64c04d0796e Move manual point handling into a Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
77 }
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 generator.addAxisSeries(series, axisName, visible);
c64c04d0796e Move manual point handling into a Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
80 }
c64c04d0796e Move manual point handling into a Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
81
c64c04d0796e Move manual point handling into a Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
82 @Override
c64c04d0796e Move manual point handling into a Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
83 public boolean canHandle(String facetType) {
c64c04d0796e Move manual point handling into a Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
84 if (facetType == null) {
c64c04d0796e Move manual point handling into a Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
85 return false;
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 return FacetTypes.IS.MANUALPOINTS(facetType);
c64c04d0796e Move manual point handling into a Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
88 }
c64c04d0796e Move manual point handling into a Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
89 }

http://dive4elements.wald.intevation.org