Changeset 4068 for trunk/sources/HeuristicLab.ExtLibs/HeuristicLab.Netron/3.0.2672.12446/Netron.Diagramming.Core-3.0.2672.12446/Diagram elements/Materials/IconMaterial.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/IconMaterial.cs
r3038 r4068 1 using System ;1 using System.Drawing; 2 2 using System.Drawing.Drawing2D; 3 using System.Collections.Generic; 4 using System.Text; 5 using System.Drawing; 6 using System.IO; 7 using System.Diagnostics; 8 namespace Netron.Diagramming.Core 9 { 3 namespace Netron.Diagramming.Core { 4 /// <summary> 5 /// Icon shape material without <see cref="IMouseListener"/> service. 6 /// <seealso cref="ClickableIconMaterial"/> 7 /// </summary> 8 public partial class IconMaterial : ShapeMaterialBase { 9 #region Fields 10 11 // ------------------------------------------------------------------ 10 12 /// <summary> 11 /// I con shape material without <see cref="IMouseListener"/> service.12 /// <seealso cref="ClickableIconMaterial"/>13 /// Implementation of IVersion - the current version of 14 /// IconMaterial. 13 15 /// </summary> 14 public partial class IconMaterial : ShapeMaterialBase 15 { 16 #region Fields 16 // ------------------------------------------------------------------ 17 protected double iconMaterialVersion = 1.0; 17 18 18 // ------------------------------------------------------------------ 19 /// <summary> 20 /// Implementation of IVersion - the current version of 21 /// IconMaterial. 22 /// </summary> 23 // ------------------------------------------------------------------ 24 protected double iconMaterialVersion = 1.0; 19 // ------------------------------------------------------------------ 20 /// <summary> 21 /// the Text field 22 /// </summary> 23 // ------------------------------------------------------------------ 24 private Bitmap mIcon; 25 25 26 // ------------------------------------------------------------------ 27 /// <summary> 28 /// the Text field 29 /// </summary> 30 // ------------------------------------------------------------------ 31 private Bitmap mIcon; 26 #endregion 32 27 33 #endregion28 #region Properties 34 29 35 #region Properties 30 // ------------------------------------------------------------------ 31 /// <summary> 32 /// Gets the current version. 33 /// </summary> 34 // ------------------------------------------------------------------ 35 public override double Version { 36 get { 37 return iconMaterialVersion; 38 } 39 } 36 40 37 // ------------------------------------------------------------------ 38 /// <summary> 39 /// Gets the current version. 40 /// </summary> 41 // ------------------------------------------------------------------ 42 public override double Version 43 { 44 get 45 { 46 return iconMaterialVersion; 47 } 48 } 41 // ------------------------------------------------------------------ 42 /// <summary> 43 /// Gets or sets the Text 44 /// </summary> 45 // ------------------------------------------------------------------ 46 public Bitmap Icon { 47 get { 48 return mIcon; 49 } 50 set { 51 mIcon = value; 52 } 53 } 49 54 50 // ------------------------------------------------------------------ 51 /// <summary> 52 /// Gets or sets the Text 53 /// </summary> 54 // ------------------------------------------------------------------ 55 public Bitmap Icon 56 { 57 get 58 { 59 return mIcon; 60 } 61 set 62 { 63 mIcon = value; 64 } 65 } 55 #endregion 66 56 67 #endregion 57 #region Constructor 58 /// <summary> 59 /// Initializes a new instance of the <see cref="IconMaterial"/> class. 60 /// </summary> 61 /// <param name="resourceLocation">The resource location.</param> 62 public IconMaterial(string resourceLocation) 63 : base() { 68 64 69 #region Constructor 70 /// <summary> 71 /// Initializes a new instance of the <see cref="IconMaterial"/> class. 72 /// </summary> 73 /// <param name="resourceLocation">The resource location.</param> 74 public IconMaterial(string resourceLocation) 75 : base() 76 { 65 mIcon = GetBitmap(resourceLocation); 66 } 77 67 78 mIcon = GetBitmap(resourceLocation); 79 } 68 protected Bitmap GetBitmap(string resourceLocation) { 69 if (resourceLocation.Length == 0) 70 throw new InconsistencyException("Invalid icon specification."); 71 try { 72 return new Bitmap(this.GetType(), resourceLocation); 73 } 74 catch { 80 75 81 protected Bitmap GetBitmap(string resourceLocation) 82 { 83 if(resourceLocation.Length == 0) 84 throw new InconsistencyException("Invalid icon specification."); 85 try 86 { 87 return new Bitmap(this.GetType(), resourceLocation); 88 } 89 catch 90 { 76 throw; 77 } 78 } 79 public IconMaterial() 80 : base() { 81 } 91 82 92 throw; 93 } 94 } 95 public IconMaterial() 96 : base() 97 { 98 } 83 #endregion 99 84 100 #endregion85 #region Methods 101 86 102 #region Methods 87 // ------------------------------------------------------------------ 88 /// <summary> 89 /// Calculates the min size needed to fit this material in. The 90 /// min size is determined by the size of the icon used. If there 91 /// isn't an icon specified, then 'Size.Empty' is returned. 92 /// </summary> 93 /// <param name="g">Graphics</param> 94 /// <returns>Size</returns> 95 // ------------------------------------------------------------------ 96 public override Size CalculateMinSize(Graphics g) { 97 Size minSizeNeeded = Size.Empty; 103 98 104 // ------------------------------------------------------------------ 105 /// <summary> 106 /// Calculates the min size needed to fit this material in. The 107 /// min size is determined by the size of the icon used. If there 108 /// isn't an icon specified, then 'Size.Empty' is returned. 109 /// </summary> 110 /// <param name="g">Graphics</param> 111 /// <returns>Size</returns> 112 // ------------------------------------------------------------------ 113 public override Size CalculateMinSize(Graphics g) 114 { 115 Size minSizeNeeded = Size.Empty; 99 if (mIcon != null) { 100 minSizeNeeded = new Size(mIcon.Width, mIcon.Height); 101 } 102 return minSizeNeeded; 103 } 116 104 117 if (mIcon != null) 118 { 119 minSizeNeeded = new Size(mIcon.Width, mIcon.Height); 120 } 121 return minSizeNeeded; 122 } 105 /// <summary> 106 /// Paints the entity using the given graphics object 107 /// </summary> 108 /// <param name="g"></param> 109 public override void Paint(Graphics g) { 110 if (!Visible) 111 return; 123 112 124 /// <summary>125 /// Paints the entity using the given graphics object126 /// </summary>127 /// <param name="g"></param>128 public override void Paint(Graphics g)129 {130 if(!Visible)131 return;113 if (mIcon != null) { 114 GraphicsContainer cto = g.BeginContainer(); 115 g.SetClip(Shape.Rectangle); 116 g.DrawImage(mIcon, Rectangle); 117 g.EndContainer(cto); 118 } 119 } 120 #endregion 132 121 133 if(mIcon != null) 134 { 135 GraphicsContainer cto = g.BeginContainer(); 136 g.SetClip(Shape.Rectangle); 137 g.DrawImage(mIcon, Rectangle); 138 g.EndContainer(cto); 139 } 140 } 141 #endregion 142 143 } 122 } 144 123 }
Note: See TracChangeset
for help on using the changeset viewer.