Mercurial > dive4elements > river
changeset 1344:51d4b51a51ed
Added icons to export chart as PNG, PDF and SVG to the ChartToolbar.
flys-client/trunk@2998 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Mon, 17 Oct 2011 17:33:27 +0000 |
parents | 0d3d3860beb5 |
children | 92074508a387 |
files | flys-client/ChangeLog flys-client/src/main/java/de/intevation/flys/client/client/FLYSImages.java flys-client/src/main/java/de/intevation/flys/client/client/images/downloadPDF.png flys-client/src/main/java/de/intevation/flys/client/client/images/downloadPNG.png flys-client/src/main/java/de/intevation/flys/client/client/images/downloadSVG.png flys-client/src/main/java/de/intevation/flys/client/client/ui/chart/ChartOutputTab.java flys-client/src/main/java/de/intevation/flys/client/client/ui/chart/ChartToolbar.java flys-client/src/main/java/de/intevation/flys/client/server/ChartOutputServiceImpl.java |
diffstat | 8 files changed, 127 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/flys-client/ChangeLog Mon Oct 17 17:28:24 2011 +0000 +++ b/flys-client/ChangeLog Mon Oct 17 17:33:27 2011 +0000 @@ -1,3 +1,24 @@ +2011-10-17 Ingo Weinzierl <ingo@intevation.de> + + * src/main/java/de/intevation/flys/client/server/ChartOutputServiceImpl.java: + Added support for chart exports. If the Http parameter "export=true" is + set, the header of the Http request is modified to trigger a download. + Currently, PNG, SVG and PDF export is supported. + + * src/main/java/de/intevation/flys/client/client/ui/chart/ChartToolbar.java: + Added a method that returns the URL for a chart export. + + * src/main/java/de/intevation/flys/client/client/ui/chart/ChartOutputTab.java: + Added download icons for png, pdf and svg. + + * src/main/java/de/intevation/flys/client/client/FLYSImages.java: Added + images for png/pdf/svg downloads. + + * src/main/java/de/intevation/flys/client/client/images/downloadPNG.png, + src/main/java/de/intevation/flys/client/client/images/downloadPDF.png, + src/main/java/de/intevation/flys/client/client/images/downloadSVG.png: + New. Icons for png/pdf/svg export of charts. + 2011-10-17 Ingo Weinzierl <ingo@intevation.de> * src/main/java/de/intevation/flys/client/client/ui/ImgLink.java: New.
--- a/flys-client/src/main/java/de/intevation/flys/client/client/FLYSImages.java Mon Oct 17 17:28:24 2011 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/client/FLYSImages.java Mon Oct 17 17:33:27 2011 +0000 @@ -28,4 +28,13 @@ @Source("images/loading.gif") ImageResource loading(); + + @Source("images/downloadPNG.png") + ImageResource downloadPNG(); + + @Source("images/downloadPDF.png") + ImageResource downloadPDF(); + + @Source("images/downloadSVG.png") + ImageResource downloadSVG(); }
Binary file flys-client/src/main/java/de/intevation/flys/client/client/images/downloadPDF.png has changed
Binary file flys-client/src/main/java/de/intevation/flys/client/client/images/downloadPNG.png has changed
Binary file flys-client/src/main/java/de/intevation/flys/client/client/images/downloadSVG.png has changed
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/chart/ChartOutputTab.java Mon Oct 17 17:28:24 2011 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/chart/ChartOutputTab.java Mon Oct 17 17:33:27 2011 +0000 @@ -593,6 +593,15 @@ } + public String getExportUrl(int width, int height, String format) { + String url = getImgUrl(width, height); + url += "&format=" + format; + url += "&export=true"; + + return url; + } + + public Map getChartAttributes() { Map<String, String> attr = new HashMap<String, String>();
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/chart/ChartToolbar.java Mon Oct 17 17:28:24 2011 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/chart/ChartToolbar.java Mon Oct 17 17:33:27 2011 +0000 @@ -3,6 +3,7 @@ import com.google.gwt.core.client.GWT; import com.smartgwt.client.widgets.Button; +import com.smartgwt.client.widgets.Canvas; import com.smartgwt.client.widgets.ImgButton; import com.smartgwt.client.widgets.Label; import com.smartgwt.client.widgets.layout.HLayout; @@ -15,8 +16,10 @@ import de.intevation.flys.client.shared.model.User; import de.intevation.flys.client.client.FLYSConstants; +import de.intevation.flys.client.client.FLYSImages; import de.intevation.flys.client.client.ui.CollectionView; import de.intevation.flys.client.client.ui.DatacageWindow; +import de.intevation.flys.client.client.ui.ImgLink; /** @@ -26,6 +29,8 @@ protected static FLYSConstants MSG = GWT.create(FLYSConstants.class); + protected static FLYSImages IMG = GWT.create(FLYSImages.class); + public static final int PANEL_HEIGHT = 30; @@ -37,6 +42,12 @@ protected Button datacage; + protected Canvas downloadPNG; + + protected Canvas downloadPDF; + + protected Canvas downloadSVG; + protected MousePositionPanel position; protected ZoomboxControl zoombox; @@ -73,6 +84,26 @@ }); String baseUrl = GWT.getHostPageBaseURL(); + + String url = "http://www.heise.de"; + downloadPNG = new ImgLink( + IMG.downloadPNG().getURL(), + chartTab.getExportUrl(1280, 1024, "png"), + 20, + 20); + + downloadPDF = new ImgLink( + IMG.downloadPDF().getURL(), + chartTab.getExportUrl(1280, 1024, "pdf"), + 20, + 20); + + downloadSVG = new ImgLink( + IMG.downloadSVG().getURL(), + chartTab.getExportUrl(1280, 1024, "svg"), + 20, + 20); + zoomToMaxExtent.setSrc(baseUrl + MSG.zoom_all()); zoomToMaxExtent.setWidth(20); zoomToMaxExtent.setHeight(20); @@ -163,6 +194,9 @@ position.setWidth("200px"); addMember(datacage); + addMember(downloadPNG); + addMember(downloadPDF); + addMember(downloadSVG); addMember(zoomToMaxExtent); addMember(historyBack); addMember(zoomOut);
--- a/flys-client/src/main/java/de/intevation/flys/client/server/ChartOutputServiceImpl.java Mon Oct 17 17:28:24 2011 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/server/ChartOutputServiceImpl.java Mon Oct 17 17:33:27 2011 +0000 @@ -38,6 +38,8 @@ String type = req.getParameter("type"); String locale = req.getParameter("locale"); + prepareHeader(req, resp); + Document request = ClientProtocolUtils.newOutCollectionDocument( uuid, type, type, ChartServiceHelper.getChartAttributes(prepareChartAttributes(req))); @@ -70,8 +72,60 @@ attr.put("maxx", req.getParameter("maxx")); attr.put("miny", req.getParameter("miny")); attr.put("maxy", req.getParameter("maxy")); + attr.put("format", req.getParameter("format")); return attr; } + + + protected void prepareHeader( + HttpServletRequest req, + HttpServletResponse resp + ) { + String export = req.getParameter("export"); + + if (export != null && export.equals("true")) { + String format = req.getParameter("format"); + + if (format == null || format.length() == 0) { + format = "png"; + } + + String fn = "chart_export" + getFileExtension(format); + + resp.setHeader("Content-Disposition", "attachment;filename=" + fn); + resp.setHeader("Content-Type", getMimeType(format)); + } + } + + + protected String getFileExtension(String format) { + if (format.equals("png")) { + return ".png"; + } + else if (format.equals("pdf")) { + return ".pdf"; + } + else if (format.equals("svg")) { + return ".svg"; + } + + return ".png"; + } + + + protected String getMimeType(String format) { + if (format.equals("png")) { + return "image/png"; + } + else if (format.equals("pdf")) { + return "application/pdf"; + } + else if (format.equals("svg")) { + return "svg+xml"; + } + + return "image/png"; + } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :