Click here to Skip to main content
15,891,033 members
Articles / Programming Languages / C# 4.0

Grandiose projects 5. Audio support

Rate me:
Please Sign up or sign in to vote.
5.00/5 (2 votes)
3 Feb 2012CPOL8 min read 23.2K   2K   8  
Audio support for grandiose projects
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.Drawing;
using System.Data;

using DataSetService;


namespace DataSetService.Forms
{
    internal class PanelLink : Panel, ILink
    {
        #region Fields
        private readonly int shift = 30;

        private static readonly Pen pen = new Pen(Color.Black);

        private PanelColumn source;
        private PanelColumn target;

        protected string sourceTable;
        protected string targetTable;
        protected string sourceColumn;
        protected string targetColumn;
        protected CheckBox mark = new CheckBox();



        #endregion

        #region Constructors

        internal PanelLink()
        {
            Width = 100;
            Height = 30;
            mark.Top = 5;
            mark.Left = 5;
            Controls.Add(mark);
            InitializeComponent();
        }

        #endregion

        #region ILink Members

        public IColumn Source
        {
            get
            {
                return source;
            }
            set
            {
                source = value as PanelColumn;
                sourceTable = source.Table.Name;
                sourceColumn = source.Name;
            }
        }

        public IColumn Target
        {
            get
            {
                return target;
            }
            set
            {
                AbstractLink.Check(this, value);
                target = value as PanelColumn;
                targetTable = target.Table.Name;
                targetColumn = target.Name;
                add(target.Parent);
                mark.Text = source.Name + " = " + target.Name;
            }
        }

        public IDataSetDesktop Desktop
        {
            get
            {
                return Parent as PanelDataSet;
            }
            set
            {
                PanelDataSet p = value as PanelDataSet;
                add(p);
            }
        }

        public string SourceTable
        {
            get
            {
                return sourceTable;
            }
            set
            {
                sourceTable = value;
            }
        }

        public string TargetTable
        {
            get
            {
                return targetTable;
            }
            set
            {
                targetTable = value;
            }
        }

        public string SourceColumn
        {
            get
            {
                return sourceColumn;
            }
            set
            {
                sourceColumn = value;
            }
        }

        public string TargetColumn
        {
            get
            {
                return targetColumn;
            }
            set
            {
                targetColumn = value;
            }
        }

        public bool IsMarked
        {
            get
            {
                return mark.Checked;
            }
            set
            {
                mark.Checked = value;
            }
        }

        public void Remove()
        {
            source.Parent.Controls.Remove(this);
            AbstractDataSetDesktop.RemoveLink(this);
        }

        #endregion

        #region Specific Members

        protected void add(Control c)
        {
            if (c == null)
            {
                return;
            }
            if (c.Controls.Contains(this))
            {
                return;
            }
            c.Controls.Add(this);
        }

        internal void Set()
        {
            int x1 = source.Xl + shift;
            int x2 = target.Xr - shift;
            int y1 = source.PosLink;
            int y2 = target.PosLink;
            int dx = Width / 2;
            int dy = Height / 2;
            Left = (x1 + x2 - Width) / 2;
            Top = (y1 + y2 - Height) / 2;
        }

        internal void Draw(Graphics g)
        {
            Set();
            int x1 = source.Xr;
            int x2 = target.Xl;
            int y1 = source.PosLink;
            int y2 = target.PosLink;
            x1 += shift;
            x2 -= shift;
            g.DrawLine(pen, source.Xl, y1, x1, y1);
            g.DrawLine(pen, x1, y1, x2, y2);
            g.DrawLine(pen, x2, y2, target.Xr, y2);
 
        }


        #endregion

        private void InitializeComponent()
        {
            this.SuspendLayout();
            // 
            // PanelLink
            // 
            this.Paint += new System.Windows.Forms.PaintEventHandler(this.PanelLink_Paint);
            this.ResumeLayout(false);

        }

        private void PanelLink_Paint(object sender, PaintEventArgs e)
        {
            Graphics g = e.Graphics;
            g.DrawRectangle(pen, 0, 0, Width - 1, Height - 1);
        }

    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Architect
Russian Federation Russian Federation
Ph. D. Petr Ivankov worked as scientific researcher at Russian Mission Control Centre since 1978 up to 2000. Now he is engaged by Aviation training simulators http://dinamika-avia.com/ . His additional interests are:

1) Noncommutative geometry

http://front.math.ucdavis.edu/author/P.Ivankov

2) Literary work (Russian only)

http://zhurnal.lib.ru/editors/3/3d_m/

3) Scientific articles
http://arxiv.org/find/all/1/au:+Ivankov_Petr/0/1/0/all/0/1

Comments and Discussions