using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
using CategoryTheory;
using ResourceService;
namespace DiagramUI
{
/// <summary>
/// Summary description for FormContainerDesigner.
/// </summary>
public class FormContainerDesigner : System.Windows.Forms.Form
{
private IContainer components;
private System.Windows.Forms.Panel panelLeft;
private System.Windows.Forms.Panel panelRight;
private System.Windows.Forms.Panel panelTop;
private System.Windows.Forms.Panel panelBottom;
private System.Windows.Forms.Panel panelCenter;
private System.Windows.Forms.Panel panelLabel;
private System.Windows.Forms.Panel panelIntTop;
private System.Windows.Forms.Panel panelIntBottom;
private System.Windows.Forms.Panel panelIntLeft;
private System.Windows.Forms.Panel panelBaseCheck;
private System.Windows.Forms.CheckedListBox checkedListBoxInter;
private System.Windows.Forms.ComboBox comboBoxInter;
private System.Windows.Forms.Button buttonAcceptInterfaces;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Panel panelDrawing;
private System.Windows.Forms.TextBox textBoxComment;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Panel panelLabelPeer;
private IDesktop desktop;
private ArrayList comp;
private ArrayList selected = new ArrayList();
private System.Windows.Forms.MainMenu mainMenuDesigner;
private System.Windows.Forms.MenuItem menuItemFile;
private System.Windows.Forms.MenuItem menuItemOpen;
private System.Windows.Forms.MenuItem menuItemSaveAs;
private System.Windows.Forms.MenuItem menuItemSeparator;
private System.Windows.Forms.SaveFileDialog saveFileDialogContainer;
private ToolStrip toolStripMain;
private ToolStripButton openToolStripButton;
private ToolStripButton toolStripButtonLoadFromDatabase;
private ToolStripButton saveToolStripButton;
private ToolStripButton toolStripButtonClear;
private ToolStripButton toolStripButtonRefresh;
private ToolStripButton toolStripButtonToolBox;
private ToolStripButton toolStripButtonFont;
private MenuItem menuItem1;
private MenuItem menuItem2;
private MenuItem menuItem3;
private Hashtable table = new Hashtable();
private FormContainerDesigner()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
}
public FormContainerDesigner(IDesktop desktop) : this()
{
Resources.LoadControlResources(this);
this.desktop = desktop;
comp = new ArrayList(PureDesktopPeer.GetAllObjects(desktop));
foreach (INamedComponent nc in comp)
{
checkedListBoxInter.Items.Add(nc.GetName(desktop));
}
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(FormContainerDesigner));
this.panelLeft = new System.Windows.Forms.Panel();
this.panelRight = new System.Windows.Forms.Panel();
this.panelTop = new System.Windows.Forms.Panel();
this.panelBottom = new System.Windows.Forms.Panel();
this.panelCenter = new System.Windows.Forms.Panel();
this.panelBaseCheck = new System.Windows.Forms.Panel();
this.checkedListBoxInter = new System.Windows.Forms.CheckedListBox();
this.panelIntLeft = new System.Windows.Forms.Panel();
this.panelIntBottom = new System.Windows.Forms.Panel();
this.buttonAcceptInterfaces = new System.Windows.Forms.Button();
this.panelIntTop = new System.Windows.Forms.Panel();
this.label1 = new System.Windows.Forms.Label();
this.panelLabel = new System.Windows.Forms.Panel();
this.label2 = new System.Windows.Forms.Label();
this.textBoxComment = new System.Windows.Forms.TextBox();
this.panelDrawing = new System.Windows.Forms.Panel();
this.panelLabelPeer = new System.Windows.Forms.Panel();
this.comboBoxInter = new System.Windows.Forms.ComboBox();
this.mainMenuDesigner = new System.Windows.Forms.MainMenu(this.components);
this.menuItemFile = new System.Windows.Forms.MenuItem();
this.menuItemOpen = new System.Windows.Forms.MenuItem();
this.menuItemSeparator = new System.Windows.Forms.MenuItem();
this.menuItemSaveAs = new System.Windows.Forms.MenuItem();
this.saveFileDialogContainer = new System.Windows.Forms.SaveFileDialog();
this.toolStripMain = new System.Windows.Forms.ToolStrip();
this.openToolStripButton = new System.Windows.Forms.ToolStripButton();
this.toolStripButtonLoadFromDatabase = new System.Windows.Forms.ToolStripButton();
this.saveToolStripButton = new System.Windows.Forms.ToolStripButton();
this.toolStripButtonClear = new System.Windows.Forms.ToolStripButton();
this.toolStripButtonRefresh = new System.Windows.Forms.ToolStripButton();
this.toolStripButtonToolBox = new System.Windows.Forms.ToolStripButton();
this.toolStripButtonFont = new System.Windows.Forms.ToolStripButton();
this.menuItem1 = new System.Windows.Forms.MenuItem();
this.menuItem2 = new System.Windows.Forms.MenuItem();
this.menuItem3 = new System.Windows.Forms.MenuItem();
this.panelTop.SuspendLayout();
this.panelCenter.SuspendLayout();
this.panelBaseCheck.SuspendLayout();
this.panelIntBottom.SuspendLayout();
this.panelIntTop.SuspendLayout();
this.panelLabel.SuspendLayout();
this.panelDrawing.SuspendLayout();
this.toolStripMain.SuspendLayout();
this.SuspendLayout();
//
// panelLeft
//
this.panelLeft.Dock = System.Windows.Forms.DockStyle.Left;
this.panelLeft.Location = new System.Drawing.Point(0, 0);
this.panelLeft.Name = "panelLeft";
this.panelLeft.Size = new System.Drawing.Size(8, 429);
this.panelLeft.TabIndex = 0;
//
// panelRight
//
this.panelRight.Dock = System.Windows.Forms.DockStyle.Right;
this.panelRight.Location = new System.Drawing.Point(752, 0);
this.panelRight.Name = "panelRight";
this.panelRight.Size = new System.Drawing.Size(8, 429);
this.panelRight.TabIndex = 1;
//
// panelTop
//
this.panelTop.Controls.Add(this.toolStripMain);
this.panelTop.Dock = System.Windows.Forms.DockStyle.Top;
this.panelTop.Location = new System.Drawing.Point(8, 0);
this.panelTop.Name = "panelTop";
this.panelTop.Size = new System.Drawing.Size(744, 48);
this.panelTop.TabIndex = 2;
//
// panelBottom
//
this.panelBottom.Dock = System.Windows.Forms.DockStyle.Bottom;
this.panelBottom.Location = new System.Drawing.Point(8, 421);
this.panelBottom.Name = "panelBottom";
this.panelBottom.Size = new System.Drawing.Size(744, 8);
this.panelBottom.TabIndex = 3;
//
// panelCenter
//
this.panelCenter.Controls.Add(this.panelBaseCheck);
this.panelCenter.Controls.Add(this.panelIntLeft);
this.panelCenter.Controls.Add(this.panelIntBottom);
this.panelCenter.Controls.Add(this.panelIntTop);
this.panelCenter.Controls.Add(this.panelLabel);
this.panelCenter.Dock = System.Windows.Forms.DockStyle.Fill;
this.panelCenter.Location = new System.Drawing.Point(8, 48);
this.panelCenter.Name = "panelCenter";
this.panelCenter.Size = new System.Drawing.Size(744, 373);
this.panelCenter.TabIndex = 4;
//
// panelBaseCheck
//
this.panelBaseCheck.Controls.Add(this.checkedListBoxInter);
this.panelBaseCheck.Dock = System.Windows.Forms.DockStyle.Fill;
this.panelBaseCheck.Location = new System.Drawing.Point(8, 40);
this.panelBaseCheck.Name = "panelBaseCheck";
this.panelBaseCheck.Size = new System.Drawing.Size(456, 293);
this.panelBaseCheck.TabIndex = 4;
//
// checkedListBoxInter
//
this.checkedListBoxInter.Dock = System.Windows.Forms.DockStyle.Fill;
this.checkedListBoxInter.Location = new System.Drawing.Point(0, 0);
this.checkedListBoxInter.Name = "checkedListBoxInter";
this.checkedListBoxInter.Size = new System.Drawing.Size(456, 289);
this.checkedListBoxInter.TabIndex = 0;
//
// panelIntLeft
//
this.panelIntLeft.Dock = System.Windows.Forms.DockStyle.Left;
this.panelIntLeft.Location = new System.Drawing.Point(0, 40);
this.panelIntLeft.Name = "panelIntLeft";
this.panelIntLeft.Size = new System.Drawing.Size(8, 293);
this.panelIntLeft.TabIndex = 3;
//
// panelIntBottom
//
this.panelIntBottom.Controls.Add(this.buttonAcceptInterfaces);
this.panelIntBottom.Dock = System.Windows.Forms.DockStyle.Bottom;
this.panelIntBottom.Location = new System.Drawing.Point(0, 333);
this.panelIntBottom.Name = "panelIntBottom";
this.panelIntBottom.Size = new System.Drawing.Size(464, 40);
this.panelIntBottom.TabIndex = 2;
//
// buttonAcceptInterfaces
//
this.buttonAcceptInterfaces.Location = new System.Drawing.Point(176, 8);
this.buttonAcceptInterfaces.Name = "buttonAcceptInterfaces";
this.buttonAcceptInterfaces.Size = new System.Drawing.Size(75, 23);
this.buttonAcceptInterfaces.TabIndex = 0;
this.buttonAcceptInterfaces.Text = "Accept";
this.buttonAcceptInterfaces.Click += new System.EventHandler(this.buttonAcceptInterfaces_Click);
//
// panelIntTop
//
this.panelIntTop.Controls.Add(this.label1);
this.panelIntTop.Dock = System.Windows.Forms.DockStyle.Top;
this.panelIntTop.Location = new System.Drawing.Point(0, 0);
this.panelIntTop.Name = "panelIntTop";
this.panelIntTop.Size = new System.Drawing.Size(464, 40);
this.panelIntTop.TabIndex = 1;
//
// label1
//
this.label1.Location = new System.Drawing.Point(136, 8);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(184, 23);
this.label1.TabIndex = 0;
this.label1.Text = "Public objects";
//
// panelLabel
//
this.panelLabel.Controls.Add(this.label2);
this.panelLabel.Controls.Add(this.textBoxComment);
this.panelLabel.Controls.Add(this.panelDrawing);
this.panelLabel.Controls.Add(this.comboBoxInter);
this.panelLabel.Dock = System.Windows.Forms.DockStyle.Right;
this.panelLabel.Location = new System.Drawing.Point(464, 0);
this.panelLabel.Name = "panelLabel";
this.panelLabel.Size = new System.Drawing.Size(280, 373);
this.panelLabel.TabIndex = 0;
//
// label2
//
this.label2.Location = new System.Drawing.Point(40, 272);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(100, 23);
this.label2.TabIndex = 3;
this.label2.Text = "Comment";
//
// textBoxComment
//
this.textBoxComment.Location = new System.Drawing.Point(32, 312);
this.textBoxComment.Name = "textBoxComment";
this.textBoxComment.Size = new System.Drawing.Size(224, 20);
this.textBoxComment.TabIndex = 2;
//
// panelDrawing
//
this.panelDrawing.BackColor = System.Drawing.SystemColors.ActiveCaptionText;
this.panelDrawing.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
this.panelDrawing.Controls.Add(this.panelLabelPeer);
this.panelDrawing.Location = new System.Drawing.Point(24, 48);
this.panelDrawing.Name = "panelDrawing";
this.panelDrawing.Size = new System.Drawing.Size(224, 200);
this.panelDrawing.TabIndex = 1;
this.panelDrawing.MouseDown += new System.Windows.Forms.MouseEventHandler(this.panelDrawing_MouseDown);
//
// panelLabelPeer
//
this.panelLabelPeer.BackColor = System.Drawing.SystemColors.Control;
this.panelLabelPeer.Location = new System.Drawing.Point(56, 48);
this.panelLabelPeer.Name = "panelLabelPeer";
this.panelLabelPeer.Size = new System.Drawing.Size(100, 100);
this.panelLabelPeer.TabIndex = 0;
//
// comboBoxInter
//
this.comboBoxInter.Location = new System.Drawing.Point(24, 16);
this.comboBoxInter.Name = "comboBoxInter";
this.comboBoxInter.Size = new System.Drawing.Size(224, 21);
this.comboBoxInter.TabIndex = 0;
this.comboBoxInter.SelectedIndexChanged += new System.EventHandler(this.comboBoxInter_SelectedIndexChanged);
//
// mainMenuDesigner
//
this.mainMenuDesigner.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuItemFile});
//
// menuItemFile
//
this.menuItemFile.Index = 0;
this.menuItemFile.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuItemOpen,
this.menuItemSeparator,
this.menuItemSaveAs,
this.menuItem1,
this.menuItem2,
this.menuItem3});
this.menuItemFile.Text = "File";
//
// menuItemOpen
//
this.menuItemOpen.Index = 0;
this.menuItemOpen.Text = "Open";
//
// menuItemSeparator
//
this.menuItemSeparator.Index = 1;
this.menuItemSeparator.Text = "-";
//
// menuItemSaveAs
//
this.menuItemSaveAs.Index = 2;
this.menuItemSaveAs.Text = "Save as";
this.menuItemSaveAs.Click += new System.EventHandler(this.menuItemSaveAs_Click);
//
// saveFileDialogContainer
//
this.saveFileDialogContainer.Filter = "Container files|*.cont";
//
// toolStripMain
//
this.toolStripMain.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.openToolStripButton,
this.toolStripButtonLoadFromDatabase,
this.saveToolStripButton,
this.toolStripButtonClear,
this.toolStripButtonRefresh,
this.toolStripButtonToolBox,
this.toolStripButtonFont});
this.toolStripMain.Location = new System.Drawing.Point(0, 0);
this.toolStripMain.Name = "toolStripMain";
this.toolStripMain.Size = new System.Drawing.Size(744, 25);
this.toolStripMain.TabIndex = 6;
this.toolStripMain.Text = "toolStrip1";
//
// openToolStripButton
//
this.openToolStripButton.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
this.openToolStripButton.Image = ((System.Drawing.Image)(resources.GetObject("openToolStripButton.Image")));
this.openToolStripButton.ImageTransparentColor = System.Drawing.Color.Black;
this.openToolStripButton.Name = "openToolStripButton";
this.openToolStripButton.Size = new System.Drawing.Size(23, 22);
this.openToolStripButton.Text = "Open";
//
// toolStripButtonLoadFromDatabase
//
this.toolStripButtonLoadFromDatabase.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
this.toolStripButtonLoadFromDatabase.Image = ((System.Drawing.Image)(resources.GetObject("toolStripButtonLoadFromDatabase.Image")));
this.toolStripButtonLoadFromDatabase.ImageTransparentColor = System.Drawing.Color.Magenta;
this.toolStripButtonLoadFromDatabase.Name = "toolStripButtonLoadFromDatabase";
this.toolStripButtonLoadFromDatabase.Size = new System.Drawing.Size(23, 22);
this.toolStripButtonLoadFromDatabase.Text = "Load from database";
//
// saveToolStripButton
//
this.saveToolStripButton.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
this.saveToolStripButton.Image = ((System.Drawing.Image)(resources.GetObject("saveToolStripButton.Image")));
this.saveToolStripButton.ImageTransparentColor = System.Drawing.Color.Black;
this.saveToolStripButton.Name = "saveToolStripButton";
this.saveToolStripButton.Size = new System.Drawing.Size(23, 22);
this.saveToolStripButton.Text = "Save";
//
// toolStripButtonClear
//
this.toolStripButtonClear.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
this.toolStripButtonClear.Image = ((System.Drawing.Image)(resources.GetObject("toolStripButtonClear.Image")));
this.toolStripButtonClear.ImageTransparentColor = System.Drawing.Color.Magenta;
this.toolStripButtonClear.Name = "toolStripButtonClear";
this.toolStripButtonClear.Size = new System.Drawing.Size(23, 22);
this.toolStripButtonClear.Text = "toolStripButtonClear";
//
// toolStripButtonRefresh
//
this.toolStripButtonRefresh.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
this.toolStripButtonRefresh.Image = ((System.Drawing.Image)(resources.GetObject("toolStripButtonRefresh.Image")));
this.toolStripButtonRefresh.ImageTransparentColor = System.Drawing.Color.Magenta;
this.toolStripButtonRefresh.Name = "toolStripButtonRefresh";
this.toolStripButtonRefresh.Size = new System.Drawing.Size(23, 22);
this.toolStripButtonRefresh.Text = "toolStripButton2";
//
// toolStripButtonToolBox
//
this.toolStripButtonToolBox.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
this.toolStripButtonToolBox.Image = ((System.Drawing.Image)(resources.GetObject("toolStripButtonToolBox.Image")));
this.toolStripButtonToolBox.ImageTransparentColor = System.Drawing.Color.Magenta;
this.toolStripButtonToolBox.Name = "toolStripButtonToolBox";
this.toolStripButtonToolBox.Size = new System.Drawing.Size(23, 22);
this.toolStripButtonToolBox.Text = "toolStripButton1";
//
// toolStripButtonFont
//
this.toolStripButtonFont.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
this.toolStripButtonFont.Image = ((System.Drawing.Image)(resources.GetObject("toolStripButtonFont.Image")));
this.toolStripButtonFont.ImageTransparentColor = System.Drawing.Color.Magenta;
this.toolStripButtonFont.Name = "toolStripButtonFont";
this.toolStripButtonFont.Size = new System.Drawing.Size(23, 22);
this.toolStripButtonFont.Text = "toolStripButton1";
//
// menuItem1
//
this.menuItem1.Index = 3;
this.menuItem1.Text = "Save";
//
// menuItem2
//
this.menuItem2.Index = 4;
this.menuItem2.Text = "-";
//
// menuItem3
//
this.menuItem3.Index = 5;
this.menuItem3.Text = "Exit";
//
// FormContainerDesigner
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(760, 429);
this.Controls.Add(this.panelCenter);
this.Controls.Add(this.panelBottom);
this.Controls.Add(this.panelTop);
this.Controls.Add(this.panelRight);
this.Controls.Add(this.panelLeft);
this.Menu = this.mainMenuDesigner;
this.Name = "FormContainerDesigner";
this.Text = "Container designer";
this.panelTop.ResumeLayout(false);
this.panelTop.PerformLayout();
this.panelCenter.ResumeLayout(false);
this.panelBaseCheck.ResumeLayout(false);
this.panelIntBottom.ResumeLayout(false);
this.panelIntTop.ResumeLayout(false);
this.panelLabel.ResumeLayout(false);
this.panelLabel.PerformLayout();
this.panelDrawing.ResumeLayout(false);
this.toolStripMain.ResumeLayout(false);
this.toolStripMain.PerformLayout();
this.ResumeLayout(false);
}
#endregion
private void buttonAcceptInterfaces_Click(object sender, System.EventArgs e)
{
selected.Clear();
ICollection check = checkedListBoxInter.CheckedIndices;
foreach (int i in check)
{
selected.Add(comp[i]);
}
fillCombo();
}
private void fillCombo()
{
comboBoxInter.Items.Clear();
table.Clear();
clearPanels();
foreach (INamedComponent nc in selected)
{
comboBoxInter.Items.Add(nc.GetName(desktop));
}
}
private void comboBoxInter_SelectedIndexChanged(object sender, System.EventArgs e)
{
int n = comboBoxInter.SelectedIndex;
object o = selected[n];
if (!table.ContainsKey(o))
{
return;
}
object[] ob = table[o] as object[];
blackPanels();
Panel p = ob[0] as Panel;
p.BackColor = Color.Red;
textBoxComment.Text = ob[1] as string;
}
private ICollection Panels
{
get
{
ArrayList c = new ArrayList(panelDrawing.Controls);
c.Remove(panelLabelPeer);
return c;
}
}
private void clearPanels()
{
ICollection c = Panels;
foreach (Control comp in c)
{
panelLabelPeer.Controls.Remove(comp);
}
}
private void blackPanels()
{
ICollection c = Panels;
foreach (Panel comp in c)
{
comp.BackColor = Color.Black;
}
}
private void panelDrawing_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
{
int n = comboBoxInter.SelectedIndex;
if (n < 0)
{
return;
}
INamedComponent o = selected[n] as INamedComponent;
blackPanels();
if (table.ContainsKey(o))
{
object[] ob = table[o] as object[];
Panel p = ob[0] as Panel;
p.Left = e.X;
p.Top = e.Y;
ob[1] = this.textBoxComment.Text;
return;
}
Panel pan = new Panel();
pan.Width = 5;
pan.Height = 5;
pan.BackColor = Color.Red;
pan.Left = e.X;
pan.Top = e.Y;
ToolTip t = new ToolTip();
t.ShowAlways = true;
t.SetToolTip(pan, o.GetName(desktop) + " :: " + textBoxComment.Text);
panelDrawing.Controls.Add(pan);
table[o] = new object[]{pan, textBoxComment.Text};
}
private void menuItemSaveAs_Click(object sender, System.EventArgs e)
{
try
{
ObjectContainer c = Container;;
if (saveFileDialogContainer.ShowDialog(this) != DialogResult.OK)
{
return;
}
int n = saveFileDialogContainer.FileName.LastIndexOf("\\") + 1;
string fn = saveFileDialogContainer.FileName.Substring(n);
Stream stream = File.OpenWrite(saveFileDialogContainer.FileName);
BinaryFormatter f = new BinaryFormatter();
c.Type = fn;
f.Serialize(stream, c);
stream.Close();
}
catch (Exception ex)
{
string s = ex.StackTrace;
s = null;
}
PureDesktopPeer.SetParents(desktop);
}
public ObjectContainer Container
{
get
{
PureDesktopPeer desk = new PureDesktopPeer();
desk.Copy(desktop.Objects, desktop.Arrows, false);
ObjectContainer c = new ObjectContainer(desk);
foreach (INamedComponent nc in selected)
{
if (!table.ContainsKey(nc))
{
MessageBox.Show(this, "Not all");
return null;
}
object[] o = table[nc] as object[];
Panel p = o[0] as Panel;
string comm = o[1] + "";
PureDesktopPeer.SetParents(desktop);
string nam = nc.GetName(desktop);
PureDesktopPeer.SetParents(desk);
INamedComponent comp = desk[nam];
c.Add(comp, p.Left - panelLabelPeer.Left, p.Top - panelLabelPeer.Top, comm);
}
return c;
}
}
}
}