annotate artifacts/src/main/java/org/dive4elements/river/exports/process/ManualPointsProcessor.java @ 9801:1d7a72a50183 3.2.x tip

Assume Compose V2, consistently
author Tom Gottfried <tom@intevation.de>
date Thu, 23 Nov 2023 10:14:13 +0100
parents 0a5239a1e46e
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
9726
0a5239a1e46e Upgrade to Log4j 2
Tom Gottfried <tom@intevation.de>
parents: 8856
diff changeset
12 import org.apache.logging.log4j.Logger;
0a5239a1e46e Upgrade to Log4j 2
Tom Gottfried <tom@intevation.de>
parents: 8856
diff changeset
13 import org.apache.logging.log4j.LogManager;
7097
c64c04d0796e Move manual point handling into a Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
14
c64c04d0796e Move manual point handling into a Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
15 import java.util.List;
c64c04d0796e Move manual point handling into a Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
16 import java.util.ArrayList;
c64c04d0796e Move manual point handling into a Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
17
c64c04d0796e Move manual point handling into a Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
18 import org.json.JSONArray;
c64c04d0796e Move manual point handling into a Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
19 import org.json.JSONException;
c64c04d0796e Move manual point handling into a Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
20
c64c04d0796e Move manual point handling into a Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
21 import org.jfree.data.xy.XYSeries;
c64c04d0796e Move manual point handling into a Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
22 import org.jfree.chart.annotations.XYTextAnnotation;
c64c04d0796e Move manual point handling into a Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
23
c64c04d0796e Move manual point handling into a Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
24 import org.dive4elements.artifactdatabase.state.ArtifactAndFacet;
c64c04d0796e Move manual point handling into a Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
25 import org.dive4elements.artifacts.CallContext;
c64c04d0796e Move manual point handling into a Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
26 import org.dive4elements.river.artifacts.model.FacetTypes;
c64c04d0796e Move manual point handling into a Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
27 import org.dive4elements.river.exports.DiagramGenerator;
c64c04d0796e Move manual point handling into a Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
28 import org.dive4elements.river.jfree.RiverAnnotation;
c64c04d0796e Move manual point handling into a Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
29 import org.dive4elements.river.jfree.CollisionFreeXYTextAnnotation;
c64c04d0796e Move manual point handling into a Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
30 import org.dive4elements.river.jfree.StyledXYSeries;
c64c04d0796e Move manual point handling into a Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
31 import org.dive4elements.river.themes.ThemeDocument;
c64c04d0796e Move manual point handling into a Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
32
c64c04d0796e Move manual point handling into a Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
33 public class ManualPointsProcessor extends DefaultProcessor {
c64c04d0796e Move manual point handling into a Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
34
9726
0a5239a1e46e Upgrade to Log4j 2
Tom Gottfried <tom@intevation.de>
parents: 8856
diff changeset
35 private static final Logger log = LogManager.getLogger(
8856
5e38e2924c07 Fix code style.
Tom Gottfried <tom@intevation.de>
parents: 8202
diff changeset
36 ManualPointsProcessor.class);
7097
c64c04d0796e Move manual point handling into a Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
37
c64c04d0796e Move manual point handling into a Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
38 @Override
c64c04d0796e Move manual point handling into a Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
39 public void doOut(
c64c04d0796e Move manual point handling into a Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
40 DiagramGenerator generator,
c64c04d0796e Move manual point handling into a Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
41 ArtifactAndFacet bundle,
c64c04d0796e Move manual point handling into a Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
42 ThemeDocument theme,
c64c04d0796e Move manual point handling into a Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
43 boolean visible) {
c64c04d0796e Move manual point handling into a Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
44 CallContext context = generator.getCallContext();
c64c04d0796e Move manual point handling into a Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
45 String seriesName = bundle.getFacetDescription();
c64c04d0796e Move manual point handling into a Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
46 XYSeries series = new StyledXYSeries(seriesName, theme);
c64c04d0796e Move manual point handling into a Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
47 String jsonData = (String) bundle.getData(context);
c64c04d0796e Move manual point handling into a Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
48
c64c04d0796e Move manual point handling into a Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
49 // Add text annotations for single points.
c64c04d0796e Move manual point handling into a Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
50 List<XYTextAnnotation> xy = new ArrayList<XYTextAnnotation>();
c64c04d0796e Move manual point handling into a Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
51
c64c04d0796e Move manual point handling into a Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
52 try {
c64c04d0796e Move manual point handling into a Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
53 JSONArray points = new JSONArray(jsonData);
c64c04d0796e Move manual point handling into a Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
54 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
55 JSONArray array = points.getJSONArray(i);
c64c04d0796e Move manual point handling into a Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
56 double x = array.getDouble(0);
c64c04d0796e Move manual point handling into a Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
57 double y = array.getDouble(1);
c64c04d0796e Move manual point handling into a Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
58 String name = array.getString(2);
c64c04d0796e Move manual point handling into a Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
59 boolean act = array.getBoolean(3);
c64c04d0796e Move manual point handling into a Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
60 if (!act) {
c64c04d0796e Move manual point handling into a Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
61 continue;
c64c04d0796e Move manual point handling into a Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
62 }
8202
e4606eae8ea5 sed src/**/*.java 's/logger/log/g'
Sascha L. Teichmann <teichmann@intevation.de>
parents: 7097
diff changeset
63 //log.debug(" x " + x + " y " + y );
7097
c64c04d0796e Move manual point handling into a Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
64 series.add(x, y, false);
c64c04d0796e Move manual point handling into a Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
65 xy.add(new CollisionFreeXYTextAnnotation(name, x, y));
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 }
c64c04d0796e Move manual point handling into a Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
68 catch(JSONException e){
8202
e4606eae8ea5 sed src/**/*.java 's/logger/log/g'
Sascha L. Teichmann <teichmann@intevation.de>
parents: 7097
diff changeset
69 log.error("Could not decode json.");
7097
c64c04d0796e Move manual point handling into a Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
70 }
c64c04d0796e Move manual point handling into a Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
71
8856
5e38e2924c07 Fix code style.
Tom Gottfried <tom@intevation.de>
parents: 8202
diff changeset
72 RiverAnnotation annotation = new RiverAnnotation(
5e38e2924c07 Fix code style.
Tom Gottfried <tom@intevation.de>
parents: 8202
diff changeset
73 null, null, null, theme);
7097
c64c04d0796e Move manual point handling into a Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
74 annotation.setTextAnnotations(xy);
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 if (visible) {
c64c04d0796e Move manual point handling into a Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
77 generator.addAnnotations(annotation);
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 generator.addAxisSeries(series, axisName, visible);
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
c64c04d0796e Move manual point handling into a Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
83 @Override
c64c04d0796e Move manual point handling into a Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
84 public boolean canHandle(String facetType) {
c64c04d0796e Move manual point handling into a Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
85 if (facetType == null) {
c64c04d0796e Move manual point handling into a Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
86 return false;
c64c04d0796e Move manual point handling into a Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
87 }
c64c04d0796e Move manual point handling into a Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
88 return FacetTypes.IS.MANUALPOINTS(facetType);
c64c04d0796e Move manual point handling into a Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
89 }
c64c04d0796e Move manual point handling into a Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
90 }

http://dive4elements.wald.intevation.org