[Commits] r1741 - in sandbox/ahocevar/playground: trunk/geoext/lib trunk/geoext/lib/GeoExt/data trunk/geoext/lib/GeoExt/widgets trunk/geoext/lib/GeoExt/widgets/form ux/Printing/examples ux/Printing/ux/widgets/form

commits at geoext.org commits at geoext.org
Wed Jan 13 23:11:56 CET 2010


Author: ahocevar
Date: 2010-01-13 23:11:55 +0100 (Wed, 13 Jan 2010)
New Revision: 1741

Added:
   sandbox/ahocevar/playground/trunk/geoext/lib/GeoExt/widgets/PrintExtent.js
Removed:
   sandbox/ahocevar/playground/trunk/geoext/lib/GeoExt/widgets/form/PrintForm.js
Modified:
   sandbox/ahocevar/playground/trunk/geoext/lib/GeoExt.js
   sandbox/ahocevar/playground/trunk/geoext/lib/GeoExt/data/PrintPage.js
   sandbox/ahocevar/playground/trunk/geoext/lib/GeoExt/data/PrintProvider.js
   sandbox/ahocevar/playground/trunk/geoext/lib/GeoExt/widgets/PrintMapPanel.js
   sandbox/ahocevar/playground/ux/Printing/examples/SimplePrint.js
   sandbox/ahocevar/playground/ux/Printing/ux/widgets/form/SimplePrint.js
Log:
renamed PrintPage::fitPage to PrintPage::fit and refactored GeoExt.form.PrintForm to GeoExt.PrintExtent, an item that can be added to a MapPanel.

Modified: sandbox/ahocevar/playground/trunk/geoext/lib/GeoExt/data/PrintPage.js
===================================================================
--- sandbox/ahocevar/playground/trunk/geoext/lib/GeoExt/data/PrintPage.js	2010-01-13 22:08:17 UTC (rev 1740)
+++ sandbox/ahocevar/playground/trunk/geoext/lib/GeoExt/data/PrintPage.js	2010-01-13 22:11:55 UTC (rev 1741)
@@ -94,6 +94,8 @@
             "change"
         );
 
+        GeoExt.data.PrintPage.superclass.constructor.apply(this, arguments);
+
         this.feature = new OpenLayers.Feature.Vector(
             OpenLayers.Geometry.fromWKT("POLYGON((-1 -1,1 -1,1 1,-1 1,-1 -1))"));
         this.handle = new OpenLayers.Feature.Vector(
@@ -106,8 +108,6 @@
             "layoutchange": this.updateByHandle,
             scope: this
         });
-
-        GeoExt.data.PrintPage.superclass.constructor.apply(this, arguments);
     },
 
     /** api: method[getCenter]
@@ -168,7 +168,7 @@
         }
     },
     
-    /** api: method[fitPage]
+    /** api: method[fit]
      *  :param map: ``OpenLayers.Map`` The map to fit the page to.
      *  :param loose: ``Boolean`` If set to true, the print extent will
      *      be at least as large as the visible map extent. Default is false.
@@ -176,7 +176,7 @@
      *  Fits the page layout to the current map extent, using the smallest
      *  scale that entirely fits the extent.
      */
-    fitPage: function(map, loose) {
+    fit: function(map, loose) {
         this.suspendEvents();
         this.setCenter(map.getCenter());
         this.resumeEvents();

Modified: sandbox/ahocevar/playground/trunk/geoext/lib/GeoExt/data/PrintProvider.js
===================================================================
--- sandbox/ahocevar/playground/trunk/geoext/lib/GeoExt/data/PrintProvider.js	2010-01-13 22:08:17 UTC (rev 1740)
+++ sandbox/ahocevar/playground/trunk/geoext/lib/GeoExt/data/PrintProvider.js	2010-01-13 22:11:55 UTC (rev 1741)
@@ -26,7 +26,7 @@
  *                  var printPage = new GeoExt.data.PrintPage({
  *                      printProvider: printProvider
  *                  });
- *                  printPage.fitPage(map);
+ *                  printPage.fit(map);
  *                  printProvider.print(map, [printPage]);
  *              }
  *          }
@@ -214,6 +214,8 @@
             "print"
         );
         
+        GeoExt.data.PrintProvider.superclass.constructor.apply(this, arguments);
+
         this.scales = new Ext.data.JsonStore({
             root: "scales",
             sortInfo: {field: "value", direction: "DESC"},
@@ -242,8 +244,6 @@
             }
             this.loadCapabilities();
         }
-
-        GeoExt.data.PrintProvider.superclass.constructor.apply(this, arguments);
     },
     
     /** api: method[setLayout]

Copied: sandbox/ahocevar/playground/trunk/geoext/lib/GeoExt/widgets/PrintExtent.js (from rev 1738, sandbox/ahocevar/playground/trunk/geoext/lib/GeoExt/widgets/form/PrintForm.js)
===================================================================
--- sandbox/ahocevar/playground/trunk/geoext/lib/GeoExt/widgets/PrintExtent.js	                        (rev 0)
+++ sandbox/ahocevar/playground/trunk/geoext/lib/GeoExt/widgets/PrintExtent.js	2010-01-13 22:11:55 UTC (rev 1741)
@@ -0,0 +1,198 @@
+/**
+ * Copyright (c) 2008-2009 The Open Source Geospatial Foundation
+ * 
+ * Published under the BSD license.
+ * See http://svn.geoext.org/core/trunk/geoext/license.txt for the full text
+ * of the license.
+ */
+Ext.namespace("GeoExt")
+
+/** api: (define)
+ *  module = GeoExt
+ *  class = PrintExtent
+ *  base_link = `Ext.Component <http://extjs.com/deploy/dev/docs/?class=Ext.Component>`_
+ */
+
+/** api: example
+ *  Sample code to create a MapPanel with a PrintExtent:
+ * 
+ *  .. code-block:: javascript
+ *     
+ *      var mapPanel = new GeoExt.MapPanel({
+ *          border: false,
+ *          renderTo: "div-id",
+ *          map: {
+ *              maxExtent: new OpenLayers.Bounds(-90, -45, 90, 45)
+ *          },
+ *          items: [{
+ *              xtype: "gx_printextent",
+ *              printProvider: new GeoExt.data.PrintProvider({
+ *                  capabilities: printCapabilities
+ *              })
+ *          }]
+ *      });
+ *      // print the map
+ *      mapPanel.items.get(0).print();
+ */
+
+/** api: constructor
+ *  .. class:: PrintExtent
+ * 
+ *  Provides a way to show and modify the extents of print pages on the map.
+ *  An instance of this class is added as item to a map. It uses a layer
+ *  to render the page extent and handle features of print pages, and provides
+ *  a control to modify them.
+ */
+GeoExt.PrintExtent = Ext.extend(Ext.Component, {
+    
+    /** api: config[printProvider]
+     *  :class:`GeoExt.data.PrintProvider` The print provider this form
+     *  is connected to.
+     */
+    
+    /** api: property[printProvider]
+     *  :class:`GeoExt.data.PrintProvider` The print provider this form
+     *  is connected to. Read-only.
+     */
+    printProvider: null,
+    
+    /** private: property[map]
+     *  ``OpenLayers.Map`` The map that layer and control is added to.
+     */
+    map: null,
+    
+    /** api: config[layer]
+     *  ``OpenLayers.Layer.Vector`` The layer used to render extent and handle
+     *  features to. Optional, will be created if not provided.
+     */
+
+    /** private: property[layer]
+     *  ``OpenLayers.Layer.Vector`` The layer used to render extent and handle
+     *  features to.
+     */
+    layer: null,
+    
+    /** private: property[control]
+     *  ``OpenLayers.Control.DragFeature`` The control used to change extent
+     *  center, rotation and scale.
+     */
+    control: null,
+    
+    /** api: config[pages]
+     *  Array of :class:`GeoExt.data.PrintPage` The pages that this form
+     *  controls. Optional, will be created if not provided.
+     */
+    
+    /** api: property[pages]
+     *  Array of :class:`GeoExt.data.PrintPage` The pages that this form
+     *  controls.
+     */
+    pages: null,
+    
+    /** private: method[initComponent]
+     */
+    initComponent: function() {
+        GeoExt.PrintExtent.superclass.initComponent.call(this);
+        if(!this.pages) {
+            this.pages = [];
+        }
+    },
+    
+    /** api: method[print]
+     *  :param options: ``Object`` Options to send to the PrintProvider's
+     *      print method. See :ref:`GeoExt.data.PrintProvider.print`.
+     *  
+     *  Prints all pages as shown on the map.
+     */
+    print: function(options) {
+        this.printProvider.print(this.map, this.pages, options);
+    },
+    
+    /** private: method[addToMapPanel]
+     *  :param mapPanel: class:`GeoExt.MapPanel`
+     */
+    addToMapPanel: function(mapPanel) {
+        this.map = mapPanel.map;
+        this.initLayer();
+        this.initControl();
+    },
+
+    /** private: method[removeFromMapPanel]
+     *  :param mapPanel: class:`GeoExt.MapPanel`
+     */
+    removeFromMapPanel: function(mapPanel) {
+        this.control.deactivate();
+        this.map.removeControl(this.control);
+        for(var i=0, len=this.pages.length; i<len; ++i) {
+            var page = this.pages[i];
+            this.layer.removeFeatures([page.feature, page.handle]);
+        }
+        this.initialConfig.layer || this.map.removeLayer(layer);
+        this.map = null;
+    },
+    
+    /** private: method[initLayer]
+     */
+    initLayer: function() {
+        if(!this.layer) {
+            this.layer = new OpenLayers.Layer.Vector(null, {
+                displayInLayerSwitcher: false
+            });
+            for(var i=0, len=this.pages.length; i<len; ++i) {
+                var page = this.pages[i];
+                this.layer.addFeatures([page.feature, page.handle]);
+            }
+        }
+        if(!this.layer.map) {
+            this.map.addLayer(this.layer);
+        }
+    },
+    
+    /** private: method[initControl]
+     */
+    initControl: function() {
+        var pages = this.pages;
+
+        if(!this.control) {
+            var updateHandles = function() {
+                for(var i=0, len=pages.length; i<len; ++i) {
+                    pages[i].updateHandle();
+                };
+            }
+            this.control = new OpenLayers.Control.DragFeature(this.layer, {
+                onDrag: function(feature) {
+                    var geom = feature.geometry;
+                    if(geom instanceof OpenLayers.Geometry.Polygon) {
+                        // a page geometry was dragged
+                        updateHandles();
+                    } else if(geom instanceof OpenLayers.Geometry.Point) {
+                        // a scale/rotation handle was dragged
+                        for(var i=0, len=pages.length; i<len; ++i) {
+                            pages[i].updateByHandle(false);
+                        }
+                    }
+                },
+                onComplete: updateHandles
+            });
+        }
+
+        this.map.addControl(this.control);
+        this.control.activate();
+    },
+    
+    /** private: method[beforeDestroy]
+     */
+    beforeDestroy: function() {
+        this.removeFromMapPanel(this.map);
+        this.control.destroy();
+        if(!this.initialConfig.layer) {
+            this.layer.destroy();
+        }
+        delete this.layer;
+        delete this.control;
+    }
+    
+});
+
+/** api: xtype = gx_printextent */
+Ext.reg('gx_printextent', GeoExt.PrintExtent); 

Modified: sandbox/ahocevar/playground/trunk/geoext/lib/GeoExt/widgets/PrintMapPanel.js
===================================================================
--- sandbox/ahocevar/playground/trunk/geoext/lib/GeoExt/widgets/PrintMapPanel.js	2010-01-13 22:08:17 UTC (rev 1740)
+++ sandbox/ahocevar/playground/trunk/geoext/lib/GeoExt/widgets/PrintMapPanel.js	2010-01-13 22:11:55 UTC (rev 1741)
@@ -167,7 +167,7 @@
      */
     updatePage: function() {
         if(!this._updating) {
-            this.printPage.fitPage(this.map, true);
+            this.printPage.fit(this.map, true);
         }
     },
     

Deleted: sandbox/ahocevar/playground/trunk/geoext/lib/GeoExt/widgets/form/PrintForm.js
===================================================================
--- sandbox/ahocevar/playground/trunk/geoext/lib/GeoExt/widgets/form/PrintForm.js	2010-01-13 22:08:17 UTC (rev 1740)
+++ sandbox/ahocevar/playground/trunk/geoext/lib/GeoExt/widgets/form/PrintForm.js	2010-01-13 22:11:55 UTC (rev 1741)
@@ -1,172 +0,0 @@
-/**
- * Copyright (c) 2008-2009 The Open Source Geospatial Foundation
- * 
- * Published under the BSD license.
- * See http://svn.geoext.org/core/trunk/geoext/license.txt for the full text
- * of the license.
- */
-Ext.namespace("GeoExt.form")
-
-/** api: (define)
- *  module = GeoExt.form
- *  class = PrintForm
- *  base_link = `Ext.form.FormPanel <http://extjs.com/deploy/dev/docs/?class=Ext.form.FormPanel>`_
- */
-
-/** api: constructor
- *  .. class:: PrintForm
- * 
- *  Provides a base class form for working with
- *  :class:`GeoExt.data.PrintProvider`, :class:`GeoExt.data.PrintPage`
- *  and the plugins available for fields to synchronize. The form uses
- *  a layer to draw the page extent and handle features of print pages,
- *  with a control to modify them.
- *  
- *  This form comes with no fields and is meant to be extended (unless it is
- *  enough to configure print extent, scale and rotation interactively on the
- *  map). See :ref:`GeoExt.ux.form.SimplePrint` for a simple implementation.
- */
-GeoExt.form.PrintForm = Ext.extend(Ext.form.FormPanel, {
-    
-    /** api: config[printProvider]
-     *  :class:`GeoExt.data.PrintProvider` The print provider this form
-     *  is connected to.
-     */
-    
-    /** api: property[printProvider]
-     *  :class:`GeoExt.data.PrintProvider` The print provider this form
-     *  is connected to. Read-only.
-     */
-    printProvider: null,
-    
-    /** api: config[map]
-     *  ``GeoExt.MapPanel``|``OpenLayers.Map`` The map the drag control will
-     *  be added to. Optional if a layer is provided and the layer has already
-     *  been added to a map.
-     */
-    
-    /** private: property[map]
-     *  ``OpenLayers.Map`` The map that layer and control will be added to.
-     */
-    map: null,
-    
-    /** api: config[layer]
-     *  ``OpenLayers.Layer.Vector`` The layer used to render extent and handle
-     *  features to. Optional, will be created if not provided.
-     */
-
-    /** private: property[layer]
-     *  ``OpenLayers.Layer.Vector`` The layer used to render extent and handle
-     *  features to.
-     */
-    layer: null,
-    
-    /** private: property[control]
-     *  ``OpenLayers.Control.DragFeature`` The control used to change extent
-     *  center, rotation and scale.
-     */
-    control: null,
-    
-    /** api: config[pages]
-     *  Array of :class:`GeoExt.data.PrintPage` The pages that this form
-     *  controls. Optional, will be created if not provided.
-     */
-    
-    /** api: property[pages]
-     *  Array of :class:`GeoExt.data.PrintPage` The pages that this form
-     *  controls.
-     */
-    pages: null,
-    
-    /** private: method[initComponent]
-     */
-    initComponent: function() {
-        GeoExt.form.PrintForm.superclass.initComponent.call(this);
-        if(this.map instanceof GeoExt.MapPanel) {
-            this.map = this.map.map;
-        }
-        if(!this.map) {
-            this.map = this.layer.map;
-        }
-        
-        if(!this.pages) {
-            this.pages = [];
-        }
-                        
-        this.initLayer();
-        this.initControl();
-
-        this.on({
-            "show": function() {
-                this.layer.setVisibility(true);
-                this.control.activate();
-            },
-            "hide": function() {
-                this.control.deactivate();
-                this.layer.setVisibility(false);
-            }
-        });
-    },
-    
-    /** private: method[initLayer]
-     */
-    initLayer: function() {
-        if(!this.layer) {
-            this.layer = new OpenLayers.Layer.Vector(null, {
-                displayInLayerSwitcher: false
-            });
-        }
-        if(!this.layer.map) {
-            this.map.addLayer(this.layer);
-        }
-    },
-    
-    /** private: method[initControl]
-     */
-    initControl: function() {
-        var pages = this.pages;
-
-        var updateHandles = function() {
-            for(var i=0, len=pages.length; i<len; ++i) {
-                pages[i].updateHandle();
-            };
-        }
-
-        this.control = new OpenLayers.Control.DragFeature(this.layer, {
-            onDrag: function(feature) {
-                if(feature.geometry instanceof OpenLayers.Geometry.Polygon) {
-                    // a page geometry was dragged
-                    updateHandles();
-                } else if(feature.geometry instanceof OpenLayers.Geometry.Point) {
-                    // a scale/rotation handle was dragged
-                    for(var i=0, len=pages.length; i<len; ++i) {
-                        pages[i].updateByHandle(false);
-                    }
-                }
-            },
-            onComplete: updateHandles
-        });
-
-        this.map.addControl(this.control);
-        this.control.activate();
-    },
-    
-    /** private: method[beforeDestroy]
-     */
-    beforeDestroy: function() {
-        Ext.each(this.pages, function(page) {
-            this.layer.removeFeatures(page.feature, page.handle);
-        }, this);
-        this.control.destroy();
-        if(!this.initialConfig.layer) {
-            this.layer.destroy();
-        }
-        delete this.layer;
-        delete this.map;
-        delete this.control;
-    }
-    
-});
-
-/** api: xtype = gx_printform */
-Ext.reg("gx_printform", GeoExt.form.PrintForm);

