annotate Implab.Diagnostics.Interactive/TraceForm.cs @ 165:e227e78d72e4 ref20160224

DFA refactoring
author cin
date Mon, 29 Feb 2016 02:02:17 +0300
parents d9d794b61bb9
children cbb0bd8fc0d1
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
45
d10034588e38 initial work on interactive logger
cin
parents:
diff changeset
1 using System;
d10034588e38 initial work on interactive logger
cin
parents:
diff changeset
2 using System.Collections.Generic;
d10034588e38 initial work on interactive logger
cin
parents:
diff changeset
3 using System.ComponentModel;
d10034588e38 initial work on interactive logger
cin
parents:
diff changeset
4 using System.Data;
d10034588e38 initial work on interactive logger
cin
parents:
diff changeset
5 using System.Drawing;
d10034588e38 initial work on interactive logger
cin
parents:
diff changeset
6 using System.Linq;
d10034588e38 initial work on interactive logger
cin
parents:
diff changeset
7 using System.Text;
d10034588e38 initial work on interactive logger
cin
parents:
diff changeset
8 using System.Threading.Tasks;
d10034588e38 initial work on interactive logger
cin
parents:
diff changeset
9 using System.Windows.Forms;
d10034588e38 initial work on interactive logger
cin
parents:
diff changeset
10
d10034588e38 initial work on interactive logger
cin
parents:
diff changeset
11 namespace Implab.Diagnostics.Interactive {
d10034588e38 initial work on interactive logger
cin
parents:
diff changeset
12 public partial class TraceForm : Form {
47
b181f7bcb259 refactoring, interactive tarce log almost complete
cin
parents: 45
diff changeset
13 readonly Dictionary<int, Color> m_threadColors = new Dictionary<int,Color>();
b181f7bcb259 refactoring, interactive tarce log almost complete
cin
parents: 45
diff changeset
14 readonly Random m_rand = new Random();
b181f7bcb259 refactoring, interactive tarce log almost complete
cin
parents: 45
diff changeset
15
48
d9d794b61bb9 Interactive tracing
cin
parents: 47
diff changeset
16 public event EventHandler PauseEvents;
d9d794b61bb9 Interactive tracing
cin
parents: 47
diff changeset
17
d9d794b61bb9 Interactive tracing
cin
parents: 47
diff changeset
18 public event EventHandler ResumeEvents;
d9d794b61bb9 Interactive tracing
cin
parents: 47
diff changeset
19
45
d10034588e38 initial work on interactive logger
cin
parents:
diff changeset
20 public TraceForm() {
d10034588e38 initial work on interactive logger
cin
parents:
diff changeset
21 InitializeComponent();
d10034588e38 initial work on interactive logger
cin
parents:
diff changeset
22 }
d10034588e38 initial work on interactive logger
cin
parents:
diff changeset
23
d10034588e38 initial work on interactive logger
cin
parents:
diff changeset
24 protected override void OnFormClosing(FormClosingEventArgs e) {
d10034588e38 initial work on interactive logger
cin
parents:
diff changeset
25 base.OnFormClosing(e);
d10034588e38 initial work on interactive logger
cin
parents:
diff changeset
26 if (!e.Cancel && e.CloseReason == CloseReason.UserClosing) {
d10034588e38 initial work on interactive logger
cin
parents:
diff changeset
27 e.Cancel = true;
d10034588e38 initial work on interactive logger
cin
parents:
diff changeset
28 Hide();
d10034588e38 initial work on interactive logger
cin
parents:
diff changeset
29 }
d10034588e38 initial work on interactive logger
cin
parents:
diff changeset
30 }
47
b181f7bcb259 refactoring, interactive tarce log almost complete
cin
parents: 45
diff changeset
31
b181f7bcb259 refactoring, interactive tarce log almost complete
cin
parents: 45
diff changeset
32 public void AddTraceEvent(TraceViewItem item) {
b181f7bcb259 refactoring, interactive tarce log almost complete
cin
parents: 45
diff changeset
33 traceViewItemBindingSource.Add(item);
48
d9d794b61bb9 Interactive tracing
cin
parents: 47
diff changeset
34 eventsDataGrid.FirstDisplayedScrollingRowIndex = eventsDataGrid.RowCount - 1;
47
b181f7bcb259 refactoring, interactive tarce log almost complete
cin
parents: 45
diff changeset
35 }
b181f7bcb259 refactoring, interactive tarce log almost complete
cin
parents: 45
diff changeset
36
b181f7bcb259 refactoring, interactive tarce log almost complete
cin
parents: 45
diff changeset
37 Color GetThreadColor(int thread) {
b181f7bcb259 refactoring, interactive tarce log almost complete
cin
parents: 45
diff changeset
38 Color result;
b181f7bcb259 refactoring, interactive tarce log almost complete
cin
parents: 45
diff changeset
39 if (!m_threadColors.TryGetValue(thread, out result)) {
b181f7bcb259 refactoring, interactive tarce log almost complete
cin
parents: 45
diff changeset
40 result = Color.FromArgb(m_rand.Next(4)*64, m_rand.Next(4)*64, m_rand.Next(4)*64);
b181f7bcb259 refactoring, interactive tarce log almost complete
cin
parents: 45
diff changeset
41 m_threadColors[thread] = result;
b181f7bcb259 refactoring, interactive tarce log almost complete
cin
parents: 45
diff changeset
42 }
b181f7bcb259 refactoring, interactive tarce log almost complete
cin
parents: 45
diff changeset
43 return result;
b181f7bcb259 refactoring, interactive tarce log almost complete
cin
parents: 45
diff changeset
44 }
b181f7bcb259 refactoring, interactive tarce log almost complete
cin
parents: 45
diff changeset
45
b181f7bcb259 refactoring, interactive tarce log almost complete
cin
parents: 45
diff changeset
46 private void eventsDataGrid_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e) {
b181f7bcb259 refactoring, interactive tarce log almost complete
cin
parents: 45
diff changeset
47 var data = (TraceViewItem)traceViewItemBindingSource[e.RowIndex];
48
d9d794b61bb9 Interactive tracing
cin
parents: 47
diff changeset
48 if (e.ColumnIndex == messageDataGridViewTextBoxColumn.Index)
d9d794b61bb9 Interactive tracing
cin
parents: 47
diff changeset
49 e.CellStyle.Padding = new Padding(data.Indent * 10,0,0,0);
47
b181f7bcb259 refactoring, interactive tarce log almost complete
cin
parents: 45
diff changeset
50 e.CellStyle.ForeColor = GetThreadColor(data.Thread);
b181f7bcb259 refactoring, interactive tarce log almost complete
cin
parents: 45
diff changeset
51 }
45
d10034588e38 initial work on interactive logger
cin
parents:
diff changeset
52 }
d10034588e38 initial work on interactive logger
cin
parents:
diff changeset
53 }