[Commits] r1188 - in apps/opengeo/geoexplorer/trunk/src: script/app script/app/GeoExplorer theme/app

commits at geoext.org commits at geoext.org
Wed Jul 1 02:49:38 CEST 2009


Author: tschaub
Date: 2009-07-01 02:49:38 +0200 (Wed, 01 Jul 2009)
New Revision: 1188

Removed:
   apps/opengeo/geoexplorer/trunk/src/script/app/GeoExplorer/MapToolMenu.js
   apps/opengeo/geoexplorer/trunk/src/script/app/GeoExplorer/MapToolSplitToggle.js
   apps/opengeo/geoexplorer/trunk/src/script/app/GeoExplorer/MapToolToggle.js
Modified:
   apps/opengeo/geoexplorer/trunk/src/script/app/GeoExplorer.js
   apps/opengeo/geoexplorer/trunk/src/script/app/loader.js
   apps/opengeo/geoexplorer/trunk/src/theme/app/geoexplorer.css
Log:
Using GeoExt.Action instead of MapTool*.

Deleted: apps/opengeo/geoexplorer/trunk/src/script/app/GeoExplorer/MapToolMenu.js
===================================================================
--- apps/opengeo/geoexplorer/trunk/src/script/app/GeoExplorer/MapToolMenu.js	2009-07-01 00:33:09 UTC (rev 1187)
+++ apps/opengeo/geoexplorer/trunk/src/script/app/GeoExplorer/MapToolMenu.js	2009-07-01 00:49:38 UTC (rev 1188)
@@ -1,75 +0,0 @@
-/**
- * Copyright (c) 2008 The Open Planning Project
- */
-
-/**
- * api: (define)
- * module = GeoExplorer
- * class = MapToolMenu(config)
- * extends = Ext.menu.Menu
- */
-
-/**
- * api: example
- *
- * This example uses default names and icons for the menu entries::
- *
- *     var measure, select, zoomBox, draw; // OpenLayers Controls
- *     var menu = new GeoExplorer.MapToolMenu({tools: [measure, select, zoomBox, draw]});
- *
- * This one provides a custom name and icon for one of the entries::
- *
- *     var measure, select, zoomBox, draw; // OpenLayers Controls
- *     var menu = new GeoExplorer.MapToolMenu({tools: [{
- *             text: 'Find a distance', 
- *             tool: measure, 
- *             iconCls: 'x-icon-distance-finder'
- *         }, 
- *         select, 
- *         zoomBox, 
- *         draw
- *     ]});
- */
-
-/*
- * api: constructor[MapToolMenu]
- * :param: config: The configuration object for the new menu
- *
- * Simply create a menu that manipulates OpenLayers map controls.
- *
- * In addition to the normal ``[items]`` array, :class:`GeoExplorer.MapToolMenu` recognizes
- * a ``[tools]`` array.  This can be an array of OpenLayers Control objects, or
- * of simple configuration objects analogous to Ext Map entries.
- *
- * ..seealso:: :class:`Ext.menu.Menu`
- */
-Ext.namespace("GeoExplorer");
-GeoExplorer.MapToolMenu = function(options) { 
-    options.items = options.items || [];
-
-    var disableTools = function() {
-        for (var i = 0, len = options.tools.length; i < len; i++) {
-            var t = options.tools[i].tool || options.tools[i];
-            t.deactivate();
-        }
-    };
-
-    for (var i = 0, len = options.tools.length; i < len; i++) {
-        var conf = options.tools[i];
-        var t = conf.tool || conf;
-        options.items.push(Ext.applyIf(conf, {
-            text: t.CLASS_NAME,
-            iconCls: t.CLASS_NAME,
-            handler: (function(tool){
-                return function() {
-                    disableTools();
-                    tool.activate();
-                };
-            })(t),
-            scope: this
-        }));
-    }
-    GeoExplorer.MapToolMenu.superclass.constructor.call(this, options);
-};
-
-Ext.extend(GeoExplorer.MapToolMenu, Ext.menu.Menu);

Deleted: apps/opengeo/geoexplorer/trunk/src/script/app/GeoExplorer/MapToolSplitToggle.js
===================================================================
--- apps/opengeo/geoexplorer/trunk/src/script/app/GeoExplorer/MapToolSplitToggle.js	2009-07-01 00:33:09 UTC (rev 1187)
+++ apps/opengeo/geoexplorer/trunk/src/script/app/GeoExplorer/MapToolSplitToggle.js	2009-07-01 00:49:38 UTC (rev 1188)
@@ -1,164 +0,0 @@
-/**
- * Copyright (c) 2008 The Open Planning Project
- * 
- * @requires GeoExplorer/MapToolMenu.js
- */
-
-/**
- * api: (define)
- * module = GeoExplorer
- * class = MapToolSplitToggle(config)
- * extends = Ext.SplitButton
- */
-
-/**
- * api: example
- *
- * This example uses default names and icons for the button and menu entries::
- *      var measure, select, zoomBox, draw; // OpenLayers Controls
- *      var menu = new GeoExplorer.MapToolSplitToggle({defaultTool: select, tools: [measure, select, zoomBox, draw]});
- *
- * This one provides a custom name and icon for one of the entries::
- *      var measure, select, zoomBox, draw; // OpenLayers Controls
- *      var menu = new GeoExplorer.MapToolSplitToggle({
- *          defaultTool: zoomBox,
- *          tools: [{
- *              text: 'Find a distance', 
- *              tool: measure, 
- *              iconCls: 'x-icon-distance-finder'
- *          }, 
- *          select, 
- *          zoomBox, 
- *          draw
- *      ]});
- */
-
-/**
- * api: constructor[MapToolSplitToggle]
- * :param: config - the configuration options for the component
- *
- * Creates an Ext SplitButton suited to switching between multiple related 
- * OpenLayers Controls. The MapToolSplitToggle accepts an array of controls,
- * which can be activated from the dropdown menu.  The main button simply 
- * toggles the most recently used control.
- *
- * In addition to the options accepted by Ext.SplitButton, the 
- * MapToolSplitToggle accepts:
- *  * defaultTool - :class:`OpenLayers.Control` the control which is to be 
- *    activated if the button is toggled before the user selects one from the
- *    drop-down menu.
- *  * tools - :class:`Array` the controls to display in the drop-down menu.  
- *    These may be simple Control objects, or Ext menu specifications with a 
- *    tool parameter containing the control.  
- *
- * ..seealso:: :class:`GeoExplorer.MapToolMenu`
- */
-Ext.namespace("GeoExplorer");
-GeoExplorer.MapToolSplitToggle = function(options) { 
-    this.lastActiveTool = options.defaultTool || options.tools[0];
-    this.tools = options.tools;
-
-    Ext.applyIf(options, {
-        enableToggle: true,
-        iconCls: this.findIconCls(),
-        toggleHandler: this.handleEvent,
-        handler: this.handleEvent,
-        scope: this,
-        menu: new GeoExplorer.MapToolMenu({tools: options.tools})
-    });
-
-    options.menu.on("itemclick", this.handleMenu, this);
-
-    GeoExplorer.MapToolSplitToggle.superclass.constructor.call(this, options);
-
-    if (options.toggleGroup) {
-        this.on("render", 
-            function() {Ext.ButtonToggleMgr.register(this);},
-            this);
-    }
-
-};
-
-Ext.extend(GeoExplorer.MapToolSplitToggle, Ext.SplitButton, {
-    /**
-     * api: property[lastActiveTool]
-     * The most recently selected :class:`OpenLayers.Control`, to be toggled 
-     * when the main button is.
-     */
-    lastActiveTool: null,
-
-    /**
-     * api: property[tools]
-     * :class:`Array` the OpenLayers tools from this component's configuration.
-     */
-    tools: null,
-
-    onClick: function (e) {
-        e.preventDefault();
-        if (!this.disabled) {
-            if (e.getTarget(".x-btn-menu-arrow-wrap")) {
-                if (this.menu && 
-                !this.menu.isVisible() && 
-                !this.ignoreNextClick) { 
-                    this.showMenu();
-                }
-                this.fireEvent("arrowclick", this, e);
-                if (this.arrowHandler) {
-                    this.arrowHandler.call(this.scope || this, this, e);
-                }
-            } else {
-                if (this.enableToggle && 
-                    (this.allowDepress !== false || 
-                    !this.pressed)) {
-                    this.toggle();
-                }
-                this.fireEvent("click", this, e);
-                if (this.handler) {
-                    this.handler.call(this.scope || this, this, e);
-                }
-            }
-        }
-    },
-    
-    /** api: method[handleEvent]
-     * :param: item: the component that triggered the event (ie, this 
-     *      SplitButton)
-     *
-     * Called when the main button is toggled, handled the (de)activation of 
-     * the last active tool.
-     */
-    handleEvent: function(item) {
-        if (item.pressed) {
-            this.lastActiveTool.activate();
-        } else { 
-            this.lastActiveTool.deactivate();
-        }
-    }, 
-
-    /** api: method[handleMenu]
-     * :param: item: the component that triggered the event (ie, the Menu item)
-     * :param: evt: the Ext selection event
-     *
-     * Called when an item in the menu is selected.  All this does is update 
-     * :attr:`~GeoExplorer.MapToolSplitToggle.lastActiveTool`; the menu should be a 
-     * :class:`GeoExplorer.MapToolMenu` to handle the control (de)activation.
-     */
-    handleMenu: function(item, evt) {
-        for (var i = 0, len = this.tools.length; i < len; i++) {
-            var t = this.tools[i].tool || this.tools[i];
-            if (t.active) {
-               this.lastActiveTool = t;
-               if (item.iconCls) this.setIconClass(item.iconCls);
-               this.toggle(true);
-            }
-        }
-    },
-    
-    /** private: method[findIconCls]
-     * Determine the icon class for this split button, based on the 
-     * :class:`OpenLayers.Control` the button has been configured with.
-     */
-    findIconCls: function() {
-        return this.lastActiveTool.CLASS_NAME;
-    }
-});

Deleted: apps/opengeo/geoexplorer/trunk/src/script/app/GeoExplorer/MapToolToggle.js
===================================================================
--- apps/opengeo/geoexplorer/trunk/src/script/app/GeoExplorer/MapToolToggle.js	2009-07-01 00:33:09 UTC (rev 1187)
+++ apps/opengeo/geoexplorer/trunk/src/script/app/GeoExplorer/MapToolToggle.js	2009-07-01 00:49:38 UTC (rev 1188)
@@ -1,87 +0,0 @@
-/**
- * Copyright (c) 2008 The Open Planning Project
- */
-
-/**
- * api: example
- *
- * This example uses default names and icons for the button:: 
- *
- *      var measure = new OpenLayers.Control.Measure(OpenLayers.Handler.Path);
- *      var btn = new GeoExplorer.MapToolToggle({tool: measure});
- *
- * This one provides a custom name and icon::
- *
- *      var measure = new OpenLayers.Control.Measure(OpenLayers.Handler.Path);
- *      var btn = new GeoExplorer.MapToolToggle({
- *              text: 'Find a distance', 
- *              tool: measure, 
- *              iconCls: 'x-icon-distance-finder'
- *          });
- */
-
-/**
- * api: constructor[MapToolToggle]
- * :param: config: :class:`Object` with the configuration options for this 
- *     split toggle
- *
- * Creates a :class:`Ext.Button` suited to activating and deactivating an 
- * :class:`OpenLayers.Control`. The MapToolToggle accepts a control as part of 
- * its configuration.
- *
- * In addition to the options accepted by :class:`Ext.Button`, the MapToolToggle
- * accepts a property named ``tool``\ , an :class:`OpenLayers.Control` to be 
- * manipulated by the button 
- *
- * .. seealso:: :class:`Ext.Button`
- */
-Ext.namespace("GeoExplorer");
-GeoExplorer.MapToolToggle = function(options) {
-    this.mapTool = options.tool;
-    Ext.applyIf(options, {
-        text: this.findLabel(),
-        enableToggle: true,
-        iconCls: this.findIconCls(),
-        handler: this.handleEvent,
-        scope: this
-    });
-    GeoExplorer.MapToolToggle.superclass.constructor.call(this, options);
-};
-
-Ext.extend(GeoExplorer.MapToolToggle, Ext.Button, {
-    /** api: property[mapTool]
-     * The OpenLayers Control that this button toggles.
-     */
-    mapTool: null,
-
-    /** api: method[handleEvent]
-     * :param: item: the component that triggered the event 
-     *     (ie, this SplitButton)
-     *
-     * Called when the button is toggled, handling the (de)activation of the 
-     * button's tool.
-     */
-    handleEvent: function(item) {
-        if (item.pressed) {
-            this.mapTool.activate();
-        } else { 
-            this.mapTool.deactivate();
-        }
-    }, 
-    
-    /** api: method[findIconCls] *
-     * Determine the icon class for this split button, based on the 
-     * :class:`OpenLayers.Control` the button has been configured with.
-     */
-    findIconCls: function() {
-        return this.mapTool.CLASS_NAME;
-    },
-
-    /** api: method[findLabel]
-     * Determine the text label for this split button, based on the 
-     * :class:`OpenLayers.Control` the button has been configured with.
-     */
-    findLabel: function() {
-        return this.mapTool.CLASS_NAME;
-    }
-});

Modified: apps/opengeo/geoexplorer/trunk/src/script/app/GeoExplorer.js
===================================================================
--- apps/opengeo/geoexplorer/trunk/src/script/app/GeoExplorer.js	2009-07-01 00:33:09 UTC (rev 1187)
+++ apps/opengeo/geoexplorer/trunk/src/script/app/GeoExplorer.js	2009-07-01 00:49:38 UTC (rev 1188)
@@ -5,7 +5,6 @@
 /*
  * @requires GeoExplorer/util.js
  * @requires GeoExplorer/GroupContainer.js
- * @requires GeoExplorer/MapToolSplitToggle.js
  * @requires GeoExplorer/CapabilitiesGrid.js
  * @requires GeoExplorer/NewSourceWindow.js
  */
@@ -1095,31 +1094,83 @@
         this.mapPanel.layers.on("add", updateInfo, this);
         this.mapPanel.layers.on("remove", updateInfo, this);
 
-        // create length measure control
-        var measureLength = this.createMeasureTool(
-            OpenLayers.Handler.Path, 'Length');
-        this.map.addControl(measureLength);
-        
-        // create area measure control
-        var measureArea = this.createMeasureTool(
-            OpenLayers.Handler.Polygon, 'Area');
-        this.map.addControl(measureArea);
-
+        // create split button for measure controls
+        var activeIndex = 0;
+        var measureSplit = new Ext.SplitButton({
+            iconCls: "icon-measure-length",
+            tooltip: "Measure",
+            enableToggle: true,
+            toggleGroup: toolGroup, // Ext doesn't respect this, registered with ButtonToggleMgr below
+            allowDepress: false, // Ext doesn't respect this, handler deals with it
+            handler: function(button, event) {
+                // allowDepress should deal with this first condition
+                if(!button.pressed) {
+                    button.toggle();
+                } else {
+                    button.menu.items.itemAt(activeIndex).setChecked(true);
+                }
+            },
+            listeners: {
+                toggle: function(button, pressed) {
+                    // toggleGroup should handle this
+                    if(!pressed) {
+                        button.menu.items.each(function(i) {
+                            i.setChecked(false);
+                        });
+                    }
+                },
+                render: function(button) {
+                    // toggleGroup should handle this
+                    Ext.ButtonToggleMgr.register(button);
+                }
+            },
+            menu: new Ext.menu.Menu({
+                items: [
+                    new Ext.menu.CheckItem(
+                        new GeoExt.Action({
+                            text: "Length",
+                            iconCls: "icon-measure-length",
+                            map: this.map,
+                            toggleGroup: toolGroup,
+                            group: toolGroup,
+                            allowDepress: false,
+                            map: this.map,
+                            control: this.createMeasureControl(
+                                OpenLayers.Handler.Path, "Length"
+                            )
+                        })
+                    ),
+                    new Ext.menu.CheckItem(
+                        new GeoExt.Action({
+                            text: "Area",
+                            iconCls: "icon-measure-area",
+                            map: this.map,
+                            toggleGroup: toolGroup,
+                            group: toolGroup,
+                            allowDepress: false,
+                            map: this.map,
+                            control: this.createMeasureControl(
+                                OpenLayers.Handler.Polygon, "Area"
+                            )
+                        })
+                    )
+                ]
+            })
+        });
+        measureSplit.menu.items.each(function(item, index) {
+            item.on({checkchange: function(item, checked) {
+                measureSplit.toggle(checked);
+                if(checked) {
+                    activeIndex = index;
+                    measureSplit.setIconClass(item.iconCls);
+                }
+            }});
+        });
+    
         var tools = [
             navAction,
             infoButton,
-            new GeoExplorer.MapToolSplitToggle({
-                tooltip: "Measure",
-                iconCls: "icon-measure-length",
-                defaultTool: measureLength,
-                allowDepress: false,
-                tools: [
-                    {text: 'Length', tool: measureLength, iconCls: 'icon-measure-length'}, 
-                    {text: 'Area', tool: measureArea, iconCls: 'icon-measure-area'}
-                ],
-                enableToggle: true,
-                toggleGroup: toolGroup 
-            }),
+            measureSplit,
             "-",
             new Ext.Button({
                 handler: function(){
@@ -1165,7 +1216,7 @@
         return tools;
     },
 
-    /** private: method[createMeasureTool]
+    /** private: method[createMeasureControl]
      * :param: handlerType: the :class:`OpenLayers.Handler` for the measurement
      *     operation
      * :param: title: the string label to display alongside results
@@ -1173,7 +1224,7 @@
      * Convenience method for creating a :class:`OpenLayers.Control.Measure` 
      * control
      */
-    createMeasureTool: function(handlerType, title) {
+    createMeasureControl: function(handlerType, title) {
         
         var styleMap = new OpenLayers.StyleMap({
             "default": new OpenLayers.Style(null, {

Modified: apps/opengeo/geoexplorer/trunk/src/script/app/loader.js
===================================================================
--- apps/opengeo/geoexplorer/trunk/src/script/app/loader.js	2009-07-01 00:33:09 UTC (rev 1187)
+++ apps/opengeo/geoexplorer/trunk/src/script/app/loader.js	2009-07-01 00:49:38 UTC (rev 1188)
@@ -1,13 +1,8 @@
 (function() {
 
-    // Since the applications are located one directory down from
-    // the base, all these includes must be prefixed by a ../
     var jsfiles = new Array(
         "../../src/script/app/GeoExplorer.js",
         "../../src/script/app/GeoExplorer/util.js",
-        "../../src/script/app/GeoExplorer/MapToolToggle.js",
-        "../../src/script/app/GeoExplorer/MapToolSplitToggle.js",
-        "../../src/script/app/GeoExplorer/MapToolMenu.js",
         "../../src/script/app/GeoExplorer/Wizard.js",
         "../../src/script/app/GeoExplorer/LayerMenuItem.js",
         "../../src/script/app/GeoExplorer/CapabilitiesGrid.js",

Modified: apps/opengeo/geoexplorer/trunk/src/theme/app/geoexplorer.css
===================================================================
--- apps/opengeo/geoexplorer/trunk/src/theme/app/geoexplorer.css	2009-07-01 00:33:09 UTC (rev 1187)
+++ apps/opengeo/geoexplorer/trunk/src/theme/app/geoexplorer.css	2009-07-01 00:49:38 UTC (rev 1188)
@@ -51,14 +51,18 @@
     background-image: url(img/silk/map_go.png);
 }
 
-.x-btn .icon-measure-length, .icon-measure-length {
-    background-image: url(img/geosilk/ruler.png);
+.x-btn .icon-measure {
+    background-image: url(img/geosilk/measure.png);
 }
 
-.x-btn .icon-measure-area, .icon-measure-area {
-   background-image: url(img/geosilk/ruler_square.png);
+.icon-measure-length {
+    background-image: url(img/geosilk/ruler.png) !important;
 }
 
+.icon-measure-area {
+   background-image: url(img/geosilk/ruler_square.png) !important;
+}
+
 .x-btn .icon-layer-switcher {
    background-image: url(img/silk/layers.png);
 }



More information about the Commits mailing list