[mapguide-commits] r6953 - branches/2.4/MgDev/Desktop/MapViewer

svn_mapguide at osgeo.org svn_mapguide at osgeo.org
Sun Aug 26 19:55:21 PDT 2012


Author: jng
Date: 2012-08-26 19:55:21 -0700 (Sun, 26 Aug 2012)
New Revision: 6953

Modified:
   branches/2.4/MgDev/Desktop/MapViewer/MgLegend.Designer.cs
   branches/2.4/MgDev/Desktop/MapViewer/MgLegend.cs
   branches/2.4/MgDev/Desktop/MapViewer/MgLegend.resx
   branches/2.4/MgDev/Desktop/MapViewer/MgLegendControlPresenter.cs
Log:
#2096: mg-desktop - Legend updates
 - Create the required TreeNode objects (and the required LayerDefinition loading, icon caching) on a background worker
 - Attach relevant layer/group context menus on background worker completion.
 - Fix extra GenerateLegendImage calls due to incorrect cache checking logic.
 - Add new IsBusy property that indicates whether the MgLegend is currently refreshing itself.
 - Implement INotifyPropertyChanged for MgLegend. Broadcast property changes for the following properties:
   - IsBusy
   - ThemeCompressionLimit

Modified: branches/2.4/MgDev/Desktop/MapViewer/MgLegend.Designer.cs
===================================================================
--- branches/2.4/MgDev/Desktop/MapViewer/MgLegend.Designer.cs	2012-08-24 08:39:06 UTC (rev 6952)
+++ branches/2.4/MgDev/Desktop/MapViewer/MgLegend.Designer.cs	2012-08-27 02:55:21 UTC (rev 6953)
@@ -31,6 +31,7 @@
             this.components = new System.ComponentModel.Container();
             this.trvLegend = new System.Windows.Forms.TreeView();
             this.imgLegend = new System.Windows.Forms.ImageList(this.components);
+            this.bgLegendUpdate = new System.ComponentModel.BackgroundWorker();
             this.SuspendLayout();
             // 
             // trvLegend
@@ -59,6 +60,11 @@
             this.imgLegend.ImageSize = new System.Drawing.Size(16, 16);
             this.imgLegend.TransparentColor = System.Drawing.Color.Transparent;
             // 
+            // bgLegendUpdate
+            // 
+            this.bgLegendUpdate.DoWork += new System.ComponentModel.DoWorkEventHandler(this.bgLegendUpdate_DoWork);
+            this.bgLegendUpdate.RunWorkerCompleted += new System.ComponentModel.RunWorkerCompletedEventHandler(this.bgLegendUpdate_RunWorkerCompleted);
+            // 
             // MgLegend
             // 
             this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
@@ -73,5 +79,6 @@
 
         private System.Windows.Forms.TreeView trvLegend;
         private System.Windows.Forms.ImageList imgLegend;
+        private System.ComponentModel.BackgroundWorker bgLegendUpdate;
     }
 }

Modified: branches/2.4/MgDev/Desktop/MapViewer/MgLegend.cs
===================================================================
--- branches/2.4/MgDev/Desktop/MapViewer/MgLegend.cs	2012-08-24 08:39:06 UTC (rev 6952)
+++ branches/2.4/MgDev/Desktop/MapViewer/MgLegend.cs	2012-08-27 02:55:21 UTC (rev 6953)
@@ -18,7 +18,7 @@
     /// <summary>
     /// A control that displays and controls visibility of layers in a runtime map
     /// </summary>
-    public partial class MgLegend : UserControl, IMapLegend, ILegendView
+    public partial class MgLegend : UserControl, IMapLegend, ILegendView, INotifyPropertyChanged 
     {
         // TODO:
         // 
@@ -55,6 +55,8 @@
             RefreshLegend();
         }
 
+        private Stopwatch _legendUpdateStopwatch = new Stopwatch();
+
         /// <summary>
         /// Refreshes this component
         /// </summary>
@@ -66,22 +68,80 @@
             if (_presenter == null)
                 return;
 
+            if (IsBusy)
+                return;
+
             ResetTreeView();
             trvLegend.BeginUpdate();
+            _legendUpdateStopwatch.Start();
+            this.IsBusy = true;
+            bgLegendUpdate.RunWorkerAsync();
+            /*
+            //Synchronous version
             try
             {
-                var sw = new Stopwatch();
-                sw.Start();
                 trvLegend.Nodes.AddRange(_presenter.CreateNodes());
-                sw.Stop();
-                Trace.TraceInformation("RefreshLegend: Completed in {0}ms", sw.ElapsedMilliseconds);
             }
             finally
             {
                 trvLegend.EndUpdate();
+            }*/
+        }
+
+        private bool _busy = false;
+
+        [Browsable(false)]
+        public bool IsBusy
+        {
+            get { return _busy; }
+            private set
+            {
+                if (_busy.Equals(value))
+                    return;
+
+                _busy = value;
+                Trace.TraceInformation("Legend IsBusy: {0}", this.IsBusy);
+                OnPropertyChanged("IsBusy");
             }
         }
 
+        private void bgLegendUpdate_DoWork(object sender, DoWorkEventArgs e)
+        {
+            e.Result = _presenter.CreateNodes();
+        }
+
+        private void bgLegendUpdate_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
+        {
+            this.IsBusy = bgLegendUpdate.IsBusy;
+            var nodes = e.Result as TreeNode[];
+            if (nodes != null)
+            {
+                //Attach relevant context menus based on attached metadata
+                foreach (var n in nodes)
+                {
+                    var lm = n.Tag as LegendNodeMetadata;
+                    if (lm != null)
+                    {
+                        if (lm.IsGroup)
+                        {
+                            n.ContextMenuStrip = this.GroupContextMenu;
+                        }
+                        else
+                        {
+                            var lyrm = n.Tag as LayerNodeMetadata;
+                            if (lyrm != null)
+                                n.ContextMenuStrip = this.LayerContextMenu;
+                        }
+                    }
+                }
+                trvLegend.Nodes.AddRange(nodes);
+            }
+            trvLegend.EndUpdate();
+            _legendUpdateStopwatch.Stop();
+            Trace.TraceInformation("RefreshLegend: Completed in {0}ms", _legendUpdateStopwatch.ElapsedMilliseconds);
+            _legendUpdateStopwatch.Reset();
+        }
+
         private static void ClearNodes(TreeNodeCollection nodes)
         {
             foreach (TreeNode node in nodes)
@@ -270,7 +330,14 @@
         public int ThemeCompressionLimit
         {
             get { return _themeCompressionLimit; }
-            set { _themeCompressionLimit = value; }
+            set 
+            {
+                if (value != _themeCompressionLimit)
+                    return;
+
+                _themeCompressionLimit = value;
+                OnPropertyChanged("ThemeCompressionLimit");
+            }
         }
         
         private void OnLayerContextMenuOpening(object sender, CancelEventArgs e)
@@ -344,7 +411,23 @@
         public bool ShowTooltips
         {
             get { return trvLegend.ShowNodeToolTips; }
-            set { trvLegend.ShowNodeToolTips = value; }
+            set 
+            {
+                if (value != trvLegend.ShowNodeToolTips)
+                    return;
+
+                trvLegend.ShowNodeToolTips = value;
+                OnPropertyChanged("ShowTooltips");
+            }
         }
+
+        public event PropertyChangedEventHandler PropertyChanged;
+
+        private void OnPropertyChanged(string propertyName)
+        {
+            var h = this.PropertyChanged;
+            if (h != null)
+                h(this, new PropertyChangedEventArgs(propertyName));
+        }
     }
 }

Modified: branches/2.4/MgDev/Desktop/MapViewer/MgLegend.resx
===================================================================
--- branches/2.4/MgDev/Desktop/MapViewer/MgLegend.resx	2012-08-24 08:39:06 UTC (rev 6952)
+++ branches/2.4/MgDev/Desktop/MapViewer/MgLegend.resx	2012-08-27 02:55:21 UTC (rev 6953)
@@ -120,7 +120,7 @@
   <metadata name="imgLegend.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
     <value>17, 17</value>
   </metadata>
-  <metadata name="legendUpdateWorker.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
+  <metadata name="bgLegendUpdate.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
     <value>130, 17</value>
   </metadata>
 </root>
\ No newline at end of file

Modified: branches/2.4/MgDev/Desktop/MapViewer/MgLegendControlPresenter.cs
===================================================================
--- branches/2.4/MgDev/Desktop/MapViewer/MgLegendControlPresenter.cs	2012-08-24 08:39:06 UTC (rev 6952)
+++ branches/2.4/MgDev/Desktop/MapViewer/MgLegendControlPresenter.cs	2012-08-27 02:55:21 UTC (rev 6953)
@@ -10,12 +10,12 @@
     using Legend.Model;
     using System.Xml;
     using System.IO;
-using System.Diagnostics;
+    using System.Diagnostics;
 
     interface ILegendView
     {
-        ContextMenuStrip LayerContextMenu { get; }
-        ContextMenuStrip GroupContextMenu { get; }
+        //ContextMenuStrip LayerContextMenu { get; }
+        //ContextMenuStrip GroupContextMenu { get; }
         void AddLegendIcon(string id, Image icon);
         int ThemeCompressionLimit { get; }
         void OnRequestRefresh();
@@ -92,7 +92,7 @@
             node.Name = layer.GetObjectId();
             node.Text = layer.GetLegendLabel();
             node.Checked = layer.GetVisible();
-            node.ContextMenuStrip = _legend.LayerContextMenu;
+            //node.ContextMenuStrip = _legend.LayerContextMenu;
             var lt = layer.GetLayerType();
             var fsId = layer.GetFeatureSourceId();
 
@@ -153,7 +153,7 @@
                 String[] ruleNames = new String[] { "PointRule", "LineRule", "AreaRule", "CompositeRule" };
 
                 node.ToolTipText = string.Format(Properties.Resources.DefaultLayerTooltip, Environment.NewLine, layer.Name, layer.FeatureSourceId, layer.FeatureClassName);
-                if (!layerMeta.HasTheme())
+                if (!layerMeta.HasTheme() || !layerMeta.HasDefaultIcons())
                 {
                     for (int sc = 0; sc < scaleRanges.Count; sc++)
                     {
@@ -210,7 +210,7 @@
                                         }
                                     }
                                 }
-                                else
+                                else if (!layerMeta.HasDefaultIconsAt(_map.ViewScale))
                                 {
                                     try
                                     {
@@ -336,7 +336,7 @@
             var meta = new GroupNodeMetadata(group);
             node.Tag = meta;
             _groups[group.GetObjectId()] = meta;
-            node.ContextMenuStrip = _legend.GroupContextMenu;
+            //node.ContextMenuStrip = _legend.GroupContextMenu;
             return node;
         }
 
@@ -949,9 +949,14 @@
                 _themeNodes[category].Add(themeMeta);
             }
 
+            internal bool HasDefaultIcons()
+            {
+                return (_defaultIcons.Count > 0);
+            }
+
             internal bool HasTheme()
             {
-                if (_themeNodes.Count == 0 || _defaultIcons.Count == 0)
+                if (_themeNodes.Count == 0)
                     return false;
 
                 foreach (var coll in _themeNodes.Values)
@@ -1028,6 +1033,16 @@
                     yield return node;
                 }
             }
+
+            internal bool HasDefaultIconsAt(double scale)
+            {
+                foreach (var cat in _defaultIcons.Keys)
+                {
+                    if (ScaleIsApplicable(scale, cat))
+                        return true;
+                }
+                return false;
+            }
         }
     }
 }



More information about the mapguide-commits mailing list