Mercurial > dive4elements > river
view flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/WQAdapted.java @ 414:0385bcc4229a
Added subtitles to the available charts.
flys-artifacts/trunk@1878 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Tue, 10 May 2011 12:19:17 +0000 |
parents | 34de11dcf355 |
children | e54053bc0e70 |
line wrap: on
line source
package de.intevation.flys.artifacts.states; import java.util.List; import org.apache.log4j.Logger; import org.w3c.dom.Element; import de.intevation.artifacts.Artifact; import de.intevation.artifacts.CallContext; import de.intevation.artifactdatabase.ProtocolUtils; import de.intevation.artifacts.common.utils.XMLUtils; import de.intevation.flys.model.Gauge; import de.intevation.flys.model.Range; import de.intevation.flys.artifacts.FLYSArtifact; /** * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> */ public class WQAdapted extends DefaultState { /** The logger used in this state.*/ private static Logger logger = Logger.getLogger(WQAdapted.class); public static final String FIELD_WQ_MODE = "wq_mode"; public static final String FIELD_WQ_VALUES = "wq_values"; /** * This method creates one element for each gauge of the selected river that * is intersected by the given kilometer range. Each element is a tuple of * (from;to) where <i>from</i> is the lower bounds of the gauge or the lower * kilometer range. <i>to</i> is the upper bounds of the gauge or the upper * kilometer range. * * @param cr The ElementCreator. * @param artifact The FLYS artifact. * @param name The name of the data item. * @param context The CallContext. * * @return a list of elements that consist of tuples of the intersected * gauges of the selected river. */ protected Element[] createItems( XMLUtils.ElementCreator cr, Artifact artifact, String name, CallContext context) { logger.debug("WQAdapted.createItems"); if (name != null && name.equals(FIELD_WQ_MODE)) { return createModeItems(cr, artifact, name, context); } else if (name != null && name.equals(FIELD_WQ_VALUES)) { return createValueItems(cr, artifact, name, context); } else { logger.warn("Unknown data object: " + name); return null; } } protected Element[] createModeItems( XMLUtils.ElementCreator cr, Artifact artifact, String name, CallContext context) { logger.debug("WQAdapted.createModeItems"); Element w = createItem(cr, new String[] { "w", "W" }); Element q = createItem(cr, new String[] { "q", "Q" }); return new Element[] { w, q }; } protected Element[] createValueItems( XMLUtils.ElementCreator cr, Artifact artifact, String name, CallContext context) { logger.debug("WQAdapted.createValueItems"); FLYSArtifact flysArtifact = (FLYSArtifact) artifact; double[] dist = flysArtifact.getDistance(); List<Gauge> gauges = flysArtifact.getGauges(); int num = gauges != null ? gauges.size() : 0; if (num == 0) { logger.warn("Selected distance matches no gauges."); return null; } Element[] elements = new Element[num]; int idx = 0; for (Gauge gauge: gauges) { Range range = gauge.getRange(); double lower = range.getA().doubleValue(); double upper = range.getB().doubleValue(); double from = dist[0] < lower ? lower : dist[0]; double to = dist[1] > upper ? upper : dist[1]; String key = Double.toString(from) + ";" + Double.toString(to); elements[idx++] = createItem(cr, new String[] {key, ""}); } return elements; } protected Element createItem(XMLUtils.ElementCreator cr, Object obj) { Element item = ProtocolUtils.createArtNode(cr, "item", null, null); Element label = ProtocolUtils.createArtNode(cr, "label", null, null); Element value = ProtocolUtils.createArtNode(cr, "value", null, null); String[] arr = (String[]) obj; label.setTextContent(arr[0]); value.setTextContent(arr[1]); item.appendChild(label); item.appendChild(value); return item; } @Override protected String getUIProvider() { return "wq_panel_adapted"; } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :