[Dive4elements-commits] [PATCH] Map print settings can now be configured via settings window

Wald Commits scm-commit at wald.intevation.org
Sun Nov 11 14:44:20 CET 2012


# HG changeset patch
# User Christian Lins <christian.lins at intevation.de>
# Date 1352641452 -3600
# Node ID bd78d2b0e309cae4b8edff964f1239c3636ecca2
# Parent  6db783627137827a90fd84934ef09620fb41fe5c
Map print settings can now be configured via settings window.

Configurable for now are page layout (A0 or A4), caption text and
comment text.

diff -r 6db783627137 -r bd78d2b0e309 flys-client/src/main/java/de/intevation/flys/client/client/ui/map/MapPrintSettingsPanel.java
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/map/MapPrintSettingsPanel.java	Sat Nov 10 23:47:38 2012 +0100
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/map/MapPrintSettingsPanel.java	Sun Nov 11 14:44:12 2012 +0100
@@ -28,6 +28,11 @@
 
 public class MapPrintSettingsPanel extends Canvas {
 
+    public static final String MAPFISH_COMMENT  = "mapfish-comment";
+    public static final String MAPFISH_LAYOUT   = "mapfish-layout";
+    public static final String MAPFISH_MAPTITLE = "mapfish-mapTitle";
+    public static final String MAPFISH_PAGESIZE = "mapfish-pageSize";
+
     /** The interface that provides i18n messages. */
     protected FLYSConstants MSG = GWT.create(FLYSConstants.class);
 
@@ -38,9 +43,15 @@
     protected Collection collection;
     protected Settings settings;
     protected TextItem pageTitle = new TextItem();
+    protected SelectItem pageFormat = createPageFormatSelectItem();
+    protected TextItem pageComment = new TextItem();
+    protected MapToolbar mapToolbar;
+    protected MapPrintSettingsWindow parent;
 
-    public MapPrintSettingsPanel(Collection collection) {
+    public MapPrintSettingsPanel(Collection collection, MapToolbar mapToolbar, MapPrintSettingsWindow parent) {
         this.collection = collection;
+        this.mapToolbar = mapToolbar;
+        this.parent     = parent;
         initLayout();
 
         this.settings = collection.getSettings("print-settings");
@@ -53,24 +64,30 @@
             for (Property prop : properties) {
                 GWT.log("prop=" + prop.getName());
                 PropertySetting props = (PropertySetting)prop;
-                if (props.getName().equals("page-format")) {
-
+                if (props.getName().equals(MAPFISH_PAGESIZE)) {
+                    this.pageFormat.setValue(props.getValue());
                 }
-                else if (props.getName().equals("page-title")) {
+                else if (props.getName().equals(MAPFISH_MAPTITLE)) {
                     this.pageTitle.setValue(props.getValue());
                     GWT.log(props.getName() + "=" + props.getValue());
                 }
+                else if (props.getName().equals(MAPFISH_COMMENT)) {
+                    this.pageComment.setValue(props.getValue());
+                }
             }
         }
     }
 
     protected void initLayout() {
+        // TODO: i18n
         this.pageTitle.setTitle("Seitentitel:");
+        this.pageComment.setTitle("Kommentar:");
 
         DynamicForm df = new DynamicForm();
         df.setFields(
-               createPageFormatSelectItem(),
+               this.pageFormat,
                this.pageTitle,
+               this.pageComment,
                createSaveSettingsButtonItem()
                );
         addChild(df);
@@ -78,11 +95,12 @@
 
     protected SelectItem createPageFormatSelectItem() {
         LinkedHashMap values = new LinkedHashMap();
-        values.put("din_a4", "DIN A4");
-        values.put("din_a0", "DIN A0");
+        // TODO: i18n
+        values.put("A4 portrait", "DIN A4 (Hochformat)");
+        values.put("A0 portrait", "DIN A0 (Hochformat)");
 
         SelectItem selItem = new SelectItem();
-        selItem.setTitle("Seitenformat:");
+        selItem.setTitle("Seitengröße:"); // TODO: i18n
         selItem.setValueMap(values);
         selItem.setDefaultToFirstOption(true);
 
@@ -96,6 +114,8 @@
             @Override
             public void onClick(ClickEvent event) {
                 updateCollection();
+                mapToolbar.updatePrintUrl();
+                parent.destroy();
             }
         });
         btn.setTitle("Speichern");
@@ -109,7 +129,9 @@
         GWT.log("MapPrintSettingsPanel.updateCollection via RPC now");
 
         List<Property> properties = new ArrayList<Property>();
-        properties.add(new PropertySetting("page-title", this.pageTitle.getValueAsString()));
+        properties.add(new PropertySetting(MAPFISH_MAPTITLE, this.pageTitle.getValueAsString()));
+        properties.add(new PropertySetting(MAPFISH_COMMENT, this.pageComment.getValueAsString()));
+        properties.add(new PropertySetting(MAPFISH_LAYOUT, this.pageFormat.getValueAsString()));
         settings.setSettings("default", properties);
 
         collection.addSettings("print-settings", settings);
diff -r 6db783627137 -r bd78d2b0e309 flys-client/src/main/java/de/intevation/flys/client/client/ui/map/MapPrintSettingsWindow.java
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/map/MapPrintSettingsWindow.java	Sat Nov 10 23:47:38 2012 +0100
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/map/MapPrintSettingsWindow.java	Sun Nov 11 14:44:12 2012 +0100
@@ -8,14 +8,18 @@
 
     protected MapPrintSettingsPanel panel;
 
-    public MapPrintSettingsWindow(Collection collection) {
+    public MapPrintSettingsWindow(Collection collection, MapToolbar mapToolbar) {
         setWidth(300);
-        setHeight(400);
+        setHeight(200);
 
+        // TODO: i18n
         setTitle("PDF-Druckeinstellungen");
 
-        this.panel = new MapPrintSettingsPanel(collection);
+        this.panel = new MapPrintSettingsPanel(collection, mapToolbar, this);
         this.panel.setPadding(20);
         addItem(this.panel);
+
+        setIsModal(true);
+        setShowModalMask(true);
     }
 }
diff -r 6db783627137 -r bd78d2b0e309 flys-client/src/main/java/de/intevation/flys/client/client/ui/map/MapToolbar.java
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/map/MapToolbar.java	Sat Nov 10 23:47:38 2012 +0100
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/map/MapToolbar.java	Sun Nov 11 14:44:12 2012 +0100
@@ -653,11 +653,12 @@
 
 
     protected ImgButton createMapPrintSettingsControl() {
+        final MapToolbar mtb = this;
         ImgButton btn = createButton(MSG.printMapSettings(), new ClickHandler() {
             @Override
             public void onClick(ClickEvent event) {
                 MapPrintSettingsWindow mpsw =
-                        new MapPrintSettingsWindow(outputTab.getCollection());
+                        new MapPrintSettingsWindow(outputTab.getCollection(), mtb);
                 outputTab.getCollectionView().addChild(mpsw);
             }
         });
@@ -693,7 +694,7 @@
 
     @Override
     public void onMapZoom(MapZoomListener.MapZoomEvent e) {
-        printMapLink.setSource(createPrintUrl());
+        updatePrintUrl();
     }
 
     protected void appendPrintSettingsToUrl(Collection collection, StringBuilder url) {
@@ -701,20 +702,19 @@
         if (settings != null) {
             List<Property> properties = settings.getSettings("default");
             for (Property prop : properties) {
-                GWT.log("prop=" + prop.getName());
                 PropertySetting props = (PropertySetting)prop;
-                if (props.getName().equals("page-format")) {
-
-                }
-                else if (props.getName().equals("page-title")) {
-                    url.append("&page-title=");
-                    url.append(props.getValue());
-                    GWT.log(props.getName() + "=" + props.getValue());
-                }
+                url.append("&");
+                url.append(props.getName());
+                url.append("=");
+                url.append(props.getValue());
             }
         }
     }
 
+    public void updatePrintUrl() {
+        printMapLink.setSource(createPrintUrl());
+    }
+
     public String createPrintUrl() {
         MapOutputTab ot = (MapOutputTab)getOutputTab();
         Collection collection = ot.getCollection();
diff -r 6db783627137 -r bd78d2b0e309 flys-client/src/main/java/de/intevation/flys/client/server/MapPrintServiceImpl.java
--- a/flys-client/src/main/java/de/intevation/flys/client/server/MapPrintServiceImpl.java	Sat Nov 10 23:47:38 2012 +0100
+++ b/flys-client/src/main/java/de/intevation/flys/client/server/MapPrintServiceImpl.java	Sun Nov 11 14:44:12 2012 +0100
@@ -19,6 +19,7 @@
 import java.net.URLEncoder;
 import java.util.ArrayList;
 import java.util.Collections;
+import java.util.Enumeration;
 import java.util.HashMap;
 import java.util.LinkedHashMap;
 import java.util.List;
@@ -124,10 +125,11 @@
         MapConfig mapConfig,
         Double minX, Double minY,
         Double maxX, Double maxY,
-        Map<String, Object> settings
+        Map<String, Object> pageSpecs
     ) {
         Map<String, Object> spec = new LinkedHashMap<String, Object>();
-        spec.put("layout",       "A4 portrait");
+        spec.put("pageSize",     "A4");
+        spec.put("landscape",    "false");
         spec.put("title",        "FLYS Druck");
         spec.put("srs",          "EPSG:" + mapConfig.getSrid());
         spec.put("dpi",          Integer.valueOf(254));
@@ -135,6 +137,8 @@
         spec.put("geodaetic",    "true");
         spec.put("outputFormat", "pdf");
 
+        spec.putAll(pageSpecs);
+
         String ns = ArtifactNamespaceContext.NAMESPACE_URI;
 
         List<Layer> ls = new ArrayList<Layer>();
@@ -187,7 +191,7 @@
         page.put("rotation", Integer.valueOf(0));
 
         // This may overwrite default settings above
-        page.putAll(settings);
+        page.putAll(pageSpecs);
 
         pages.add(page);
         spec.put("pages", pages);
@@ -256,9 +260,15 @@
         }
 
         // Retrieve print settings from request
-        Map<String, Object> settings = new HashMap<String, Object>();
-        String pageTitle = req.getParameter("page-title");
-        settings.put("mapTitle", pageTitle);
+        Map<String, Object> pageSpecs = new HashMap<String, Object>();
+        Enumeration<String> paramNames = req.getParameterNames();
+        while (paramNames.hasMoreElements()) {
+            String paramName = paramNames.nextElement();
+            if (paramName.startsWith("mapfish-")) {
+                String paramValue = req.getParameter(paramName);
+                pageSpecs.put(paramName.substring(8), paramValue);
+            }
+        }
 
         String url = getURL();
 
@@ -325,7 +335,7 @@
             mapConfig,
             minX, minY,
             maxX, maxY,
-            settings);
+            pageSpecs);
 
         if (log.isDebugEnabled()) {
             log.debug("Generated spec:");
diff -r 6db783627137 -r bd78d2b0e309 flys-client/src/main/webapp/WEB-INF/config.yaml
--- a/flys-client/src/main/webapp/WEB-INF/config.yaml	Sat Nov 10 23:47:38 2012 +0100
+++ b/flys-client/src/main/webapp/WEB-INF/config.yaml	Sun Nov 11 14:44:12 2012 +0100
@@ -146,3 +146,50 @@
           maxIconWidth: 32
           maxIconHeight: 32
       footer: *commonFooter
+      
+  #===========================================================================
+  A0 portrait:
+  #===========================================================================
+    metaData:
+      title: '${title}'
+      author: 'MapFish print module'
+      subject: 'Simple layout'
+      keywords: 'map,print'
+      creator: 'MapFish'
+
+    #-------------------------------------------------------------------------
+    mainPage:
+      pageSize: A0
+      rotation: true
+      header:
+        height: 50
+        items:
+          - !text
+            font: Helvetica
+            fontSize: 30
+            align: right
+            text: '${mapTitle}'
+      items:
+        - !map
+          spacingAfter: 30
+          width: 1760
+          height: 1932
+        - !scalebar
+          type: bar
+          maxSize: 100
+          barBgColor: white
+          fontSize: 8
+          align: right
+        - !text
+          text: '${comment}'
+          spacingAfter: 30
+        - !text
+          font: Helvetica
+          fontSize: 9
+          align: right
+          text: '1:${scale} ${now MM.dd.yyyy}'
+        - !legends
+          align: left
+          maxIconWidth: 32
+          maxIconHeight: 32
+      footer: *commonFooter


More information about the Dive4elements-commits mailing list