Click here to Skip to main content
15,886,840 members
Articles / Desktop Programming / WPF

The Time Machine

Rate me:
Please Sign up or sign in to vote.
4.91/5 (13 votes)
9 May 2012CPOL6 min read 34.1K   1.2K   32  
Long time strategy of software design and development
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Windows.Forms;
using System.Reflection;

using ResourceService;
using CommonService;
using DiagramUI.Utils;
using DiagramUI.Interfaces;
using Diagram.UI.Interfaces;


namespace DiagramUI
{
    /// <summary>
    /// Wrapper of button
    /// </summary>
    public class ButtonWrapper
    {
        #region Fields

        private Type type;

        private string stringKind;

        private string toolTipText;

        private Image buttonImage;

        private bool isVisible;

        private bool isArrow;

        private IUIFactory factory;

        #endregion

        #region Ctor

        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="type">Type</param>
        /// <param name="kind">Kind</param>
        /// <param name="toolTipText">ToolTip</param>
        /// <param name="factory">Factory</param>
        /// <param name="buttonImage">Image</param>
        /// <param name="isVisible">The "is visible" sign</param>
        /// <param name="isArrow">The "is arrow" sign</param>
        public ButtonWrapper(Type type, string kind, string toolTipText, Image buttonImage, IUIFactory factory, bool isVisible, bool isArrow)
        {
            this.type = type;
            this.stringKind = kind;
            this.toolTipText = toolTipText;
            this.buttonImage = buttonImage;
            this.factory = factory;
            this.isVisible = isVisible;
            this.isArrow = isArrow;
        }

        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="type">Type</param>
        /// <param name="kind">Kind</param>
        /// <param name="toolTipText">ToolTip</param>
        /// <param name="factory">Factory</param>
        /// <param name="icon">Icon</param>
        /// <param name="isVisible">The "is visible" sign</param>
        /// <param name="isArrow">The "is arrow" sign</param>
        public ButtonWrapper(Type type, string kind, string toolTipText, Icon icon, IUIFactory factory, bool isVisible, bool isArrow) :
            this(type, kind, toolTipText, icon.ToBitmap(), factory, isVisible, isArrow)
        {
        }


        #endregion

        #region Methods

        /// <summary>
        /// Creates toolbar
        /// </summary>
        /// <param name="buttons">Buttons</param>
        /// <param name="tools">Tools</param>
        /// <param name="size">Size</param>
        /// <param name="translate">The "translate" sign</param>
        /// <param name="resources">Resources</param>
        /// <returns>Toolbar</returns>
        public static PaletteToolBar CreateToolBar(IList<ButtonWrapper> buttons, ToolsDiagram tools, Size size, bool translate,
            Dictionary<string, object>[] resources)
        {
            ImageList imageList = new ImageList();
            imageList.ImageSize = size;
            foreach (ButtonWrapper bw in buttons)
            {
                imageList.Images.Add(bw.buttonImage);
            }
            PaletteToolBar toolbar = new PaletteToolBar(tools);
            toolbar.ImageList = imageList;
            for (int i = 0; i < buttons.Count; i++)
            {
                ButtonWrapper b = buttons[i];
                string tt = b.toolTipText;
                if (translate)
                {

                    tt = Resources.GetControlResource(tt, resources);
                }
                PaletteButton pb = new PaletteButton(toolbar, b.type, b.stringKind, tt, b.buttonImage, i, b.isArrow);
                if (!b.isVisible)
                {
                    pb.Visible = false;
                }
            }
            return toolbar;
        }


        /// <summary>
        /// Creates toolbar
        /// </summary>
        /// <param name="buttons">Buttons</param>
        /// <param name="tools">Tools</param>
        /// <param name="size">Size</param>
        /// <param name="resources">Resources</param>
        /// <param name="translate">The "translate" sign</param>
        /// <returns>Toolbar</returns>
        public static PaletteToolBar CreateToolBar(ButtonWrapper[] buttons, ToolsDiagram tools, Size size,
            Dictionary<string, object>[] resources, bool translate)
        {
            List<ButtonWrapper> l = new List<ButtonWrapper>(buttons);
            return CreateToolBar(l, tools, size, translate, resources);
        }

        /// <summary>
        /// Adds buttons to Tab control
        /// </summary>
        /// <param name="tab">The tab</param>
        /// <param name="buttons">Buttons</param>
        /// <param name="tools">Tools</param>
        /// <param name="size">Size</param>
        /// <param name="resources">Resources</param>
        /// <param name="translate">The "translate" sign</param>
        public static void Add(LightDictionary<string, ButtonWrapper[]> buttons, TabControl tab, 
            ToolsDiagram tools, Size size, Dictionary<string, object>[] resources, bool translate)
        {
            IList<string> keys = buttons.Keys;
            foreach (string key in keys)
            {
                Add(key, buttons[key], tab, tools, size, resources, translate);
            }
        }

        /// <summary>
        /// Adds buttons
        /// </summary>
        /// <param name="keys">Keys</param>
        /// <param name="buttons">Buttons</param>
        /// <param name="tab">Tab control</param>
        /// <param name="tools">Tools</param>
        /// <param name="size">Size</param>
        /// <param name="resources">Resources</param>
        /// <param name="translate">Translate sign</param>
        public static void Add(string[] keys, ButtonWrapper[][] buttons, TabControl tab, ToolsDiagram tools, Size size,
            Dictionary<string, object>[] resources, bool translate)
        {
            LightDictionary<string, ButtonWrapper[]> d = new LightDictionary<string, ButtonWrapper[]>();
            d.Add(keys, buttons);
            Add(d, tab, tools, size, resources, translate);
        }

        /// <summary>
        /// Creates dictionary of images
        /// </summary>
        /// <param name="buttons"></param>
        /// <returns></returns>
        public static Dictionary<Type, Image> CreateImageDictionary(ICollection<ButtonWrapper> buttons)
        {
            Dictionary<Type, Image> dic = new Dictionary<Type, Image>();
            foreach (ButtonWrapper bw in buttons)
            {
                dic[bw.type] = bw.buttonImage;
            }
            return dic;
        }

 

        static private void Add(string key, ButtonWrapper[] buttons, TabControl tab, ToolsDiagram tools, Size size, 
            Dictionary<string, object>[] resources, bool translate)
        {
                TabPage tp = new TabPage();
                string tt = key + "";
                if (translate)
                {
                    tt = Resources.GetControlResource(tt, resources);
                }
                tp.Text = tt;
                PaletteToolBar toolbar = CreateToolBar(buttons, tools, size, resources, translate);
                tp.Controls.Add(toolbar);
                tab.Controls.Add(tp);
        }


    /*    static void Add(TabControl tab, LightDictionary<string, ButtonWrapper> buttons,
            ToolsDiagram tools, Size size, bool translate)
        {
        }*/
       /* public static void Add(TabControl tab, string[] keys, ButtonWrapper[] buttons, ToolsDiagram tools, Size size, bool translate)
        {
            LightDictionary<string
            List<string> lk = new List<string>(keys);
            List<ButtonWrapper> lb = new List<ButtonWrapper>(buttons);
            Add(tab, lk, lb, tools, size, translate);
        }*/


        #endregion
    }
}

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