In Test/System.ComponentModel:
[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
46                 static object lockobj = new object ();
47
48                 public CategoryAttribute ()
49                 {
50                         this.category = "Misc";
51                 }
52
53                 public CategoryAttribute (string category)
54                 {
55                         this.category = category;
56                 }
57
58
59                 public static CategoryAttribute Action {
60                         get {
61                                 if (action != null)
62                                         return action;
63
64                                 lock (lockobj) {
65                                         if (action == null)
66                                                 action = new CategoryAttribute ("Action");
67                                 }
68                                 return action;
69                         }
70                 }
71
72                 public static CategoryAttribute Appearance {
73                         get {
74                                 if (appearance != null)
75                                         return appearance;
76
77                                 lock (lockobj) {
78                                         if (appearance == null)
79                                                 appearance = new CategoryAttribute ("Appearance");
80                                 }
81                                 return appearance;
82                         }
83                 }
84
85                 public static CategoryAttribute Behavior {
86                         get {
87                                 if (behaviour != null)
88                                         return behaviour;
89
90                                 lock (lockobj) {
91                                         if (behaviour == null)
92                                                 behaviour = new CategoryAttribute ("Behavior");
93                                 }
94                                 return behaviour;
95                         }
96                 }
97
98                 public static CategoryAttribute Data {
99                         get {
100                                 if (data != null)
101                                         return data;
102
103                                 lock (lockobj) {
104                                         if (data == null)
105                                                 data = new CategoryAttribute ("Data");
106                                 }
107                                 return data;
108                         }
109                 }
110
111                 public static CategoryAttribute Default {
112                         get {
113                                 if (def != null)
114                                         return def;
115
116                                 lock (lockobj) {
117                                         if (def == null)
118                                                 def = new CategoryAttribute ();
119                                 }
120                                 return def;
121                         }
122                 }
123
124                 public static CategoryAttribute Design {
125                         get {
126                                 if (design != null)
127                                         return design;
128
129                                 lock (lockobj) {
130                                         if (design == null)
131                                                 design = new CategoryAttribute ("Design");
132                                 }
133                                 return design;
134                         }
135                 }
136
137                 public static CategoryAttribute DragDrop {
138                         get {
139                                 if (drag_drop != null)
140                                         return drag_drop;
141
142                                 lock (lockobj) {
143                                         if (drag_drop == null)
144                                                 drag_drop = new CategoryAttribute ("Drag Drop");
145                                 }
146                                 return drag_drop;
147                         }
148                 }
149
150                 public static CategoryAttribute Focus {
151                         get {
152                                 if (focus != null)
153                                         return focus;
154
155                                 lock (lockobj) {
156                                         if (focus == null)
157                                                 focus = new CategoryAttribute ("Focus");
158                                 }
159                                 return focus;
160                         }
161                 }
162
163                 public static CategoryAttribute Format {
164                         get {
165                                 if (format != null)
166                                         return format;
167
168                                 lock (lockobj) {
169                                         if (format == null)
170                                                 format = new CategoryAttribute ("Format");
171                                 }
172                                 return format;
173                         }
174                 }
175
176                 public static CategoryAttribute Key {
177                         get {
178                                 if (key != null)
179                                         return key;
180
181                                 lock (lockobj) {
182                                         if (key == null)
183                                                 key = new CategoryAttribute ("Key");
184                                 }
185                                 return key;
186                         }
187                 }
188
189                 public static CategoryAttribute Layout {
190                         get {
191                                 if (layout != null)
192                                         return layout;
193
194                                 lock (lockobj) {
195                                         if (layout == null)
196                                                 layout = new CategoryAttribute ("Layout");
197                                 }
198                                 return layout;
199                         }
200                 }
201
202                 public static CategoryAttribute Mouse {
203                         get {
204                                 if (mouse != null)
205                                         return mouse;
206
207                                 lock (lockobj) {
208                                         if (mouse == null)
209                                                 mouse = new CategoryAttribute ("Mouse");
210                                 }
211                                 return mouse;
212                         }
213                 }
214
215                 public static CategoryAttribute WindowStyle {
216                         get {
217                                 if (window_style != null)
218                                         return window_style;
219
220                                 lock (lockobj) {
221                                         if (window_style == null)
222                                                 window_style = new CategoryAttribute ("Window Style");
223                                 }
224                                 return window_style;
225                         }
226                 }
227
228                 protected virtual string GetLocalizedString (string value)
229                 {
230                         return Locale.GetText (value);
231                 }
232
233                 public string Category {
234                         get {
235                                 if (IsLocalized == false) {
236                                         IsLocalized = true;
237                                         string LocalizedString = GetLocalizedString (category);
238                                         if (LocalizedString != null)
239                                                 category = LocalizedString;
240                                 }
241
242                                 return category;
243                         }
244                 }
245
246                 public override bool Equals (object obj)
247                 {
248                         if (!(obj is CategoryAttribute))
249                                 return false;
250                         if (obj == this)
251                                 return true;
252                         return ((CategoryAttribute) obj).Category == category;
253                 }
254
255                 public override int GetHashCode ()
256                 {
257                         return category.GetHashCode ();
258                 }
259
260                 public override bool IsDefaultAttribute ()
261                 {
262                         return category == CategoryAttribute.Default.Category;
263                 }
264         }
265 }
266