1 | using System;
|
---|
2 | using System.Collections.Generic;
|
---|
3 | using System.Drawing;
|
---|
4 | using System.Drawing.Drawing2D;
|
---|
5 | using System.IO;
|
---|
6 | using System.Reflection;
|
---|
7 |
|
---|
8 | namespace Netron.Diagramming.Core {
|
---|
9 | // ----------------------------------------------------------------------
|
---|
10 | /// <summary>
|
---|
11 | /// The typical shape shipping with Visual Studio 2005 in the class
|
---|
12 | /// designer.
|
---|
13 | /// </summary>
|
---|
14 | // ----------------------------------------------------------------------
|
---|
15 | [Shape(
|
---|
16 | "Class shape",
|
---|
17 | "ClassShape",
|
---|
18 | "Special",
|
---|
19 | "The typical shape shipping with Visual Studio 2005 in the class " +
|
---|
20 | "designer.")]
|
---|
21 | public partial class ClassShape : ComplexShapeBase {
|
---|
22 |
|
---|
23 | #region Fields
|
---|
24 |
|
---|
25 | // ------------------------------------------------------------------
|
---|
26 | /// <summary>
|
---|
27 | /// Implementation of IVersion - the current version of
|
---|
28 | /// ClassShape.
|
---|
29 | /// </summary>
|
---|
30 | // ------------------------------------------------------------------
|
---|
31 | protected const double classShapeVersion = 1.0;
|
---|
32 |
|
---|
33 | private Color mHeadColor = ArtPalette.RandomLowSaturationColor;
|
---|
34 |
|
---|
35 | // ------------------------------------------------------------------
|
---|
36 | /// <summary>
|
---|
37 | /// the xpansion icon
|
---|
38 | /// </summary>
|
---|
39 | // ------------------------------------------------------------------
|
---|
40 | private SwitchIconMaterial xicon;
|
---|
41 |
|
---|
42 | // ------------------------------------------------------------------
|
---|
43 | /// <summary>
|
---|
44 | /// the pen used to draw the edge of the shape, which is switching
|
---|
45 | /// between the highlighted and normal state.
|
---|
46 | /// </summary>
|
---|
47 | // ------------------------------------------------------------------
|
---|
48 | private Pen pen;
|
---|
49 |
|
---|
50 | /// <summary>
|
---|
51 | /// holds the connectors
|
---|
52 | /// </summary>
|
---|
53 | private Connector cBottom, cLeft, cRight, cTop;
|
---|
54 | /// <summary>
|
---|
55 | /// the height of the body
|
---|
56 | /// </summary>
|
---|
57 | private int bodyHeight;
|
---|
58 | /// <summary>
|
---|
59 | /// the type of body
|
---|
60 | /// </summary>
|
---|
61 | private BodyType mBodyType = BodyType.None;
|
---|
62 | /// <summary>
|
---|
63 | /// the main text in the head
|
---|
64 | /// </summary>
|
---|
65 | private string mTitle;
|
---|
66 | /// <summary>
|
---|
67 | /// the mSubTitle
|
---|
68 | /// </summary>
|
---|
69 | private string mSubTitle;
|
---|
70 | /// <summary>
|
---|
71 | /// the collapse state is a flagged enum
|
---|
72 | /// </summary>
|
---|
73 | private bool mCollapsed = true;
|
---|
74 | /// <summary>
|
---|
75 | /// the list of items when set to list-type
|
---|
76 | /// </summary>
|
---|
77 | private CollectionBase<ClassShapeItem> mList = new CollectionBase<ClassShapeItem>();
|
---|
78 | /// <summary>
|
---|
79 | /// the <see cref="LabelMaterial"/> to display the free text
|
---|
80 | /// </summary>
|
---|
81 | private LabelMaterial textMaterial;
|
---|
82 | /// <summary>
|
---|
83 | /// graphics utility to paint the shape
|
---|
84 | /// </summary>
|
---|
85 | private GraphicsPath path, gradientPath;
|
---|
86 | /// <summary>
|
---|
87 | /// graphics utility to paint the shape
|
---|
88 | /// </summary>
|
---|
89 | private Region darkRegion, gradientRegion;
|
---|
90 | /// <summary>
|
---|
91 | /// the brush used to paint the gradient of the shape-head
|
---|
92 | /// </summary>
|
---|
93 | private Brush gradientBrush;
|
---|
94 | /// <summary>
|
---|
95 | /// typographic string formatting
|
---|
96 | /// </summary>
|
---|
97 | StringFormat sf = StringFormat.GenericTypographic;
|
---|
98 |
|
---|
99 | // ------------------------------------------------------------------
|
---|
100 | /// <summary>
|
---|
101 | /// The collection of <see cref="FolderMaterial"/> folders displayed
|
---|
102 | /// when the shape is in <see cref="BodyType.List"/> mode.
|
---|
103 | /// </summary>
|
---|
104 | // ------------------------------------------------------------------
|
---|
105 | private CollectionBase<FolderMaterial> mFolders =
|
---|
106 | new CollectionBase<FolderMaterial>();
|
---|
107 |
|
---|
108 | #endregion
|
---|
109 |
|
---|
110 | #region Properties
|
---|
111 |
|
---|
112 | // ------------------------------------------------------------------
|
---|
113 | /// <summary>
|
---|
114 | /// Gets the current version.
|
---|
115 | /// </summary>
|
---|
116 | // ------------------------------------------------------------------
|
---|
117 | public override double Version {
|
---|
118 | get {
|
---|
119 | return classShapeVersion;
|
---|
120 | }
|
---|
121 | }
|
---|
122 |
|
---|
123 | private FolderMaterial mPropertiesNode;
|
---|
124 | private FolderMaterial mMethodsNode;
|
---|
125 |
|
---|
126 | public FolderMaterial PropertiesNode {
|
---|
127 | get { return mPropertiesNode; }
|
---|
128 | }
|
---|
129 | public FolderMaterial MethodsNode {
|
---|
130 | get { return mMethodsNode; }
|
---|
131 | }
|
---|
132 |
|
---|
133 | /// <summary>
|
---|
134 | /// Gets or sets the color of the head.
|
---|
135 | /// </summary>
|
---|
136 | /// <value>The color of the head.</value>
|
---|
137 | public Color HeadColor {
|
---|
138 | get { return mHeadColor; }
|
---|
139 | set {
|
---|
140 | mHeadColor = value;
|
---|
141 |
|
---|
142 | if (PaintStyle is GradientPaintStyle)
|
---|
143 | (PaintStyle as GradientPaintStyle).StartColor = value;
|
---|
144 | else if (PaintStyle is SolidPaintStyle)
|
---|
145 | (PaintStyle as SolidPaintStyle).SolidColor = value;
|
---|
146 | }
|
---|
147 | }
|
---|
148 |
|
---|
149 | /// <summary>
|
---|
150 | /// Gets the friendly name of the entity to be displayed in the UI
|
---|
151 | /// </summary>
|
---|
152 | /// <value></value>
|
---|
153 | public override string EntityName {
|
---|
154 | get {
|
---|
155 | return "Class Shape";
|
---|
156 | }
|
---|
157 | }
|
---|
158 |
|
---|
159 | /// <summary>
|
---|
160 | /// Gets or sets the type of content displayed in the body of the bundle
|
---|
161 | /// </summary>
|
---|
162 | public BodyType BodyType {
|
---|
163 | get {
|
---|
164 | return mBodyType;
|
---|
165 | }
|
---|
166 | set {
|
---|
167 | mBodyType = value;
|
---|
168 | this.UpdateBody();
|
---|
169 | }
|
---|
170 | }
|
---|
171 |
|
---|
172 | /// <summary>
|
---|
173 | /// Collapses the shape
|
---|
174 | /// </summary>
|
---|
175 | public void Collapse() {
|
---|
176 | this.mCollapsed = true;
|
---|
177 | UpdateBody();
|
---|
178 | this.Invalidate();
|
---|
179 | }
|
---|
180 |
|
---|
181 | /// <summary>
|
---|
182 | /// Expands the bundle to display the body
|
---|
183 | /// </summary>
|
---|
184 | public void Expand() {
|
---|
185 | mCollapsed = false;
|
---|
186 |
|
---|
187 | UpdateBody();
|
---|
188 | this.Invalidate();
|
---|
189 | }
|
---|
190 |
|
---|
191 | /// <summary>
|
---|
192 | /// Collapses the bundle and hides the body
|
---|
193 | /// </summary>
|
---|
194 | public bool Collapsed {
|
---|
195 | get {
|
---|
196 | return mCollapsed;
|
---|
197 | }
|
---|
198 | //set{mCollapsed = value;}
|
---|
199 | }
|
---|
200 |
|
---|
201 | /// <summary>
|
---|
202 | /// Gets the list of items displayed in the body
|
---|
203 | /// </summary>
|
---|
204 | public CollectionBase<ClassShapeItem> List {
|
---|
205 | get {
|
---|
206 | return this.mList;
|
---|
207 | }
|
---|
208 | }
|
---|
209 |
|
---|
210 | /// <summary>
|
---|
211 | /// Gets or sets the mSubTitle of the bundle
|
---|
212 | /// </summary>
|
---|
213 | public string SubTitle {
|
---|
214 | get {
|
---|
215 | return mSubTitle;
|
---|
216 | }
|
---|
217 | set {
|
---|
218 | mSubTitle = value;
|
---|
219 | this.Invalidate();
|
---|
220 | }
|
---|
221 | }
|
---|
222 |
|
---|
223 | /// <summary>
|
---|
224 | /// Gets or sets the text to be displayed if the body-type is set to FreeText
|
---|
225 | /// </summary>
|
---|
226 | public string FreeText {
|
---|
227 | get {
|
---|
228 | return textMaterial.Text;
|
---|
229 | }
|
---|
230 | set {
|
---|
231 | textMaterial.Text = value;
|
---|
232 | //UpdateBody();
|
---|
233 | }
|
---|
234 | }
|
---|
235 |
|
---|
236 | /// <summary>
|
---|
237 | /// Gets or sets the mTitle of the bundle
|
---|
238 | /// </summary>
|
---|
239 | public string Title {
|
---|
240 | get {
|
---|
241 | return mTitle;
|
---|
242 | }
|
---|
243 | set {
|
---|
244 | mTitle = value;
|
---|
245 | }
|
---|
246 | }
|
---|
247 | public override string Text {
|
---|
248 | get {
|
---|
249 | if (BodyType == BodyType.FreeText)
|
---|
250 | return textMaterial.Text;
|
---|
251 | else
|
---|
252 | return string.Empty;
|
---|
253 |
|
---|
254 |
|
---|
255 | }
|
---|
256 | set {
|
---|
257 | if (BodyType == BodyType.FreeText)
|
---|
258 | textMaterial.Text = value;
|
---|
259 | }
|
---|
260 | }
|
---|
261 |
|
---|
262 | /// <summary>
|
---|
263 | /// Gets the folders of the shape which are displayed when its in <see cref="BodyType.List"/> mode.
|
---|
264 | /// </summary>
|
---|
265 | /// <value>The folders.</value>
|
---|
266 | public CollectionBase<FolderMaterial> Folders {
|
---|
267 | get { return mFolders; }
|
---|
268 | internal set { mFolders = value; }
|
---|
269 | }
|
---|
270 | #endregion
|
---|
271 |
|
---|
272 | #region Constructors
|
---|
273 |
|
---|
274 | // ------------------------------------------------------------------
|
---|
275 | /// <summary>
|
---|
276 | /// Constructor
|
---|
277 | /// </summary>
|
---|
278 | // ------------------------------------------------------------------
|
---|
279 | public ClassShape(IModel model)
|
---|
280 | : base(model) {
|
---|
281 | }
|
---|
282 |
|
---|
283 | // ------------------------------------------------------------------
|
---|
284 | /// <summary>
|
---|
285 | /// Initializes a new instance of the <see cref="T:ClassShape"/>
|
---|
286 | /// class.
|
---|
287 | /// </summary>
|
---|
288 | // ------------------------------------------------------------------
|
---|
289 | public ClassShape()
|
---|
290 | : base() {
|
---|
291 | }
|
---|
292 |
|
---|
293 | // ------------------------------------------------------------------
|
---|
294 | /// <summary>
|
---|
295 | /// Initialize of the bundle
|
---|
296 | /// </summary>
|
---|
297 | // ------------------------------------------------------------------
|
---|
298 | protected override void Initialize() {
|
---|
299 | base.Initialize();
|
---|
300 | Name = "Class Shape";
|
---|
301 | mTitle = "Class shape";
|
---|
302 | mSubTitle = "by The Netron Project";
|
---|
303 | this.Resizable = false;
|
---|
304 | sf.Trimming = StringTrimming.EllipsisCharacter;
|
---|
305 | //the initial size
|
---|
306 | Transform(0, 0, 200, 50);
|
---|
307 |
|
---|
308 |
|
---|
309 | //mList.OnItemAdded += new EventHandler<CollectionEventArgs<ClassShapeItem>>(mList_OnItemAdded);
|
---|
310 |
|
---|
311 | #region The icon material
|
---|
312 | CreateShapeIcon();
|
---|
313 | #endregion
|
---|
314 |
|
---|
315 | #region The xpand icon material
|
---|
316 | CreateXpansionIcon();
|
---|
317 | #endregion
|
---|
318 |
|
---|
319 | #region The free text
|
---|
320 | textMaterial = new LabelMaterial();
|
---|
321 | textMaterial.Transform(new Rectangle(Rectangle.X + 5, Rectangle.Y + 18, Rectangle.Width - 10, bodyHeight));
|
---|
322 | textMaterial.Text = GetQuotation();
|
---|
323 | textMaterial.Visible = false;
|
---|
324 | Children.Add(textMaterial);
|
---|
325 |
|
---|
326 | #endregion
|
---|
327 |
|
---|
328 | #region The folders
|
---|
329 |
|
---|
330 | /* The following code is only an example of what is possible.
|
---|
331 | * You can add any shape material here but I guess the properties/methods nodes
|
---|
332 | * are quite useful for many purposes.
|
---|
333 | */
|
---|
334 |
|
---|
335 | string[] props = new string[] { "Rectangle", "Size", "Visible" };
|
---|
336 | FolderMaterial folder1 = new FolderMaterial("Properties", props, "Resources.PublicProperty.ico");
|
---|
337 | folder1.Transform(new Rectangle(Rectangle.X + 5, Rectangle.Y + 55, Rectangle.Width - 10, FolderMaterial.HeaderHeight));
|
---|
338 | folder1.Visible = false;
|
---|
339 | folder1.ShowLines = true;
|
---|
340 | mFolders.Add(folder1);
|
---|
341 | folder1.OnFolderChanged += new EventHandler<RectangleEventArgs>(folders_OnFolderChanged);
|
---|
342 | Children.Add(folder1);
|
---|
343 | mPropertiesNode = folder1;
|
---|
344 |
|
---|
345 | string[] methds = new string[] { "Invalidate", "Transform", "Update", "Reset", "Delete" };
|
---|
346 | FolderMaterial folder2 = new FolderMaterial("Methods", methds, "Resources.PublicMethod.ico");
|
---|
347 | folder2.Transform(new Rectangle(Rectangle.X + 5, Rectangle.Y + 55 + FolderMaterial.HeaderHeight + 10, Rectangle.Width - 10, FolderMaterial.HeaderHeight));
|
---|
348 | folder2.Visible = false;
|
---|
349 | folder2.ShowLines = true;
|
---|
350 | mFolders.Add(folder2);
|
---|
351 | folder2.OnFolderChanged += new EventHandler<RectangleEventArgs>(folders_OnFolderChanged);
|
---|
352 | Children.Add(folder2);
|
---|
353 | mMethodsNode = folder2;
|
---|
354 |
|
---|
355 | #region this calculates the initial body height
|
---|
356 |
|
---|
357 |
|
---|
358 | foreach (FolderMaterial folder in mFolders)
|
---|
359 | bodyHeight += folder.Rectangle.Height + 3;
|
---|
360 |
|
---|
361 | //UpdateBody();
|
---|
362 | #endregion
|
---|
363 |
|
---|
364 | #endregion
|
---|
365 |
|
---|
366 | #region Connectors
|
---|
367 | cTop = new Connector(new Point((int)(Rectangle.Left + Rectangle.Width / 2), Rectangle.Top), Model);
|
---|
368 | cTop.Name = "Top connector";
|
---|
369 | cTop.Parent = this;
|
---|
370 | Connectors.Add(cTop);
|
---|
371 |
|
---|
372 | cRight = new Connector(new Point(Rectangle.Right, (int)(Rectangle.Top + Rectangle.Height / 2)), Model);
|
---|
373 | cRight.Name = "Right connector";
|
---|
374 | cRight.Parent = this;
|
---|
375 | Connectors.Add(cRight);
|
---|
376 |
|
---|
377 | cBottom = new Connector(new Point((int)(Rectangle.Left + Rectangle.Width / 2), Rectangle.Bottom), Model);
|
---|
378 | cBottom.Name = "Bottom connector";
|
---|
379 | cBottom.Parent = this;
|
---|
380 | Connectors.Add(cBottom);
|
---|
381 |
|
---|
382 | cLeft = new Connector(new Point(Rectangle.Left, (int)(Rectangle.Top + Rectangle.Height / 2)), Model);
|
---|
383 | cLeft.Name = "Left connector";
|
---|
384 | cLeft.Parent = this;
|
---|
385 | Connectors.Add(cLeft);
|
---|
386 | #endregion
|
---|
387 |
|
---|
388 |
|
---|
389 |
|
---|
390 | }
|
---|
391 |
|
---|
392 | private void CreateXpansionIcon() {
|
---|
393 | //we use a custom version of the ClickableIconMaterial
|
---|
394 | xicon = new SwitchIconMaterial(SwitchIconType.UpDown);
|
---|
395 | //Rectangle rec = new Rectangle(new Point(Rectangle.Right -20, Rectangle.Y + 5), xicon.Icon.Size);
|
---|
396 | xicon.Transform(new Rectangle(new Point(Rectangle.Right - 20, Rectangle.Y + 7), xicon.Icon.Size));
|
---|
397 | xicon.Gliding = false;
|
---|
398 | xicon.OnExpand += new EventHandler(xicon_OnExpand);
|
---|
399 | xicon.OnCollapse += new EventHandler(xicon_OnCollapse);
|
---|
400 | Children.Add(xicon);
|
---|
401 | }
|
---|
402 |
|
---|
403 | private void CreateShapeIcon() {
|
---|
404 | ClickableIconMaterial icon = new ClickableIconMaterial("Resources.ClassShape.png");
|
---|
405 | //IconMaterial icon = new IconMaterial("Resources.idea.gif");
|
---|
406 | if (icon.Icon == null)
|
---|
407 | throw new InconsistencyException("The icon resource of the class shape could not be found.");
|
---|
408 | //Rectangle rec = new Rectangle(new Point(Rectangle.X + 5, Rectangle.Y + 3), icon.Icon.Size);
|
---|
409 | icon.Transform(new Rectangle(new Point(Rectangle.X + 5, Rectangle.Y + 5), icon.Icon.Size));
|
---|
410 | icon.Gliding = false;
|
---|
411 | Children.Add(icon);
|
---|
412 | }
|
---|
413 | /// <summary>
|
---|
414 | /// Handles the <see cref="FolderMaterial.OnFolderChanged"/> event and recalculates the bounding rectangle of the body, which
|
---|
415 | /// depends on the state of the folders when the class shape is in <see cref="BodyType.List"/> mode.
|
---|
416 | /// </summary>
|
---|
417 | /// <param name="sender"></param>
|
---|
418 | /// <param name="e"></param>
|
---|
419 | void folders_OnFolderChanged(object sender, RectangleEventArgs e) {
|
---|
420 | if (mFolders.Count == 0) return;
|
---|
421 | bodyHeight = 0;
|
---|
422 | if (mFolders.Count > 1) //shifting of the folder with respect to its predecessor
|
---|
423 | {
|
---|
424 | for (int k = 1; k < mFolders.Count; k++) {
|
---|
425 | mFolders[k].Transform(new Rectangle(Rectangle.X + 5, mFolders[k - 1].Rectangle.Bottom + 10, Rectangle.Width - 10, FolderMaterial.HeaderHeight));
|
---|
426 | }
|
---|
427 | }
|
---|
428 | foreach (FolderMaterial folder in mFolders)
|
---|
429 | bodyHeight += folder.Rectangle.Height + 3;
|
---|
430 |
|
---|
431 | UpdateBody();
|
---|
432 | }
|
---|
433 | /// <summary>
|
---|
434 | /// Handles the <see cref="SwitchIconMaterial.OnCollapse"/> event and sets the state of the class shape to 'collapsed'.
|
---|
435 | /// </summary>
|
---|
436 | /// <param name="sender"></param>
|
---|
437 | /// <param name="e"></param>
|
---|
438 | void xicon_OnCollapse(object sender, EventArgs e) {
|
---|
439 | Collapse();
|
---|
440 | }
|
---|
441 |
|
---|
442 | /// <summary>
|
---|
443 | /// Handles the <see cref="SwitchIconMaterial.OnCollapse"/> event and sets the state of the class shape to 'expanded'.
|
---|
444 | /// </summary>
|
---|
445 | /// <param name="sender"></param>
|
---|
446 | /// <param name="e"></param>
|
---|
447 | void xicon_OnExpand(object sender, EventArgs e) {
|
---|
448 | Expand();
|
---|
449 | }
|
---|
450 |
|
---|
451 | #endregion
|
---|
452 |
|
---|
453 | #region Methods
|
---|
454 |
|
---|
455 | /// <summary>
|
---|
456 | /// Updates pens and brushes
|
---|
457 | /// </summary>
|
---|
458 | protected override void UpdatePaintingMaterial() {
|
---|
459 | base.UpdatePaintingMaterial();
|
---|
460 | if (PaintStyle is GradientPaintStyle)
|
---|
461 | mHeadColor = (PaintStyle as GradientPaintStyle).StartColor;
|
---|
462 | else if (PaintStyle is SolidPaintStyle)
|
---|
463 | mHeadColor = (PaintStyle as SolidPaintStyle).SolidColor;
|
---|
464 |
|
---|
465 | }
|
---|
466 |
|
---|
467 | /// <summary>
|
---|
468 | /// You can safely delete this method, it's gives some variety and tests different text sizes.
|
---|
469 | /// </summary>
|
---|
470 | /// <returns></returns>
|
---|
471 | private string GetQuotation() {
|
---|
472 | Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("Netron.Diagramming.Core.Resources.Quotations.txt");
|
---|
473 | if (stream != null) {
|
---|
474 | Random rnd = new Random();
|
---|
475 | StreamReader reader = new StreamReader(stream);
|
---|
476 | string all = reader.ReadToEnd();
|
---|
477 | string[] quotes = all.Split((char)10);
|
---|
478 | reader.Close();
|
---|
479 | stream.Close();
|
---|
480 | return quotes[rnd.Next(0, quotes.Length)];
|
---|
481 |
|
---|
482 | } else
|
---|
483 | return "Intelligence is characterized by a natural incomprehension of life.";
|
---|
484 | }
|
---|
485 |
|
---|
486 | /// <summary>
|
---|
487 | /// Paints the bundle on the canvas
|
---|
488 | /// </summary>
|
---|
489 | /// <param name="g"></param>
|
---|
490 | public override void Paint(Graphics g) {
|
---|
491 | #region Set the quality of the drawing
|
---|
492 | g.SmoothingMode = SmoothingMode.HighQuality;
|
---|
493 | #endregion
|
---|
494 |
|
---|
495 | #region Artist's material
|
---|
496 | if (Hovered)
|
---|
497 | pen = ArtPalette.HighlightPen;
|
---|
498 | else
|
---|
499 | pen = mPenStyle.DrawingPen();
|
---|
500 | #endregion
|
---|
501 |
|
---|
502 | #region Shape's shadow and container
|
---|
503 | path = new GraphicsPath();
|
---|
504 | path.AddArc(Rectangle.X, Rectangle.Y, 20, 20, -180, 90);
|
---|
505 | path.AddLine(Rectangle.X + 10, Rectangle.Y, Rectangle.X + Rectangle.Width - 10, Rectangle.Y);
|
---|
506 | path.AddArc(Rectangle.X + Rectangle.Width - 20, Rectangle.Y, 20, 20, -90, 90);
|
---|
507 | path.AddLine(Rectangle.X + Rectangle.Width, Rectangle.Y + 10, Rectangle.X + Rectangle.Width, Rectangle.Y + Rectangle.Height - 10);
|
---|
508 | path.AddArc(Rectangle.X + Rectangle.Width - 20, Rectangle.Y + Rectangle.Height - 20, 20, 20, 0, 90);
|
---|
509 | path.AddLine(Rectangle.X + Rectangle.Width - 10, Rectangle.Y + Rectangle.Height, Rectangle.X + 10, Rectangle.Y + Rectangle.Height);
|
---|
510 | path.AddArc(Rectangle.X, Rectangle.Y + Rectangle.Height - 20, 20, 20, 90, 90);
|
---|
511 | path.AddLine(Rectangle.X, Rectangle.Y + Rectangle.Height - 10, Rectangle.X, Rectangle.Y + 10);
|
---|
512 | //shadow
|
---|
513 | if (ArtPalette.EnableShadows) {
|
---|
514 | darkRegion = new Region(path);
|
---|
515 | darkRegion.Translate(5, 5);
|
---|
516 | g.FillRegion(ArtPalette.ShadowBrush, darkRegion);
|
---|
517 | }
|
---|
518 | //background
|
---|
519 | g.FillPath(Brush, path);
|
---|
520 |
|
---|
521 | #endregion
|
---|
522 |
|
---|
523 | #region the header
|
---|
524 | if (mCollapsed) {
|
---|
525 | //paint the gradient
|
---|
526 | using (gradientBrush = new LinearGradientBrush(Rectangle.Location, new Point(Rectangle.X + Rectangle.Width, Rectangle.Y), HeadColor, Color.White)) {
|
---|
527 | gradientRegion = new Region(path);
|
---|
528 | g.FillRegion(gradientBrush, gradientRegion);
|
---|
529 | }
|
---|
530 | } else {
|
---|
531 | gradientPath = new GraphicsPath();
|
---|
532 | gradientPath.AddArc(Rectangle.X + 1, Rectangle.Y + 1, 18, 18, -180, 90);
|
---|
533 | gradientPath.AddLine(Rectangle.X + 11, Rectangle.Y + 1, Rectangle.X + Rectangle.Width - 11, Rectangle.Y + 1);
|
---|
534 | gradientPath.AddArc(Rectangle.X + Rectangle.Width - 19, Rectangle.Y + 1, 18, 18, -90, 90);
|
---|
535 | gradientPath.AddLine(Rectangle.X + Rectangle.Width - 1, Rectangle.Y + 50, Rectangle.X + 1, Rectangle.Y + 50);
|
---|
536 | //gradient
|
---|
537 | using (gradientBrush = new LinearGradientBrush(Rectangle.Location, new Point(((int)(Rectangle.X + Rectangle.Width)), ((int)(Rectangle.Y))), HeadColor, Color.White)) {
|
---|
538 | gradientRegion = new Region(gradientPath);
|
---|
539 | g.FillRegion(gradientBrush, gradientRegion);
|
---|
540 | }
|
---|
541 | }
|
---|
542 | #endregion
|
---|
543 |
|
---|
544 | #region Border
|
---|
545 | //the border
|
---|
546 | g.DrawPath(pen, path);
|
---|
547 | #endregion
|
---|
548 |
|
---|
549 | #region Text and body
|
---|
550 |
|
---|
551 | g.DrawString(mTitle, ArtPalette.DefaultBoldFont, Brushes.Black, new Rectangle(Rectangle.X + 20, Rectangle.Y + 5, Rectangle.Width - 45, 27));
|
---|
552 | g.DrawString(mSubTitle, ArtPalette.DefaultFont, Brushes.Black, new RectangleF(Rectangle.X + 20, Rectangle.Y + 35, Rectangle.Width - 10, 30), sf);
|
---|
553 |
|
---|
554 |
|
---|
555 | #endregion
|
---|
556 |
|
---|
557 | #region The material
|
---|
558 | foreach (IPaintable material in Children) {
|
---|
559 | material.Paint(g);
|
---|
560 | }
|
---|
561 | #endregion
|
---|
562 |
|
---|
563 | #region The connectors
|
---|
564 | //the connectors
|
---|
565 | if (this.ShowConnectors) {
|
---|
566 | for (int k = 0; k < Connectors.Count; k++) {
|
---|
567 | Connectors[k].Paint(g);
|
---|
568 | }
|
---|
569 | }
|
---|
570 | #endregion
|
---|
571 |
|
---|
572 | }
|
---|
573 |
|
---|
574 | /// <summary>
|
---|
575 | /// Updates the collapsible body in function of the added properties and methods
|
---|
576 | /// </summary>
|
---|
577 | private void UpdateBody() {
|
---|
578 | if (mCollapsed) {
|
---|
579 |
|
---|
580 | if (BodyType == BodyType.None) {
|
---|
581 | xicon.Visible = false;
|
---|
582 | } else
|
---|
583 | xicon.Visible = true;
|
---|
584 | Transform(Rectangle.X, Rectangle.Y, 200, 50);
|
---|
585 |
|
---|
586 | textMaterial.Visible = false;
|
---|
587 | foreach (IShapeMaterial material in mFolders)
|
---|
588 | material.Visible = false;
|
---|
589 | return;
|
---|
590 | } else {
|
---|
591 |
|
---|
592 | if (BodyType == BodyType.FreeText) {
|
---|
593 | textMaterial.Visible = true;
|
---|
594 | xicon.Visible = true;
|
---|
595 | foreach (IShapeMaterial material in mFolders)
|
---|
596 | material.Visible = false;
|
---|
597 | Transform(Rectangle.X, Rectangle.Y, 200, 90 + 60 + 10);
|
---|
598 |
|
---|
599 | } else if (BodyType == BodyType.List) {
|
---|
600 | xicon.Visible = true;
|
---|
601 | textMaterial.Visible = false;
|
---|
602 | foreach (IShapeMaterial material in mFolders)
|
---|
603 | material.Visible = true;
|
---|
604 | Transform(Rectangle.X, Rectangle.Y, 200, bodyHeight + 60 + 10);
|
---|
605 | } else if (BodyType == BodyType.None) {
|
---|
606 | textMaterial.Visible = false;
|
---|
607 | foreach (IShapeMaterial material in mFolders)
|
---|
608 | material.Visible = false;
|
---|
609 | Transform(Rectangle.X, Rectangle.Y, 200, 60 + 10);
|
---|
610 | xicon.Visible = false;
|
---|
611 | }
|
---|
612 | }
|
---|
613 |
|
---|
614 |
|
---|
615 | }
|
---|
616 |
|
---|
617 | /// <summary>
|
---|
618 | /// Updates the body of the bundle when an item is added to the list
|
---|
619 | /// </summary>
|
---|
620 | /// <param name="sender">The sender.</param>
|
---|
621 | /// <param name="e">The e.</param>
|
---|
622 | private void mList_OnItemAdded(object sender, CollectionEventArgs<ClassShapeItem> e) {
|
---|
623 | if (this.mBodyType == BodyType.List)
|
---|
624 | this.UpdateBody();
|
---|
625 | }
|
---|
626 | #endregion
|
---|
627 | }
|
---|
628 |
|
---|
629 | #region Utility classes
|
---|
630 | /// <summary>
|
---|
631 | /// The <see cref="ClassShape"/>'s two possible variations
|
---|
632 | /// </summary>
|
---|
633 | public enum BodyType {
|
---|
634 | /// <summary>
|
---|
635 | /// The class shape displays a series of <see cref="FolderMaterial"/> folders.
|
---|
636 | /// </summary>
|
---|
637 | List,
|
---|
638 | /// <summary>
|
---|
639 | /// The class shape displays a simple <see cref="LabelMaterial"/> in its body.
|
---|
640 | /// </summary>
|
---|
641 | FreeText,
|
---|
642 | /// <summary>
|
---|
643 | /// The class shape displays only a header and no body content.
|
---|
644 | /// </summary>
|
---|
645 | None
|
---|
646 | }
|
---|
647 |
|
---|
648 | [Obsolete]
|
---|
649 | public class ClassShapeItemCollection : Netron.Diagramming.Core.CollectionBase<ClassShapeItem>, IEnumerable<ClassShapeItem> {
|
---|
650 |
|
---|
651 |
|
---|
652 | }
|
---|
653 |
|
---|
654 |
|
---|
655 |
|
---|
656 |
|
---|
657 | /// <summary>
|
---|
658 | /// An item in the <see cref="ClassShape"/>.
|
---|
659 | /// </summary>
|
---|
660 | public class ClassShapeItem {
|
---|
661 | #region Fields
|
---|
662 | private string mText;
|
---|
663 | private Bitmap mIcon;
|
---|
664 | #endregion
|
---|
665 |
|
---|
666 | #region Properties
|
---|
667 | /// <summary>
|
---|
668 | /// Gets or sets the text.
|
---|
669 | /// </summary>
|
---|
670 | /// <value>The text.</value>
|
---|
671 | public string Text {
|
---|
672 | get {
|
---|
673 | return mText;
|
---|
674 | }
|
---|
675 | set {
|
---|
676 | mText = value;
|
---|
677 | }
|
---|
678 | }
|
---|
679 |
|
---|
680 | /// <summary>
|
---|
681 | /// Gets or sets the icon.
|
---|
682 | /// </summary>
|
---|
683 | /// <value>The icon.</value>
|
---|
684 | public Bitmap Icon {
|
---|
685 | get {
|
---|
686 | return mIcon;
|
---|
687 | }
|
---|
688 | set {
|
---|
689 | mIcon = value;
|
---|
690 | }
|
---|
691 | }
|
---|
692 |
|
---|
693 | #endregion
|
---|
694 |
|
---|
695 | /// <summary>
|
---|
696 | /// Initializes a new instance of the <see cref="T:ClassShapeItem"/> class.
|
---|
697 | /// </summary>
|
---|
698 | public ClassShapeItem() {
|
---|
699 | }
|
---|
700 |
|
---|
701 | /// <summary>
|
---|
702 | /// Initializes a new instance of the <see cref="T:ClassShapeItem"/> class.
|
---|
703 | /// </summary>
|
---|
704 | /// <param name="text">The text.</param>
|
---|
705 | public ClassShapeItem(string text) {
|
---|
706 | this.mText = text;
|
---|
707 | }
|
---|
708 |
|
---|
709 | /// <summary>
|
---|
710 | /// Initializes a new instance of the <see cref="T:ClassShapeItem"/> class.
|
---|
711 | /// </summary>
|
---|
712 | /// <param name="text">The text.</param>
|
---|
713 | /// <param name="icon">The icon.</param>
|
---|
714 | public ClassShapeItem(string text, Bitmap icon)
|
---|
715 | : this(text) {
|
---|
716 | this.mIcon = icon;
|
---|
717 | }
|
---|
718 |
|
---|
719 | }
|
---|
720 | /// <summary>
|
---|
721 | /// Utility class to pass ClassShape info via events.
|
---|
722 | /// </summary>
|
---|
723 | public class ClassShapeEventArgs : EventArgs {
|
---|
724 | private ClassShapeItem item;
|
---|
725 |
|
---|
726 | /// <summary>
|
---|
727 | /// Gets or sets the item.
|
---|
728 | /// </summary>
|
---|
729 | /// <value>The item.</value>
|
---|
730 | public ClassShapeItem Item {
|
---|
731 | get {
|
---|
732 | return item;
|
---|
733 | }
|
---|
734 | set {
|
---|
735 | item = value;
|
---|
736 | }
|
---|
737 | }
|
---|
738 |
|
---|
739 | /// <summary>
|
---|
740 | /// Initializes a new instance of the <see cref="T:ClassShapeEventArgs"/> class.
|
---|
741 | /// </summary>
|
---|
742 | /// <param name="item">The item.</param>
|
---|
743 | public ClassShapeEventArgs(ClassShapeItem item) {
|
---|
744 | this.item = item;
|
---|
745 | }
|
---|
746 | }
|
---|
747 | #endregion
|
---|
748 | }
|
---|