# HG changeset patch # User Raimund Renkert # Date 1339762389 0 # Node ID 1780841d79afbbf65d9677b48e4b5e2342dbe1ca # Parent 51ed89b754ae89d56026a5e7b9209305099a5cc2 Added navigation to fix analysis charts. flys-client/trunk@4673 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r 51ed89b754ae -r 1780841d79af flys-client/ChangeLog --- a/flys-client/ChangeLog Fri Jun 15 09:35:37 2012 +0000 +++ b/flys-client/ChangeLog Fri Jun 15 12:13:09 2012 +0000 @@ -1,3 +1,23 @@ +2012-06-15 Raimund Renkert + + Added navigation to fix analysis charts. + + * src/main/java/de/intevation/flys/client/client/ui/chart/NaviChartOutputTab.java: + New. Chart output tab with km navigation. + + * src/main/java/de/intevation/flys/client/client/ui/CollectionView.java: + Added member variables and getter/setter for km navigation values. + + * src/main/java/de/intevation/flys/client/shared/model/ChartMode.java: + Create NaviChartOutputTabs for chart tabs in fix analysis. + + * src/main/java/de/intevation/flys/client/server/ChartOutputServiceImpl.java, + src/main/java/de/intevation/flys/client/server/ChartServiceHelper.java: + Added the current km as parameter in requests. + + * src/main/java/de/intevation/flys/client/shared/model/FixAnalysisArtifact.java: + Create the filter by getting the attributes via artifact description. + 2012-06-15 Sascha L. Teichmann * src/main/java/de/intevation/flys/client/**/*.java: Removed trailing whitespace. diff -r 51ed89b754ae -r 1780841d79af flys-client/src/main/java/de/intevation/flys/client/client/ui/CollectionView.java --- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/CollectionView.java Fri Jun 15 09:35:37 2012 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/CollectionView.java Fri Jun 15 12:13:09 2012 +0000 @@ -118,6 +118,11 @@ protected int recommendationQueue; protected Stack newRecommendations; + /** Values for fix analysis charts*/ + protected double currentKm; + protected double minKm; + protected double maxKm; + protected double steps; /** * This constructor creates a new CollectionView that is used to display the @@ -140,6 +145,11 @@ this.recommendationQueue = 0; this.newRecommendations = new Stack(); + this.currentKm = -1d; + this.minKm = -1d; + this.maxKm = -1d; + this.steps = -1d; + addCollectionChangeHandler(this); addCollectionChangeHandler(parameterList); addCollectionChangeHandler(flys); @@ -165,6 +175,11 @@ this.outHandlers = new ArrayList(); this.layout = new VLayout(); + this.currentKm = -1d; + this.minKm = -1d; + this.maxKm = -1d; + this.steps = -1d; + if (artifact != null) { this.parameterList = new ParameterList( flys, @@ -679,5 +694,38 @@ public void registerTabHandler(TabSelectedHandler tse) { tabs.addTabSelectedHandler(tse); } + + + public void setCurrentKm(double currentKm) { + this.currentKm = currentKm; + } + + public double getCurrentKm() { + return this.currentKm; + } + + public void setMinKm(double km) { + this.minKm = km; + } + + public double getMinKm() { + return this.minKm; + } + + public void setMaxKm(double km) { + this.maxKm = km; + } + + public double getMaxKm() { + return this.maxKm; + } + + public void setSteps(double step) { + this.steps = step; + } + + public double getSteps() { + return this.steps; + } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : diff -r 51ed89b754ae -r 1780841d79af flys-client/src/main/java/de/intevation/flys/client/client/ui/chart/NaviChartOutputTab.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/chart/NaviChartOutputTab.java Fri Jun 15 12:13:09 2012 +0000 @@ -0,0 +1,227 @@ +package de.intevation.flys.client.client.ui.chart; + +import java.util.Date; + +import com.google.gwt.core.client.GWT; + +import com.smartgwt.client.widgets.layout.HLayout; +import com.smartgwt.client.widgets.layout.VLayout; +import com.smartgwt.client.widgets.Button; + +import com.smartgwt.client.widgets.form.DynamicForm; +import com.smartgwt.client.widgets.form.fields.TextItem; +import com.smartgwt.client.widgets.form.fields.events.ChangedHandler; +import com.smartgwt.client.widgets.form.fields.events.ChangedEvent; +import com.smartgwt.client.widgets.events.ClickHandler; +import com.smartgwt.client.widgets.events.ClickEvent; +import com.smartgwt.client.widgets.form.validator.IsFloatValidator; +import com.smartgwt.client.widgets.Canvas; +import com.smartgwt.client.widgets.Img; +import com.smartgwt.client.types.Alignment; +import com.smartgwt.client.widgets.tab.events.TabSelectedHandler; +import com.smartgwt.client.widgets.tab.events.TabSelectedEvent; + +import de.intevation.flys.client.shared.model.Collection; +import de.intevation.flys.client.shared.model.OutputMode; +import de.intevation.flys.client.client.ui.CollectionView; +import de.intevation.flys.client.shared.model.FixAnalysisArtifact; +import de.intevation.flys.client.shared.model.Artifact; +import de.intevation.flys.client.client.Config; + + +/** + * Tab representing and showing one Chart-output. + * + * @author Ingo Weinzierl + */ +public class NaviChartOutputTab +extends ChartOutputTab +implements TabSelectedHandler +{ + protected TextItem currentkm; + + public NaviChartOutputTab( + String title, + Collection collection, + OutputMode mode, + CollectionView collectionView + ){ + super(title, collection, mode, collectionView); + right.removeChild(chart); + right.addChild(createNaviChart()); + collectionView.registerTabHandler(this); + } + + + protected Canvas createNaviChart() { + final Artifact art = collectionView.getArtifact(); + VLayout root = new VLayout(); + root.setWidth100(); + root.setHeight100(); + + HLayout layout = new HLayout(); + layout.setAlign(Alignment.CENTER); + + DynamicForm form = new DynamicForm(); + Button lower = new Button("<<"); + lower.setWidth(30); + Button upper = new Button(">>"); + upper.setWidth(30); + currentkm = new TextItem(); + currentkm.setWidth(60); + currentkm.setShowTitle(false); + currentkm.setValidators(new IsFloatValidator()); + + form.setFields(currentkm); + form.setWidth(60); + FixAnalysisArtifact fix = (FixAnalysisArtifact) art; + + String s = fix.getArtifactDescription().getDataValueAsString("step"); + try { + double ds = Double.valueOf(s).doubleValue(); + collectionView.setSteps(ds); + } + catch(NumberFormatException nfe) { + collectionView.setSteps(100d); + } + collectionView.setMinKm(fix.getFilter().getFromKm()); + collectionView.setMaxKm(fix.getFilter().getToKm()); + + if (collectionView.getCurrentKm() == -1d) { + currentkm.setValue(fix.getFilter().getFromKm()); + collectionView.setCurrentKm(fix.getFilter().getFromKm()); + } + else { + currentkm.setValue(collectionView.getCurrentKm()); + } + + lower.addClickHandler(new ClickHandler() { + public void onClick(ClickEvent ce) { + updateChartDown(); + currentkm.setValue(collectionView.getCurrentKm()); + } + }); + + upper.addClickHandler(new ClickHandler() { + public void onClick(ClickEvent ce) { + updateChartUp(); + currentkm.setValue(collectionView.getCurrentKm()); + } + }); + + currentkm.addChangedHandler(new ChangedHandler() { + public void onChanged(ChangedEvent ce) { + if(ce.getForm().validate() && ce.getItem().getValue() != null) { + try { + String s = ce.getItem().getValue().toString(); + Double d = new Double(s); + if (d < collectionView.getMaxKm() && + d > collectionView.getMinKm()) { + collectionView.setCurrentKm(d); + if (right != null) { + updateChartPanel(); + updateChartInfo(); + } + } + } + catch(NumberFormatException nfe) { + // Do nothing. + } + } + } + }); + layout.addMember(lower); + layout.addMember(form); + layout.addMember(upper); + + root.addMember(chart); + root.addMember(layout); + return root; + } + + + protected void updateChartUp() { + double currentKm = collectionView.getCurrentKm(); + if (currentKm < collectionView.getMaxKm()) { + double newVal = currentKm * 100; + newVal += (collectionView.getSteps() / 10); + collectionView.setCurrentKm((double)Math.round(newVal) / 100); + updateChartPanel(); + updateChartInfo(); + } + } + protected void updateChartDown() { + double currentKm = collectionView.getCurrentKm(); + if (currentKm > collectionView.getMinKm()) { + double newVal = currentKm * 100; + newVal -= (collectionView.getSteps() / 10); + collectionView.setCurrentKm((double)Math.round(newVal) / 100); + updateChartPanel(); + updateChartInfo(); + } + + } + + /** + * Builds the URL that points to the chart image. + * + * @param width The width of the requested chart. + * @param height The height of the requested chart. + * @param xr Optional x range (used for zooming). + * @param yr Optional y range (used for zooming). + * + * @return the URL to the chart image. + */ + @Override + protected String getImgUrl(int width, int height) { + Config config = Config.getInstance(); + + String imgUrl = GWT.getModuleBaseURL(); + imgUrl += "chart"; + imgUrl += "?uuid=" + collection.identifier(); + imgUrl += "&type=" + mode.getName(); + imgUrl += "&locale=" + config.getLocale(); + imgUrl += "×tamp=" + new Date().getTime(); + imgUrl += "&width=" + Integer.toString(width); + imgUrl += "&height=" + Integer.toString(height - 40); + + Number[] zoom = getZoomValues(); + + if (zoom != null) { + if (zoom[0].intValue() != 0 || zoom[1].intValue() != 1) { + // a zoom range of 0-1 means displaying the whole range. In such + // case we don't need to zoom. + imgUrl += "&minx=" + zoom[0]; + imgUrl += "&maxx=" + zoom[1]; + } + + if (zoom[2].intValue() != 0 || zoom[3].intValue() != 1) { + // a zoom range of 0-1 means displaying the whole range. In such + // case we don't need to zoom. + imgUrl += "&miny=" + zoom[2]; + imgUrl += "&maxy=" + zoom[3]; + } + } + + if(collectionView.getArtifact() instanceof FixAnalysisArtifact) { + if (collectionView.getCurrentKm() == -1) { + FixAnalysisArtifact fix = + (FixAnalysisArtifact) collectionView.getArtifact(); + collectionView.setCurrentKm(fix.getFilter().getFromKm()); + } + imgUrl += "¤tKm=" + collectionView.getCurrentKm(); + } + GWT.log(imgUrl); + + return imgUrl; + } + + public void onTabSelected(TabSelectedEvent tse) { + if (this.equals(tse.getTab())) { + updateChartPanel(); + updateChartInfo(); + currentkm.setValue(collectionView.getCurrentKm()); + } + } + +} diff -r 51ed89b754ae -r 1780841d79af flys-client/src/main/java/de/intevation/flys/client/server/ChartOutputServiceImpl.java --- a/flys-client/src/main/java/de/intevation/flys/client/server/ChartOutputServiceImpl.java Fri Jun 15 09:35:37 2012 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/server/ChartOutputServiceImpl.java Fri Jun 15 12:13:09 2012 +0000 @@ -78,6 +78,7 @@ attr.put("miny", req.getParameter("miny")); attr.put("maxy", req.getParameter("maxy")); attr.put("format", req.getParameter("format")); + attr.put("km", req.getParameter("currentKm")); if (logger.isDebugEnabled()) { logger.debug("====== ZOOM VALUES ======="); diff -r 51ed89b754ae -r 1780841d79af flys-client/src/main/java/de/intevation/flys/client/server/ChartServiceHelper.java --- a/flys-client/src/main/java/de/intevation/flys/client/server/ChartServiceHelper.java Fri Jun 15 09:35:37 2012 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/server/ChartServiceHelper.java Fri Jun 15 12:13:09 2012 +0000 @@ -56,6 +56,7 @@ appendFormat(req, attributes, ec); appendXRange(req, attributes, ec); appendYRange(req, attributes, ec); + appendCurrentKm(req, attributes, ec); doc.appendChild(attributes); @@ -183,5 +184,34 @@ attributes.appendChild(format); } + + + /** + * This method extracts the current km for the chart from request object and + * appends this km - if it exists - to the attribute document used to + * adjust the chart settings. + * + * @param req The request object that might contain the chart size. + * @param doc The attribute document used to adjust chart settings. + * @param ec The ElementCreator that might be used to create new Elements. + */ + protected static void appendCurrentKm( + Map req, + Element attributes, + ElementCreator ec) + { + logger.debug("ChartServiceHelper.appendCurrentKm"); + + Element currentKm = ec.create("currentKm"); + + String km = req.get("km"); + + if (km != null) { + ec.addAttr(currentKm, "km", km, true); + + attributes.appendChild(currentKm); + } + } + } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : diff -r 51ed89b754ae -r 1780841d79af flys-client/src/main/java/de/intevation/flys/client/shared/model/ChartMode.java --- a/flys-client/src/main/java/de/intevation/flys/client/shared/model/ChartMode.java Fri Jun 15 09:35:37 2012 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/shared/model/ChartMode.java Fri Jun 15 12:13:09 2012 +0000 @@ -5,6 +5,7 @@ import de.intevation.flys.client.client.ui.CollectionView; import de.intevation.flys.client.client.ui.OutputTab; import de.intevation.flys.client.client.ui.chart.ChartOutputTab; +import de.intevation.flys.client.client.ui.chart.NaviChartOutputTab; /** @@ -33,6 +34,11 @@ @Override public OutputTab createOutputTab(String t, Collection c, CollectionView p) { + if (this.getName().equals("fix_wq_curve") || + this.getName().equals("fix_deltawt_curve") || + this.getName().equals("fix_derivate_curve")) { + return new NaviChartOutputTab(t, c, this, p); + } return new ChartOutputTab(t, c, this, p); } } diff -r 51ed89b754ae -r 1780841d79af flys-client/src/main/java/de/intevation/flys/client/shared/model/FixAnalysisArtifact.java --- a/flys-client/src/main/java/de/intevation/flys/client/shared/model/FixAnalysisArtifact.java Fri Jun 15 09:35:37 2012 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/shared/model/FixAnalysisArtifact.java Fri Jun 15 12:13:09 2012 +0000 @@ -2,6 +2,8 @@ import java.util.List; +import com.google.gwt.core.client.GWT; + import de.intevation.flys.client.client.ui.fixation.FixationPanel; import de.intevation.flys.client.client.ui.fixation.FixationPanel.FixFilter; @@ -53,65 +55,88 @@ this.filter = new FixFilter(); } DataList[] old = artifactDescription.getOldData(); - for (int i = 0; i < old.length; i++) { - DataList data = old[i]; - List items = data.getAll(); - String state = data.getState(); - if (state.equals("state.fix.river")) { - Data d = getData(items, "river"); - this.filter.setRiver(d.getItems()[0].getLabel()); - } - if (state.equals("state.fix.location")) { - Data df = getData(items, "from"); - Data dt = getData(items, "to"); - try { - String from = df.getItems()[0].getLabel(); - String to = dt.getItems()[0].getLabel(); - double fkm = Double.valueOf(from).doubleValue(); - double tkm = Double.valueOf(to).doubleValue(); - this.filter.setFromKm(fkm); - this.filter.setToKm(tkm); - if (fkm > filter.getCurrentKm()) { - this.filter.setCurrentKm(fkm); - } - } - catch(NumberFormatException nfe) { - } + + String river = artifactDescription.getDataValueAsString("river"); + if (river != null) { + this.filter.setRiver(river); + } + + String from = artifactDescription.getDataValueAsString("from"); + if (from != null) { + try { + double fkm = Double.valueOf(from).doubleValue(); + this.filter.setFromKm(fkm); } - if (state.equals("state.fix.period")) { - Data ds = getData(items, "start"); - Data de = getData(items, "end"); - try { - String start = ds.getItems()[0].getStringValue(); - String end = de.getItems()[0].getStringValue(); - long sp = Long.parseLong(start); - long ep = Long.parseLong(end); - this.filter.setFromDate(sp); - this.filter.setToDate(ep); - } - catch(NumberFormatException nfe) { - } + catch(NumberFormatException nfe) { + GWT.log("Could not parse from km."); } - if (state.equals("state.fix.gaugerange")) { - Data gr1 = getData(items, "q1"); - Data gr2 = getData(items, "q2"); - try { - String q1s = gr1.getItems()[0].getLabel(); - String q2s = gr2.getItems()[0].getLabel(); - int q1 = Integer.valueOf(q1s).intValue(); - int q2 = Integer.valueOf(q2s).intValue(); - this.filter.setFromClass(q1); - this.filter.setToClass(q2); - } - catch(NumberFormatException nfe) { - } + } + + String to = artifactDescription.getDataValueAsString("to"); + if (to != null) { + try { + double tkm = Double.valueOf(to).doubleValue(); + this.filter.setToKm(tkm); } + catch(NumberFormatException nfe) { + GWT.log("Could not parse to km"); + } + } + + String start = artifactDescription.getDataValueAsString("start"); + if (start != null) { + try { + long s = Long.parseLong(start); + this.filter.setFromDate(s); + } + catch(NumberFormatException nfe) { + GWT.log("Could not parse start date"); + } + } + + String end = artifactDescription.getDataValueAsString("end"); + if (end != null) { + try { + long e = Long.parseLong(end); + this.filter.setToDate(e); + } + catch(NumberFormatException nfe) { + GWT.log("Could not parse end date"); + } + } + + String q1 = artifactDescription.getDataValueAsString("q1"); + if (q1 != null) { + try { + int q1i = Integer.valueOf(q1).intValue(); + this.filter.setFromClass(q1i); + } + catch(NumberFormatException nfe) { + GWT.log("Could not parse start class"); + } + } + + String q2 = artifactDescription.getDataValueAsString("q2"); + if (q2 != null) { + try { + int q2i =Integer.valueOf(q2).intValue(); + this.filter.setToClass(q2i); + } + catch(NumberFormatException nfe) { + GWT.log("could not parse end class"); + } + } + + for (DataList list: old) { + List items = list.getAll(); + String state = list.getState(); if(state.equals("state.fix.eventselect")) { Data de = getData(items, "events"); IntegerArrayData iad = (IntegerArrayData) de; this.filter.setEvents(iad.getValues()); } } + return this.filter; }