comparison artifacts/src/main/java/org/dive4elements/river/exports/process/ManualPointsProcessor.java @ 7097:c64c04d0796e generator-refactoring

Move manual point handling into a Processor
author Andre Heinecke <aheinecke@intevation.de>
date Mon, 23 Sep 2013 12:21:08 +0200
parents
children e4606eae8ea5
comparison
equal deleted inserted replaced
7096:5c059c05b100 7097:c64c04d0796e
1 /* Copyright (C) 2013 by Bundesanstalt für Gewässerkunde
2 * Software engineering by Intevation GmbH
3 *
4 * This file is Free Software under the GNU AGPL (>=v3)
5 * and comes with ABSOLUTELY NO WARRANTY! Check out the
6 * documentation coming with Dive4Elements River for details.
7 */
8
9
10 package org.dive4elements.river.exports.process;
11
12 import org.apache.log4j.Logger;
13
14 import java.util.List;
15 import java.util.ArrayList;
16
17 import org.json.JSONArray;
18 import org.json.JSONException;
19
20 import org.jfree.data.xy.XYSeries;
21 import org.jfree.chart.annotations.XYTextAnnotation;
22
23 import org.dive4elements.artifactdatabase.state.ArtifactAndFacet;
24 import org.dive4elements.artifacts.CallContext;
25 import org.dive4elements.river.artifacts.model.FacetTypes;
26 import org.dive4elements.river.exports.DiagramGenerator;
27 import org.dive4elements.river.jfree.RiverAnnotation;
28 import org.dive4elements.river.jfree.CollisionFreeXYTextAnnotation;
29 import org.dive4elements.river.jfree.StyledXYSeries;
30 import org.dive4elements.river.themes.ThemeDocument;
31
32 public class ManualPointsProcessor extends DefaultProcessor {
33
34 private static final Logger logger = Logger.getLogger(ManualPointsProcessor.class);
35
36 @Override
37 public void doOut(
38 DiagramGenerator generator,
39 ArtifactAndFacet bundle,
40 ThemeDocument theme,
41 boolean visible) {
42 CallContext context = generator.getCallContext();
43 String seriesName = bundle.getFacetDescription();
44 XYSeries series = new StyledXYSeries(seriesName, theme);
45 String jsonData = (String) bundle.getData(context);
46
47 // Add text annotations for single points.
48 List<XYTextAnnotation> xy = new ArrayList<XYTextAnnotation>();
49
50 try {
51 JSONArray points = new JSONArray(jsonData);
52 for (int i = 0, P = points.length(); i < P; i++) {
53 JSONArray array = points.getJSONArray(i);
54 double x = array.getDouble(0);
55 double y = array.getDouble(1);
56 String name = array.getString(2);
57 boolean act = array.getBoolean(3);
58 if (!act) {
59 continue;
60 }
61 //logger.debug(" x " + x + " y " + y );
62 series.add(x, y, false);
63 xy.add(new CollisionFreeXYTextAnnotation(name, x, y));
64 }
65 }
66 catch(JSONException e){
67 logger.error("Could not decode json.");
68 }
69
70 RiverAnnotation annotation = new RiverAnnotation(null, null, null, theme);
71 annotation.setTextAnnotations(xy);
72
73 if (visible) {
74 generator.addAnnotations(annotation);
75 }
76
77 generator.addAxisSeries(series, axisName, visible);
78 }
79
80 @Override
81 public boolean canHandle(String facetType) {
82 if (facetType == null) {
83 return false;
84 }
85 return FacetTypes.IS.MANUALPOINTS(facetType);
86 }
87 }

http://dive4elements.wald.intevation.org