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