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