teichmann@5861: /* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde teichmann@5861: * Software engineering by Intevation GmbH teichmann@5861: * teichmann@5993: * This file is Free Software under the GNU AGPL (>=v3) teichmann@5861: * and comes with ABSOLUTELY NO WARRANTY! Check out the teichmann@5993: * documentation coming with Dive4Elements River for details. teichmann@5861: */ teichmann@5861: teichmann@5835: package org.dive4elements.river.client.client.ui.chart; ingo@533: ingo@533: import com.google.gwt.core.client.GWT; christian@4013: ingo@533: import com.smartgwt.client.widgets.Button; ingo@543: import com.smartgwt.client.widgets.ImgButton; ingo@534: import com.smartgwt.client.widgets.Label; ingo@533: import com.smartgwt.client.widgets.events.ClickEvent; ingo@533: import com.smartgwt.client.widgets.events.ClickHandler; ingo@533: teichmann@5835: import org.dive4elements.river.client.client.Config; teichmann@5835: import org.dive4elements.river.client.client.FLYSConstants; teichmann@5835: import org.dive4elements.river.client.client.event.ZoomEvent; teichmann@5835: import org.dive4elements.river.client.client.event.ZoomHandler; teichmann@5835: import org.dive4elements.river.client.client.ui.ImgLink; teichmann@5835: import org.dive4elements.river.client.client.ui.Toolbar; ingo@533: ingo@533: ingo@533: /** felix@1540: * Toolbar with buttons/icons to open datacage, switch to zoom mode, zoom out felix@1540: * etc. felix@1540: * ingo@533: * @author Ingo Weinzierl ingo@533: */ ingo@2391: public class ChartToolbar extends Toolbar implements ZoomHandler { ingo@533: ingo@533: protected static FLYSConstants MSG = GWT.create(FLYSConstants.class); ingo@533: christian@3347: public static final int PANEL_HEIGHT = 35; ingo@533: christian@2983: protected Button manageThemes; ingo@534: protected Button datacage; ingo@2391: protected ImgLink downloadPNG; ingo@2391: protected ImgLink downloadPDF; ingo@2391: protected ImgLink downloadSVG; aheinecke@7606: protected ImgLink downloadCSV; ingo@534: protected MousePositionPanel position; ingo@540: protected ZoomboxControl zoombox; ingo@543: protected ImgButton zoomToMaxExtent; ingo@1281: protected ImgButton historyBack; ingo@544: protected ImgButton zoomOut; raimund@1429: protected ImgButton chartProperties; felix@1541: protected Button addPoints; felix@2925: protected Button addWSP; raimund@3499: protected ImgLink exportAT; ingo@552: protected PanControl panControl; ingo@552: ingo@534: felix@1545: /** @param chartTab Output-Tab on which this toolbar is located. */ felix@1545: public ChartToolbar(ChartOutputTab chartTab) { ingo@1364: super(chartTab); ingo@3370: initTools(); ingo@3370: } sascha@3371: sascha@3371: ingo@3370: protected void initTools() { ingo@3370: ChartOutputTab chartTab = getChartOutputTab(); sascha@3371: christian@2983: manageThemes = new Button(MSG.manageThemes()); ingo@543: datacage = new Button(MSG.databasket()); ingo@543: position = new MousePositionPanel(chartTab); ingo@543: zoombox = new ZoomboxControl(chartTab, MSG.zoom_in()); ingo@543: zoomToMaxExtent = new ImgButton(); ingo@544: zoomOut = new ImgButton(); ingo@1281: historyBack = new ImgButton(); ingo@552: panControl = new PanControl(chartTab, MSG.pan()); raimund@1429: chartProperties = new ImgButton(); felix@1558: addPoints = new Button(MSG.points()); felix@1541: christian@2983: if (chartTab.getMode().getName().equals("cross_section")) { felix@2926: addWSP = new Button(MSG.addWSPButton()); felix@2927: addWSP.setTooltip(MSG.addWSPTooltip()); felix@2925: final ChartOutputTab finalChartTab = chartTab; felix@2925: addWSP.addClickHandler(new ClickHandler() { christian@2983: @Override felix@2925: public void onClick(ClickEvent ce) { felix@2925: new ManualWSPEditor(finalChartTab.getView().getCollection(), felix@2925: finalChartTab, finalChartTab.getMode().getName()).show(); felix@2925: }}); felix@2925: } felix@2925: felix@1541: addPoints.addClickHandler(new ClickHandler() { christian@2983: @Override felix@1541: public void onClick(ClickEvent event) { felix@1541: openPointWindow(); felix@1541: } felix@1541: }); raimund@2545: addPoints.setTooltip(MSG.addPointsTooltip()); ingo@538: christian@2983: manageThemes.addClickHandler(new ClickHandler() { christian@2983: christian@2983: @Override christian@2983: public void onClick(ClickEvent event) { christian@2983: getChartOutputTab().toggleThemePanel(); christian@2983: } christian@2983: }); christian@2983: ingo@533: datacage.addClickHandler(new ClickHandler() { christian@2983: @Override ingo@533: public void onClick(ClickEvent event) { ingo@533: GWT.log("Clicked 'datacage' button."); ingo@1364: openDatacageWindow((ChartOutputTab) getOutputTab()); ingo@533: } ingo@533: }); ingo@533: ingo@543: String baseUrl = GWT.getHostPageBaseURL(); raimund@3499: String moduleUrl = GWT.getModuleBaseURL(); raimund@3499: Config config = Config.getInstance(); raimund@3499: raimund@3499: if (chartTab.getMode().getName().equals("fix_wq_curve")) { raimund@3499: exportAT = new ImgLink( aheinecke@6222: baseUrl + MSG.downloadAT(), raimund@3499: moduleUrl + "export" + raimund@3499: "?uuid=" + chartTab.getCollection().identifier() + rrenkert@5055: "&name=" + chartTab.getMode().getName() + raimund@3499: "&mode=" + chartTab.getMode().getName() + "_at_export" + raimund@3499: "&type=at" + raimund@3499: "&server=" + config.getServerUrl() + raimund@3499: "&locale=" + config.getLocale() + raimund@3499: "&km=" + chartTab.getCollectionView().getCurrentKm(), raimund@3499: 20, raimund@3499: 20 raimund@3499: ); raimund@3499: exportAT.setTooltip(MSG.exportATTooltip()); raimund@3499: } ingo@1344: ingo@1344: downloadPNG = new ImgLink( raimund@1399: baseUrl + MSG.downloadPNG(), ingo@1484: chartTab.getExportUrl(-1, -1, "png"), ingo@1344: 20, ingo@1344: 20); raimund@2545: downloadPNG.setTooltip(MSG.downloadPNGTooltip()); ingo@1344: ingo@1344: downloadPDF = new ImgLink( raimund@1399: baseUrl + MSG.downloadPDF(), ingo@1344: chartTab.getExportUrl(1280, 1024, "pdf"), ingo@1344: 20, ingo@1344: 20); raimund@2545: downloadPDF.setTooltip(MSG.downloadPDFTooltip()); ingo@1344: ingo@1344: downloadSVG = new ImgLink( raimund@1399: baseUrl + MSG.downloadSVG(), ingo@1344: chartTab.getExportUrl(1280, 1024, "svg"), ingo@1344: 20, ingo@1344: 20); raimund@2545: downloadSVG.setTooltip(MSG.downloadSVGTooltip()); ingo@1344: raimund@1587: downloadCSV = new ImgLink( raimund@1587: baseUrl + MSG.downloadCSV(), felix@7138: chartTab.getExportUrl(-1, -1, "csv", "windows-1252"), raimund@1587: 20, raimund@1587: 20); raimund@2545: downloadCSV.setTooltip(MSG.downloadCSVTooltip()); raimund@1587: ingo@543: zoomToMaxExtent.setSrc(baseUrl + MSG.zoom_all()); felix@1540: adjustImageButton(zoomToMaxExtent); ingo@543: zoomToMaxExtent.addClickHandler(new ClickHandler() { christian@2983: @Override ingo@543: public void onClick(ClickEvent event) { ingo@543: getChartOutputTab().resetRanges(); felix@2910: // Relink the export buttons. felix@2910: onZoom(null); ingo@543: } ingo@543: }); raimund@2545: zoomToMaxExtent.setTooltip(MSG.zoomToMaxExtentTooltip()); ingo@543: ingo@544: zoomOut.setSrc(baseUrl + MSG.zoom_out()); felix@1540: adjustImageButton(zoomOut); ingo@544: zoomOut.addClickHandler(new ClickHandler() { christian@2983: @Override ingo@544: public void onClick(ClickEvent event) { ingo@1281: getChartOutputTab().zoomOut(10); felix@2910: // Relink the export buttons. felix@2910: onZoom(null); ingo@1281: } ingo@1281: }); raimund@2545: zoomOut.setTooltip(MSG.zoomOutTooltip()); ingo@1281: ingo@1281: historyBack.setSrc(baseUrl + MSG.zoom_back()); felix@1540: adjustImageButton(historyBack); ingo@1281: historyBack.addClickHandler(new ClickHandler() { christian@2983: @Override ingo@1281: public void onClick(ClickEvent event) { ingo@1280: getChartOutputTab().zoomOut(); felix@2910: // Relink the export buttons. felix@2910: onZoom(null); ingo@544: } ingo@544: }); raimund@2545: historyBack.setTooltip(MSG.historyBackTooltip()); ingo@544: ingo@541: zoombox.addZoomHandler(chartTab); ingo@2391: zoombox.addZoomHandler(this); ingo@552: zoombox.addClickHandler(new ClickHandler() { christian@2983: @Override ingo@552: public void onClick(ClickEvent event) { ingo@552: panControl.deselect(); ingo@552: } ingo@552: }); raimund@2545: zoombox.setTooltip(MSG.zoomboxTooltip()); ingo@552: ingo@552: panControl.addPanHandler(chartTab); ingo@552: panControl.addClickHandler(new ClickHandler() { christian@2983: @Override ingo@552: public void onClick(ClickEvent event) { ingo@552: zoombox.deselect(); ingo@552: } ingo@552: }); raimund@2545: panControl.setTooltip(MSG.panControlTooltip()); ingo@541: raimund@1429: chartProperties.setSrc(baseUrl + MSG.properties_ico()); felix@1540: adjustImageButton(chartProperties); raimund@1429: chartProperties.addClickHandler(new ClickHandler() { christian@2983: @Override raimund@1429: public void onClick(ClickEvent event) { raimund@1429: openPropertiesEditor(); raimund@1429: } raimund@1429: }); raimund@2545: chartProperties.setTooltip(MSG.chartPropertiesTooltip()); felix@1541: ingo@533: initLayout(); ingo@533: } ingo@533: felix@1540: /** Set width, height and other properties of an imagebutton. */ felix@1541: public void adjustImageButton(ImgButton imgButton) { felix@1540: imgButton.setWidth(20); felix@1540: imgButton.setHeight(20); felix@1540: imgButton.setShowDown(false); felix@1540: imgButton.setShowRollOver(false); ingo@2471: imgButton.setShowRollOverIcon(false); felix@1540: imgButton.setShowDisabled(false); felix@1540: imgButton.setShowDisabledIcon(true); felix@1540: imgButton.setShowDownIcon(false); felix@1540: imgButton.setShowFocusedIcon(false); felix@1540: } felix@1540: ingo@533: ingo@3370: protected ChartOutputTab getChartOutputTab() { christian@2983: return (ChartOutputTab)getOutputTab(); ingo@543: } ingo@543: ingo@543: ingo@533: protected void initLayout() { ingo@533: setWidth100(); ingo@533: setHeight(PANEL_HEIGHT); ingo@533: setMembersMargin(10); ingo@533: setPadding(5); ingo@533: setBorder("1px solid black"); ingo@533: ingo@534: Label spacer = new Label(); ingo@539: spacer.setWidth("*"); ingo@534: datacage.setWidth("95px"); ingo@538: position.setWidth("200px"); ingo@534: christian@2983: addMember(manageThemes); ingo@533: addMember(datacage); ingo@1344: addMember(downloadPNG); ingo@1344: addMember(downloadPDF); ingo@1344: addMember(downloadSVG); raimund@1587: addMember(downloadCSV); raimund@3499: if (getChartOutputTab().getMode().getName().equals("fix_wq_curve")) { raimund@3499: addMember(exportAT); raimund@3499: } ingo@543: addMember(zoomToMaxExtent); ingo@1281: addMember(historyBack); ingo@544: addMember(zoomOut); ingo@540: addMember(zoombox); ingo@552: addMember(panControl); raimund@1429: addMember(chartProperties); felix@1541: addMember(addPoints); felix@2925: christian@2983: if (getChartOutputTab().getMode().getName().equals("cross_section")) { felix@2925: addMember(addWSP); felix@2925: } felix@2925: ingo@534: addMember(spacer); ingo@534: addMember(position); ingo@533: } raimund@1429: raimund@1429: /** raimund@1429: * Open the chart property editor dialog. raimund@1429: */ raimund@1429: protected void openPropertiesEditor() { raimund@1429: ChartPropertiesEditor editor = raimund@1429: new ChartPropertiesEditor(getChartOutputTab()); raimund@1429: editor.show(); raimund@1429: } raimund@1429: felix@1541: felix@1541: /** Open editor for custom points. */ felix@1541: protected void openPointWindow() { christian@2983: ChartOutputTab chartTab = getChartOutputTab(); christian@2983: if (chartTab.getMode().getName().equals("historical_discharge")) { raimund@2479: new ManualDatePointsEditor(chartTab.getView().getCollection(), christian@2983: chartTab, chartTab.getMode().getName()).show(); raimund@2479: } raimund@2479: else { raimund@2479: new ManualPointsEditor(chartTab.getView().getCollection(), christian@2983: chartTab, chartTab.getMode().getName()).show(); raimund@2479: } felix@1541: } ingo@2391: ingo@2391: felix@2910: /** felix@2910: * Sets new sources to the export button/images, such that the felix@2910: * correct zoom values are included in the request when clicked. felix@2910: * @param evt ignored. felix@2910: */ christian@2983: @Override ingo@2391: public void onZoom(ZoomEvent evt) { christian@2983: ChartOutputTab chartTab = getChartOutputTab(); ingo@2391: downloadPNG.setSource(chartTab.getExportUrl(-1, -1, "png")); ingo@2391: downloadPDF.setSource(chartTab.getExportUrl(-1, -1, "pdf")); ingo@2391: downloadSVG.setSource(chartTab.getExportUrl(-1, -1, "svg")); ingo@2391: } raimund@2936: raimund@2936: public void deselectControls() { raimund@2936: zoombox.deselect(); raimund@2936: } raimund@3499: raimund@3499: public void updateLinks() { raimund@3499: ChartOutputTab chartTab = getChartOutputTab(); raimund@3499: String moduleUrl = GWT.getModuleBaseURL(); raimund@3499: Config config = Config.getInstance(); raimund@3499: aheinecke@7606: // make sure that the current km is set correctly aheinecke@7606: // for the other buttons this is handled by onZoom aheinecke@7606: downloadCSV.setSource( aheinecke@7606: chartTab.getExportUrl(-1, -1, "csv", "windows-1252")); aheinecke@7606: raimund@3499: if (chartTab.getMode().getName().equals("fix_wq_curve")) { raimund@3499: exportAT.setSource( raimund@3499: moduleUrl + "export" + raimund@3499: "?uuid=" + chartTab.getCollection().identifier() + aheinecke@6222: "&name=" + chartTab.getMode().getName() + raimund@3499: "&mode=" + chartTab.getMode().getName() + "_at_export" + raimund@3499: "&type=at" + raimund@3499: "&server=" + config.getServerUrl() + raimund@3499: "&locale=" + config.getLocale() + raimund@3499: "&km=" + chartTab.getCollectionView().getCurrentKm()); raimund@3499: } raimund@3499: } ingo@533: } ingo@533: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :