Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.ExtLibs/HeuristicLab.Netron/3.0.2672.12446/Netron.Diagramming.Core-3.0.2672.12446/Diagram elements/Materials/ClickableIconLabelMaterial.cs @ 4068

Last change on this file since 4068 was 4068, checked in by swagner, 14 years ago

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

File size: 6.5 KB
Line 
1using System;
2using System.Diagnostics;
3using System.Windows.Forms;
4namespace Netron.Diagramming.Core {
5  /// <summary>
6  /// Clickable icon-and-label shape material, i.e. an hyperlink with an icon. This material combines
7  /// the <see cref="IconMaterial"/> and the <see cref="ClcikableLabelMaterial"/>
8  /// </summary>
9  public partial class ClickableIconLabelMaterial :
10      IconLabelMaterial,
11      IMouseListener,
12      IHoverListener {
13    #region Fields
14    /// <summary>
15    /// the url of this link
16    /// </summary>
17    private string mUrl = string.Empty;
18
19    // ------------------------------------------------------------------
20    /// <summary>
21    /// Implementation of IVersion - the current version of
22    /// ClickableIconLabelMaterial.
23    /// </summary>
24    // ------------------------------------------------------------------
25    protected double clickableIconLabelMaterialVersion = 1.0;
26
27    #endregion
28
29    #region Properties
30
31    // ------------------------------------------------------------------
32    /// <summary>
33    /// Gets or sets the URL of this clickable material. Note that the
34    /// material can handle more than just Url's by overriding the mouse
35    /// event handlers.  Settings this property is just a convenient way
36    /// to accelerate the development or customization of shapes.
37    /// </summary>
38    /// <value>The URL.</value>
39    // ------------------------------------------------------------------
40    public string Url {
41      get { return mUrl; }
42      set { mUrl = value; }
43    }
44
45    // ------------------------------------------------------------------
46    /// <summary>
47    /// Gets the current version.
48    /// </summary>
49    // ------------------------------------------------------------------
50    public override double Version {
51      get {
52        return clickableIconLabelMaterialVersion;
53      }
54    }
55    #endregion
56
57    #region Constructor
58    /// <summary>
59    /// Initializes a new instance of the <see cref="T:ClickableIconLabelMaterial"/> class.
60    /// </summary>
61    public ClickableIconLabelMaterial()
62      : base() {
63      //Resizable = false;
64    }
65
66    /// <summary>
67    /// Initializes a new instance of the <see cref="T:ClickableIconLabelMaterial"/> class.
68    /// </summary>
69    /// <param name="text">The text.</param>
70    public ClickableIconLabelMaterial(string text) : base(text) { }
71
72    /// <summary>
73    /// Initializes a new instance of the <see cref="T:ClickableIconLabelMaterial"/> class.
74    /// </summary>
75    /// <param name="text">The text.</param>
76    /// <param name="resourceLocation">The resource location.</param>
77    public ClickableIconLabelMaterial(string text, string resourceLocation)
78      : base(text, resourceLocation) {
79
80    }
81
82    /// <summary>
83    /// Initializes a new instance of the <see cref="T:ClickableIconLabelMaterial"/> class.
84    /// </summary>
85    /// <param name="text">The text.</param>
86    /// <param name="resourceLocation">The resource location.</param>
87    /// <param name="url">The URL.</param>
88    public ClickableIconLabelMaterial(string text, string resourceLocation, string url)
89      : base(text, resourceLocation) {
90      this.mUrl = url;
91    }
92    #endregion
93
94    #region Methods
95
96    #region IMouseListener Members
97    /// <summary>
98    /// Gets the service object of the specified type.
99    /// </summary>
100    /// <param name="serviceType">An object that specifies the type of service object to get.</param>
101    /// <returns>
102    /// A service object of type serviceType.-or- null if there is no service object of type serviceType.
103    /// </returns>
104    public override object GetService(Type serviceType) {
105      if (serviceType.Equals(typeof(IMouseListener)))
106        return this;
107      else if (serviceType.Equals(typeof(IHoverListener)))
108        return this;
109      else
110        return null;
111    }
112
113    /// <summary>
114    /// Handles the mouse-down event
115    /// </summary>
116    /// <param name="e">The <see cref="T:MouseEventArgs"/> instance containing the event data.</param>
117    public virtual bool MouseDown(MouseEventArgs e) {
118      if (this.Rectangle.Contains(e.Location)) {
119        if (mUrl.Length > 0) {
120          try {
121            Process.Start(mUrl);
122          }
123
124          catch (ObjectDisposedException oex) {
125            Trace.WriteLine(oex.Message);
126          }
127          catch (System.ComponentModel.Win32Exception wex) {
128            Trace.WriteLine(wex.Message);
129          }
130          catch (ArgumentException aex) {
131            Trace.WriteLine(aex.Message);
132          }
133          catch (InvalidOperationException iex) {
134            Trace.WriteLine(iex.Message);
135          }
136        }
137        return true;//let the rest of the loop go, the event was handled
138      }
139      return false;
140    }
141
142    /// <summary>
143    /// Handles the mouse-move event
144    /// </summary>
145    /// <param name="e">The <see cref="T:MouseEventArgs"/> instance containing the event data.</param>
146    public void MouseMove(MouseEventArgs e) {
147      System.Diagnostics.Trace.WriteLine(e.Location.ToString());
148    }
149
150    /// <summary>
151    /// Handles the mouse-up event
152    /// </summary>
153    /// <param name="e">The <see cref="T:MouseEventArgs"/> instance containing the event data.</param>
154    public virtual void MouseUp(MouseEventArgs e) {
155
156    }
157
158    #endregion
159
160    #region IHoverListener Members
161    /// <summary>
162    /// Handles the <see cref="OnMouseHover"/> event.
163    /// </summary>
164    /// <param name="e">The <see cref="T:System.Windows.Forms.MouseEventArgs"/> instance containing the event data.</param>
165    public void MouseHover(MouseEventArgs e) {
166
167    }
168    private Cursor previousCursor;
169
170    /// <summary>
171    /// Handles the OnMouseEnter event.
172    /// </summary>
173    /// <param name="e">The <see cref="T:System.Windows.Forms.MouseEventArgs"/> instance containing the event data.</param>
174    public void MouseEnter(MouseEventArgs e) {
175      previousCursor = Cursor.Current;
176      this.Shape.Model.RaiseOnCursorChange(Cursors.Hand);
177    }
178
179    /// <summary>
180    /// Handles the OnMouseLeave event.
181    /// </summary>
182    /// <param name="e">The <see cref="T:System.Windows.Forms.MouseEventArgs"/> instance containing the event data.</param>
183    public void MouseLeave(MouseEventArgs e) {
184      this.Shape.Model.RaiseOnCursorChange(previousCursor);
185    }
186
187    //public override void Paint(Graphics g)
188    //{
189    //    g.DrawRectangle(Pens.Violet, Rectangle);
190    //    base.Paint(g);
191    //}
192    #endregion
193
194    #endregion
195
196  }
197}
Note: See TracBrowser for help on using the repository browser.