Click here to Skip to main content
Click here to Skip to main content
 
Add your own
alternative version
Go to top

User-driven applications

, 10 Apr 2010
User-driven applications are the programs in which full control is given to the users. Designers of such programs are responsible only for developing an instrument for solving some task, but they do not enforce users to work with this instrument according with a predefined scenario.
TheoryOfUserDrivenApplications.zip
TheoryOfUserDrivenApplications
TheoryOfUserDrivenApplications
bin
Debug
TheoryOfUserDrivenApplications.vshost.exe
Release
MoveGraphLibrary.dll
TheoryOfUserDrivenApplications.bin
TheoryOfUserDrivenApplications.exe
TheoryOfUserDrivenApplications.vshost.exe
Properties
Settings.settings
Resources
ArrowDown.bmp
ArrowUp.bmp
DELETE.BMP
Hangar.bmp
Lock.bmp
palette_.bmp
RuralHouse.bmp
RuralLeftPlus.bmp
RuralRightPlus.bmp
SimpleHouse.bmp
User_driven_applications.doc
User_driven_applications.pdf
using System;
using System .Collections .Generic;
using System .Drawing;
using System .Drawing .Drawing2D;
using System .IO;
using System .Windows .Forms;
using Microsoft .Win32;

using MoveGraphLibrary;

namespace UserDrivenApplications
{
    public class GroupABArrays : GraphicalObject
    {
        // elements:    ElasticGroup
        //              GroupEditABArray
        //
        int version = 606;
        Form formParent;
        ElasticGroup groupList;
        GroupEditABArray groupData;
        GroupVisibleParameters visParams;
        string title;

        Rectangle rcFrame;  // only through calculation
        Rectangle rcGap;    // only through calculation

        Size sizeTitle;
        int minFrameSpace = 6;  // min space on three sides; at the top it is a min addition to hStr / 2
        int minminFrameWidth = 16; 

