Changeset 4068 for trunk/sources/HeuristicLab.ExtLibs/HeuristicLab.Netron/3.0.2672.12446/Netron.Diagramming.Core-3.0.2672.12446/Tools/AlignmentToolBase.cs
- Timestamp:
- 07/22/10 00:44:01 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.ExtLibs/HeuristicLab.Netron/3.0.2672.12446/Netron.Diagramming.Core-3.0.2672.12446/Tools/AlignmentToolBase.cs
r2868 r4068 1 using System; 2 using System.Collections.Generic; 3 using System.Text; 1 using System.Drawing; 4 2 using System.Windows.Forms; 5 using System.Drawing;6 3 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; 4 namespace 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; 18 13 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 } 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 } 29 23 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(); 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(); 42 35 43 // Make sure enough items were selected. 44 if (this.Controller.Model.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); 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); 52 44 53 54 45 return; 46 } 55 47 56 if (this.Controller.Model.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); 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); 63 54 64 65 55 return; 56 } 66 57 67 68 69 70 71 72 73 74 75 76 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; 77 68 78 69 this.Align(this.Controller.Model.Selection.SelectedItems.ToArray()); 79 70 80 81 82 83 71 // Reset the Tracker. 72 this.Controller.View.ShowTracker(); 73 DeactivateTool(); 74 } 84 75 85 86 87 88 89 90 91 92 93 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 } 94 85 }
Note: See TracChangeset
for help on using the changeset viewer.