Modified: sandbox/ahocevar/playground/trunk/geoext/lib/GeoExt.js
===================================================================
--- sandbox/ahocevar/playground/trunk/geoext/lib/GeoExt.js	2010-01-13 22:08:17 UTC (rev 1740)
+++ sandbox/ahocevar/playground/trunk/geoext/lib/GeoExt.js	2010-01-13 22:11:55 UTC (rev 1741)
@@ -113,7 +113,7 @@
             "GeoExt/plugins/PrintPageField.js",
             "GeoExt/plugins/PrintProviderField.js",
             "GeoExt/widgets/PrintMapPanel.js",
-            "GeoExt/widgets/form/PrintForm.js"
+            "GeoExt/widgets/PrintExtent.js"
         );
 
         var agent = navigator.userAgent;

Modified: sandbox/ahocevar/playground/ux/Printing/examples/SimplePrint.js
===================================================================
--- sandbox/ahocevar/playground/ux/Printing/examples/SimplePrint.js	2010-01-13 22:08:17 UTC (rev 1740)
+++ sandbox/ahocevar/playground/ux/Printing/examples/SimplePrint.js	2010-01-13 22:11:55 UTC (rev 1741)
@@ -44,7 +44,7 @@
     
     // a simple print form
     printForm = new GeoExt.ux.form.SimplePrint({
-        map: mapPanel,
+        mapPanel: mapPanel,
         printProvider: printProvider,
         bodyStyle: {padding: "5px"},
         labelWidth: 65,
@@ -93,7 +93,7 @@
      */
     formCt.add(printForm);
     formCt.doLayout();
-    printForm.pages[0].fitPage(mapPanel.map);
+    printForm.pages[0].fit(mapPanel.map);
 
     /* use this code block instead of the above one if you configured the
      * printProvider with url instead of capabilities
@@ -103,7 +103,7 @@
         myMask.hide();
         formCt.add(printForm);
         formCt.doLayout();
-        printForm.pages[0].fitPage(mapPanel.map);
+        printForm.pages[0].fit(mapPanel.map);
     });
      */
     

Modified: sandbox/ahocevar/playground/ux/Printing/ux/widgets/form/SimplePrint.js
===================================================================
--- sandbox/ahocevar/playground/ux/Printing/ux/widgets/form/SimplePrint.js	2010-01-13 22:08:17 UTC (rev 1740)
+++ sandbox/ahocevar/playground/ux/Printing/ux/widgets/form/SimplePrint.js	2010-01-13 22:11:55 UTC (rev 1741)
@@ -14,21 +14,17 @@
 /** api: (define)
  *  module = GeoExt.form
  *  class = SimplePrint
+ *  base_link = `Ext.form.FormPanel <http://extjs.com/deploy/dev/docs/?class=Ext.form.FormPanel>`_
  */
 
-/** api: (extends)
- * ../../trunk/lib/GeoExt/widgets/form/PrintForm.js
- */
-
 /** api: constructor
  *  .. class:: SimplePrint
  * 
- *  A simple implementation of :ref:`GeoExt.form.PrintForm`. The form
- *  creates a single print page. Layout, DPI, scale and rotation are
- *  configurable. A Print button is also added to actually let the
- *  printProvider send the configuration to the print service.
+ *  An instance of this form creates a single print page. Layout, DPI, scale
+ *  and rotation are configurable in the form. A Print button is also added to
+ *  the form.
  */
-GeoExt.ux.form.SimplePrint = Ext.extend(GeoExt.form.PrintForm, {
+GeoExt.ux.form.SimplePrint = Ext.extend(GeoExt.form.FormPanel, {
     
     /* begin i18n */
     /** api: config[layoutText] ``String`` i18n */
@@ -45,6 +41,16 @@
     creatingPdfText: "Creating PDF...",
     /* end i18n */
    
+    /** api: config[printProvider]
+     *  :class:`GeoExt.data.PrintProvider` The print provider this form
+     *  is connected to.
+     */
+    
+    /** api: config[mapPanel]
+     *  :class:`GeoExt.MapPanel` The map panel that this form should be
+     *  connected to.
+     */
+
     /** api: config[printOptions]
      *  ``Object`` Optional options for the printProvider's print command.
      */
@@ -75,32 +81,43 @@
      */
     busyMask: null,
    
+    /** private: property[printExtent]
+     *  :class:`GeoExt.PrintExtent`
+     */
+    printExtent: null,
+   
     /** private: method[initComponent]
      */
     initComponent: function() {
         GeoExt.ux.form.SimplePrint.superclass.initComponent.call(this);
         
-        this.pages.push(new GeoExt.data.PrintPage({
-            printProvider: this.printProvider,
-            layer: this.layer
-        }));
+        this.pages = [new GeoExt.data.PrintPage({
+            printProvider: this.initialConfig.printProvider
+        })];
         
+        this.printExtent = new GeoExt.PrintExtent({
+            printProvider: this.initialConfig.printProvider,
+            pages: this.pages
+        });
+        
+        this.mapPanel.add(this.printExtent);
+        
         if (!this.busyMask) {
             this.busyMask = new Ext.LoadMask(Ext.getBody(), {
                 msg: this.creatingPdfText
             });
         }
 
-        this.printProvider.on({
+        this.printExtent.printProvider.on({
             "beforeprint": this.busyMask.show,
             "print": this.busyMask.hide,
             scope: this.busyMask
         });
 
-        if(this.printProvider.capabilities) {
+        if(this.printExtent.printProvider.capabilities) {
             this.initForm();
         } else {
-            this.printProvider.on({
+            this.printExtent.printProvider.on({
                 "loadcapabilities": this.initForm,
                 scope: this,
                 single: true
@@ -112,7 +129,7 @@
      *  Creates and adds items to the form.
      */
     initForm: function() {
-        var p = this.printProvider;
+        var p = this.printExtent.printProvider;
         var hideUnique = this.initialConfig.hideUnique !== false;
         !(hideUnique && p.layouts.getCount() <= 1) && this.add({
             xtype: "combo",
@@ -168,8 +185,7 @@
         this.addButton({
             text: this.printText,
             handler: function() {
-                p.print(this.map, this.pages,
-                    this.printOptions);
+                this.printExtent.print(this.printOptions);
             },
             scope: this
         });
@@ -180,8 +196,9 @@
     /** private: method[beforeDestroy]
      */
     beforeDestroy: function() {
-        this.printProvider.un("beforePrint", this.busyMask.show, this.busyMask);
-        this.printProvider.un("print", this.busyMask.hide, this.busyMask);
+        var p = this.printExtent.printProvider;
+        p.un("beforePrint", this.busyMask.show, this.busyMask);
+        p.un("print", this.busyMask.hide, this.busyMask);
         GeoExt.SimplePrint.superclass.beforeDestroy.apply(this, arguments);
     }
     



More information about the Commits mailing list