|
From: <Di...@us...> - 2009-01-17 12:19:33
|
Revision: 460
http://acmcontester.svn.sourceforge.net/acmcontester/?rev=460&view=rev
Author: DixonD
Date: 2009-01-17 12:19:20 +0000 (Sat, 17 Jan 2009)
Log Message:
-----------
Some refactoring for LogDataGridView.
Modified Paths:
--------------
smallprojects/sps/brus07/LogDataGridView/trunk/src/LogDataGridView/LogDataGridView.cs
smallprojects/sps/brus07/LogDataGridView/trunk/src/LogDataGridView/impl/SystemMessage.cs
Modified: smallprojects/sps/brus07/LogDataGridView/trunk/src/LogDataGridView/LogDataGridView.cs
===================================================================
--- smallprojects/sps/brus07/LogDataGridView/trunk/src/LogDataGridView/LogDataGridView.cs 2009-01-17 10:54:43 UTC (rev 459)
+++ smallprojects/sps/brus07/LogDataGridView/trunk/src/LogDataGridView/LogDataGridView.cs 2009-01-17 12:19:20 UTC (rev 460)
@@ -1,5 +1,4 @@
using System;
-using System.Data;
using System.Windows.Forms;
using System.Collections.Generic;
using System.Drawing;
@@ -10,14 +9,14 @@
[ToolboxBitmap(typeof(LogDataGridView), "notas1.ico")]
public partial class LogDataGridView : UserControl
{
- Type systemMessageType = null;
+ Type systemMessageType;
public LogDataGridView()
{
InitializeComponent();
}
- private void Init(IList<DataGridViewColumn> columns)
+ private void Init(IEnumerable<DataGridViewColumn> columns)
{
foreach(DataGridViewColumn column in columns)
{
@@ -28,12 +27,15 @@
private void AddRowInner(Message message)
{
if (message == null)
- throw new ArgumentNullException("message", "Can't be null");
+ {
+ throw new ArgumentNullException("message", "Can't be null.");
+ }
if (systemMessageType == null)
{
systemMessageType = message.GetType();
Init(message.GetDataGridViewColumns());
}
+
if (message.GetType() != systemMessageType)
throw new ArgumentException("Type of systemMessage must be equal", "message");
if (dataGridView.ColumnCount != message.GetValues().Length)
@@ -50,10 +52,10 @@
delegate void AddRowCallback(Message message);
public void AddRow(Message message)
{
- if (this.dataGridView.InvokeRequired)
+ if (dataGridView.InvokeRequired)
{
- AddRowCallback d = new AddRowCallback(AddRow);
- this.Invoke(d, new object[] { message });
+ AddRowCallback d = AddRow;
+ Invoke(d, new object[] { message });
}
else
{
Modified: smallprojects/sps/brus07/LogDataGridView/trunk/src/LogDataGridView/impl/SystemMessage.cs
===================================================================
--- smallprojects/sps/brus07/LogDataGridView/trunk/src/LogDataGridView/impl/SystemMessage.cs 2009-01-17 10:54:43 UTC (rev 459)
+++ smallprojects/sps/brus07/LogDataGridView/trunk/src/LogDataGridView/impl/SystemMessage.cs 2009-01-17 12:19:20 UTC (rev 460)
@@ -7,15 +7,15 @@
{
public class SystemMessage : Message
{
- string text;
- SystemMessageMode mode;
+ readonly string text;
+ readonly SystemMessageMode mode;
- private ContextMenuStrip contextMenuStrip = new ContextMenuStrip();
- private ToolStripMenuItem toolStripMenuItemTime = new ToolStripMenuItem();
- private ToolStripMenuItem toolStripMenuItemDate = new ToolStripMenuItem();
- private ToolStripMenuItem toolStripMenuItemText = new ToolStripMenuItem();
- private ToolStripMenuItem toolStripMenuItemMode = new ToolStripMenuItem();
+ private readonly ContextMenuStrip contextMenuStrip = new ContextMenuStrip();
+ private readonly ToolStripMenuItem toolStripMenuItemTime = new ToolStripMenuItem();
+ private readonly ToolStripMenuItem toolStripMenuItemDate = new ToolStripMenuItem();
+ private readonly ToolStripMenuItem toolStripMenuItemText = new ToolStripMenuItem();
+ private readonly ToolStripMenuItem toolStripMenuItemMode = new ToolStripMenuItem();
private void InitContexMenu()
{
contextMenuStrip.Items.AddRange(new ToolStripItem[]{
@@ -23,7 +23,7 @@
toolStripMenuItemDate,
toolStripMenuItemText,
toolStripMenuItemMode});
- contextMenuStrip.Name = "ContexMenuStrip";
+ contextMenuStrip.Name = "ContextMenuStrip";
contextMenuStrip.ShowCheckMargin = true;
contextMenuStrip.ShowImageMargin = false;
contextMenuStrip.Size = new Size(180, 92);
@@ -31,22 +31,22 @@
toolStripMenuItemTime.Size = new Size(179, 22);
toolStripMenuItemTime.Text = "Visible Time Column";
toolStripMenuItemTime.Checked = true;
- toolStripMenuItemTime.Click += new EventHandler(toolStripMenuItem_Click);
+ toolStripMenuItemTime.Click += toolStripMenuItem_Click;
toolStripMenuItemDate.Size = new Size(179, 22);
toolStripMenuItemDate.Text = "Visible Date Column";
toolStripMenuItemDate.Checked = true;
- toolStripMenuItemDate.Click += new EventHandler(toolStripMenuItem_Click);
+ toolStripMenuItemDate.Click += toolStripMenuItem_Click;
toolStripMenuItemText.Size = new Size(179, 22);
toolStripMenuItemText.Text = "Visible Text Column";
toolStripMenuItemText.Checked = true;
- toolStripMenuItemText.Click += new EventHandler(toolStripMenuItem_Click);
+ toolStripMenuItemText.Click += toolStripMenuItem_Click;
toolStripMenuItemMode.Size = new Size(179, 22);
toolStripMenuItemMode.Text = "Visible Mode Columna";
toolStripMenuItemMode.Checked = true;
- toolStripMenuItemMode.Click += new EventHandler(toolStripMenuItem_Click);
+ toolStripMenuItemMode.Click += toolStripMenuItem_Click;
}
void toolStripMenuItem_Click(object sender, EventArgs e)
@@ -54,64 +54,21 @@
//Bug: jaksho shovaty vsi kolonky, todi ne mozna vidkryty ContextMenu
ToolStripMenuItem toolStrip = (ToolStripMenuItem)sender;
- if (toolStrip == toolStripMenuItemTime)
+ for (int i = 0; i < 4; ++i)
{
- if (toolStripMenuItemTime.Checked)
+ if (toolStrip == toolStripMenuItemTime)
{
- columns[0].Visible = false;
- toolStripMenuItemTime.Checked = false;
+ if (i == 2 && !toolStripMenuItemText.Checked)
+ {
+ //Hack: jaksho shovaty, a potim vidobrazyty Text'ovu kolonky
+ // todi vysota rjadkiv stane defoltnoju, a ne roztjagnetsja avtomatom, po tekstu.
+ // Tomu roblju she taki dvi zminy, shob updejtnyty GridView
+ columns[1].Visible = !columns[1].Visible;
+ columns[1].Visible = !columns[1].Visible;
+ }
+ columns[i].Visible = toolStripMenuItemTime.Checked = !toolStripMenuItemTime.Checked;
}
- else
- {
- columns[0].Visible = true;
- toolStripMenuItemTime.Checked = true;
- }
}
- if (toolStrip == toolStripMenuItemDate)
- {
- if (toolStripMenuItemDate.Checked)
- {
- columns[1].Visible = false;
- toolStripMenuItemDate.Checked = false;
- }
- else
- {
- columns[1].Visible = true;
- toolStripMenuItemDate.Checked = true;
- }
- }
- if (toolStrip == toolStripMenuItemText)
- {
- if (toolStripMenuItemText.Checked)
- {
- columns[2].Visible = false;
- toolStripMenuItemText.Checked = false;
- }
- else
- {
- columns[2].Visible = true;
- toolStripMenuItemText.Checked = true;
-
- //Hack: jaksho shovaty, a potim vidobrazyty Text'ovu kolonky
- // todi vysota rjadkiv stane defoltnoju, a ne roztjagnetsja avtomatom, po tekstu.
- // Tomu roblju she taki dvi zminy, shob updejtnyty GridView
- columns[1].Visible = !columns[1].Visible;
- columns[1].Visible = !columns[1].Visible;
- }
- }
- if (toolStrip == toolStripMenuItemMode)
- {
- if (toolStripMenuItemMode.Checked)
- {
- columns[3].Visible = false;
- toolStripMenuItemMode.Checked = false;
- }
- else
- {
- columns[3].Visible = true;
- toolStripMenuItemMode.Checked = true;
- }
- }
}
IList<DataGridViewColumn> columns;
@@ -124,26 +81,26 @@
DataGridViewColumn column = new DataGridViewTextBoxColumn();
column.Name = "Time";
column.AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells;
- column.ContextMenuStrip = this.contextMenuStrip;
+ column.ContextMenuStrip = contextMenuStrip;
result.Add(column);
column = new DataGridViewTextBoxColumn();
column.Name = "Date";
column.AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells;
- column.ContextMenuStrip = this.contextMenuStrip;
+ column.ContextMenuStrip = contextMenuStrip;
result.Add(column);
column = new DataGridViewTextBoxColumn();
column.Name = "Log text";
column.MinimumWidth = 150;
column.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
- column.ContextMenuStrip = this.contextMenuStrip;
+ column.ContextMenuStrip = contextMenuStrip;
result.Add(column);
column = new DataGridViewTextBoxColumn();
column.Name = "Mode";
column.AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells;
- column.ContextMenuStrip = this.contextMenuStrip;
+ column.ContextMenuStrip = contextMenuStrip;
result.Add(column);
columns = result;
@@ -155,52 +112,46 @@
this.text = text;
try
{
- this.mode = (SystemMessageMode)Enum.Parse(typeof(SystemMessageMode), type, true);
+ mode = (SystemMessageMode)Enum.Parse(typeof(SystemMessageMode), type, true);
}
catch (ArgumentException)
{
- this.mode = SystemMessageMode.Other;
+ mode = SystemMessageMode.Other;
}
}
public SystemMessage(string text, SystemMessageMode type)
{
this.text = text;
- this.mode = type;
+ mode = type;
}
public override object[] GetValues()
{
object[] result = new object[4];
- result[0] = this.Time;
- result[1] = this.Date;
- result[2] = this.Text;
- result[3] = this.Mode;
+ result[0] = Time;
+ result[1] = Date;
+ result[2] = Text;
+ result[3] = Mode;
return result;
}
- private string Time
+ private static string Time
{
get
{
DateTime dt = DateTime.Now;
- string result = "";
- result += dt.ToLongTimeString();
- result += ".";
- result += dt.Millisecond.ToString();
- return result;
+ return dt.ToLongTimeString() + "." + dt.Millisecond;
}
}
- private string Date
+ private static string Date
{
get
{
- DateTime dt = DateTime.Now;
- string result = "";
- result += dt.ToShortDateString();
- return result;
+ return DateTime.Now.ToShortDateString();
}
}
+
private string Text
{
get
@@ -208,6 +159,7 @@
return text;
}
}
+
private string Mode
{
get
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|