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