Free cookie consent management tool by TermsFeed Policy Generator

source: tags/3.3.7/HeuristicLab.ExtLibs/HeuristicLab.Netron/3.0.2672.12446/Netron.Diagramming.Core-3.0.2672.12446/Diagram elements/Materials/SwitchIconMaterial.cs @ 8259

Last change on this file since 8259 was 4068, checked in by swagner, 14 years ago

Sorted usings and removed unused usings in entire solution (#1094)

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