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