Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.ExtLibs/HeuristicLab.Netron/3.0.2672.12446/Netron.Diagramming.Core-3.0.2672.12446/Diagram elements/Shapes/ComplexRectangle.cs @ 2768

Last change on this file since 2768 was 2768, checked in by mkommend, 14 years ago

added solution folders and sources for the netron library (ticket #867)

File size: 8.0 KB
Line 
1using System;
2using System.Drawing;
3using System.Drawing.Drawing2D;
4namespace Netron.Diagramming.Core
5{
6  /// <summary>
7  /// A complex rectangular shape
8  /// </summary>
9   public partial class ComplexRectangle : ComplexShapeBase, IAdditionCallback
10  {
11        #region Fields
12
13        // ------------------------------------------------------------------
14        /// <summary>
15        /// Implementation of IVersion - the current version of
16        /// ComplexRectangle.
17        /// </summary>
18        // ------------------------------------------------------------------
19        protected const double complexRectangleVersion = 1.0;
20
21    /// <summary>
22    /// holds the bottom connector
23    /// </summary>
24    Connector cBottom, cLeft, cRight, cTop;
25    #endregion
26
27        #region Properties
28
29        // ------------------------------------------------------------------
30        /// <summary>
31        /// Gets the current version.
32        /// </summary>
33        // ------------------------------------------------------------------
34        public override double Version
35        {
36            get
37            {
38                return complexRectangleVersion;
39            }
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        {
48            get { return "Complex Rectangle"; }
49        }
50        #endregion
51
52    #region Constructor
53    /// <summary>
54    /// Default ctor
55    /// </summary>
56    /// <param name="s"></param>
57    public ComplexRectangle(IModel s) : base(s)
58    {
59    }
60        /// <summary>
61        /// Initializes a new instance of the <see cref="T:ComplexRectangle"/> class.
62        /// </summary>
63         public ComplexRectangle()
64             : base()
65         {
66         }
67
68         // -----------------------------------------------------------------
69         /// <summary>
70         /// Initializes this instance.
71         /// </summary>
72         // -----------------------------------------------------------------
73         protected override void Initialize()
74         {
75             base.Initialize();
76             cTop = new Connector(new Point((int)(Rectangle.Left + Rectangle.Width / 2), Rectangle.Top), Model);
77             cTop.Name = "Top connector";
78             cTop.Parent = this;
79             Connectors.Add(cTop);
80
81             cRight = new Connector(new Point(Rectangle.Right, (int)(Rectangle.Top + Rectangle.Height / 2)), Model);
82             cRight.Name = "Right connector";
83             cRight.Parent = this;
84             Connectors.Add(cRight);
85
86             cBottom = new Connector(new Point((int)(Rectangle.Left + Rectangle.Width / 2), Rectangle.Bottom), Model);
87             cBottom.Name = "Bottom connector";
88             cBottom.Parent = this;
89             Connectors.Add(cBottom);
90
91             cLeft = new Connector(new Point(Rectangle.Left, (int)(Rectangle.Top + Rectangle.Height / 2)), Model);
92             cLeft.Name = "Left connector";
93             cLeft.Parent = this;
94             Connectors.Add(cLeft);
95
96             #region Some examples of materials; feel free to add/remove what you wish
97             /*
98             ClickableIconMaterial cicon = new ClickableIconMaterial("Resources.Schema.ico");
99             cicon.Resizable = false;
100             cicon.Gliding = false;
101             cicon.Transform(new Rectangle(Rectangle.X + 10, Rectangle.Y + 10, 16, 16));
102             Children.Add(cicon);
103              */
104             /*
105             SwitchIconMaterial xicon = new SwitchIconMaterial(SwitchIconType.PlusMinus);
106             xicon.Gliding = false;
107             xicon.Resizable = false;
108             xicon.Transform(new Rectangle(Rectangle.X + 10, Rectangle.Y + 10, 16, 16));
109             Children.Add(xicon);
110             */
111             /*
112             IconLabelMaterial ilab = new IconLabelMaterial("Resources.PublicMethod.ico", "ISerializable.GetObjectData");
113             ilab.Gliding = false;
114             ilab.Resizable = false;
115             ilab.Transform(new Rectangle(Rectangle.X + 10, Rectangle.Y + 10, Rectangle.Width - 20, Rectangle.Height - 30));
116             Children.Add(ilab);
117             */
118             /*
119             IconMaterial icon = new IconMaterial("Resources.Web.png");
120             icon.Resizable = false;
121             icon.Gliding = false;
122             if(icon.Icon!=null)
123                icon.Transform(new Rectangle(Rectangle.X + 10, Rectangle.Y + 10, icon.Icon.Width , icon.Icon.Height));
124            Children.Add(icon);
125             */
126             /*
127             LabelMaterial label = new LabelMaterial();
128             label.Text = "Complex rectangle example";
129             label.Transform( new Rectangle(Rectangle.X + 10, Rectangle.Y + 10, Rectangle.Width - 20, Rectangle.Height-30));
130             this.Children.Add(label);
131              */
132
133             string[] stuff = new string[] {
134                 "Wagner",
135                 "van Beethoven",
136                 "Sibelius",
137                 "Lutovski",
138                 "Haydn",
139                 "Prokofiev",
140                 "Karduso" };
141
142             FolderMaterial folder = new FolderMaterial("Expand me!", stuff);
143             folder.Transform(
144                 new Rectangle(
145                 Rectangle.X + 10,
146                 Rectangle.Y + 10,
147                 Rectangle.Width - 20,
148                 Rectangle.Height - 30));
149
150             folder.OnFolderChanged +=
151                 new EventHandler<RectangleEventArgs>(folder_OnFolderChanged);
152             this.Children.Add(folder);
153
154             #endregion
155             Resizable = true;
156
157             Services[typeof(IAdditionCallback)] = this;
158         }
159
160         void folder_OnFolderChanged(object sender, RectangleEventArgs e)
161         {
162             Rectangle rec = e.Rectangle;
163             Transform(
164                 new Rectangle(
165                 Rectangle.Location,
166                 new Size(Rectangle.Width, rec.Height + 20)));
167         }
168    #endregion
169
170    #region Methods
171
172    /// <summary>
173    /// Paints the bundle on the canvas
174    /// </summary>
175    /// <param name="g"></param>
176    public override void Paint(System.Drawing.Graphics g)
177    {
178            /*
179            Matrix or = g.Transform;
180            Matrix m = new Matrix();
181            m.RotateAt(20, Rectangle.Location);           
182            g.MultiplyTransform(m, MatrixOrder.Append);
183             */
184      g.SmoothingMode = SmoothingMode.HighQuality;
185      //the shadow
186            if (ArtPalette.EnableShadows)
187            {
188                g.FillRectangle(
189                    ArtPalette.ShadowBrush,
190                    Rectangle.X + 5,
191                    Rectangle.Y + 5,
192                    Rectangle.Width,
193                    Rectangle.Height);
194            }
195      //the actual bundle
196      g.FillRectangle(Brush,Rectangle);
197      //the edge of the bundle
198      if(Hovered)
199        g.DrawRectangle(ArtPalette.HighlightPen,Rectangle);
200      else
201                g.DrawRectangle(ArtPalette.BlackPen, Rectangle);
202      //the connectors
203            if (this.ShowConnectors)
204            {
205                for (int k = 0; k < Connectors.Count; k++)
206                {
207                    Connectors[k].Paint(g);
208                }
209            }
210            foreach (IPaintable material in Children)
211            {
212                material.Paint(g);
213            }
214     
215   
216       
217        }
218
219        /// <summary>
220        /// Called when the shape is added to the canvas.
221        /// </summary>
222         public void OnAddition()
223         {
224             Transform(new Rectangle(Rectangle.Location, new Size(150, FolderMaterial.HeaderHeight + 20)));
225             //use a light color rather than the random low saturation color to show off the connection lines
226             PaintStyle = ArtPalette.GetDefaultSolidPaintStyle();
227
228              (PaintStyle as SolidPaintStyle).SolidColor= Color.WhiteSmoke;
229
230         }
231
232 
233
234 
235
236       
237    #endregion 
238               
239    }
240}
Note: See TracBrowser for help on using the repository browser.