1 | using System;
|
---|
2 | using System.Collections.Generic;
|
---|
3 | using System.Text;
|
---|
4 | using System.Drawing;
|
---|
5 | namespace Netron.Diagramming.Core
|
---|
6 | {
|
---|
7 | /// <summary>
|
---|
8 | /// Pen style command
|
---|
9 | /// </summary>
|
---|
10 | class PenStyleCommand : Command
|
---|
11 | {
|
---|
12 | #region Fields
|
---|
13 | CollectionBase<IDiagramEntity> bundle;
|
---|
14 | IController controller;
|
---|
15 |
|
---|
16 | IPenStyle newStyle;
|
---|
17 | Dictionary<string, IPenStyle> previousStyles = new Dictionary<string, IPenStyle>();
|
---|
18 | #endregion
|
---|
19 |
|
---|
20 | #region Properties
|
---|
21 |
|
---|
22 |
|
---|
23 |
|
---|
24 |
|
---|
25 | /// <summary>
|
---|
26 | /// Gets the entities.
|
---|
27 | /// </summary>
|
---|
28 | /// <value>The shape.</value>
|
---|
29 | public CollectionBase<IDiagramEntity> Entities
|
---|
30 | {
|
---|
31 | get { return bundle; }
|
---|
32 | }
|
---|
33 |
|
---|
34 | #endregion
|
---|
35 |
|
---|
36 | #region Constructor
|
---|
37 | /// <summary>
|
---|
38 | /// Initializes a new instance of the <see cref="T:PenStyleCommand"/> class.
|
---|
39 | /// </summary>
|
---|
40 | /// <param name="controller">The controller.</param>
|
---|
41 | /// <param name="bundle">The bundle.</param>
|
---|
42 | /// <param name="penStyle">The pen style.</param>
|
---|
43 | public PenStyleCommand(IController controller, CollectionBase<IDiagramEntity> bundle, IPenStyle penStyle)
|
---|
44 | : base(controller)
|
---|
45 | {
|
---|
46 | this.Text = "Fill style";
|
---|
47 | this.controller = controller;
|
---|
48 | this.bundle = bundle;//the bundle should contain only IShape and IConnection entities!
|
---|
49 | this.newStyle = penStyle;
|
---|
50 | }
|
---|
51 | #endregion
|
---|
52 |
|
---|
53 | #region Methods
|
---|
54 |
|
---|
55 | /// <summary>
|
---|
56 | /// Perform redo of this command.
|
---|
57 | /// </summary>
|
---|
58 | public override void Redo()
|
---|
59 | {
|
---|
60 | if (bundle == null || bundle.Count == 0)
|
---|
61 | return;
|
---|
62 | previousStyles.Clear();
|
---|
63 | foreach (IDiagramEntity entity in bundle)
|
---|
64 | {
|
---|
65 | if (entity is IConnection)
|
---|
66 | {
|
---|
67 | previousStyles.Add(entity.Uid.ToString(), entity.PenStyle);
|
---|
68 | (entity as IConnection).PenStyle = newStyle;
|
---|
69 | }
|
---|
70 | }
|
---|
71 | }
|
---|
72 |
|
---|
73 | /// <summary>
|
---|
74 | /// Perform undo of this command.
|
---|
75 | /// </summary>
|
---|
76 | public override void Undo()
|
---|
77 | {
|
---|
78 | if (bundle == null || bundle.Count == 0)
|
---|
79 | return;
|
---|
80 | foreach (IDiagramEntity entity in bundle)
|
---|
81 | {
|
---|
82 | if (entity is IConnection)
|
---|
83 | (entity as IConnection).PenStyle = previousStyles[entity.Uid.ToString()];
|
---|
84 | }
|
---|
85 |
|
---|
86 |
|
---|
87 |
|
---|
88 |
|
---|
89 | }
|
---|
90 |
|
---|
91 |
|
---|
92 | #endregion
|
---|
93 | }
|
---|
94 |
|
---|
95 | } |
---|