Mercurial > dive4elements > river
view flys-client/src/main/java/de/intevation/flys/client/client/ui/chart/NaviChartOutputTab.java @ 4253:a1bc5b8cff0f
Refactor GaugePanel to create it's own SectionStackSection
The GaugePanel constructor now creates a SectionStackSection instead of
using a provided one.
Improve the rendering of the GaugePanel by having access to the SmartGWT wrapper
(WidgetCanvas) object for the GWT Tree (GaugeTree) directly.
Add methods to close and open the section. Also add a getter for the section.
author | Björn Ricks <bjoern.ricks@intevation.de> |
---|---|
date | Thu, 25 Oct 2012 13:52:58 +0200 |
parents | 17c66d38f095 |
children | a17d0afd0db9 |
line wrap: on
line source
package de.intevation.flys.client.client.ui.chart; import java.util.Map; import java.util.HashMap; import com.google.gwt.core.client.GWT; import com.google.gwt.i18n.client.NumberFormat; import com.smartgwt.client.types.Alignment; import com.smartgwt.client.widgets.Button; import com.smartgwt.client.widgets.Canvas; import com.smartgwt.client.widgets.events.ClickEvent; import com.smartgwt.client.widgets.events.ClickHandler; import com.smartgwt.client.widgets.form.DynamicForm; import com.smartgwt.client.widgets.form.fields.TextItem; import com.smartgwt.client.widgets.form.fields.events.KeyPressEvent; import com.smartgwt.client.widgets.form.fields.events.KeyPressHandler; import com.smartgwt.client.widgets.layout.HLayout; import com.smartgwt.client.widgets.layout.VLayout; import com.smartgwt.client.widgets.tab.events.TabSelectedEvent; import com.smartgwt.client.widgets.tab.events.TabSelectedHandler; import de.intevation.flys.client.client.Config; import de.intevation.flys.client.client.ui.CollectionView; import de.intevation.flys.client.shared.model.Artifact; import de.intevation.flys.client.shared.model.Collection; import de.intevation.flys.client.shared.model.FixAnalysisArtifact; import de.intevation.flys.client.shared.model.OutputMode; import java.util.Date; /** * Tab representing and showing one Chart-output. * * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> */ 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); form.setFields(currentkm); form.setWidth(60); FixAnalysisArtifact fix = (FixAnalysisArtifact) art; String s = fix.getArtifactDescription().getDataValueAsString("step"); try { double ds = Double.parseDouble(s); collectionView.setSteps(ds); } catch(NumberFormatException nfe) { collectionView.setSteps(100d); } collectionView.setMinKm(fix.getFilter().getFromKm()); collectionView.setMaxKm(fix.getFilter().getToKm()); NumberFormat nf = NumberFormat.getDecimalFormat(); if (collectionView.getCurrentKm() == -1d) { try { double d = Double.valueOf(fix.getFilter().getFromKm()); currentkm.setValue(nf.format(d)); } catch (NumberFormatException e) { currentkm.setValue(fix.getFilter().getFromKm()); } collectionView.setCurrentKm(fix.getFilter().getFromKm()); } else { try { double d = Double.valueOf(fix.getFilter().getFromKm()); currentkm.setValue(nf.format(d)); } catch (NumberFormatException e) { currentkm.setValue(fix.getFilter().getFromKm()); } currentkm.setValue(collectionView.getCurrentKm()); } lower.addClickHandler(new ClickHandler() { public void onClick(ClickEvent ce) { tbarPanel.deselectControls(); updateChartDown(); try { NumberFormat nf = NumberFormat.getDecimalFormat(); double d = Double.valueOf(collectionView.getCurrentKm()); currentkm.setValue(nf.format(d)); } catch (NumberFormatException e) { currentkm.setValue(collectionView.getCurrentKm()); } } }); upper.addClickHandler(new ClickHandler() { public void onClick(ClickEvent ce) { tbarPanel.deselectControls(); updateChartUp(); try { NumberFormat nf = NumberFormat.getDecimalFormat(); double d = Double.valueOf(collectionView.getCurrentKm()); currentkm.setValue(nf.format(d)); } catch (NumberFormatException e) { currentkm.setValue(collectionView.getCurrentKm()); } } }); currentkm.addKeyPressHandler(new KeyPressHandler() { public void onKeyPress(KeyPressEvent kpe) { if (!kpe.getKeyName().equals("Enter")) { return; } if(kpe.getItem().getValue() != null) { tbarPanel.deselectControls(); try { String s = kpe.getItem().getValue().toString(); double d; try { NumberFormat nf = NumberFormat.getDecimalFormat(); d = nf.parse(s); currentkm.setValue(nf.format(d)); } catch (NumberFormatException e) { d = -1d; } if (d <= collectionView.getMaxKm() && d >= collectionView.getMinKm()) { collectionView.setCurrentKm(d); tbarPanel.updateLinks(); 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); tbarPanel.updateLinks(); 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); tbarPanel.updateLinks(); updateChartPanel(); updateChartInfo(); } } /** * Returns the existing chart panel. * * @return the existing chart panel. */ @Override public Canvas getChartPanel() { return chart; } /** * 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(); } return imgUrl; } public void onTabSelected(TabSelectedEvent tse) { if (this.equals(tse.getTab())) { updateChartPanel(); updateChartInfo(); currentkm.setValue(collectionView.getCurrentKm()); } } @Override public Map<String, String> getChartAttributes() { Map<String, String> attr = new HashMap<String, String>(); attr = super.getChartAttributes(); attr.put("km", String.valueOf(collectionView.getCurrentKm())); return attr; } }