sysperfana/heapanalyser/Libraries/UI/HeapCtrlLib/Utilities/HeapCellFilterTriplet.cs
changeset 8 15296fd0af4a
equal deleted inserted replaced
7:8e12a575a9b5 8:15296fd0af4a
       
     1 /*
       
     2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 *
       
     5 * Redistribution and use in source and binary forms, with or without
       
     6 * modification, are permitted provided that the following conditions are met:
       
     7 *
       
     8 * - Redistributions of source code must retain the above copyright notice,
       
     9 *   this list of conditions and the following disclaimer.
       
    10 * - Redistributions in binary form must reproduce the above copyright notice,
       
    11 *   this list of conditions and the following disclaimer in the documentation
       
    12 *   and/or other materials provided with the distribution.
       
    13 * - Neither the name of Nokia Corporation nor the names of its contributors
       
    14 *   may be used to endorse or promote products derived from this software
       
    15 *   without specific prior written permission.
       
    16 *
       
    17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
       
    18 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
       
    19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
       
    20 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
       
    21 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
       
    22 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
       
    23 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
       
    24 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
       
    25 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
       
    26 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
       
    27 * POSSIBILITY OF SUCH DAMAGE.
       
    28 * 
       
    29 * Initial Contributors:
       
    30 * Nokia Corporation - initial contribution.
       
    31 *
       
    32 * Contributors:
       
    33 *
       
    34 * Description: 
       
    35 *
       
    36 */
       
    37 
       
    38 using System;
       
    39 using System.Collections.Generic;
       
    40 using System.Text;
       
    41 using System.Drawing;
       
    42 using HeapLib.Statistics.Tracking.Base;
       
    43 
       
    44 namespace HeapCtrlLib.Utilities
       
    45 {
       
    46     internal class HeapCellFilterTriplet
       
    47     {
       
    48         #region Constructors & destructor
       
    49         public HeapCellFilterTriplet()
       
    50             : this( string.Empty, KDisabledColour, false, null )
       
    51         {
       
    52         }
       
    53 
       
    54         public HeapCellFilterTriplet( string aEntity, Color aColor, bool aEnabled, TrackingInfo aTrackingInfo )
       
    55         {
       
    56             iEntity = aEntity;
       
    57             iColor = aColor;
       
    58             iEnabled = aEnabled;
       
    59             iTrackingInfo = aTrackingInfo;
       
    60         }
       
    61         #endregion
       
    62 
       
    63         #region API
       
    64         #endregion
       
    65 
       
    66         #region Properties
       
    67         public bool Enabled
       
    68         {
       
    69             get { return iEnabled; }
       
    70             set { iEnabled = value; }
       
    71         }
       
    72 
       
    73         public Color Color
       
    74         {
       
    75             get
       
    76             {
       
    77                 Color ret = iColor;
       
    78                 //
       
    79                 if ( iEnabled == false )
       
    80                 {
       
    81                     ret = KDisabledColour;
       
    82                 }
       
    83                 //
       
    84                 return ret;
       
    85             }
       
    86             set { iColor = value; }
       
    87         }
       
    88 
       
    89         public Color ColorAbsolute
       
    90         {
       
    91             get { return iColor; }
       
    92         }
       
    93 
       
    94         public string Entity
       
    95         {
       
    96             get { return iEntity; }
       
    97         }
       
    98 
       
    99         public TrackingInfo TrackingInfo
       
   100         {
       
   101             get { return iTrackingInfo; }
       
   102         }
       
   103         #endregion
       
   104 
       
   105         #region Constants
       
   106         public static Color KDisabledColour = Color.WhiteSmoke;
       
   107         #endregion
       
   108 
       
   109         #region Data members
       
   110         private bool iEnabled = true;
       
   111         private Color iColor = KDisabledColour;
       
   112         private readonly string iEntity;
       
   113         private readonly TrackingInfo iTrackingInfo;
       
   114         #endregion
       
   115     }
       
   116 
       
   117     internal class HeapCellFilterTripletDictionary : IEnumerable<KeyValuePair<string,HeapCellFilterTriplet>>
       
   118     {
       
   119         #region Constructors & destructor
       
   120         public HeapCellFilterTripletDictionary()
       
   121         {
       
   122         }
       
   123 
       
   124         public HeapCellFilterTripletDictionary( HeapCellFilterTripletDictionary aCopy )
       
   125         {
       
   126             foreach( KeyValuePair<string, HeapCellFilterTriplet> entry in aCopy )
       
   127             {
       
   128                 Add( entry.Key, entry.Value.Entity, entry.Value.ColorAbsolute, entry.Value.Enabled, entry.Value.TrackingInfo );
       
   129             }
       
   130         }
       
   131         #endregion
       
   132 
       
   133         #region API
       
   134         public void Clear()
       
   135         {
       
   136             iEntries.Clear();
       
   137         }
       
   138 
       
   139         public void Add( string aEntity, string aCaption, Color aColor, TrackingInfo aTrackingInfo )
       
   140         {
       
   141             HeapCellFilterTriplet triplet = new HeapCellFilterTriplet( aCaption, aColor, true, aTrackingInfo );
       
   142             iEntries.Add( aEntity, triplet );
       
   143         }
       
   144 
       
   145         public void Add( string aEntity, string aCaption, Color aColor, bool aEnabled, TrackingInfo aTrackingInfo )
       
   146         {
       
   147             HeapCellFilterTriplet triplet = new HeapCellFilterTriplet( aCaption, aColor, aEnabled, aTrackingInfo );
       
   148             iEntries.Add( aEntity, triplet );
       
   149         }
       
   150         #endregion
       
   151 
       
   152         #region Properties
       
   153         public HeapCellFilterTriplet this[ string aEntity ]
       
   154         {
       
   155             get
       
   156             {
       
   157                 bool contained = iEntries.ContainsKey( aEntity );
       
   158                 System.Diagnostics.Debug.Assert( contained );
       
   159                 HeapCellFilterTriplet ret = iEntries[ aEntity ];
       
   160                 return ret;
       
   161             }
       
   162         }
       
   163 
       
   164         public int Count
       
   165         {
       
   166             get { return iEntries.Count; }
       
   167         }
       
   168         #endregion
       
   169 
       
   170         #region IEnumerable<KeyValuePair<string,HeapCellFilterTriplet>> Members
       
   171         public IEnumerator<KeyValuePair<string, HeapCellFilterTriplet>> GetEnumerator()
       
   172         {
       
   173             return iEntries.GetEnumerator();
       
   174         }
       
   175 
       
   176         System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
       
   177         {
       
   178             return iEntries.GetEnumerator();
       
   179         }
       
   180         #endregion
       
   181 
       
   182         #region Data members
       
   183         private Dictionary<string, HeapCellFilterTriplet> iEntries = new Dictionary<string, HeapCellFilterTriplet>();
       
   184         #endregion
       
   185     }
       
   186 }