Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
07/22/10 00:44:01 (14 years ago)
Author:
swagner
Message:

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

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/ScribbleTool.cs

    r2768 r4068  
    11using System;
    2 using System.Diagnostics;
    3 using System.Collections;
    4 using System.Collections.Generic;
    52using System.Drawing;
    63using System.Windows.Forms;
    74
    8 namespace Netron.Diagramming.Core
    9 {
     5namespace Netron.Diagramming.Core {
    106
    11     class ScribbleTool : AbstractTool, IMouseListener, IKeyboardListener
    12     {
     7  class ScribbleTool : AbstractTool, IMouseListener, IKeyboardListener {
    138
    14         #region Fields
    15         /// <summary>
    16         /// the location of the mouse when the motion starts
    17         /// </summary>
     9    #region Fields
     10    /// <summary>
     11    /// the location of the mouse when the motion starts
     12    /// </summary>
    1813
    19         private bool doDraw;
    20         private Point[] points;
    21         #endregion
    22         #region Constructor
    23         /// <summary>
    24         /// Initializes a new instance of the <see cref="T:ScribbleTool"/> class.
    25         /// </summary>
    26         /// <param name="name">The name of the tool.</param>
    27         public ScribbleTool(string name)
    28             : base(name)
    29         {
     14    private bool doDraw;
     15    private Point[] points;
     16    #endregion
     17    #region Constructor
     18    /// <summary>
     19    /// Initializes a new instance of the <see cref="T:ScribbleTool"/> class.
     20    /// </summary>
     21    /// <param name="name">The name of the tool.</param>
     22    public ScribbleTool(string name)
     23      : base(name) {
     24    }
     25    #endregion
     26
     27    #region Methods
     28
     29    /// <summary>
     30    /// Called when the tool is activated.
     31    /// </summary>
     32    protected override void OnActivateTool() {
     33      Controller.View.CurrentCursor = CursorPalette.Cross;
     34      this.SuspendOtherTools();
     35      doDraw = false;
     36      points = new Point[1];
     37    }
     38
     39    /// <summary>
     40    /// Handles the mouse down event
     41    /// </summary>
     42    /// <param name="e">The <see cref="T:System.Windows.Forms.MouseEventArgs"/> instance containing the event data.</param>
     43    /// <returns>Returns 'true' if the event was handled, otherwise 'false'.</returns>
     44    public bool MouseDown(MouseEventArgs e) {
     45      if (e == null)
     46        throw new ArgumentNullException("The argument object is 'null'");
     47      if (e.Button == MouseButtons.Left && Enabled && !IsSuspended) {
     48        Point p = e.Location;
     49        if (Closure(p)) {
     50          points[points.Length - 1] = points[0];
     51          doDraw = false;
     52          DeactivateTool();
     53          Package();
     54
     55          return true;
    3056        }
    31         #endregion
     57        Array.Resize<Point>(ref points, points.Length + 1);
     58        points[points.Length - 2] = e.Location;
     59        doDraw = true;
     60        return true;
     61      }
     62      return false;
     63    }
    3264
    33         #region Methods
     65    /// <summary>
     66    /// Handles the mouse move event
     67    /// </summary>
     68    /// <param name="e">The <see cref="T:System.Windows.Forms.MouseEventArgs"/> instance containing the event data.</param>
     69    public void MouseMove(MouseEventArgs e) {
     70      if (e == null)
     71        throw new ArgumentNullException("The argument object is 'null'");
     72      Point point = e.Location;
     73      if (IsActive && doDraw) {
     74        points[points.Length - 1] = e.Location;
     75        Controller.View.PaintGhostLine(MultiPointType.Curve, points);
     76        //Controller.View.Invalidate(System.Drawing.Rectangle.Inflate(Controller.View.Ghost.Rectangle, 20, 20));
     77        //TODO: find a more performant way to invalidate the area
     78        Controller.View.Invalidate();
     79      }
     80    }
     81    private bool Closure(Point p) {
     82      for (int k = 0; k < points.Length - 1; k++) {
     83        if (new Rectangle(points[k].X - 6, points[k].Y - 6, 12, 12).Contains(p)) {
     84          DialogResult res = MessageBox.Show("Do you wish to close the curve?", "Closure?", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
     85          if (res == DialogResult.Yes)
     86            return true;
    3487
    35         /// <summary>
    36         /// Called when the tool is activated.
    37         /// </summary>
    38         protected override void OnActivateTool()
    39         {
    40             Controller.View.CurrentCursor = CursorPalette.Cross;
    41             this.SuspendOtherTools();
    42             doDraw = false;
    43             points = new Point[1];
    4488        }
     89      }
     90      return false;
     91    }
     92    /// <summary>
     93    ///
     94    /// </summary>
     95    /// <param name="e">The <see cref="T:System.Windows.Forms.MouseEventArgs"/> instance containing the event data.</param>
     96    public void MouseUp(MouseEventArgs e) {
     97      if (IsActive) {
    4598
    46         /// <summary>
    47         /// Handles the mouse down event
    48         /// </summary>
    49         /// <param name="e">The <see cref="T:System.Windows.Forms.MouseEventArgs"/> instance containing the event data.</param>
    50         /// <returns>Returns 'true' if the event was handled, otherwise 'false'.</returns>
    51         public bool MouseDown(MouseEventArgs e)
    52         {
    53             if (e == null)
    54                 throw new ArgumentNullException("The argument object is 'null'");
    55             if (e.Button == MouseButtons.Left && Enabled && !IsSuspended)
    56             {
    57                 Point p = e.Location;
    58                 if (Closure(p))
    59                 {
    60                     points[points.Length - 1] = points[0];
    61                     doDraw = false;
    62                     DeactivateTool();
    63                     Package();
     99      }
     100    }
     101    private void Package() {
     102      if ((points == null) ||
     103         (points.Length < 1) ||
     104         (points[0] == Point.Empty)) {
     105        return;
     106      }
    64107
    65                     return true;
    66                 }
    67                 Array.Resize<Point>(ref points, points.Length + 1);
    68                 points[points.Length - 2] = e.Location;
    69                 doDraw = true;
    70                 return true;
    71             }
    72             return false;
    73         }
     108      MultiPointShape shape = new MultiPointShape(
     109          this.Controller.Model,
     110          points,
     111          MultiPointType.Curve);
    74112
    75         /// <summary>
    76         /// Handles the mouse move event
    77         /// </summary>
    78         /// <param name="e">The <see cref="T:System.Windows.Forms.MouseEventArgs"/> instance containing the event data.</param>
    79         public void MouseMove(MouseEventArgs e)
    80         {
    81             if (e == null)
    82                 throw new ArgumentNullException("The argument object is 'null'");
    83             Point point = e.Location;
    84             if (IsActive && doDraw)
    85             {
    86                 points[points.Length - 1] = e.Location;
    87                 Controller.View.PaintGhostLine(MultiPointType.Curve, points);
    88                 //Controller.View.Invalidate(System.Drawing.Rectangle.Inflate(Controller.View.Ghost.Rectangle, 20, 20));
    89                 //TODO: find a more performant way to invalidate the area
    90                 Controller.View.Invalidate();
    91             }
    92         }
    93         private bool Closure(Point p)
    94         {
    95             for (int k = 0; k < points.Length - 1; k++)
    96             {
    97                 if (new Rectangle(points[k].X - 6, points[k].Y - 6, 12, 12).Contains(p))
    98                 {
    99                     DialogResult res = MessageBox.Show("Do you wish to close the curve?", "Closure?", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
    100                     if (res == DialogResult.Yes)
    101                         return true;
     113      AddMultiPointShapeCommand cmd = new AddMultiPointShapeCommand(this.Controller, shape);
     114      this.Controller.UndoManager.AddUndoCommand(cmd);
     115      this.Controller.View.ResetGhost();
     116      cmd.Redo();
     117    }
     118    #endregion
    102119
    103                 }
    104             }
    105             return false;
    106         }
    107         /// <summary>
    108         ///
    109         /// </summary>
    110         /// <param name="e">The <see cref="T:System.Windows.Forms.MouseEventArgs"/> instance containing the event data.</param>
    111         public void MouseUp(MouseEventArgs e)
    112         {
    113             if (IsActive)
    114             {
     120    #region IKeyboardListener Members
    115121
    116             }
    117         }
    118         private void Package()
    119         {
    120             if ((points == null) ||
    121                (points.Length < 1) ||
    122                (points[0] == Point.Empty) )
    123             {
    124                 return;
    125             }
    126 
    127             MultiPointShape shape = new MultiPointShape(
    128                 this.Controller.Model,
    129                 points,
    130                 MultiPointType.Curve);
    131 
    132             AddMultiPointShapeCommand cmd = new AddMultiPointShapeCommand(this.Controller, shape);
    133             this.Controller.UndoManager.AddUndoCommand(cmd);
    134             this.Controller.View.ResetGhost();
    135             cmd.Redo();
    136         }
    137         #endregion
    138 
    139         #region IKeyboardListener Members
    140 
    141         public void KeyDown(KeyEventArgs e)
    142         {
     122    public void KeyDown(KeyEventArgs e) {
    143123
    144124
    145             if (e.KeyData == System.Windows.Forms.Keys.Escape && IsActive)
    146             {
    147                 DeactivateTool();
    148                 Package();
    149                 e.Handled = true;
    150             }
    151         }
    152 
    153         public void KeyUp(KeyEventArgs e)
    154         {
    155         }
    156 
    157         public void KeyPress(KeyPressEventArgs e)
    158         {
    159         }
    160 
    161         #endregion
     125      if (e.KeyData == System.Windows.Forms.Keys.Escape && IsActive) {
     126        DeactivateTool();
     127        Package();
     128        e.Handled = true;
     129      }
    162130    }
    163131
     132    public void KeyUp(KeyEventArgs e) {
     133    }
     134
     135    public void KeyPress(KeyPressEventArgs e) {
     136    }
     137
     138    #endregion
     139  }
     140
    164141}
Note: See TracChangeset for help on using the changeset viewer.