Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2817-BinPackingSpeedup/HeuristicLab.ExtLibs/HeuristicLab.Netron/3.0.2672.12446/Netron.Diagramming.Core-3.0.2672.12446/Diagram elements/Shapes/TextLabel.cs

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

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

File size: 3.2 KB
Line 
1using System;
2using System.Drawing;
3namespace Netron.Diagramming.Core {
4  /// <summary>
5  /// A simple bundle to display textual information
6  /// </summary>
7  public class TextLabel : SimpleShapeBase {
8    #region Fields
9
10    // ------------------------------------------------------------------
11    /// <summary>
12    /// Implementation of IVersion - the current version of
13    /// TextLabel.
14    /// </summary>
15    // ------------------------------------------------------------------
16    protected const double textLabelVersion = 1.0;
17
18    private Connector connector;
19    #endregion
20
21    #region Properties
22
23    // ------------------------------------------------------------------
24    /// <summary>
25    /// Gets the current version.
26    /// </summary>
27    // ------------------------------------------------------------------
28    public override double Version {
29      get {
30        return textLabelVersion;
31      }
32    }
33
34    /// <summary>
35    /// Gets the connector.
36    /// </summary>
37    /// <value>The connector.</value>
38    public Connector Connector {
39      get { return connector; }
40    }
41
42    /// <summary>
43    /// Gets the friendly name of the entity to be displayed in the UI
44    /// </summary>
45    /// <value></value>
46    public override string EntityName {
47      get { return "Text Label"; }
48    }
49
50    #endregion
51
52    #region Constructor
53
54    /// <summary>
55    /// Default ctor
56    /// </summary>
57    /// <param name="s"></param>
58    public TextLabel(IModel s)
59      : base(s) {
60    }
61    /// <summary>
62    /// Initializes a new instance of the <see cref="T:TextLabel"/> class.
63    /// </summary>
64    public TextLabel()
65      : base() {
66    }
67
68    #endregion
69
70    #region Methods
71
72    // -----------------------------------------------------------------
73    /// <summary>
74    /// Initializes this instance.
75    /// </summary>
76    // -----------------------------------------------------------------
77    protected override void Initialize() {
78      base.Initialize();
79
80      PaintStyle = ArtPalette.GetDefaultSolidPaintStyle();
81      Resizable = false;
82      connector = new Connector(new Point((int)(Rectangle.Left + Rectangle.Width / 2), Rectangle.Bottom), Model);
83      connector.Name = "Central connector";
84      connector.Parent = this;
85      Connectors.Add(connector);
86    }
87
88    /// <summary>
89    /// Paints the bundle on the canvas
90    /// </summary>
91    /// <param name="g">a Graphics object onto which to paint</param>
92    public override void Paint(System.Drawing.Graphics g) {
93      if (g == null)
94        throw new ArgumentNullException("The Graphics object is 'null'.");
95
96      g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
97      //the shadow
98      if (ArtPalette.EnableShadows)
99        g.FillRectangle(ArtPalette.ShadowBrush, Rectangle.X + 5, Rectangle.Y + 5, Rectangle.Width, Rectangle.Height);
100      //the container
101      g.FillRectangle(Brush, Rectangle);
102      //the edge
103      if (Hovered)
104        g.DrawRectangle(new Pen(Color.Red, 2F), Rectangle);
105      //the text   
106      if (!string.IsNullOrEmpty(Text))
107        g.DrawString(Text, ArtPalette.DefaultFont, Brushes.Black, Rectangle);
108    }
109    #endregion
110  }
111}
Note: See TracBrowser for help on using the repository browser.