Mercurial > dive4elements > river
changeset 2953:75e9eab05ee4
Added overview chart to sq relation period input panel.
flys-client/trunk@4932 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Raimund Renkert <raimund.renkert@intevation.de> |
---|---|
date | Wed, 11 Jul 2012 11:24:27 +0000 |
parents | 3cacd42a0336 |
children | b9433322fcaf |
files | flys-client/ChangeLog flys-client/src/main/java/de/intevation/flys/client/client/ui/UIProviderFactory.java flys-client/src/main/java/de/intevation/flys/client/client/ui/sq/SQMultiPeriodPanel.java flys-client/src/main/java/de/intevation/flys/client/server/SQKMChartServiceImpl.java flys-client/src/main/webapp/WEB-INF/web.xml |
diffstat | 5 files changed, 239 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/flys-client/ChangeLog Wed Jul 11 10:57:24 2012 +0000 +++ b/flys-client/ChangeLog Wed Jul 11 11:24:27 2012 +0000 @@ -1,3 +1,17 @@ +2012-07-11 Raimund Renkert <raimund.renkert@intevation.de> + + * src/main/java/de/intevation/flys/client/server/SQKMChartServiceImpl.java: + New. Service to request the sq relation helper chart. + + * src/main/java/de/intevation/flys/client/client/ui/sq/SQMultiPeriodPanel.java: + New. Multi period input panel with overview chart in helper panel. + + * src/main/java/de/intevation/flys/client/client/ui/UIProviderFactory.java: + Use the new panel in sq relation period input. + + * src/main/webapp/WEB-INF/web.xml: + Added new service to config. + 2012-07-11 Björn Ricks <bjoern.ricks@intevation.de> * src/main/java/de/intevation/flys/client/server/GGInAFilter.java:
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/UIProviderFactory.java Wed Jul 11 10:57:24 2012 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/UIProviderFactory.java Wed Jul 11 11:24:27 2012 +0000 @@ -7,6 +7,7 @@ import de.intevation.flys.client.client.ui.fixation.FixGaugeSelectPanel; import de.intevation.flys.client.client.ui.fixation.FixEventSelect; import de.intevation.flys.client.client.ui.fixation.FixMultiPeriodPanel; +import de.intevation.flys.client.client.ui.sq.SQMultiPeriodPanel; /** * Depending on the provider the state declared, return a UIProvider. @@ -108,7 +109,7 @@ return new BooleanPanel(); } else if (uiProvider.equals("periods_select")) { - return new MultiPeriodPanel(); + return new SQMultiPeriodPanel(); } else if (uiProvider.equals("outliers_input")) { return new DoubleInputPanel();
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/sq/SQMultiPeriodPanel.java Wed Jul 11 11:24:27 2012 +0000 @@ -0,0 +1,102 @@ +package de.intevation.flys.client.client.ui.sq; + +import com.google.gwt.json.client.JSONObject; +import com.google.gwt.json.client.JSONNumber; +import com.google.gwt.json.client.JSONString; + +import com.google.gwt.core.client.GWT; + +import com.smartgwt.client.types.Alignment; + +import com.smartgwt.client.widgets.Img; +import com.smartgwt.client.widgets.Canvas; +import com.smartgwt.client.widgets.layout.VLayout; +import com.smartgwt.client.widgets.events.ResizedHandler; +import com.smartgwt.client.widgets.events.ResizedEvent; + +import de.intevation.flys.client.client.ui.MultiPeriodPanel; + +import de.intevation.flys.client.shared.model.DataList; + +import de.intevation.flys.client.client.Config; +/** + * This UIProvider creates helper panel for sq relation. + * + * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> + */ +public class SQMultiPeriodPanel +extends MultiPeriodPanel +implements ResizedHandler +{ + protected VLayout chartContainer; + + protected Img chartImg; + + public SQMultiPeriodPanel() { + chartImg = new Img(); + } + + + protected Canvas createHelper() { + Config config = Config.getInstance(); + String locale = config.getLocale (); + + chartContainer = new VLayout(); + chartContainer.addResizedHandler(this); + chartContainer.setAlign(Alignment.CENTER); + + return chartContainer; + } + + + protected void updateChart() { + Config config = Config.getInstance(); + String locale = config.getLocale (); + + int hWidth = chartContainer.getWidth() - 12; + int hHeight = chartContainer.getHeight() - 12; + + if ((int)(hHeight *4f/3) < hWidth) { + hWidth = (int)(hHeight * 4f/3); + } + else { + hHeight = (int)(hWidth *3f/4); + } + String river = artifact.getArtifactDescription().getRiver(); + + JSONObject jfix = new JSONObject(); + JSONObject jfilter = new JSONObject(); + JSONObject jrName = new JSONObject(); + JSONString jrValue = new JSONString(river); + JSONObject jextent = new JSONObject(); + JSONNumber jwidth = new JSONNumber(hWidth); + JSONNumber jheight = new JSONNumber(hHeight); + + jrName.put("name", jrValue); + jfilter.put("river", jrName); + jextent.put("width", jwidth); + jextent.put("height", jheight); + jfilter.put("extent", jextent); + jfix.put("sq", jfilter); + String filter = jfix.toString(); + + String imgUrl = GWT.getModuleBaseURL(); + imgUrl += "sq-km-chart"; + imgUrl += "?locale=" + locale; + imgUrl += "&filter=" + filter; + if (chartContainer.hasMember(chartImg)) { + chartImg.setWidth(hWidth); + chartImg.setHeight(hHeight); + chartImg.setSrc(imgUrl); + } + else { + chartImg = new Img(imgUrl, hWidth, hHeight); + chartContainer.addMember(chartImg); + } + } + + + public void onResized(ResizedEvent re) { + updateChart(); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/server/SQKMChartServiceImpl.java Wed Jul 11 11:24:27 2012 +0000 @@ -0,0 +1,111 @@ +package de.intevation.flys.client.server; + +import org.apache.log4j.Logger; + +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; + +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.NodeList; + +import de.intevation.artifacts.common.utils.XMLUtils; + +import de.intevation.artifacts.httpclient.exceptions.ConnectionException; +import de.intevation.artifacts.httpclient.http.HttpClient; +import de.intevation.artifacts.httpclient.http.HttpClientImpl; + +import de.intevation.artifacts.httpclient.http.response.StreamResponseHandler; + +public class SQKMChartServiceImpl +extends HttpServlet +{ + private static final Logger log = + Logger.getLogger(FixingsKMChartServiceImpl.class); + + public static final String SERVICE_NAME = "sq-km-chart"; + + public SQKMChartServiceImpl() { + } + + public void doGet(HttpServletRequest req, HttpServletResponse resp) { + + log.info("SQKMChartServiceImpl.doGet"); + + String url = getServletContext().getInitParameter("server-url"); + String locale = req.getParameter("locale"); + String filter = req.getParameter("filter"); + + if (filter == null || filter.length() == 0) { + log.warn("Missing 'filter' parameter."); + return; + } + + if (locale == null || locale.length() == 0) { + locale = "de"; + } + + Document filterDoc = XMLUtils.jsonToXML(filter); + + if (filterDoc == null) { + log.warn("Creating filter document failed."); + return; + } + + InputStream in; + + try { + HttpClient client = new HttpClientImpl(url, locale); + in = (InputStream)client.callService( + url, // XXX: Why? The URL is passed by construction already. + SERVICE_NAME, + filterDoc, + new StreamResponseHandler()); + } + catch (ConnectionException ce) { + log.error(ce); + return; + } + + resp.setHeader("Content-Type", guessMIMEType(filterDoc)); + + try { + OutputStream out = resp.getOutputStream(); + + byte [] buf = new byte[4096]; + int i = -1; + while ((i = in.read(buf)) >= 0) { + out.write(buf, 0, i); + } + out.flush(); + } + catch (IOException ioe) { + log.error(ioe); + } + finally { + try { in.close(); } + catch (IOException ioe) { /* ignored */ } + } + } + + protected static String guessMIMEType(Document document) { + + NodeList formats = document.getElementsByTagName("format"); + + String format = "png"; + + if (formats.getLength() > 0) { + String type = ((Element)formats.item(0)).getAttribute("type"); + if (type.length() > 0) { + format = type; + } + } + + return "image/" + format; + } +}
--- a/flys-client/src/main/webapp/WEB-INF/web.xml Wed Jul 11 10:57:24 2012 +0000 +++ b/flys-client/src/main/webapp/WEB-INF/web.xml Wed Jul 11 11:24:27 2012 +0000 @@ -469,6 +469,16 @@ </servlet-mapping> <servlet> + <servlet-name>SQKMChart</servlet-name> + <servlet-class>de.intevation.flys.client.server.SQKMChartServiceImpl</servlet-class> + </servlet> + + <servlet-mapping> + <servlet-name>SQKMChart</servlet-name> + <url-pattern>/flys/sq-km-chart</url-pattern> + </servlet-mapping> + + <servlet> <servlet-name>login</servlet-name> <servlet-class>de.intevation.flys.client.server.LoginServlet</servlet-class> </servlet>