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/BaseClasses/AbstractTool.cs

    r2768 r4068  
    11using System;
    2 using System.Collections.Generic;
    3 using System.Text;
    42using System.Windows.Forms;
    5 using System.Diagnostics;
    6 namespace Netron.Diagramming.Core
    7 {
    8     // ----------------------------------------------------------------------
    9     /// <summary>
    10     /// The base class for any tool <see cref="ITool"/>.
    11     /// </summary>
    12     // ----------------------------------------------------------------------
    13     public abstract class AbstractTool : ITool
    14     {
    15         #region Events
    16 
    17         // ------------------------------------------------------------------
    18         /// <summary>
    19         /// Occurs when this tool is deactivated.
    20         /// </summary>
    21         // ------------------------------------------------------------------
    22         public event EventHandler<ToolEventArgs> OnToolDeactivate;
    23 
    24         // ------------------------------------------------------------------
    25         /// <summary>
    26         /// Occurs when this tool is activated.
    27         /// </summary>
    28         // ------------------------------------------------------------------
    29         public event EventHandler<ToolEventArgs> OnToolActivate;
    30 
    31         #endregion
    32 
    33         #region Fields
    34         /// <summary>
    35         /// the Name field
    36         /// </summary>
    37         private string mName;
    38         /// <summary>
    39         /// the Enabled field
    40         /// </summary>
    41         private bool mEnabled = true;
    42         /// <summary>
    43         /// a pointer to the controller
    44         /// </summary>
    45         private IController mController;
    46         /// <summary>
    47         /// the tool's cursor
    48         /// </summary>
    49         private Cursor mCursor = Cursors.Default;
    50         /// <summary>
    51         /// whether the tool is currently active
    52         /// </summary>
    53         private bool mIsActive;
    54         /// <summary>
    55         /// keeps a reference to the previous cursor
    56         /// </summary>
    57         Cursor previousCursor ;
    58         /// <summary>
    59         /// the suspend state of the tool
    60         /// </summary>
    61         private bool mIsSuspended;
    62         #endregion
    63 
    64         #region Properties
    65 
    66         /// <summary>
    67         /// Gets or sets a value indicating whether this instance is suspended. A tool enters in a suspended mode when another tool has been activated and disallows another to continue its normal activity. For example, the <see cref="MoveTool"/> and <see cref="SelectionTool"/> are
    68         /// mutually exclusive and similarly for the drawing tools and the selection tool.
    69         /// <para>This suspended state is independent of the <see cref="IsActive"/> and the <see cref="Enabled"/> states.</para>
    70         /// </summary>
    71         /// <value>
    72         ///   <c>true</c> if this instance is suspended; otherwise, <c>false</c>.
    73         /// </value>
    74         public bool IsSuspended
    75         {
    76             get { return mIsSuspended; }
    77             set { mIsSuspended = value; }
     3namespace Netron.Diagramming.Core {
     4  // ----------------------------------------------------------------------
     5  /// <summary>
     6  /// The base class for any tool <see cref="ITool"/>.
     7  /// </summary>
     8  // ----------------------------------------------------------------------
     9  public abstract class AbstractTool : ITool {
     10    #region Events
     11
     12    // ------------------------------------------------------------------
     13    /// <summary>
     14    /// Occurs when this tool is deactivated.
     15    /// </summary>
     16    // ------------------------------------------------------------------
     17    public event EventHandler<ToolEventArgs> OnToolDeactivate;
     18
     19    // ------------------------------------------------------------------
     20    /// <summary>
     21    /// Occurs when this tool is activated.
     22    /// </summary>
     23    // ------------------------------------------------------------------
     24    public event EventHandler<ToolEventArgs> OnToolActivate;
     25
     26    #endregion
     27
     28    #region Fields
     29    /// <summary>
     30    /// the Name field
     31    /// </summary>
     32    private string mName;
     33    /// <summary>
     34    /// the Enabled field
     35    /// </summary>
     36    private bool mEnabled = true;
     37    /// <summary>
     38    /// a pointer to the controller
     39    /// </summary>
     40    private IController mController;
     41    /// <summary>
     42    /// the tool's cursor
     43    /// </summary>
     44    private Cursor mCursor = Cursors.Default;
     45    /// <summary>
     46    /// whether the tool is currently active
     47    /// </summary>
     48    private bool mIsActive;
     49    /// <summary>
     50    /// keeps a reference to the previous cursor
     51    /// </summary>
     52    Cursor previousCursor;
     53    /// <summary>
     54    /// the suspend state of the tool
     55    /// </summary>
     56    private bool mIsSuspended;
     57    #endregion
     58
     59    #region Properties
     60
     61    /// <summary>
     62    /// Gets or sets a value indicating whether this instance is suspended. A tool enters in a suspended mode when another tool has been activated and disallows another to continue its normal activity. For example, the <see cref="MoveTool"/> and <see cref="SelectionTool"/> are
     63    /// mutually exclusive and similarly for the drawing tools and the selection tool.
     64    /// <para>This suspended state is independent of the <see cref="IsActive"/> and the <see cref="Enabled"/> states.</para>
     65    /// </summary>
     66    /// <value>
     67    ///   <c>true</c> if this instance is suspended; otherwise, <c>false</c>.
     68    /// </value>
     69    public bool IsSuspended {
     70      get { return mIsSuspended; }
     71      set { mIsSuspended = value; }
     72    }
     73
     74    /// <summary>
     75    /// Gets or sets a value indicating whether this tool is active.
     76    /// </summary>
     77    /// <value><c>true</c> if this instance is active; otherwise, <c>false</c>.</value>
     78    public bool IsActive {
     79      get { return mIsActive; }
     80      set { mIsActive = value; }
     81    }
     82    /// <summary>
     83    /// Gets or sets the name of the tool.
     84    /// </summary>
     85    /// <value>The name.</value>
     86    public string Name {
     87      get { return mName; }
     88      set { mName = value; }
     89    }
     90    /// <summary>
     91    /// Gets or sets the controller.
     92    /// </summary>
     93    /// <value>The controller.</value>
     94    public IController Controller {
     95      get {
     96        return mController;
     97      }
     98
     99      set {
     100        mController = value;
     101      }
     102    }
     103
     104    /// <summary>
     105    /// Gets or sets the cursor.
     106    /// </summary>
     107    /// <value>The cursor.</value>
     108    public Cursor Cursor {
     109      get {
     110        return mCursor;
     111      }
     112      set {
     113        mCursor = value;
     114        //prevCursor = Controller.View.CurrentCursor;
     115        Controller.View.CurrentCursor = value;
     116      }
     117    }
     118
     119    /// <summary>
     120    /// Gets or sets the Enabled
     121    /// </summary>
     122    public bool Enabled {
     123      get {
     124        return this.mEnabled;
     125      }
     126
     127      set {
     128        //disable the tool first if it is active
     129        if (!value && IsActive) {
     130          DeactivateTool();
    78131        }
    79 
    80         /// <summary>
    81         /// Gets or sets a value indicating whether this tool is active.
    82         /// </summary>
    83         /// <value><c>true</c> if this instance is active; otherwise, <c>false</c>.</value>
    84         public bool IsActive
    85         {
    86             get { return mIsActive; }
    87             set { mIsActive = value; }
     132        mEnabled = value;
     133      }
     134    }
     135
     136    /// <summary>
     137    /// Gets a value indicating whether this tool excludes other tools.
     138    /// </summary>
     139    /// <value>
     140    ///   <c>true</c> if this instance is exclusive; otherwise, <c>false</c>.
     141    /// </value>
     142    public virtual bool IsExclusive {
     143      get {
     144        return true;
     145      }
     146    }
     147
     148    /// <summary>
     149    /// Gets or sets a value indicating whether this tool can activated.
     150    /// </summary>
     151    /// <value>
     152    ///   <c>true</c> if this instance can activate; otherwise, <c>false</c>.
     153    /// </value>
     154    public virtual bool CanActivate {
     155      get {
     156        if (mEnabled) {
     157          return !IsActive;
     158        } else {
     159          return false;
    88160        }
    89         /// <summary>
    90         /// Gets or sets the name of the tool.
    91         /// </summary>
    92         /// <value>The name.</value>
    93         public string Name
    94         {
    95             get { return mName; }
    96             set { mName = value; }
     161      }
     162
     163    }
     164    #endregion
     165
     166    #region Constructor
     167    /// <summary>
     168    /// Default constructor
     169    /// </summary>
     170    /// <param name="name">The name of the tool.</param>
     171    public AbstractTool(string name) {
     172      this.mName = name;
     173    }
     174    #endregion
     175
     176    #region Methods
     177
     178    protected void RestoreCursor() {
     179      // I ran into an issue where the RectangleTool was activated,
     180      // nothing drawn, then the EllipseTool was activated.  When
     181      // the EllipseTool was deactivated the cursor was set to the
     182      // previous cursor, which was the cursor for the RectangleTool.
     183
     184      // Update: Rather than fixing it here, I changed
     185      // ControllerBase.ActivateTool(string) so it deactivates
     186      // the current tool first.
     187      //Controller.View.CurrentCursor = Cursors.Default;
     188
     189      if (previousCursor != null) {
     190        if (Controller != null) {
     191          Controller.View.CurrentCursor = previousCursor;
    97192        }
    98         /// <summary>
    99         /// Gets or sets the controller.
    100         /// </summary>
    101         /// <value>The controller.</value>
    102         public IController Controller
    103         {
    104             get
    105             {
    106                 return mController;
    107             }
    108 
    109             set
    110             {
    111                 mController = value;
    112             }
    113         }
    114 
    115         /// <summary>
    116         /// Gets or sets the cursor.
    117         /// </summary>
    118         /// <value>The cursor.</value>
    119         public Cursor Cursor
    120         {
    121             get
    122             {
    123                 return mCursor;
    124             }
    125             set
    126             {
    127                 mCursor = value;
    128                 //prevCursor = Controller.View.CurrentCursor;
    129                 Controller.View.CurrentCursor = value;
    130             }
    131         }
    132 
    133         /// <summary>
    134         /// Gets or sets the Enabled
    135         /// </summary>
    136         public bool Enabled
    137         {
    138             get
    139             {
    140                 return this.mEnabled;
    141             }
    142 
    143             set
    144             {
    145                 //disable the tool first if it is active
    146                 if (!value && IsActive)
    147                 {                       
    148                     DeactivateTool();
    149                 }
    150                 mEnabled = value;
    151             }
    152         }
    153 
    154         /// <summary>
    155         /// Gets a value indicating whether this tool excludes other tools.
    156         /// </summary>
    157         /// <value>
    158         ///   <c>true</c> if this instance is exclusive; otherwise, <c>false</c>.
    159         /// </value>
    160         public virtual bool IsExclusive
    161         {
    162             get
    163             {
    164                 return true;
    165             }
    166         }
    167 
    168         /// <summary>
    169         /// Gets or sets a value indicating whether this tool can activated.
    170         /// </summary>
    171         /// <value>
    172         ///   <c>true</c> if this instance can activate; otherwise, <c>false</c>.
    173         /// </value>
    174         public virtual bool CanActivate
    175         {
    176             get
    177             {
    178                 if (mEnabled )
    179                 {
    180                     return !IsActive ;
    181                 }
    182                 else
    183                 {
    184                     return false;
    185                 }
    186             }
    187            
    188         }
    189         #endregion
    190 
    191         #region Constructor
    192         /// <summary>
    193         /// Default constructor
    194         /// </summary>
    195         /// <param name="name">The name of the tool.</param>
    196         public AbstractTool(string name)
    197         {
    198             this.mName = name;
    199         }
    200         #endregion
    201 
    202         #region Methods
    203 
    204         protected void RestoreCursor()
    205         {
    206             // I ran into an issue where the RectangleTool was activated,
    207             // nothing drawn, then the EllipseTool was activated.  When
    208             // the EllipseTool was deactivated the cursor was set to the
    209             // previous cursor, which was the cursor for the RectangleTool.
    210  
    211             // Update: Rather than fixing it here, I changed
    212             // ControllerBase.ActivateTool(string) so it deactivates
    213             // the current tool first.
    214             //Controller.View.CurrentCursor = Cursors.Default;
    215 
    216             if (previousCursor != null)
    217             {
    218                 if (Controller != null)
    219                 {
    220                     Controller.View.CurrentCursor = previousCursor;
    221                 }
    222                 previousCursor = null;
    223             }
    224         }
    225 
    226         // ------------------------------------------------------------------
    227         /// <summary>
    228         /// Raises the <see cref="OnToolActivate"/> event
    229         /// </summary>
    230         /// <param name="e">ConnectionCollection event argument</param>
    231         // ------------------------------------------------------------------
    232         public virtual void RaiseOnToolActivate(ToolEventArgs e)
    233         {
    234             EventHandler<ToolEventArgs> handler = OnToolActivate;
    235             if (handler != null)
    236             {
    237                 handler(this, e);
    238             }
    239         }
    240 
    241         // ------------------------------------------------------------------
    242         /// <summary>
    243         /// Raises the <see cref="OnToolDeactivate"/> event.
    244         /// </summary>
    245         /// <param name="e">ConnectionCollection event argument</param>
    246         // ------------------------------------------------------------------
    247         public virtual void RaiseOnToolDeactivate(ToolEventArgs e)
    248         {
    249             EventHandler<ToolEventArgs> handler = OnToolDeactivate;
    250             if (handler != null)
    251             {
    252                 handler(this, e);
    253             }
    254         }
    255 
    256         #region Activation & deactivation
    257 
    258         /// <summary>
    259         /// Deactivates the tool.
    260         /// </summary>
    261         /// <returns></returns>
    262         public bool DeactivateTool()
    263         {
    264             if (IsActive)
    265             {
    266                 OnDeactivateTool();
    267                 IsActive = false;
    268                 RestoreCursor();
    269                 UnsuspendTools();
    270                 RaiseOnToolDeactivate(new ToolEventArgs(this));
    271                 return true;
    272             }
    273             return false;
    274         }
    275 
    276         /// <summary>
    277         /// Activates the tool.
    278         /// </summary>
    279         /// <returns></returns>
    280         public bool ActivateTool()
    281         {
    282             //halt other actions
    283             SuspendOtherTools();
    284            
    285             if (Enabled && !IsActive)
    286             {
    287                 previousCursor = this.Controller.View.CurrentCursor;
    288                 IsActive = true;
    289                 OnActivateTool();
    290                 RaiseOnToolActivate(new ToolEventArgs(this));
    291             }
    292             return IsActive;
    293         }
    294 
    295         /// <summary>
    296         /// Suspends the other tools.
    297         /// </summary>
    298         public void SuspendOtherTools()
    299         {
    300             foreach (ITool tool in Controller.Tools)
    301             {
    302                 if (tool != this)
    303                     tool.IsSuspended = true;
    304             }
    305         }
    306 
    307         /// <summary>
    308         /// Releases the previously suspeneded tools <see cref="SuspendOtherTools"/>
    309         /// </summary>
    310         public void UnsuspendTools()
    311         {
    312             foreach (ITool tool in Controller.Tools)
    313             {                 
    314                tool.IsSuspended = false;
    315             }
    316         }
    317 
    318         #endregion
    319 
    320         /// <summary>
    321         /// Called when the tool is activated.
    322         /// </summary>
    323         protected virtual void OnActivateTool(){}
    324 
    325         /// <summary>
    326         /// Called when the tool is deactivated.
    327         /// </summary>
    328         protected virtual void OnDeactivateTool(){}
    329 
    330         /// <summary>
    331         /// Gets the service object of the specified type.
    332         /// </summary>
    333         /// <param name="serviceType">An object that specifies the type of service object to get.</param>
    334         /// <returns>
    335         /// A service object of type serviceType.-or- null if there is no service object of type serviceType.
    336         /// </returns>
    337         public object GetService(Type serviceType)
    338         {
    339             return null;
    340         }
    341         #endregion
    342 
    343     }
     193        previousCursor = null;
     194      }
     195    }
     196
     197    // ------------------------------------------------------------------
     198    /// <summary>
     199    /// Raises the <see cref="OnToolActivate"/> event
     200    /// </summary>
     201    /// <param name="e">ConnectionCollection event argument</param>
     202    // ------------------------------------------------------------------
     203    public virtual void RaiseOnToolActivate(ToolEventArgs e) {
     204      EventHandler<ToolEventArgs> handler = OnToolActivate;
     205      if (handler != null) {
     206        handler(this, e);
     207      }
     208    }
     209
     210    // ------------------------------------------------------------------
     211    /// <summary>
     212    /// Raises the <see cref="OnToolDeactivate"/> event.
     213    /// </summary>
     214    /// <param name="e">ConnectionCollection event argument</param>
     215    // ------------------------------------------------------------------
     216    public virtual void RaiseOnToolDeactivate(ToolEventArgs e) {
     217      EventHandler<ToolEventArgs> handler = OnToolDeactivate;
     218      if (handler != null) {
     219        handler(this, e);
     220      }
     221    }
     222
     223    #region Activation & deactivation
     224
     225    /// <summary>
     226    /// Deactivates the tool.
     227    /// </summary>
     228    /// <returns></returns>
     229    public bool DeactivateTool() {
     230      if (IsActive) {
     231        OnDeactivateTool();
     232        IsActive = false;
     233        RestoreCursor();
     234        UnsuspendTools();
     235        RaiseOnToolDeactivate(new ToolEventArgs(this));
     236        return true;
     237      }
     238      return false;
     239    }
     240
     241    /// <summary>
     242    /// Activates the tool.
     243    /// </summary>
     244    /// <returns></returns>
     245    public bool ActivateTool() {
     246      //halt other actions
     247      SuspendOtherTools();
     248
     249      if (Enabled && !IsActive) {
     250        previousCursor = this.Controller.View.CurrentCursor;
     251        IsActive = true;
     252        OnActivateTool();
     253        RaiseOnToolActivate(new ToolEventArgs(this));
     254      }
     255      return IsActive;
     256    }
     257
     258    /// <summary>
     259    /// Suspends the other tools.
     260    /// </summary>
     261    public void SuspendOtherTools() {
     262      foreach (ITool tool in Controller.Tools) {
     263        if (tool != this)
     264          tool.IsSuspended = true;
     265      }
     266    }
     267
     268    /// <summary>
     269    /// Releases the previously suspeneded tools <see cref="SuspendOtherTools"/>
     270    /// </summary>
     271    public void UnsuspendTools() {
     272      foreach (ITool tool in Controller.Tools) {
     273        tool.IsSuspended = false;
     274      }
     275    }
     276
     277    #endregion
     278
     279    /// <summary>
     280    /// Called when the tool is activated.
     281    /// </summary>
     282    protected virtual void OnActivateTool() { }
     283
     284    /// <summary>
     285    /// Called when the tool is deactivated.
     286    /// </summary>
     287    protected virtual void OnDeactivateTool() { }
     288
     289    /// <summary>
     290    /// Gets the service object of the specified type.
     291    /// </summary>
     292    /// <param name="serviceType">An object that specifies the type of service object to get.</param>
     293    /// <returns>
     294    /// A service object of type serviceType.-or- null if there is no service object of type serviceType.
     295    /// </returns>
     296    public object GetService(Type serviceType) {
     297      return null;
     298    }
     299    #endregion
     300
     301  }
    344302}
Note: See TracChangeset for help on using the changeset viewer.