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);
|
48
|
34 eventsDataGrid.FirstDisplayedScrollingRowIndex = eventsDataGrid.RowCount - 1;
|
47
|
35 }
|
|
36
|
|
37 Color GetThreadColor(int thread) {
|
|
38 Color result;
|
|
39 if (!m_threadColors.TryGetValue(thread, out result)) {
|
|
40 result = Color.FromArgb(m_rand.Next(4)*64, m_rand.Next(4)*64, m_rand.Next(4)*64);
|
|
41 m_threadColors[thread] = result;
|
|
42 }
|
|
43 return result;
|
|
44 }
|
|
45
|
|
46 private void eventsDataGrid_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e) {
|
|
47 var data = (TraceViewItem)traceViewItemBindingSource[e.RowIndex];
|
48
|
48 if (e.ColumnIndex == messageDataGridViewTextBoxColumn.Index)
|
|
49 e.CellStyle.Padding = new Padding(data.Indent * 10,0,0,0);
|
47
|
50 e.CellStyle.ForeColor = GetThreadColor(data.Thread);
|
|
51 }
|
45
|
52 }
|
|
53 }
|