        // -------------------------------------------------        
        public GroupABArrays (Form form, ElasticGroup grpStandard, GroupEditABArray grpSpecial, string strTitle) 
        {
            formParent = form;

            groupList = grpStandard;
            groupData = grpSpecial;

            title = strTitle;
            visParams = new GroupVisibleParameters (form, true, true);
            visParams .GroupID = this .ID;
            MeasureTitleSize ();
            FrameArea ();
        }
        // -------------------------------------------------        GroupVisibleParameters
        public GroupVisibleParameters GroupVisibleParameters
        {
            get { return (visParams); }
            set { visParams = value; }
        }
        // -------------------------------------------------        GroupList
        public ElasticGroup GroupList
        {
            get { return (groupList); }
        }
        // -------------------------------------------------        GroupData
        public GroupEditABArray GroupData
        {
            get { return (groupData); }
        }
        // -------------------------------------------------        Controls
        public List<Control> Controls
        {
            get
            {
                List<Control> ctrls = new List<Control> ();
                ctrls .AddRange (groupList .Controls);
                ctrls .AddRange (groupData .Controls);
                return (ctrls);
            }
        }
        // -------------------------------------------------        MSPlot
        public MSPlot MSPlot
        {
            get { return (groupData .MSPlot); }
        }
        // -------------------------------------------------        Dots
        public DotsOnPlot Dots
        {
            get { return (groupData .Dots); }
        }
        // -------------------------------------------------        DotNest
        public DotNest DotNest
        {
            get { return (groupData .DotNest); }
        }
        // -------------------------------------------------        MeasureTitleSize
        private void MeasureTitleSize ()
        {
            sizeTitle = Auxi_Geometry .RoundMeasureString (formParent, title, visParams .TitleFont);
        }
        // -------------------------------------------------        FrameArea
        private void FrameArea ()
        {
            Rectangle unionArea = Rectangle .Union (groupList .RectAround, groupData .RectAround);
            int spaceOnTop = visParams .SideSpaces [1] + sizeTitle .Height / 2;
            unionArea .X -= visParams .SideSpaces [0];
            unionArea .Y -= spaceOnTop;
            unionArea .Width += visParams .SideSpaces [0] + visParams .SideSpaces [2];
            unionArea .Height += spaceOnTop + visParams .SideSpaces [3];
            rcFrame = unionArea;

            int minFrameWidth = minminFrameWidth;
            int gap = sizeTitle .Width + 2 * visParams .TitleSideSpace;
            minFrameWidth += gap;
            rcFrame .Width = Math .Max (rcFrame .Width, minFrameWidth);
            rcGap = Auxi_Geometry .CurvedFrameGapArea (rcFrame, visParams .TitleAlignmentCoef, sizeTitle, visParams .TitleSideSpace);
        }
        // -------------------------------------------------        RectAround
        new public Rectangle RectAround
        {
            get
            {
                FrameArea ();
                return (rcFrame);
            }
        }
        // -------------------------------------------------        Update
        public void Update ()
        {
            groupList .Update ();
            groupData .Update ();
            FrameArea ();
            DefineCover ();
        }
        // -------------------------------------------------        ID
        new public long ID
        {
            get { return (id); }
            set
            {
                id = value;
                groupList .ParentID = id;
                groupData .ParentID = id;
            }
        }
        // -------------------------------------------------        Visible
        new public bool Visible
        {
            get { return (visible); }
            set
            {
                visible = value;
                groupList .Visible = visible;
                groupData .Visible = visible;
                if (visible)
                {
                    Update ();
                }
            }
        }
        // -------------------------------------------------        SideSpaces
        public int [] SideSpaces
        {
            get { return (visParams .SideSpaces); }  
        }
        // -------------------------------------------------        ShowFrame
        public bool ShowFrame
        {
            get { return (visParams .ShowFrame); }   
            set { visParams .ShowFrame = value; }  
        }
        // -------------------------------------------------        FrameColor
        public Color FrameColor
        {
            get { return (visParams .FrameColor); }  
            set { visParams .FrameColor = value; }  
        }
        // -------------------------------------------------        BackColor
        public Color BackColor
        {
            get { return (visParams .GroupBackColor); }
            set { visParams .GroupBackColor = value; }
        }
        // -------------------------------------------------        BackColorSpreadInside
        public bool BackColorSpreadInside
        {
            get { return (visParams .BackColorSpreadInside); }
            set { visParams .BackColorSpreadInside = value; }
        }
        // -------------------------------------------------        HasTitle
        public bool HasTitle
        {
            get { return (!string .IsNullOrEmpty (title)); }
        }
        // -------------------------------------------------        Title
        public string Title
        {
            get { return (title); }
            set
            {
                title = value;
                MeasureTitleSize ();
                Update ();
            }
        }
        // -------------------------------------------------        TitleAlignmentCoef
        public double TitleAlignmentCoef
        {
            get { return (visParams .TitleAlignmentCoef); }
            set
            {
                visParams .TitleAlignmentCoef = Math .Min (Math .Max (0, value), 1);
                DefineCover ();
            }
        }
        // -------------------------------------------------        Font
        public Font Font
        {
            set
            {
                visParams .TitleFont = value;
                visParams .ElementsFont = value;

                TitleFont = visParams .TitleFont; 
                ElementsFont = visParams .ElementsFont; 
                MeasureTitleSize ();
                Update ();
            }
        }
        // -------------------------------------------------        ElementsFont
        public Font ElementsFont
        {
            set
            {
                visParams .ElementsFont = value;
                groupList .Font = visParams .ElementsFont; 
                groupData .Font = visParams .ElementsFont;
                Update ();
            }
        }
        // -------------------------------------------------        ElementsColor
        public Color ElementsColor
        {
            set
            {
                visParams .ElementsColor = value;
                groupList .BackColor = visParams .ElementsColor; 
                groupData .BackColor = visParams .ElementsColor; 
            }
        }
        // -------------------------------------------------        ControlsBackColor
        public Color ControlsBackColor
        {
            set
            {
                groupList .ControlsBackColor = value;
                groupData .ControlsBackColor = value;
            }
        }
        // -------------------------------------------------        TitleFont
        public Font TitleFont
        {
            get { return (visParams .TitleFont); } 
            set
            {
                visParams .TitleFont = value;
                MeasureTitleSize ();
                Update ();
            }
        }
        // -------------------------------------------------        TitleColor
        public Color TitleColor
        {
            get { return (visParams .TitleColor); } 
            set { visParams .TitleColor = value; }
        }
        // -------------------------------------------------        Draw
        public void Draw (Graphics grfx)
        {
            if (visible)
            {
                MeasureTitleSize ();
                Rectangle rc = Rectangle .FromLTRB (rcFrame .Left - 3, rcFrame .Top - 3, rcFrame .Right + 3, rcFrame .Bottom + 3);
                SolidBrush brush = new SolidBrush (visParams .GroupBackColor);
                grfx .FillRectangle (brush, rc);
                Rectangle rcAbove = Rectangle .FromLTRB (rcGap .Left, rcGap .Top, rcGap .Right, rc .Top);
                grfx .FillRectangle (brush, rcAbove);
                Auxi_Drawing .CurvedFrameWithTitle (grfx, rcFrame, new Pen (visParams .FrameColor), visParams .ShowFrame,
                                                    visParams .TitleAlignmentCoef, sizeTitle, visParams .TitleSideSpace, title, 
                                                    visParams .TitleFont, visParams .TitleColor);
                groupData .Draw (grfx);
                groupList .Draw (grfx);
            }
        }
        // -------------------------------------------------        IntoMover
        new public void IntoMover (Mover mover, int iPos)
        {
            if (visible)
            {
                if (iPos < 0 || mover .Count < iPos)
                {
                    return;
                }
                mover .Insert (iPos, this);
                groupData .IntoMover (mover, iPos);
                groupList .IntoMover (mover, iPos);
            }
        }
        // -------------------------------------------------        PositionsInMover
        new public int PositionsInMover
        {
            get
            {
                int nPos = 1;
                nPos += groupData .PositionsInMover;
                nPos += groupList .PositionsInMover;
                return (nPos);
            }
        }
        // -------------------------------------------------        DefineCover
        public override void DefineCover ()
        {
            MeasureTitleSize ();
            FrameArea ();
            rcGap = Auxi_Geometry .CurvedFrameGapArea (rcFrame, visParams .TitleAlignmentCoef, sizeTitle, visParams .TitleSideSpace);
            Rectangle rc = Rectangle .FromLTRB (rcFrame .Left - 3, rcFrame .Top - 3, rcFrame .Right + 3, rcFrame .Bottom + 3);
            CoverNode [] nodes = new CoverNode [] { new CoverNode (0, rcGap, Cursors .SizeWE), 
                                                    new CoverNode (0, rc, Cursors .Hand) };
            cover = new Cover (nodes);
            if (!Movable)
            {
                cover .SetFreedom (MovementFreedom .Freeze);
            }
        }
        // -------------------------------------------------        Move
        public override void Move (int dx, int dy)
        {
            rcFrame .X += dx;
            rcFrame .Y += dy;
            rcGap .X += dx;
            rcGap .Y += dy;
            groupList .Move (dx, dy);
            groupData .Move (dx, dy);
        }
        // -------------------------------------------------        MoveNode
        public override bool MoveNode (int i, int dx, int dy, Point ptM, MouseButtons mb)
        {
            bool bRet = false;
            if (mb == MouseButtons .Left)
            {
                switch (i)
                {
                    case 0:
                        int cx_0 = rcFrame .Left + 8;
                        int cx_1 = rcFrame .Right - (rcGap .Width + 8);
                        int cxNew = rcGap .X + dx;
                        if (cx_0 <= cxNew && cxNew <= cx_1)
                        {
                            visParams .TitleAlignmentCoef = (cxNew - cx_0) / (double) (cx_1 - cx_0);
                            bRet = true;
                        }
                        break;
                    case 1:
                        Move (dx, dy);
                        bRet = true;
                        break;
                }
            }
            return (bRet);
        }

