using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using System.IO;
using DiagramUI;
using DataPerformer;
using DataPerformerUI.Performers;
namespace DataPerformerUI.UserControls
{
/// <summary>
/// 2D Table user control
/// </summary>
public partial class UserControlTable2D : UserControl
{
#region Fields
/// <summary>
/// The table
/// </summary>
protected Table2D table;
/// <summary>
/// Bitmap for table
/// </summary>
protected Bitmap bmp;
#endregion
#region Ctor
/// <summary>
/// Constructor
/// </summary>
public UserControlTable2D()
{
InitializeComponent();
CreateBitmap();
}
#endregion
internal Table2D Table
{
get
{
return table;
}
set
{
if (value == null)
{
return;
}
table = value;
DrawBitmap();
Refresh();
}
}
internal void Open()
{
if (openFileDialogTable2D.ShowDialog(this.ParentForm) != DialogResult.OK)
{
return;
}
Stream stream = null;
try
{
stream = File.OpenRead(openFileDialogTable2D.FileName);
table.Load(stream);
Refresh();
}
catch (Exception ex)
{
ex.Log();
}
if (stream != null)
{
stream.Close();
}
}
internal void Save()
{
Stream stream = null;
if (saveFileDialogTable2D.ShowDialog(this.ParentForm) != DialogResult.OK)
{
return;
}
try
{
stream = File.OpenWrite(saveFileDialogTable2D.FileName);
table.Save(stream);
}
catch (Exception ex)
{
ex.Log();
}
if (stream != null)
{
stream.Close();
}
}
private void CreateBitmap()
{
bmp = new Bitmap(Width, Height);
}
private void DrawBitmap()
{
Graphics g = Graphics.FromImage(bmp);
if (table != null)
{
Table2DPerformer.Draw(table, g, 0, 0, Width, Height);
}
}
private void UserControlTable2D_Paint(object sender, PaintEventArgs e)
{
e.Graphics.DrawImage(bmp, 0, 0);
}
private void UserControlTable2D_Resize(object sender, EventArgs e)
{
CreateBitmap();
DrawBitmap();
Refresh();
}
}
}