1 | using System;
|
---|
2 | using System.Collections.Generic;
|
---|
3 | using System.Text;
|
---|
4 | using System.Drawing;
|
---|
5 | using System.Drawing.Drawing2D;
|
---|
6 | using System.Drawing.Design;
|
---|
7 | using System.Runtime.Serialization;
|
---|
8 | using System.Xml.Serialization;
|
---|
9 | using System.Windows.Forms;
|
---|
10 |
|
---|
11 | namespace Netron.Diagramming.Core
|
---|
12 | {
|
---|
13 | /// <summary>
|
---|
14 | /// <para>
|
---|
15 | /// The ambient properties of the canvas (background style, default line
|
---|
16 | /// style etc) are collected in this class. The ambience class is part
|
---|
17 | /// of the model and is serialized together with the diagram.
|
---|
18 | /// </para>
|
---|
19 | /// </summary>
|
---|
20 | public partial class Ambience : IDisposable, IVersion
|
---|
21 | {
|
---|
22 | #region Events
|
---|
23 | /// <summary>
|
---|
24 | /// Occurs when the Ambience has changed
|
---|
25 | /// </summary>
|
---|
26 | public event EventHandler<AmbienceEventArgs> OnAmbienceChanged;
|
---|
27 | #endregion
|
---|
28 |
|
---|
29 | #region Fields
|
---|
30 |
|
---|
31 | // ------------------------------------------------------------------
|
---|
32 | /// <summary>
|
---|
33 | /// Implementation of IVersion - the current version of
|
---|
34 | /// Ambience.
|
---|
35 | /// </summary>
|
---|
36 | // ------------------------------------------------------------------
|
---|
37 | protected const double ambienceVersion = 1.0;
|
---|
38 |
|
---|
39 | // ------------------------------------------------------------------
|
---|
40 | /// <summary>
|
---|
41 | /// pointer to the model
|
---|
42 | /// </summary>
|
---|
43 | // ------------------------------------------------------------------
|
---|
44 | private IModel mModel;
|
---|
45 |
|
---|
46 | // ------------------------------------------------------------------
|
---|
47 | /// <summary>
|
---|
48 | /// the background type
|
---|
49 | /// </summary>
|
---|
50 | // ------------------------------------------------------------------
|
---|
51 | private CanvasBackgroundTypes mBackgroundType;
|
---|
52 |
|
---|
53 | // ------------------------------------------------------------------
|
---|
54 | /// <summary>
|
---|
55 | /// the GradientColor1 field
|
---|
56 | /// </summary>
|
---|
57 | // ------------------------------------------------------------------
|
---|
58 | private Color mGradientColor1;
|
---|
59 |
|
---|
60 | /// <summary>
|
---|
61 | /// the GradientColor2 field
|
---|
62 | /// </summary>
|
---|
63 | private Color mGradientColor2;
|
---|
64 |
|
---|
65 | // ------------------------------------------------------------------
|
---|
66 | /// <summary>
|
---|
67 | /// the BackgroundColor field
|
---|
68 | /// </summary>
|
---|
69 | // ------------------------------------------------------------------
|
---|
70 | private Color mBackgroundColor;
|
---|
71 |
|
---|
72 | // ------------------------------------------------------------------
|
---|
73 | /// <summary>
|
---|
74 | /// The color of the page.
|
---|
75 | /// </summary>
|
---|
76 | // ------------------------------------------------------------------
|
---|
77 | private Color mPageColor;
|
---|
78 |
|
---|
79 | // ------------------------------------------------------------------
|
---|
80 | /// <summary>
|
---|
81 | /// The starting gradient color for the page.
|
---|
82 | /// </summary>
|
---|
83 | // ------------------------------------------------------------------
|
---|
84 | private Color mPageGradientColor1;
|
---|
85 |
|
---|
86 | // ------------------------------------------------------------------
|
---|
87 | /// <summary>
|
---|
88 | /// The ending gradient color for the page.
|
---|
89 | /// </summary>
|
---|
90 | // ------------------------------------------------------------------
|
---|
91 | private Color mPageGradientColor2;
|
---|
92 |
|
---|
93 | // ------------------------------------------------------------------
|
---|
94 | /// <summary>
|
---|
95 | /// The background type of the page.
|
---|
96 | /// </summary>
|
---|
97 | // ------------------------------------------------------------------
|
---|
98 | private CanvasBackgroundTypes mPageBackgroundType =
|
---|
99 | CanvasBackgroundTypes.FlatColor;
|
---|
100 |
|
---|
101 | // ------------------------------------------------------------------
|
---|
102 | /// <summary>
|
---|
103 | /// Specifies if the page is rendered in landscape orientation.
|
---|
104 | /// </summary>
|
---|
105 | // ------------------------------------------------------------------
|
---|
106 | private bool mLandscape = true;
|
---|
107 |
|
---|
108 | // ------------------------------------------------------------------
|
---|
109 | /// <summary>
|
---|
110 | /// The size of the page in mils (thousandths of an inch).
|
---|
111 | /// </summary>
|
---|
112 | // ------------------------------------------------------------------
|
---|
113 | private Size mPageSize = new Size(8500, 11000);
|
---|
114 |
|
---|
115 | // ------------------------------------------------------------------
|
---|
116 | /// <summary>
|
---|
117 | /// The title of the page.
|
---|
118 | /// </summary>
|
---|
119 | // ------------------------------------------------------------------
|
---|
120 | private string mTitle = "Default page: no title.";
|
---|
121 |
|
---|
122 | // ------------------------------------------------------------------
|
---|
123 | /// <summary>
|
---|
124 | /// the Page field
|
---|
125 | /// </summary>
|
---|
126 | // ------------------------------------------------------------------
|
---|
127 | private IPage mPage;
|
---|
128 |
|
---|
129 | #endregion
|
---|
130 |
|
---|
131 | #region Properties
|
---|
132 |
|
---|
133 | // ------------------------------------------------------------------
|
---|
134 | /// <summary>
|
---|
135 | /// Gets the current version.
|
---|
136 | /// </summary>
|
---|
137 | // ------------------------------------------------------------------
|
---|
138 | public virtual double Version
|
---|
139 | {
|
---|
140 | get
|
---|
141 | {
|
---|
142 | return ambienceVersion;
|
---|
143 | }
|
---|
144 | }
|
---|
145 |
|
---|
146 | // ------------------------------------------------------------------
|
---|
147 | /// <summary>
|
---|
148 | /// Gets or sets the title of the page.
|
---|
149 | /// </summary>
|
---|
150 | /// <value>The title.</value>
|
---|
151 | // ------------------------------------------------------------------
|
---|
152 | public string Title
|
---|
153 | {
|
---|
154 | get { return mTitle; }
|
---|
155 | set { mTitle = value; }
|
---|
156 | }
|
---|
157 |
|
---|
158 | // ------------------------------------------------------------------
|
---|
159 | /// <summary>
|
---|
160 | /// Gets or sets the size of the page in mils (thousandths of an inch).
|
---|
161 | /// The default is letter 8.5" x 11".
|
---|
162 | /// </summary>
|
---|
163 | /// <value>The size of the page.</value>
|
---|
164 | // ------------------------------------------------------------------
|
---|
165 | public Size PageSize
|
---|
166 | {
|
---|
167 | get { return mPageSize; }
|
---|
168 | set { mPageSize = value; }
|
---|
169 | }
|
---|
170 |
|
---|
171 | // ------------------------------------------------------------------
|
---|
172 | /// <summary>
|
---|
173 | /// Gets or sets the Page to which this ambience belongs
|
---|
174 | /// </summary>
|
---|
175 | // ------------------------------------------------------------------
|
---|
176 | public IPage Page
|
---|
177 | {
|
---|
178 | get
|
---|
179 | {
|
---|
180 | return mPage;
|
---|
181 | }
|
---|
182 | set
|
---|
183 | {
|
---|
184 | mPage = value;
|
---|
185 | }
|
---|
186 | }
|
---|
187 |
|
---|
188 | // ------------------------------------------------------------------
|
---|
189 | /// <summary>
|
---|
190 | /// Gets or sets if the page is rendered and printed in landscape
|
---|
191 | /// orientation.
|
---|
192 | /// </summary>
|
---|
193 | // ------------------------------------------------------------------
|
---|
194 | public bool Landscape
|
---|
195 | {
|
---|
196 | get
|
---|
197 | {
|
---|
198 | return mLandscape;
|
---|
199 | }
|
---|
200 | set
|
---|
201 | {
|
---|
202 | mLandscape = value;
|
---|
203 | }
|
---|
204 | }
|
---|
205 |
|
---|
206 | // ------------------------------------------------------------------
|
---|
207 | /// <summary>
|
---|
208 | /// Gets or sets the type of the background.
|
---|
209 | /// </summary>
|
---|
210 | /// <value>The type of the background.</value>
|
---|
211 | // ------------------------------------------------------------------
|
---|
212 | public CanvasBackgroundTypes BackgroundType
|
---|
213 | {
|
---|
214 | get { return this.mBackgroundType; }
|
---|
215 | set
|
---|
216 | {
|
---|
217 | this.mBackgroundType = value;
|
---|
218 | RaiseOnAmbienceChanged();
|
---|
219 | }
|
---|
220 | }
|
---|
221 |
|
---|
222 | // ------------------------------------------------------------------
|
---|
223 | /// <summary>
|
---|
224 | /// Gets or sets the type of the background for the page portion.
|
---|
225 | /// </summary>
|
---|
226 | /// <value>The type of the background.</value>
|
---|
227 | // ------------------------------------------------------------------
|
---|
228 | public CanvasBackgroundTypes PageBackgroundType
|
---|
229 | {
|
---|
230 | get { return this.mPageBackgroundType; }
|
---|
231 | set
|
---|
232 | {
|
---|
233 | this.mPageBackgroundType = value;
|
---|
234 | RaiseOnAmbienceChanged();
|
---|
235 | }
|
---|
236 | }
|
---|
237 |
|
---|
238 | // ------------------------------------------------------------------
|
---|
239 | /// <summary>
|
---|
240 | /// Gets or sets the first gradient color for the background.
|
---|
241 | /// </summary>
|
---|
242 | /// <value>The first gradient color.</value>
|
---|
243 | // ------------------------------------------------------------------
|
---|
244 | public Color BackgroundGradientColor1
|
---|
245 | {
|
---|
246 | get { return mGradientColor1; }
|
---|
247 | set
|
---|
248 | {
|
---|
249 | mGradientColor1 = value;
|
---|
250 | RaiseOnAmbienceChanged();
|
---|
251 | }
|
---|
252 | }
|
---|
253 |
|
---|
254 | // ------------------------------------------------------------------
|
---|
255 | /// <summary>
|
---|
256 | /// Gets or sets the second gradient color
|
---|
257 | /// </summary>
|
---|
258 | /// <value>The second gradient color.</value>
|
---|
259 | // ------------------------------------------------------------------
|
---|
260 | public Color BackgroundGradientColor2
|
---|
261 | {
|
---|
262 | get { return mGradientColor2; }
|
---|
263 | set
|
---|
264 | {
|
---|
265 | mGradientColor2 = value;
|
---|
266 | RaiseOnAmbienceChanged();
|
---|
267 | }
|
---|
268 | }
|
---|
269 |
|
---|
270 | // ------------------------------------------------------------------
|
---|
271 | /// <summary>
|
---|
272 | /// Gets or sets the BackgroundColor
|
---|
273 | /// </summary>
|
---|
274 | /// <value>The color of the background.</value>
|
---|
275 | // ------------------------------------------------------------------
|
---|
276 | public Color BackgroundColor
|
---|
277 | {
|
---|
278 | get { return mBackgroundColor; }
|
---|
279 | set
|
---|
280 | {
|
---|
281 | mBackgroundColor = value;
|
---|
282 | //notify the world that things have changed
|
---|
283 | RaiseOnAmbienceChanged();
|
---|
284 |
|
---|
285 | }
|
---|
286 | }
|
---|
287 |
|
---|
288 | // ------------------------------------------------------------------
|
---|
289 | /// <summary>
|
---|
290 | /// Gets or sets the first gradient color for the background.
|
---|
291 | /// </summary>
|
---|
292 | /// <value>The first gradient color.</value>
|
---|
293 | // ------------------------------------------------------------------
|
---|
294 | public Color PageGradientColor1
|
---|
295 | {
|
---|
296 | get { return mPageGradientColor1; }
|
---|
297 | set
|
---|
298 | {
|
---|
299 | mPageGradientColor1 = value;
|
---|
300 | RaiseOnAmbienceChanged();
|
---|
301 | }
|
---|
302 | }
|
---|
303 |
|
---|
304 | // ------------------------------------------------------------------
|
---|
305 | /// <summary>
|
---|
306 | /// Gets or sets the second gradient color
|
---|
307 | /// </summary>
|
---|
308 | /// <value>The second gradient color.</value>
|
---|
309 | // ------------------------------------------------------------------
|
---|
310 | public Color PageGradientColor2
|
---|
311 | {
|
---|
312 | get { return mPageGradientColor2; }
|
---|
313 | set
|
---|
314 | {
|
---|
315 | mPageGradientColor2 = value;
|
---|
316 | RaiseOnAmbienceChanged();
|
---|
317 | }
|
---|
318 | }
|
---|
319 |
|
---|
320 | // ------------------------------------------------------------------
|
---|
321 | /// <summary>
|
---|
322 | /// Gets or sets the BackgroundColor
|
---|
323 | /// </summary>
|
---|
324 | /// <value>The color of the background.</value>
|
---|
325 | // ------------------------------------------------------------------
|
---|
326 | public Color PageColor
|
---|
327 | {
|
---|
328 | get { return mPageColor; }
|
---|
329 | set
|
---|
330 | {
|
---|
331 | mPageColor = value;
|
---|
332 | //notify the world that things have changed
|
---|
333 | RaiseOnAmbienceChanged();
|
---|
334 |
|
---|
335 | }
|
---|
336 | }
|
---|
337 |
|
---|
338 | // ------------------------------------------------------------------
|
---|
339 | /// <summary>
|
---|
340 | /// Gets the model.
|
---|
341 | /// </summary>
|
---|
342 | /// <value>The model.</value>
|
---|
343 | // ------------------------------------------------------------------
|
---|
344 | public IModel Model
|
---|
345 | {
|
---|
346 | get
|
---|
347 | {
|
---|
348 | return mModel;
|
---|
349 | }
|
---|
350 | internal set
|
---|
351 | {
|
---|
352 | mModel = value;
|
---|
353 | }
|
---|
354 | }
|
---|
355 |
|
---|
356 | #endregion
|
---|
357 |
|
---|
358 | #region Constructor
|
---|
359 |
|
---|
360 | // ------------------------------------------------------------------
|
---|
361 | /// <summary>
|
---|
362 | /// Default constructor
|
---|
363 | /// </summary>
|
---|
364 | /// <param name="page">The page.</param>
|
---|
365 | // ------------------------------------------------------------------
|
---|
366 | public Ambience(IPage page)
|
---|
367 | {
|
---|
368 | if (page == null)
|
---|
369 | throw new ArgumentNullException(
|
---|
370 | "The page paramter cannot be 'null'");
|
---|
371 | if (page.Model == null)
|
---|
372 | throw new ArgumentNullException("The Model is 'null'");
|
---|
373 |
|
---|
374 | //set default ambience
|
---|
375 | //mBackgroundColor = Color.FromArgb(116, 118, 124);
|
---|
376 | mBackgroundColor = ArtPalette.DefaultPageBackgroundColor;
|
---|
377 | mBackgroundType = CanvasBackgroundTypes.FlatColor;
|
---|
378 | mGradientColor1 = Color.WhiteSmoke;
|
---|
379 | mGradientColor2 = Color.LightSlateGray;
|
---|
380 | mPageBackgroundType = CanvasBackgroundTypes.FlatColor;
|
---|
381 | mPageColor = ArtPalette.DefaultPageColor;
|
---|
382 | mPageGradientColor1 = Color.WhiteSmoke;
|
---|
383 | mPageGradientColor2 = Color.Silver;
|
---|
384 | mModel = page.Model;
|
---|
385 | }
|
---|
386 |
|
---|
387 | #endregion
|
---|
388 |
|
---|
389 | #region Methods
|
---|
390 |
|
---|
391 | /// <summary>
|
---|
392 | /// Raises the <see cref="OnAmbienceChanged"/> event
|
---|
393 | /// </summary>
|
---|
394 | protected virtual void RaiseOnAmbienceChanged()
|
---|
395 | {
|
---|
396 | EventHandler<AmbienceEventArgs> handler = OnAmbienceChanged;
|
---|
397 | if (handler != null)
|
---|
398 | {
|
---|
399 | handler(this, new AmbienceEventArgs(this));
|
---|
400 | }
|
---|
401 | }
|
---|
402 |
|
---|
403 | #endregion
|
---|
404 |
|
---|
405 | #region Standard IDispose implementation
|
---|
406 | /// <summary>
|
---|
407 | /// Disposes the view
|
---|
408 | /// </summary>
|
---|
409 | public void Dispose()
|
---|
410 | {
|
---|
411 | Dispose(true);
|
---|
412 | GC.SuppressFinalize(this);
|
---|
413 |
|
---|
414 |
|
---|
415 | }
|
---|
416 | /// <summary>
|
---|
417 | /// Part of the dispose implementation
|
---|
418 | /// </summary>
|
---|
419 | /// <param name="disposing">if set to <c>true</c> disposing.</param>
|
---|
420 | protected virtual void Dispose(bool disposing)
|
---|
421 | {
|
---|
422 | if (disposing)
|
---|
423 | {
|
---|
424 | #region free managed resources
|
---|
425 |
|
---|
426 | #endregion
|
---|
427 | }
|
---|
428 |
|
---|
429 | }
|
---|
430 |
|
---|
431 | #endregion
|
---|
432 | }
|
---|
433 | }
|
---|