Click here to Skip to main content
15,886,362 members
Articles / Programming Languages / C#

Universal Framework for Science and Engineering - Part 4: Space elevator

Rate me:
Please Sign up or sign in to vote.
4.56/5 (6 votes)
14 Aug 20066 min read 36.6K   2.2K   37  
An article on framework applications to the space elevator.
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.Drawing;
using System.Data;

using DataSetService;

namespace DataSetForm
{
    internal class PanelTable : Panel, ITable
    {

        #region Fields
        static internal readonly int panelWidth = 150;
        static internal readonly int panelTop = 30;
        static readonly Brush brush = new SolidBrush(Color.Blue);
        static readonly Brush pbrush = new SolidBrush(Color.White);
        static internal readonly Font font = new Font("Times", 15);
        Dictionary<string, IColumn> columns = new Dictionary<string, IColumn>();
        DataTable table;
        bool isMoved;
        int mouseX;
        int mouseY;
        const int MaxHeight = 400;
        Panel pTop = new Panel();
        Panel pLeft = new Panel();
        Panel pRight = new Panel();
        Panel pBottom = new Panel();
        Panel pCenter = new Panel();

        
        #endregion

        #region ITable Members


        public Dictionary<string, IColumn> Columns
        {
            get
            {
                return columns;
            }
        }

        public int X
        {
            get
            {
                return Left;
            }
            set
            {
                Left = value;
            }
        }

        public int Y
        {
            get
            {
                return Top;
            }
            set
            {
                Top = value;
            }
        }

        public DataTable Table
        {
            get
            {
                return table;
            }
            set
            {
                table = value;
            }
        }

        public void Remove()
        {
            AbstractDataSetDesktop.RemoveTable(this);
        }

        public IDataSetDesktop Desktop
        {
            get
            {
                return Parent as IDataSetDesktop;
            }
            set
            {
                if (Parent == null)
                {
                    Control c = value as Control;
                    if (!c.Controls.Contains(this))
                    {
                        c.Controls.Add(this);
                    }
                }
            }
        }

        #endregion

        private void InitializeComponent()
        {
            this.SuspendLayout();
            // 
            // TablePanel
            // 
           /* this.Paint += new System.Windows.Forms.PaintEventHandler(this.TablePanel_Paint);
            this.MouseMove += new System.Windows.Forms.MouseEventHandler(this.TablePanel_MouseMove);
            this.MouseUp += new System.Windows.Forms.MouseEventHandler(this.TablePanel_MouseUp);
            this.MouseDown += new System.Windows.Forms.MouseEventHandler(this.TablePanel_MouseDown);
            this.ResumeLayout(false);*/

        }

        private void TablePanel_Paint(object sender, PaintEventArgs e)
        {
            Graphics g = e.Graphics;
            g.FillRectangle(brush, 0, 0, Width, Height);
            g.DrawString(Name, font, pbrush, 3, 3); 

        }

        internal void init()
        {
            InitializeComponent();
            pTop.Height = panelTop;
            Width = panelWidth;
            pTop.Dock = DockStyle.Top;
            pTop.Paint += TablePanel_Paint;
            pTop.MouseMove += TablePanel_MouseMove;
            pTop.MouseUp += TablePanel_MouseUp;
            pTop.MouseDown += TablePanel_MouseDown;
            pLeft.Width = 1;
            pLeft.Dock = DockStyle.Left;
            pRight.Width = 1;
            pRight.Dock = DockStyle.Right;
            pBottom.Height = 1;
            pBottom.Dock = DockStyle.Bottom;
            //pCenter.Dock = DockStyle.Fill;
            pRight.BackColor = Color.Black;
            pLeft.BackColor = Color.Black;
            pTop.BackColor = Color.Black;
            pBottom.BackColor = Color.Black;
            pCenter.BackColor = Color.Black;
            Controls.Add(pTop);
            Controls.Add(pBottom);
            Controls.Add(pLeft);
            Controls.Add(pRight);
            Controls.Add(pCenter);
            int y = 1;
            foreach (IColumn c in columns.Values)
            {
                PanelColumn col = c as PanelColumn;
                col.Left = 1;
                col.Width = Width - 2;
                col.Top = y;
                col.init();
                col.BackColor = Color.White;
                pCenter.Controls.Add(col);
                y = col.Top + col.Height;
                /*Panel p = new Panel();
                p.Width = Width;
                p.Height = 2;
                p.BackColor = Color.White;
                p.Top = y;
                pCenter.Controls.Add(p);*/
                y = col.Bottom + 2;
            }
            Height = y + pTop.Bottom + 2;
            if (y > MaxHeight)
            {
                Height = MaxHeight;
                pCenter.AutoScroll = true;
                pCenter.Scroll += pCenter_Scroll;

            }
            pCenter.Top = pTop.Height + 1;
            pCenter.Left = pLeft.Width + 1;
            pCenter.Width = Width - pLeft.Width - pRight.Width - 2;
            pCenter.Height = Height - pTop.Height - pBottom.Height - 2;
        }

        void pCenter_Scroll(object sender, ScrollEventArgs e)
        {
            Parent.Refresh();
        }


        private void TablePanel_MouseDown(object sender, MouseEventArgs e)
        {
            isMoved = true;
            mouseX = e.X;
            mouseY = e.Y;
        }

        private void TablePanel_MouseUp(object sender, MouseEventArgs e)
        {
            isMoved = false;
            if (e.Button == MouseButtons.Right)
            {
                PanelDataSet p = Parent as PanelDataSet;
                Remove();
                p.Invalidate();
            }
        }

        private void TablePanel_MouseMove(object sender, MouseEventArgs e)
        {
            if (!isMoved)
            {
                return;
            }
            Left += e.X - mouseX;
            Top += e.Y - mouseY;
            PanelDataSet p = Parent as PanelDataSet;
            p.Set();
            p.Invalidate();
        }

        internal PanelColumn Get(int x, int y)
        {
            foreach (PanelColumn c in Columns.Values)
            {
                if (c.Get(x, y))
                {
                    return c;
                }
            }
            return null;
        }
    }
}

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 has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


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