annotate Implab.Diagnostics.Interactive/TraceViewControl.cs @ 45:d10034588e38 interactive logger

initial work on interactive logger
author cin
date Thu, 17 Apr 2014 03:05:53 +0400
parents
children
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.Drawing;
d10034588e38 initial work on interactive logger
cin
parents:
diff changeset
5 using System.Data;
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 TraceViewControl : UserControl {
d10034588e38 initial work on interactive logger
cin
parents:
diff changeset
13 int m_maxEvents = 1000;
d10034588e38 initial work on interactive logger
cin
parents:
diff changeset
14
d10034588e38 initial work on interactive logger
cin
parents:
diff changeset
15 string m_status = "ready";
d10034588e38 initial work on interactive logger
cin
parents:
diff changeset
16
d10034588e38 initial work on interactive logger
cin
parents:
diff changeset
17 readonly LinkedList<TraceViewItem> m_events = new LinkedList<TraceViewItem>();
d10034588e38 initial work on interactive logger
cin
parents:
diff changeset
18 public TraceViewControl() {
d10034588e38 initial work on interactive logger
cin
parents:
diff changeset
19 InitializeComponent();
d10034588e38 initial work on interactive logger
cin
parents:
diff changeset
20
d10034588e38 initial work on interactive logger
cin
parents:
diff changeset
21 var ticks = Environment.TickCount;
d10034588e38 initial work on interactive logger
cin
parents:
diff changeset
22
d10034588e38 initial work on interactive logger
cin
parents:
diff changeset
23 for (int i = 0; i < 1333; i++) {
d10034588e38 initial work on interactive logger
cin
parents:
diff changeset
24 AddViewItem(new TraceViewItem {
d10034588e38 initial work on interactive logger
cin
parents:
diff changeset
25 indent = i % 4,
d10034588e38 initial work on interactive logger
cin
parents:
diff changeset
26 message = String.Format("Auto generated {0}", i),
d10034588e38 initial work on interactive logger
cin
parents:
diff changeset
27 thread = 2,
d10034588e38 initial work on interactive logger
cin
parents:
diff changeset
28 timestamp = ticks + i*10
d10034588e38 initial work on interactive logger
cin
parents:
diff changeset
29 });
d10034588e38 initial work on interactive logger
cin
parents:
diff changeset
30 }
d10034588e38 initial work on interactive logger
cin
parents:
diff changeset
31 }
d10034588e38 initial work on interactive logger
cin
parents:
diff changeset
32
d10034588e38 initial work on interactive logger
cin
parents:
diff changeset
33 public void AddViewItem(TraceViewItem item) {
d10034588e38 initial work on interactive logger
cin
parents:
diff changeset
34 m_events.AddLast(item);
d10034588e38 initial work on interactive logger
cin
parents:
diff changeset
35 if (m_events.Count > m_maxEvents)
d10034588e38 initial work on interactive logger
cin
parents:
diff changeset
36 m_events.RemoveFirst();
d10034588e38 initial work on interactive logger
cin
parents:
diff changeset
37 }
d10034588e38 initial work on interactive logger
cin
parents:
diff changeset
38
d10034588e38 initial work on interactive logger
cin
parents:
diff changeset
39 protected override void OnPaint(PaintEventArgs e) {
d10034588e38 initial work on interactive logger
cin
parents:
diff changeset
40 base.OnPaint(e);
d10034588e38 initial work on interactive logger
cin
parents:
diff changeset
41
d10034588e38 initial work on interactive logger
cin
parents:
diff changeset
42 if (m_status != null)
d10034588e38 initial work on interactive logger
cin
parents:
diff changeset
43 e.Graphics.DrawString(m_status, DefaultFont, Brushes.Black, 0, 0);
d10034588e38 initial work on interactive logger
cin
parents:
diff changeset
44
d10034588e38 initial work on interactive logger
cin
parents:
diff changeset
45 }
d10034588e38 initial work on interactive logger
cin
parents:
diff changeset
46
d10034588e38 initial work on interactive logger
cin
parents:
diff changeset
47 protected override void OnMouseMove(MouseEventArgs e) {
d10034588e38 initial work on interactive logger
cin
parents:
diff changeset
48 base.OnMouseMove(e);
d10034588e38 initial work on interactive logger
cin
parents:
diff changeset
49
d10034588e38 initial work on interactive logger
cin
parents:
diff changeset
50 m_status = String.Format("({0},{1})", e.X, e.Y);
d10034588e38 initial work on interactive logger
cin
parents:
diff changeset
51 Invalidate();
d10034588e38 initial work on interactive logger
cin
parents:
diff changeset
52 }
d10034588e38 initial work on interactive logger
cin
parents:
diff changeset
53
d10034588e38 initial work on interactive logger
cin
parents:
diff changeset
54 }
d10034588e38 initial work on interactive logger
cin
parents:
diff changeset
55 }