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