Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2389-EpsLexicase/HeuristicLab.ExtLibs/HeuristicLab.Netron/3.0.2672.12446/Netron.Diagramming.Core-3.0.2672.12446/Tools/AlignTool.cs

Last change on this file was 4068, checked in by swagner, 14 years ago

Sorted usings and removed unused usings in entire solution (#1094)

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