Free cookie consent management tool by TermsFeed Policy Generator

source: stable/HeuristicLab.ExtLibs/HeuristicLab.Netron/3.0.2672.12446/Netron.Diagramming.Core-3.0.2672.12446/Tools/AlignmentToolBase.cs @ 17958

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

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

File size: 3.2 KB
Line 
1using System.Drawing;
2using System.Windows.Forms;
3
4namespace Netron.Diagramming.Core {
5  public abstract class AlignmentToolBase : AbstractTool {
6    protected IDiagramEntity firstEntity;
7    protected int xLocationOfFirstEntity;
8    protected int yLocationOfFirstEntity;
9    protected int topEdgeOfFirstEntity;
10    protected int bottomEdgeOfFirstEntity;
11    protected Point centerOfFirstEntity;
12    protected int rightEdgeOfFirstEntity;
13
14    // ------------------------------------------------------------------
15    /// <summary>
16    /// Constructor.
17    /// </summary>
18    /// <param name="toolName">string: The name of this tool</param>
19    // ------------------------------------------------------------------
20    public AlignmentToolBase(string toolName)
21      : base(toolName) {
22    }
23
24    // ------------------------------------------------------------------
25    /// <summary>
26    /// Activates the tool.  First a check is performed to ensure there
27    /// are at least two IDiagramEntities selected.  If so, then the
28    /// x, y, top edge, bottom edge, and center of the first entity
29    /// is stored in local, protected variables for all other alignment
30    /// tools to use.
31    /// </summary>
32    // ------------------------------------------------------------------
33    protected override void OnActivateTool() {
34      base.OnActivateTool();
35
36      // Make sure enough items were selected.
37      if (this.Controller.Model.Selection.SelectedItems == null) {
38        MessageBox.Show(
39            "Nothing is selected, you need to select at " +
40            "least two items to align.",
41            "Nothing selected.",
42            MessageBoxButtons.OK,
43            MessageBoxIcon.Hand);
44
45        return;
46      }
47
48      if (this.Controller.Model.Selection.SelectedItems.Count <= 1) {
49        MessageBox.Show(
50            "You need to select at least two items to align.",
51            "Nothing selected.",
52            MessageBoxButtons.OK,
53            MessageBoxIcon.Hand);
54
55        return;
56      }
57
58      // Since there are enough items, peform the alignment.  But
59      // first get all aspects about the location of the first
60      // entity.
61      this.firstEntity = this.Controller.Model.Selection.SelectedItems[0];
62      this.xLocationOfFirstEntity = firstEntity.Rectangle.X;
63      this.yLocationOfFirstEntity = firstEntity.Rectangle.Y;
64      this.topEdgeOfFirstEntity = firstEntity.Rectangle.Top;
65      this.bottomEdgeOfFirstEntity = firstEntity.Rectangle.Bottom;
66      this.rightEdgeOfFirstEntity = firstEntity.Rectangle.Right;
67      this.centerOfFirstEntity = firstEntity.Center;
68
69      this.Align(this.Controller.Model.Selection.SelectedItems.ToArray());
70
71      // Reset the Tracker.
72      this.Controller.View.ShowTracker();
73      DeactivateTool();
74    }
75
76    // ------------------------------------------------------------------
77    /// <summary>
78    /// Abstract method to be implemented by all alignment tools.
79    /// </summary>
80    /// <param name="entities">IDiagramEntity[]: All selected
81    /// entities.</param>
82    // ------------------------------------------------------------------
83    public abstract void Align(IDiagramEntity[] entities);
84  }
85}
Note: See TracBrowser for help on using the repository browser.