        // -------------------------------------------------        IntoRegistry
        public void IntoRegistry (RegistryKey regkey, string name)
        {
            try
            {
                groupList .IntoRegistry (regkey, name + "_grList");
                groupData .IntoRegistry (regkey, name + "_grData");
                visParams .IntoRegistry (regkey, name + "_VisParamAB");

                regkey .SetValue (name, new string [] { version .ToString (),           // 0
                                                        id .ToString (),                // 1

                                                        title,                          // 2 
                                                        idParent .ToString (),          // 3
                                                        visible .ToString (),       // 4
                                                     },
                                         RegistryValueKind .MultiString);
            }
            catch
            {
            }
            finally
            {
            }
        }
        // -------------------------------------------------        FromRegistry
        public static GroupABArrays FromRegistry (Form form, RegistryKey regkey, string name,
                                                  Control [] ctrlsStandard, Control [] ctrlsSpecial)
        {
            try
            {
                ElasticGroup grpStandard = ElasticGroup .FromRegistry (form, regkey, name + "_grList", ctrlsStandard);
                GroupEditABArray grpSpecial = GroupEditABArray .FromRegistry (form, regkey, name + "_grData", ctrlsSpecial);
                GroupVisibleParameters vispars = GroupVisibleParameters .FromRegistry (regkey, name + "_VisParamAB");

                GroupABArrays grp = null;
                string [] strs = (string []) regkey .GetValue (name);
                if (strs != null &&
                    strs .Length == 5 &&
                    Convert .ToInt32 (strs [0]) == 606 &&
                    grpStandard != null &&
                    grpSpecial != null &&
                    vispars != null)
                {
                    grp = new GroupABArrays (form, grpStandard, grpSpecial, strs [2]);  // , vispars
                    if (grp != null)
                    {
                        grp .ID = Convert .ToInt64 (strs [1]);
                        grp .ParentID = Convert .ToInt64 (strs [3]);
                        grp .Visible = Convert .ToBoolean (strs [4]);
                        grp .GroupVisibleParameters = vispars;
                    }
                }
                return (grp);
            }
            catch
            {
                return (null);
            }
            finally
            {

            }
        }

    }
}

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)

Share

About the Author

SergeyAndreyev

United States United States
No Biography provided

| Advertise | Privacy | Mobile
Web02 | 2.8.140926.1 | Last Updated 10 Apr 2010
Article Copyright 2010 by SergeyAndreyev
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid