2009-06-22 Marek Habersack <mhabersack@novell.com>
[mono.git] / mcs / class / System / System.ComponentModel / CategoryAttribute.cs
1 //
2 // System.ComponentModel.CategoryAttribute.cs
3 //
4 // Author:
5 //   Miguel de Icaza (miguel@ximian.com)
6 //   Andreas Nahr (ClassDevelopment@A-SoftTech.com)
7 //
8 // (C) Ximian, Inc.  http://www.ximian.com
9 // (C) 2003 Andreas Nahr
10 //
11 //
12
13 //
14 // Permission is hereby granted, free of charge, to any person obtaining
15 // a copy of this software and associated documentation files (the
16 // "Software"), to deal in the Software without restriction, including
17 // without limitation the rights to use, copy, modify, merge, publish,
18 // distribute, sublicense, and/or sell copies of the Software, and to
19 // permit persons to whom the Software is furnished to do so, subject to
20 // the following conditions:
21 // 
22 // The above copyright notice and this permission notice shall be
23 // included in all copies or substantial portions of the Software.
24 // 
25 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
26 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
27 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
28 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
29 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
30 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
31 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32 //
33
34 namespace System.ComponentModel {
35
36         [AttributeUsage (AttributeTargets.All)]
37         public class CategoryAttribute : Attribute
38         {
39                 private string category;
40                 private bool IsLocalized;
41
42                 static volatile CategoryAttribute action, appearance, behaviour, data,   def;
43                 static volatile CategoryAttribute design, drag_drop,  focus,     format, key;
44                 static volatile CategoryAttribute layout, mouse,      window_style;
45 #if NET_2_0
46                 static volatile CategoryAttribute async;
47 #endif
48
49                 static object lockobj = new object ();
50
51                 public CategoryAttribute ()
52                 {
53                         this.category = "Misc";
54                 }
55
56                 public CategoryAttribute (string category)
57                 {
58                         this.category = category;
59                 }
60
61
62                 public static CategoryAttribute Action {
63                         get {
64                                 if (action != null)
65                                         return action;
66
67                                 lock (lockobj) {
68                                         if (action == null)
69                                                 action = new CategoryAttribute ("Action");
70                                 }
71                                 return action;
72                         }
73                 }
74
75                 public static CategoryAttribute Appearance {
76                         get {
77                                 if (appearance != null)
78                                         return appearance;
79
80                                 lock (lockobj) {
81                                         if (appearance == null)
82                                                 appearance = new CategoryAttribute ("Appearance");
83                                 }
84                                 return appearance;
85                         }
86                 }
87
88 #if NET_2_0
89                 public static CategoryAttribute Asynchronous {
90                         get {
91                                 if (behaviour != null)
92                                         return behaviour;
93
94                                 lock (lockobj) {
95                                         if (async == null)
96                                                 async = new CategoryAttribute ("Asynchrinous");
97                                 }
98                                 return async;
99                         }
100                 }
101 #endif
102
103                 public static CategoryAttribute Behavior {
104                         get {
105                                 if (behaviour != null)
106                                         return behaviour;
107
108                                 lock (lockobj) {
109                                         if (behaviour == null)
110                                                 behaviour = new CategoryAttribute ("Behavior");
111                                 }
112                                 return behaviour;
113                         }
114                 }
115
116                 public static CategoryAttribute Data {
117                         get {
118                                 if (data != null)
119                                         return data;
120
121                                 lock (lockobj) {
122                                         if (data == null)
123                                                 data = new CategoryAttribute ("Data");
124                                 }
125                                 return data;
126                         }
127                 }
128
129                 public static CategoryAttribute Default {
130                         get {
131                                 if (def != null)
132                                         return def;
133
134                                 lock (lockobj) {
135                                         if (def == null)
136                                                 def = new CategoryAttribute ();
137                                 }
138                                 return def;
139                         }
140                 }
141
142                 public static CategoryAttribute Design {
143                         get {
144                                 if (design != null)
145                                         return design;
146
147                                 lock (lockobj) {
148                                         if (design == null)
149                                                 design = new CategoryAttribute ("Design");
150                                 }
151                                 return design;
152                         }
153                 }
154
155                 public static CategoryAttribute DragDrop {
156                         get {
157                                 if (drag_drop != null)
158                                         return drag_drop;
159
160                                 lock (lockobj) {
161                                         if (drag_drop == null)
162                                                 drag_drop = new CategoryAttribute ("Drag Drop");
163                                 }
164                                 return drag_drop;
165                         }
166                 }
167
168                 public static CategoryAttribute Focus {
169                         get {
170                                 if (focus != null)
171                                         return focus;
172
173                                 lock (lockobj) {
174                                         if (focus == null)
175                                                 focus = new CategoryAttribute ("Focus");
176                                 }
177                                 return focus;
178                         }
179                 }
180
181                 public static CategoryAttribute Format {
182                         get {
183                                 if (format != null)
184                                         return format;
185
186                                 lock (lockobj) {
187                                         if (format == null)
188                                                 format = new CategoryAttribute ("Format");
189                                 }
190                                 return format;
191                         }
192                 }
193
194                 public static CategoryAttribute Key {
195                         get {
196                                 if (key != null)
197                                         return key;
198
199                                 lock (lockobj) {
200                                         if (key == null)
201                                                 key = new CategoryAttribute ("Key");
202                                 }
203                                 return key;
204                         }
205                 }
206
207                 public static CategoryAttribute Layout {
208                         get {
209                                 if (layout != null)
210                                         return layout;
211
212                                 lock (lockobj) {
213                                         if (layout == null)
214                                                 layout = new CategoryAttribute ("Layout");
215                                 }
216                                 return layout;
217                         }
218                 }
219
220                 public static CategoryAttribute Mouse {
221                         get {
222                                 if (mouse != null)
223                                         return mouse;
224
225                                 lock (lockobj) {
226                                         if (mouse == null)
227                                                 mouse = new CategoryAttribute ("Mouse");
228                                 }
229                                 return mouse;
230                         }
231                 }
232
233                 public static CategoryAttribute WindowStyle {
234                         get {
235                                 if (window_style != null)
236                                         return window_style;
237
238                                 lock (lockobj) {
239                                         if (window_style == null)
240                                                 window_style = new CategoryAttribute ("Window Style");
241                                 }
242                                 return window_style;
243                         }
244                 }
245
246                 protected virtual string GetLocalizedString (string value)
247                 {
248                         return Locale.GetText (value);
249                 }
250
251                 public string Category {
252                         get {
253                                 if (IsLocalized == false) {
254                                         IsLocalized = true;
255                                         string LocalizedString = GetLocalizedString (category);
256                                         if (LocalizedString != null)
257                                                 category = LocalizedString;
258                                 }
259
260                                 return category;
261                         }
262                 }
263
264                 public override bool Equals (object obj)
265                 {
266                         if (!(obj is CategoryAttribute))
267                                 return false;
268                         if (obj == this)
269                                 return true;
270                         return ((CategoryAttribute) obj).Category == category;
271                 }
272
273                 public override int GetHashCode ()
274                 {
275                         return category.GetHashCode ();
276                 }
277
278                 public override bool IsDefaultAttribute ()
279                 {
280                         return category == CategoryAttribute.Default.Category;
281                 }
282         }
283 }
284