Mercurial > dive4elements > river
view flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/WQSelect.java @ 321:9581b88f2920
Removed testing code that has been comitted by accident in the last revision.
flys-artifacts/trunk@1714 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Mon, 18 Apr 2011 09:34:18 +0000 |
parents | a8e7c351bdf1 |
children | 448d0dc64357 |
line wrap: on
line source
package de.intevation.flys.artifacts.states; import org.apache.log4j.Logger; import org.w3c.dom.Element; import de.intevation.artifacts.Artifact; import de.intevation.artifacts.CallContext; import de.intevation.artifacts.common.utils.XMLUtils; import de.intevation.artifactdatabase.ProtocolUtils; import de.intevation.artifactdatabase.data.StateData; import de.intevation.flys.model.Gauge; import de.intevation.flys.model.River; import de.intevation.flys.model.Wst; import de.intevation.flys.artifacts.FLYSArtifact; import de.intevation.flys.artifacts.model.WstFactory; import de.intevation.flys.artifacts.resources.Resources; /** * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> */ public class WQSelect extends DefaultState { /** The logger used in this class.*/ private static Logger logger = Logger.getLogger(WQSelect.class); /** The default step width for Qs.*/ public static final String DEFAULT_STEP_Q = "50"; /** The default step width for Qs.*/ public static final String DEFAULT_STEP_W = "30"; /** * The default constructor that initializes an empty State object. */ public WQSelect() { } protected Element createData( XMLUtils.ElementCreator cr, Artifact artifact, StateData data, CallContext context) { Element select = ProtocolUtils.createArtNode( cr, "select", null, null); cr.addAttr(select, "name", data.getName(), true); Element label = ProtocolUtils.createArtNode( cr, "label", null, null); Element choices = ProtocolUtils.createArtNode( cr, "choices", null, null); label.setTextContent(Resources.getMsg( context.getMeta(), data.getName(), data.getName())); select.appendChild(label); return select; } protected Element[] createItems( XMLUtils.ElementCreator cr, Artifact artifact, String name, CallContext context) { // TODO Insert correct min/max values! double[] minmaxW = determineMinMaxW(artifact); double[] minmaxQ = determineMinMaxQ(artifact); if (name.equals("wq_from")) { Element minW = createItem( cr, new String[] {"minW", new Double(minmaxW[0]).toString()}); Element minQ = createItem( cr, new String[] {"minQ", new Double(minmaxQ[0]).toString()}); return new Element[] { minW, minQ }; } else if (name.equals("wq_to")) { Element maxW = createItem( cr, new String[] {"maxW", new Double(minmaxW[1]).toString()}); Element maxQ = createItem( cr, new String[] {"maxQ", new Double(minmaxQ[1]).toString()}); return new Element[] { maxW, maxQ }; } else { Element stepW = createItem(cr, new String[] {"stepW", DEFAULT_STEP_W}); Element stepQ = createItem(cr, new String[] {"stepQ", DEFAULT_STEP_Q}); return new Element[] { stepW, stepQ }; } } 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; } protected String getUIProvider() { return "wq_panel"; } /** * Determines the min and max W value for the current gauge. If no min and * max values could be determined, this method will return * [Double.MIN_VALUE, Double.MAX_VALUE]. * * @param artifact The FLYSArtifact. * * @return the min and max W values for the current gauge. */ protected double[] determineMinMaxW(Artifact artifact) { logger.debug("WQSelect.determineCurrentGauge"); Gauge gauge = ((FLYSArtifact) artifact).getGauge(); double[] minmaxW = gauge != null ? gauge.determineMinMaxW() : null; double minW = minmaxW != null ? minmaxW[0] : Double.MIN_VALUE; double maxW = minmaxW != null ? minmaxW[1] : Double.MAX_VALUE; return new double[] { minW, maxW }; } /** * Determines the min and max Q value for the current gauge. If no min and * max values could be determined, this method will return * [Double.MIN_VALUE, Double.MAX_VALUE]. * * @param artifact The FLYSArtifact. * * @return the min and max Q values for the current gauge. */ protected double[] determineMinMaxQ(Artifact artifact) { logger.debug("WQSelect.determineMinMaxQ"); FLYSArtifact flysArtifact = (FLYSArtifact) artifact; River river = flysArtifact.getRiver(); Gauge gauge = flysArtifact.getGauge(); Wst wst = WstFactory.getWst(river); double[] minmaxQ = gauge != null ? wst.determineMinMaxQ(gauge.getRange()) : null; double minQ = minmaxQ != null ? minmaxQ[0] : Double.MIN_VALUE; double maxQ = minmaxQ != null ? minmaxQ[1] : Double.MAX_VALUE; return new double[] { minQ, maxQ }; } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :