sysperfana/heapanalyser/Libraries/UI/HeapUiLib/Dialogs/HeapReconstructorProgressDialog.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.Drawing;
       
    40 using System.Collections;
       
    41 using System.ComponentModel;
       
    42 using System.Windows.Forms;
       
    43 using SymbianUtils;
       
    44 using HeapLib;
       
    45 using HeapLib.Reconstructor;
       
    46 
       
    47 namespace HeapUiLib.Dialogs
       
    48 {
       
    49 	public class HeapReconstructorProgressDialog : System.Windows.Forms.Form
       
    50 	{
       
    51 		#region Windows Form Designer generated code
       
    52         private IContainer components;
       
    53         private Timer iTimer_OpStart;
       
    54         private System.Windows.Forms.ProgressBar iProgressBar;
       
    55 		#endregion
       
    56 
       
    57 		#region Constructors & destructor
       
    58 		public static void ParseLog( HeapReconstructor aReconstructor  )
       
    59 		{
       
    60             ParseLog( aReconstructor, string.Empty );
       
    61 		}
       
    62 
       
    63 		public static void ParseLog( HeapReconstructor aReconstructor, string aTitle  )
       
    64 		{
       
    65             HeapReconstructorProgressDialog self = new HeapReconstructorProgressDialog( aReconstructor, aTitle );
       
    66 			self.ShowDialog();
       
    67 		}
       
    68 
       
    69         internal HeapReconstructorProgressDialog( HeapReconstructor aReconstructor, string aTitle )
       
    70 		{
       
    71             iReconstructor = aReconstructor;
       
    72             //
       
    73 			InitializeComponent();
       
    74             //
       
    75             iTimer_OpStart.Start();
       
    76             //
       
    77             if ( aTitle != string.Empty )
       
    78             {
       
    79                 this.Text = aTitle;
       
    80             }
       
    81             //
       
    82             iReconstructor.iObserver += new HeapReconstructor.Observer( HeapReconstructorObserver );
       
    83         }
       
    84 
       
    85 		protected override void Dispose( bool disposing )
       
    86 		{
       
    87 			if( disposing )
       
    88 			{
       
    89 				if(components != null)
       
    90 				{
       
    91 					components.Dispose();
       
    92 				}
       
    93 			}
       
    94 			base.Dispose( disposing );
       
    95 		}
       
    96 		#endregion
       
    97 
       
    98 		#region Windows Form Designer generated code
       
    99 		private void InitializeComponent()
       
   100 		{
       
   101             this.components = new System.ComponentModel.Container();
       
   102             this.iProgressBar = new System.Windows.Forms.ProgressBar();
       
   103             this.iTimer_OpStart = new System.Windows.Forms.Timer( this.components );
       
   104             this.SuspendLayout();
       
   105             // 
       
   106             // iProgressBar
       
   107             // 
       
   108             this.iProgressBar.Location = new System.Drawing.Point( 8, 8 );
       
   109             this.iProgressBar.Name = "iProgressBar";
       
   110             this.iProgressBar.Size = new System.Drawing.Size( 376, 24 );
       
   111             this.iProgressBar.TabIndex = 0;
       
   112             // 
       
   113             // iTimer_OpStart
       
   114             // 
       
   115             this.iTimer_OpStart.Interval = 10;
       
   116             this.iTimer_OpStart.Tick += new System.EventHandler( this.iTimer_OpStart_Tick );
       
   117             // 
       
   118             // HeapCellReconstructorProgressDialog
       
   119             // 
       
   120             this.AutoScaleBaseSize = new System.Drawing.Size( 5, 13 );
       
   121             this.ClientSize = new System.Drawing.Size( 392, 39 );
       
   122             this.ControlBox = false;
       
   123             this.Controls.Add( this.iProgressBar );
       
   124             this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
       
   125             this.MaximizeBox = false;
       
   126             this.MinimizeBox = false;
       
   127             this.Name = "HeapCellReconstructorProgressDialog";
       
   128             this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
       
   129             this.Text = " Analysing Heap Data...";
       
   130             this.ResumeLayout( false );
       
   131 
       
   132 		}
       
   133 		#endregion
       
   134 
       
   135         #region Heap reconstructor callback
       
   136         private void HeapReconstructorObserver( HeapReconstructor.TEvent aEvent, HeapReconstructor aReconstructor )
       
   137         {
       
   138             if ( InvokeRequired )
       
   139             {
       
   140                 HeapReconstructor.Observer observer = new HeapReconstructor.Observer( HeapReconstructorObserver );
       
   141                 this.BeginInvoke( observer, new object[] { aEvent, aReconstructor } );
       
   142             }
       
   143             else
       
   144             {
       
   145                 switch ( aEvent )
       
   146                 {
       
   147                     case HeapReconstructor.TEvent.EReconstructingStarted:
       
   148                         iProgressBar.Maximum = 100; //%
       
   149                         iProgressBar.Minimum = 0; //%
       
   150                         iProgressBar.Value = 0;
       
   151                         break;
       
   152                     case HeapReconstructor.TEvent.EReconstructingProgress:
       
   153                         iProgressBar.Value = iReconstructor.Progress;
       
   154                         break;
       
   155                     case HeapReconstructor.TEvent.EReconstructingComplete:
       
   156                         Close();
       
   157                         break;
       
   158                 }
       
   159             }
       
   160         }
       
   161         #endregion
       
   162 
       
   163         #region Event handlers
       
   164         private void iTimer_OpStart_Tick( object sender, EventArgs e )
       
   165         {
       
   166             iTimer_OpStart.Stop();
       
   167             iTimer_OpStart.Enabled = false;
       
   168             //
       
   169             iReconstructor.Reconstruct();
       
   170         }
       
   171         #endregion
       
   172 
       
   173 		#region Data members
       
   174 		private readonly HeapReconstructor iReconstructor;
       
   175 		#endregion
       
   176 	}
       
   177 }