comparison artifacts/src/main/java/org/dive4elements/river/artifacts/model/AreaFacet.java @ 5838:5aa05a7a34b7

Rename modules to more fitting names.
author Sascha L. Teichmann <teichmann@intevation.de>
date Thu, 25 Apr 2013 15:23:37 +0200
parents flys-artifacts/src/main/java/org/dive4elements/river/artifacts/model/AreaFacet.java@bd047b71ab37
children 4897a58c8746
comparison
equal deleted inserted replaced
5837:d9901a08d0a6 5838:5aa05a7a34b7
1 package org.dive4elements.river.artifacts.model;
2
3 import java.util.List;
4
5 import org.apache.log4j.Logger;
6
7 import org.dive4elements.artifacts.Artifact;
8 import org.dive4elements.artifacts.CallContext;
9
10 import org.dive4elements.artifactdatabase.state.DefaultFacet;
11 import org.dive4elements.artifactdatabase.state.Facet;
12
13 import org.dive4elements.artifacts.DataProvider;
14
15 import org.dive4elements.river.artifacts.AreaArtifact;
16
17
18 /**
19 * Trival Facet for areas.
20 * Note that this Facet comes in two "types" (names):
21 * <ul>
22 * <li>CROSS_SECTION_AREA (cross_section.area) and</li>
23 * <li>LONGITUDINAL_SECTION_AREA (longitudinal.area</li>
24 * </ul>
25 * This is to support different diagram types without being painted in both
26 * at the same time. The name has to be given when constructing.
27 */
28 public class AreaFacet
29 extends DefaultFacet
30 {
31 private static Logger logger = Logger.getLogger(AreaFacet.class);
32
33 /**
34 * Constructor, set (maybe localized) description and name.
35 * @param idx Index given when querying artifact for data.
36 * @param name important to discern areas in different diagram types.
37 */
38 public AreaFacet(int idx, String name, String description) {
39 super(idx, name, description);
40 }
41
42
43 /**
44 * Gets Cross Section (profile).
45 * @param art artifact to get data from.
46 * @param context ignored
47 */
48 public Object getData(Artifact art, CallContext context) {
49 logger.debug("Get data for area.");
50
51 // Get information from artifact about which
52 // info to grab from blackboard.
53 //
54 // All compatible facets should provide their data
55 // under the key (Artifact-UUID + Facet-Index).
56 AreaArtifact artifact = (AreaArtifact) art;
57 Object lowerData = null;
58 Object upperData = null;
59 String stemFacetName = null;
60
61 List<DataProvider> providers = context.
62 getDataProvider(artifact.getLowerDPKey());
63 if (providers.size() < 1) {
64 logger.warn("No 'lower' provider given for area [" +
65 artifact.getLowerDPKey() + "]");
66 }
67 else {
68 lowerData = providers.get(0).provideData(
69 artifact.getLowerDPKey(), null, context);
70 logger.debug("'Lower' data provider key for area [" +
71 artifact.getLowerDPKey() + "]");
72 stemFacetName = artifact.getLowerDPKey().split(":")[1];
73 }
74
75 providers = context.getDataProvider(artifact.getUpperDPKey());
76 if (providers.size() < 1) {
77 logger.warn("No 'upper' provider given for area [" +
78 artifact.getUpperDPKey() + "]");
79 }
80 else {
81 upperData = providers.get(0).provideData(
82 artifact.getUpperDPKey(), null, context);
83 logger.debug("'Upper' data provider key for area [" +
84 artifact.getUpperDPKey() + "]");
85 if (stemFacetName == null) {
86 stemFacetName = artifact.getUpperDPKey().split(":")[1];
87 }
88 }
89
90 if (upperData == null && lowerData == null) {
91 logger.warn("Not given 'upper' and 'lower' for area");
92 }
93
94 return new Data(stemFacetName, lowerData, upperData,
95 Boolean.valueOf(artifact.getPaintBetween()));
96 }
97
98
99 /** Do a deep copy. */
100 @Override
101 public Facet deepCopy() {
102 AreaFacet copy = new AreaFacet(this.index, this.name, this.description);
103 copy.set(this);
104 return copy;
105 }
106
107 /** Result data bundle. */
108 public class Data {
109 protected String rootFacetName;
110 protected Object upperData;
111 protected Object lowerData;
112 protected boolean doPaintBetween;
113
114 /** Create a new result data bundle. */
115 public Data(String rootName, Object low, Object up, boolean between) {
116 this.rootFacetName = rootName;
117 this.lowerData = low;
118 this.upperData = up;
119 this.doPaintBetween = between;
120 }
121
122 /** Get name of a facet that is involved in area generation
123 * to induce type (e.g. longitudinal_section.w -> "W over km"). */
124 public String getRootFacetName() {
125 return this.rootFacetName;
126 }
127
128 /** Get data for 'upper' curve of area. */
129 public Object getUpperData() {
130 return this.upperData;
131 }
132
133 /** Get data for 'lower' curve of area. */
134 public Object getLowerData() {
135 return this.lowerData;
136 }
137
138 /** Whether to fill whole area between (in contrast to 'under'
139 * or 'over'). */
140 public boolean doPaintBetween() {
141 return this.doPaintBetween;
142 }
143 }
144 }
145 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org