Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.ExtLibs/HeuristicLab.Netron/3.0.2672.12446/Netron.Diagramming.Core-3.0.2672.12446/Tools/AlignTool.cs @ 2861

Last change on this file since 2861 was 2768, checked in by mkommend, 15 years ago

added solution folders and sources for the netron library (ticket #867)

File size: 3.3 KB
Line 
1using System;
2using System.Diagnostics;
3using System.Collections;
4using System.Drawing;
5using System.Windows.Forms;
6
7namespace Netron.Diagramming.Core
8{
9    // ----------------------------------------------------------------------
10    /// <summary>
11    /// Tool to align shapes in various ways
12    /// </summary>
13    // ----------------------------------------------------------------------
14    public class AlignTool : AbstractTool
15    {
16
17        #region Fields
18
19        // ------------------------------------------------------------------
20        /// <summary>
21        /// The type of alignment to apply.
22        /// </summary>
23        // ------------------------------------------------------------------
24        private ShapeAlignment mAlignment;
25
26        // ------------------------------------------------------------------
27        /// <summary>
28        /// Gets or sets the type of alignment to apply.
29        /// </summary>
30        // ------------------------------------------------------------------
31        public ShapeAlignment Alignment
32        {
33            get { return mAlignment; }
34            set { mAlignment = value; }
35        }
36
37 
38        #endregion
39
40        #region Constructor
41
42        // ------------------------------------------------------------------
43        /// <summary>
44        /// Initializes a new instance of the <see cref="T:AlignTool"/> class.
45        /// </summary>
46        /// <param name="name">The name of the tool.</param>
47        // ------------------------------------------------------------------
48        public AlignTool(string name) : base(name)
49        {
50        }
51        #endregion
52
53        #region Methods
54
55        /// <summary>
56        /// Called when the tool is activated.
57        /// </summary>
58        protected override void OnActivateTool()
59        {
60            bool valid = true;
61           
62            #region Validation of the selection
63           
64            //make sure we have the correct stuff on the table
65            if (Selection.SelectedItems==null || Selection.SelectedItems.Count ==0)
66            {
67                MessageBox.Show("Nothing is selected, you need to select an existing group.", "Nothing selected.", MessageBoxButtons.OK, MessageBoxIcon.Hand);
68                valid = false;               
69            }
70            else if (Selection.SelectedItems.Count != 1)
71            {
72                MessageBox.Show("Multiple items are selected, select only one group.", "Multiple items", MessageBoxButtons.OK, MessageBoxIcon.Hand);
73                valid = false;
74            }
75            else if (!(Selection.SelectedItems[0] is IGroup))
76            {
77                MessageBox.Show("The selected item is not a group.", "Not a group.", MessageBoxButtons.OK, MessageBoxIcon.Hand);
78                valid = false;
79            }
80            #endregion
81
82            if (valid)
83            {
84                UngroupCommand cmd = new UngroupCommand(
85                    this.Controller,
86                    Selection.SelectedItems[0] as IGroup);
87
88                this.Controller.UndoManager.AddUndoCommand(cmd);
89                cmd.Redo();
90            }
91             DeactivateTool();
92             return;
93        }
94
95     
96        #endregion
97
98     
99    }
100
101}
Note: See TracBrowser for help on using the repository browser.