felix@2001: package de.intevation.flys.artifacts.model;
felix@2001:
felix@2001: import java.util.List;
felix@2001:
felix@2001: import org.apache.log4j.Logger;
felix@2001:
felix@2001: import de.intevation.artifacts.Artifact;
felix@2001: import de.intevation.artifacts.CallContext;
felix@2001:
felix@2001: import de.intevation.artifactdatabase.state.DefaultFacet;
felix@2001: import de.intevation.artifactdatabase.state.Facet;
felix@2001:
felix@2001: import de.intevation.artifacts.DataProvider;
felix@2001:
felix@2001: import de.intevation.flys.artifacts.AreaArtifact;
felix@2001:
felix@2001:
felix@2001: /**
felix@2001: * Trival Facet for areas.
felix@2018: * Note that this Facet comes in two "types" (names):
felix@2018: *
felix@2018: * - CROSS_SECTION_AREA (cross_section.area) and
felix@2018: * - LONGITUDINAL_SECTION_AREA (longitudinal.area
felix@2018: *
felix@2018: * This is to support different diagram types without being painted in both
felix@2018: * at the same time. The name has to be given when constructing.
felix@2001: */
felix@2001: public class AreaFacet
felix@2001: extends DefaultFacet
sascha@3774: {
felix@2001: private static Logger logger = Logger.getLogger(AreaFacet.class);
felix@2001:
felix@2018: /**
felix@2018: * Constructor, set (maybe localized) description and name.
felix@2018: * @param idx Index given when querying artifact for data.
felix@2018: * @param name important to discern areas in different diagram types.
felix@2018: */
felix@2018: public AreaFacet(int idx, String name, String description) {
felix@2018: super(idx, name, description);
felix@2001: }
felix@2001:
felix@2001:
felix@2001: /**
felix@2001: * Gets Cross Section (profile).
felix@2001: * @param art artifact to get data from.
felix@2001: * @param context ignored
felix@2001: */
felix@2001: public Object getData(Artifact art, CallContext context) {
felix@2010: logger.debug("Get data for area.");
felix@2001:
felix@2001: // Get information from artifact about which
felix@2001: // info to grab from blackboard.
felix@2001: //
felix@2001: // All compatible facets should provide their data
felix@2001: // under the key (Artifact-UUID + Facet-Index).
felix@2001: AreaArtifact artifact = (AreaArtifact) art;
felix@2001: Object lowerData = null;
felix@2001: Object upperData = null;
felix@2104: String stemFacetName = null;
felix@2001:
felix@2001: List providers = context.
felix@2001: getDataProvider(artifact.getLowerDPKey());
felix@2001: if (providers.size() < 1) {
sascha@3076: logger.warn("No 'lower' provider given for area [" +
felix@2018: artifact.getLowerDPKey() + "]");
felix@2001: }
felix@2001: else {
felix@2001: lowerData = providers.get(0).provideData(
felix@2001: artifact.getLowerDPKey(), null, context);
sascha@3076: logger.debug("'Lower' data provider key for area [" +
felix@2104: artifact.getLowerDPKey() + "]");
felix@2104: stemFacetName = artifact.getLowerDPKey().split(":")[1];
felix@2001: }
felix@2001:
felix@2001: providers = context.getDataProvider(artifact.getUpperDPKey());
felix@2001: if (providers.size() < 1) {
felix@2018: logger.warn("No 'upper' provider given for area [" +
felix@2018: artifact.getUpperDPKey() + "]");
felix@2001: }
felix@2001: else {
felix@2001: upperData = providers.get(0).provideData(
felix@2001: artifact.getUpperDPKey(), null, context);
felix@2104: logger.debug("'Upper' data provider key for area [" +
felix@2104: artifact.getUpperDPKey() + "]");
felix@2104: if (stemFacetName == null) {
felix@2104: stemFacetName = artifact.getUpperDPKey().split(":")[1];
felix@2104: }
felix@2001: }
felix@2001:
felix@2001: if (upperData == null && lowerData == null) {
felix@2010: logger.warn("Not given 'upper' and 'lower' for area");
felix@2001: }
felix@2001:
felix@2104: return new Data(stemFacetName, lowerData, upperData,
felix@2104: Boolean.valueOf(artifact.getPaintBetween()));
felix@2001: }
felix@2001:
felix@2001:
felix@2001: /** Do a deep copy. */
sascha@3076: @Override
felix@2001: public Facet deepCopy() {
felix@2018: AreaFacet copy = new AreaFacet(this.index, this.name, this.description);
felix@2001: copy.set(this);
felix@2001: return copy;
felix@2001: }
felix@2104:
felix@2104: /** Result data bundle. */
felix@2104: public class Data {
felix@2104: protected String rootFacetName;
felix@2104: protected Object upperData;
felix@2104: protected Object lowerData;
felix@2104: protected boolean doPaintBetween;
felix@2104:
felix@2104: /** Create a new result data bundle. */
felix@2104: public Data(String rootName, Object low, Object up, boolean between) {
felix@2104: this.rootFacetName = rootName;
felix@2104: this.lowerData = low;
felix@2104: this.upperData = up;
felix@2104: this.doPaintBetween = between;
felix@2104: }
felix@2104:
felix@2104: /** Get name of a facet that is involved in area generation
felix@2104: * to induce type (e.g. longitudinal_section.w -> "W over km"). */
felix@2104: public String getRootFacetName() {
felix@2104: return this.rootFacetName;
felix@2104: }
felix@2104:
felix@2104: /** Get data for 'upper' curve of area. */
felix@2104: public Object getUpperData() {
felix@2104: return this.upperData;
felix@2104: }
felix@2104:
felix@2104: /** Get data for 'lower' curve of area. */
felix@2104: public Object getLowerData() {
felix@2104: return this.lowerData;
felix@2104: }
felix@2104:
felix@2104: /** Whether to fill whole area between (in contrast to 'under'
felix@2104: * or 'over'). */
felix@2104: public boolean doPaintBetween() {
felix@2104: return this.doPaintBetween;
felix@2104: }
felix@2104: }
felix@2001: }
felix@2001: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :