Mercurial > dive4elements > river
annotate artifacts/src/main/java/org/dive4elements/river/exports/process/AreaProcessor.java @ 7540:9344aa0fb021
Fixed logger instantiations that were done with wrong class.
author | Felix Wolfsteller <felix.wolfsteller@intevation.de> |
---|---|
date | Fri, 08 Nov 2013 10:38:37 +0100 |
parents | d07a8a36c4d4 |
children | dfe3f78fd3e5 |
rev | line source |
---|---|
7101 | 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 | |
15 import org.dive4elements.artifactdatabase.state.ArtifactAndFacet; | |
16 import org.dive4elements.artifacts.CallContext; | |
17 | |
18 import org.dive4elements.river.artifacts.geom.Lines; | |
19 import org.dive4elements.river.artifacts.model.WKms; | |
20 import org.dive4elements.river.artifacts.model.WQKms; | |
21 import org.dive4elements.river.artifacts.model.AreaFacet; | |
22 import org.dive4elements.river.artifacts.model.FacetTypes; | |
23 import org.dive4elements.river.exports.DiagramGenerator; | |
24 import org.dive4elements.river.exports.StyledSeriesBuilder; | |
25 import org.dive4elements.river.jfree.StyledAreaSeriesCollection; | |
26 import org.dive4elements.river.jfree.StyledXYSeries; | |
27 import org.dive4elements.river.themes.ThemeDocument; | |
28 | |
29 import org.jfree.data.xy.XYSeries; | |
30 | |
31 public class AreaProcessor extends DefaultProcessor { | |
32 | |
7540
9344aa0fb021
Fixed logger instantiations that were done with wrong class.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
7101
diff
changeset
|
33 private static final Logger logger = Logger.getLogger(AreaProcessor.class); |
7101 | 34 |
35 @Override | |
36 public void doOut( | |
37 DiagramGenerator generator, | |
38 ArtifactAndFacet bundle, | |
39 ThemeDocument theme, | |
40 boolean visible) { | |
41 CallContext context = generator.getCallContext(); | |
42 String seriesName = bundle.getFacetDescription(); | |
43 StyledAreaSeriesCollection area = new StyledAreaSeriesCollection(theme); | |
44 | |
45 logger.debug("Area Processor processing: " + seriesName); | |
46 | |
47 AreaFacet.Data data = (AreaFacet.Data) bundle.getData(context); | |
48 | |
49 XYSeries up = null; | |
50 XYSeries down = null; | |
51 | |
52 if (data.getUpperData() != null) { | |
53 up = new StyledXYSeries(seriesName, false, theme); | |
54 if (data.getUpperData() instanceof WQKms) { | |
55 if (FacetTypes.IS.Q(data.getRootFacetName())) { | |
56 StyledSeriesBuilder.addPointsKmQ(up, (WQKms) data.getUpperData()); | |
57 } | |
58 else { | |
59 StyledSeriesBuilder.addPoints(up, (WKms) data.getUpperData()); | |
60 } | |
61 } | |
62 else if (data.getUpperData() instanceof double[][]) { | |
63 StyledSeriesBuilder.addPoints(up, (double [][]) data.getUpperData(), false); | |
64 } | |
65 else if (data.getUpperData() instanceof WKms) { | |
66 StyledSeriesBuilder.addPoints(up, (WKms) data.getUpperData()); | |
67 } | |
68 else if (data.getUpperData() instanceof Lines.LineData) { | |
69 StyledSeriesBuilder.addPoints(up, ((Lines.LineData) data.getUpperData()).points, false); | |
70 } | |
71 else { | |
72 logger.error("Do not know how to deal with (up) area info from: " | |
73 + data.getUpperData()); | |
74 } | |
75 } | |
76 | |
77 // TODO Depending on style, the area (e.g. 20m^2) should be added as annotation. | |
78 | |
79 if (data.getLowerData() != null) { | |
80 // TODO: Sort this out: when the two series have the same name, | |
81 // the renderer (or anything in between) will not work correctly. | |
82 down = new StyledXYSeries(seriesName + " ", false, theme); | |
83 if (data.getLowerData() instanceof WQKms) { | |
84 if (FacetTypes.IS.Q(data.getRootFacetName())) { | |
85 StyledSeriesBuilder.addPointsKmQ(down, (WQKms) data.getLowerData()); | |
86 } | |
87 else { | |
88 StyledSeriesBuilder.addPoints(down, (WQKms) data.getLowerData()); | |
89 } | |
90 } | |
91 else if (data.getLowerData() instanceof double[][]) { | |
92 StyledSeriesBuilder.addPoints(down, (double[][]) data.getLowerData(), false); | |
93 } | |
94 else if (data.getLowerData() instanceof WKms) { | |
95 StyledSeriesBuilder.addPoints(down, (WKms) data.getLowerData()); | |
96 } | |
97 else if (data.getLowerData() instanceof Lines.LineData) { | |
98 StyledSeriesBuilder.addPoints(down, ((Lines.LineData) data.getLowerData()).points, false); | |
99 } | |
100 else { | |
101 logger.error("Do not know how to deal with (down) area info from: " | |
102 + data.getLowerData()); | |
103 } | |
104 } | |
105 | |
106 if (up == null && down != null) { | |
107 area.setMode(StyledAreaSeriesCollection.FILL_MODE.ABOVE); | |
108 down.setKey(seriesName); | |
109 area.addSeries(down); | |
110 area.addSeries(StyledSeriesBuilder.createGroundAtInfinity(down)); | |
111 } | |
112 else if (up != null && down == null) { | |
113 area.setMode(StyledAreaSeriesCollection.FILL_MODE.UNDER); | |
114 area.addSeries(up); | |
115 area.addSeries(StyledSeriesBuilder.createGroundAtInfinity(up)); | |
116 } | |
117 else if (up != null && down != null) { | |
118 if (data.doPaintBetween()) { | |
119 area.setMode(StyledAreaSeriesCollection.FILL_MODE.BETWEEN); | |
120 } | |
121 else { | |
122 area.setMode(StyledAreaSeriesCollection.FILL_MODE.ABOVE); | |
123 } | |
124 area.addSeries(up); | |
125 area.addSeries(down); | |
126 } | |
127 | |
128 /* Decide axis name based on facet name */ | |
129 generator.addAreaSeries(area, | |
130 axisNameForFacet(data.getRootFacetName()), visible); | |
131 } | |
132 | |
133 /** Look up the axis identifier for a given facet type. */ | |
134 private String axisNameForFacet(String facetName) { | |
135 if (FacetTypes.IS.W(facetName)) { | |
136 return "W"; | |
137 } | |
138 else if (FacetTypes.IS.Q(facetName)) { | |
139 return "Q"; | |
140 } | |
141 else { | |
142 logger.warn("Could not find axis for facet " + facetName); | |
143 return "W"; | |
144 } | |
145 } | |
146 | |
147 @Override | |
148 public boolean canHandle(String facetType) { | |
149 if (facetType == null) { | |
150 return false; | |
151 } | |
152 return FacetTypes.IS.AREA(facetType); | |
153 } | |
154 } |