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/ClickableLabelMaterial.cs @ 3038

Last change on this file since 3038 was 3038, checked in by mkommend, 14 years ago

removed warnings from HeuristicLab.Netron (ticket #915)

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