45
|
1 using System;
|
|
2 using System.Collections.Generic;
|
|
3 using System.ComponentModel;
|
|
4 using System.Data;
|
|
5 using System.Drawing;
|
|
6 using System.Linq;
|
|
7 using System.Text;
|
|
8 using System.Threading.Tasks;
|
|
9 using System.Windows.Forms;
|
|
10
|
|
11 namespace Implab.Diagnostics.Interactive {
|
|
12 public partial class TraceForm : Form {
|
47
|
13 readonly Dictionary<int, Color> m_threadColors = new Dictionary<int,Color>();
|
|
14 readonly Random m_rand = new Random();
|
|
15
|
48
|
16 public event EventHandler PauseEvents;
|
|
17
|
|
18 public event EventHandler ResumeEvents;
|
|
19
|
45
|
20 public TraceForm() {
|
|
21 InitializeComponent();
|
|
22 }
|
|
23
|
|
24 protected override void OnFormClosing(FormClosingEventArgs e) {
|
|
25 base.OnFormClosing(e);
|
|
26 if (!e.Cancel && e.CloseReason == CloseReason.UserClosing) {
|
|
27 e.Cancel = true;
|
|
28 Hide();
|
|
29 }
|
|
30 }
|
47
|
31
|
|
32 public void AddTraceEvent(TraceViewItem item) {
|
|
33 traceViewItemBindingSource.Add(item);
|
204
|
34 if(eventsDataGrid.RowCount > 0)
|
|
35 eventsDataGrid.FirstDisplayedScrollingRowIndex = eventsDataGrid.RowCount - 1;
|
47
|
36 }
|
|
37
|
|
38 Color GetThreadColor(int thread) {
|
|
39 Color result;
|
|
40 if (!m_threadColors.TryGetValue(thread, out result)) {
|
|
41 result = Color.FromArgb(m_rand.Next(4)*64, m_rand.Next(4)*64, m_rand.Next(4)*64);
|
|
42 m_threadColors[thread] = result;
|
|
43 }
|
|
44 return result;
|
|
45 }
|
|
46
|
|
47 private void eventsDataGrid_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e) {
|
|
48 var data = (TraceViewItem)traceViewItemBindingSource[e.RowIndex];
|
48
|
49 if (e.ColumnIndex == messageDataGridViewTextBoxColumn.Index)
|
|
50 e.CellStyle.Padding = new Padding(data.Indent * 10,0,0,0);
|
47
|
51 e.CellStyle.ForeColor = GetThreadColor(data.Thread);
|
|
52 }
|
45
|
53 }
|
|
54 }
|