1 | using System.Diagnostics;
|
---|
2 | using System.Collections.Generic;
|
---|
3 | using System.Text;
|
---|
4 | using System.Reflection;
|
---|
5 | using System;
|
---|
6 | using System.Data;
|
---|
7 | using System.Collections;
|
---|
8 | using System.ComponentModel;
|
---|
9 | using System.Drawing;
|
---|
10 | using System.Drawing.Design;
|
---|
11 | using System.Drawing.Drawing2D;
|
---|
12 | using Netron.Diagramming.Core;
|
---|
13 | using System.Windows.Forms;
|
---|
14 | using System.Runtime.Serialization;
|
---|
15 | using System.IO;
|
---|
16 |
|
---|
17 | namespace Netron.Diagramming.Core
|
---|
18 | {
|
---|
19 | public partial class SwitchIconMaterial : ClickableIconMaterial
|
---|
20 | {
|
---|
21 |
|
---|
22 | #region Events
|
---|
23 | /// <summary>
|
---|
24 | /// Occurs when the icon is switched into the 'collapsed' state.
|
---|
25 | /// </summary>
|
---|
26 | public event EventHandler OnCollapse;
|
---|
27 | /// <summary>
|
---|
28 | /// Occurs when the icon is switched into the 'expanded' state.
|
---|
29 | /// </summary>
|
---|
30 | public event EventHandler OnExpand;
|
---|
31 | #endregion
|
---|
32 |
|
---|
33 | #region Fields
|
---|
34 |
|
---|
35 | // ------------------------------------------------------------------
|
---|
36 | /// <summary>
|
---|
37 | /// Implementation of IVersion - the current version of
|
---|
38 | /// SwitchIconMaterial.
|
---|
39 | /// </summary>
|
---|
40 | // ------------------------------------------------------------------
|
---|
41 | protected double switchIconMaterialVersion = 1.0;
|
---|
42 |
|
---|
43 | // ------------------------------------------------------------------
|
---|
44 | /// <summary>
|
---|
45 | /// the 'down/expanded' icon
|
---|
46 | /// </summary>
|
---|
47 | // ------------------------------------------------------------------
|
---|
48 | private Bitmap downBmp;
|
---|
49 |
|
---|
50 | // ------------------------------------------------------------------
|
---|
51 | /// <summary>
|
---|
52 | /// the 'up/collapsed' icon
|
---|
53 | /// </summary>
|
---|
54 | // ------------------------------------------------------------------
|
---|
55 | private Bitmap upBmp;
|
---|
56 |
|
---|
57 | // ------------------------------------------------------------------
|
---|
58 | /// <summary>
|
---|
59 | /// the mCollapsed field
|
---|
60 | /// </summary>
|
---|
61 | // ------------------------------------------------------------------
|
---|
62 | private bool mCollapsed = true;
|
---|
63 |
|
---|
64 | // ------------------------------------------------------------------
|
---|
65 | /// <summary>
|
---|
66 | /// the current switch type
|
---|
67 | /// </summary>
|
---|
68 | // ------------------------------------------------------------------
|
---|
69 | private SwitchIconType mSwitchType;
|
---|
70 |
|
---|
71 | #endregion
|
---|
72 |
|
---|
73 | #region Properties
|
---|
74 |
|
---|
75 | // ------------------------------------------------------------------
|
---|
76 | /// <summary>
|
---|
77 | /// Gets the current version.
|
---|
78 | /// </summary>
|
---|
79 | // ------------------------------------------------------------------
|
---|
80 | public virtual double Version
|
---|
81 | {
|
---|
82 | get
|
---|
83 | {
|
---|
84 | return switchIconMaterialVersion;
|
---|
85 | }
|
---|
86 | }
|
---|
87 |
|
---|
88 | // ------------------------------------------------------------------
|
---|
89 | /// <summary>
|
---|
90 | /// Gets or sets the type of the switch.
|
---|
91 | /// </summary>
|
---|
92 | /// <value>The type of the switch.</value>
|
---|
93 | // ------------------------------------------------------------------
|
---|
94 | public SwitchIconType SwitchType
|
---|
95 | {
|
---|
96 | get
|
---|
97 | {
|
---|
98 | return mSwitchType;
|
---|
99 | }
|
---|
100 |
|
---|
101 | internal set
|
---|
102 | {
|
---|
103 | SwitchToType(value);
|
---|
104 | Collapsed = true;
|
---|
105 | mSwitchType = value;
|
---|
106 | }
|
---|
107 | }
|
---|
108 |
|
---|
109 | #endregion
|
---|
110 |
|
---|
111 | #region Constructor
|
---|
112 | /// <summary>
|
---|
113 | /// Initializes a new instance of the <see cref="SwitchIconMaterial"/> class.
|
---|
114 | /// </summary>
|
---|
115 | /// <param name="type">The type.</param>
|
---|
116 | public SwitchIconMaterial(SwitchIconType type)
|
---|
117 | : base()
|
---|
118 | {
|
---|
119 | Gliding = false;
|
---|
120 | mSwitchType = type;
|
---|
121 | //fetch the two bitmaps
|
---|
122 | try
|
---|
123 | {
|
---|
124 | SwitchToType(type);
|
---|
125 |
|
---|
126 | }
|
---|
127 | catch (Exception exc)
|
---|
128 | {
|
---|
129 | throw new InconsistencyException("The necessary resource could not be found.", exc);
|
---|
130 | }
|
---|
131 |
|
---|
132 | }
|
---|
133 | /// <summary>
|
---|
134 | /// Sets the switch to the given <see cref="SwitchIconType"/>
|
---|
135 | /// </summary>
|
---|
136 | /// <param name="type"></param>
|
---|
137 | private void SwitchToType(SwitchIconType type)
|
---|
138 | {
|
---|
139 | switch(type)
|
---|
140 | {
|
---|
141 | case SwitchIconType.UpDown:
|
---|
142 | downBmp = GetBitmap("Resources.down.ico");
|
---|
143 | upBmp = GetBitmap("Resources.up.ico");
|
---|
144 | this.Icon = downBmp;
|
---|
145 | break;
|
---|
146 | case SwitchIconType.PlusMinus:
|
---|
147 | downBmp = GetBitmap("Resources.plus.ico");
|
---|
148 | upBmp = GetBitmap("Resources.minus.ico");
|
---|
149 | this.Icon = downBmp;
|
---|
150 | break;
|
---|
151 | default:
|
---|
152 | break;
|
---|
153 | }
|
---|
154 | }
|
---|
155 | #endregion
|
---|
156 |
|
---|
157 | #region Methods
|
---|
158 | /// <summary>
|
---|
159 | /// Handles the mouse-down event.
|
---|
160 | /// </summary>
|
---|
161 | /// <param name="e">The <see cref="T:MouseEventArgs"/> instance containing the event data.</param>
|
---|
162 | /// <returns>Returns 'true' if the event was handled, otherwise 'false'.</returns>
|
---|
163 | public override bool MouseDown(MouseEventArgs e)
|
---|
164 | {
|
---|
165 | base.MouseDown(e);
|
---|
166 | if(e.Clicks == 1)
|
---|
167 | {
|
---|
168 | Collapsed = !Collapsed;
|
---|
169 | return true;
|
---|
170 | }
|
---|
171 | return false;
|
---|
172 | }
|
---|
173 |
|
---|
174 | /// <summary>
|
---|
175 | /// Gets or sets the Collapsed
|
---|
176 | /// </summary>
|
---|
177 | public bool Collapsed
|
---|
178 | {
|
---|
179 | get
|
---|
180 | {
|
---|
181 | return mCollapsed;
|
---|
182 | }
|
---|
183 | set
|
---|
184 | {
|
---|
185 | if(value)
|
---|
186 | {
|
---|
187 | this.Icon = downBmp;
|
---|
188 | RaiseOnCollapse();
|
---|
189 | }
|
---|
190 | else
|
---|
191 | {
|
---|
192 | this.Icon = upBmp;
|
---|
193 | RaiseOnExpand();
|
---|
194 | }
|
---|
195 |
|
---|
196 | mCollapsed = value;
|
---|
197 | }
|
---|
198 | }
|
---|
199 |
|
---|
200 |
|
---|
201 | /// <summary>
|
---|
202 | /// Raises the <see cref="OnExpand"/> event.
|
---|
203 | /// </summary>
|
---|
204 | private void RaiseOnExpand()
|
---|
205 | {
|
---|
206 | if(OnExpand != null)
|
---|
207 | OnExpand(this, EventArgs.Empty);
|
---|
208 | }
|
---|
209 | /// <summary>
|
---|
210 | /// Raises the <see cref="OnCollapse"/> event
|
---|
211 | /// </summary>
|
---|
212 | private void RaiseOnCollapse()
|
---|
213 | {
|
---|
214 | if(OnCollapse != null)
|
---|
215 | OnCollapse(this, EventArgs.Empty);
|
---|
216 | }
|
---|
217 | #endregion
|
---|
218 |
|
---|
219 | }
|
---|
220 |
|
---|
221 | // ----------------------------------------------------------------------
|
---|
222 | /// <summary>
|
---|
223 | /// The two type of bitmaps intrinsically defined by the
|
---|
224 | /// <see cref="SwitchIconMaterial"/>
|
---|
225 | /// </summary>
|
---|
226 | // ----------------------------------------------------------------------
|
---|
227 | public enum SwitchIconType
|
---|
228 | {
|
---|
229 | /// <summary>
|
---|
230 | /// The up/down arrows are displayed
|
---|
231 | /// </summary>
|
---|
232 | UpDown,
|
---|
233 | /// <summary>
|
---|
234 | /// The plus/minus icon are displayed
|
---|
235 | /// </summary>
|
---|
236 | PlusMinus
|
---|
237 | }
|
---|
238 | }
|
---|