Changeset 4068 for trunk/sources/HeuristicLab.ExtLibs/HeuristicLab.Netron/3.0.2672.12446/Netron.Diagramming.Core-3.0.2672.12446/Tools/ConnectorMoverTool.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/ConnectorMoverTool.cs
r2868 r4068 1 1 using System; 2 using System.Diagnostics;3 using System.Collections;4 2 using System.Drawing; 5 3 using System.Windows.Forms; 6 4 7 namespace Netron.Diagramming.Core 8 { 5 namespace Netron.Diagramming.Core { 6 /// <summary> 7 /// This tool implement the action of moving shape connectors on the canvas. 8 /// </summary> 9 class ConnectorMoverTool : AbstractTool, IMouseListener { 10 11 #region Fields 9 12 /// <summary> 10 /// This tool implement the action of moving shape connectors on the canvas.13 /// the location of the mouse when the motion starts 11 14 /// </summary> 12 class ConnectorMoverTool : AbstractTool, IMouseListener 13 { 15 private Point initialPoint; 16 /// <summary> 17 /// the intermediate location of the mouse during the motion 18 /// </summary> 19 private Point lastPoint; 20 /// <summary> 21 /// the connector being moved 22 /// </summary> 23 private IConnector fetchedConnector; 24 /// <summary> 25 /// whether we are currently moving something 26 /// </summary> 27 private bool motionStarted; 14 28 15 #region Fields 16 /// <summary> 17 /// the location of the mouse when the motion starts 18 /// </summary> 19 private Point initialPoint; 20 /// <summary> 21 /// the intermediate location of the mouse during the motion 22 /// </summary> 23 private Point lastPoint; 24 /// <summary> 25 /// the connector being moved 26 /// </summary> 27 private IConnector fetchedConnector; 28 /// <summary> 29 /// whether we are currently moving something 30 /// </summary> 31 private bool motionStarted; 29 #endregion 32 30 33 #endregion 31 #region Constructor 32 /// <summary> 33 /// Initializes a new instance of the <see cref="T:ConnectorMoverTool"/> class. 34 /// </summary> 35 /// <param name="name">The name of the tool.</param> 36 public ConnectorMoverTool(string name) 37 : base(name) { 38 } 39 #endregion 34 40 35 #region Constructor 36 /// <summary> 37 /// Initializes a new instance of the <see cref="T:ConnectorMoverTool"/> class. 38 /// </summary> 39 /// <param name="name">The name of the tool.</param> 40 public ConnectorMoverTool(string name) : base(name) 41 { 42 } 43 #endregion 41 #region Methods 44 42 45 #region Methods 46 47 /// <summary> 48 /// Called when the tool is activated. 49 /// </summary> 50 protected override void OnActivateTool() 51 { 52 Controller.View.CurrentCursor = CursorPalette.Select; 53 motionStarted = false; 54 fetchedConnector = null; 55 } 56 57 /// <summary> 58 /// Handles the mouse down event 59 /// </summary> 60 /// <param name="e">The <see cref="T:System.Windows.Forms.MouseEventArgs"/> instance containing the event data.</param> 61 public bool MouseDown(MouseEventArgs e) 62 { 63 if (e == null) 64 throw new ArgumentNullException("The argument object is 'null'"); 65 if (e.Button == MouseButtons.Left && Enabled && !IsSuspended) 66 { 67 fetchedConnector =this.Controller.Model.Selection.FindShapeConnector(e.Location); 68 if(fetchedConnector != null) 69 { 70 71 initialPoint = e.Location; 72 lastPoint = initialPoint; 73 motionStarted = true; 74 return true; 75 } 76 } 77 return false; 78 } 79 80 /// <summary> 81 /// Handles the mouse move event 82 /// </summary> 83 /// <param name="e">The <see cref="T:System.Windows.Forms.MouseEventArgs"/> instance containing the event data.</param> 84 public void MouseMove(MouseEventArgs e) 85 { 86 if (e == null) 87 throw new ArgumentNullException("The argument object is 'null'"); 88 Point point = e.Location; 89 if(IsActive && motionStarted) 90 { 91 92 fetchedConnector.MoveBy(new Point(point.X - lastPoint.X, point.Y - lastPoint.Y)); 93 94 lastPoint = point; 95 } 96 } 97 /// <summary> 98 /// Handles the mouse up event 99 /// </summary> 100 /// <param name="e">The <see cref="T:System.Windows.Forms.MouseEventArgs"/> instance containing the event data.</param> 101 public void MouseUp(MouseEventArgs e) 102 { 103 if (IsActive) 104 { 105 DeactivateTool(); 106 if(fetchedConnector == null) 107 return; 108 Bundle bundle = new Bundle(Controller.Model); 109 bundle.Entities.Add(fetchedConnector); 110 MoveCommand cmd = new MoveCommand(this.Controller, bundle, new Point(lastPoint.X - initialPoint.X, lastPoint.Y - initialPoint.Y)); 111 Controller.UndoManager.AddUndoCommand(cmd); 112 //not necessary to perform the Redo action of the command since the mouse-move already moved the bundle! 113 } 114 } 115 #endregion 43 /// <summary> 44 /// Called when the tool is activated. 45 /// </summary> 46 protected override void OnActivateTool() { 47 Controller.View.CurrentCursor = CursorPalette.Select; 48 motionStarted = false; 49 fetchedConnector = null; 116 50 } 117 51 52 /// <summary> 53 /// Handles the mouse down event 54 /// </summary> 55 /// <param name="e">The <see cref="T:System.Windows.Forms.MouseEventArgs"/> instance containing the event data.</param> 56 public bool MouseDown(MouseEventArgs e) { 57 if (e == null) 58 throw new ArgumentNullException("The argument object is 'null'"); 59 if (e.Button == MouseButtons.Left && Enabled && !IsSuspended) { 60 fetchedConnector = this.Controller.Model.Selection.FindShapeConnector(e.Location); 61 if (fetchedConnector != null) { 62 63 initialPoint = e.Location; 64 lastPoint = initialPoint; 65 motionStarted = true; 66 return true; 67 } 68 } 69 return false; 70 } 71 72 /// <summary> 73 /// Handles the mouse move event 74 /// </summary> 75 /// <param name="e">The <see cref="T:System.Windows.Forms.MouseEventArgs"/> instance containing the event data.</param> 76 public void MouseMove(MouseEventArgs e) { 77 if (e == null) 78 throw new ArgumentNullException("The argument object is 'null'"); 79 Point point = e.Location; 80 if (IsActive && motionStarted) { 81 82 fetchedConnector.MoveBy(new Point(point.X - lastPoint.X, point.Y - lastPoint.Y)); 83 84 lastPoint = point; 85 } 86 } 87 /// <summary> 88 /// Handles the mouse up event 89 /// </summary> 90 /// <param name="e">The <see cref="T:System.Windows.Forms.MouseEventArgs"/> instance containing the event data.</param> 91 public void MouseUp(MouseEventArgs e) { 92 if (IsActive) { 93 DeactivateTool(); 94 if (fetchedConnector == null) 95 return; 96 Bundle bundle = new Bundle(Controller.Model); 97 bundle.Entities.Add(fetchedConnector); 98 MoveCommand cmd = new MoveCommand(this.Controller, bundle, new Point(lastPoint.X - initialPoint.X, lastPoint.Y - initialPoint.Y)); 99 Controller.UndoManager.AddUndoCommand(cmd); 100 //not necessary to perform the Redo action of the command since the mouse-move already moved the bundle! 101 } 102 } 103 #endregion 104 } 105 118 106 }
Note: See TracChangeset
for help on using the changeset viewer.