2 // System.Drawing.SystemIcons.cs
5 // Vladimir Krasnov (vladimirk@mainsoft.com)
7 // Copyright (C) 2005 Mainsoft Corporation (http://www.mainsoft.com)
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
33 using System.Configuration;
34 using System.Collections;
35 using System.Collections.Specialized;
37 namespace System.Drawing
39 public sealed class SystemIcons
41 private static readonly string SYSTEM_ICONS = "IconsResource";
47 public static Icon Application { get { return LoadIcon("Application");} }
48 public static Icon Asterisk { get { return LoadIcon("Asterisk");} }
49 public static Icon Error { get { return LoadIcon("Error");} }
50 public static Icon Exclamation { get { return LoadIcon("Exclamation");} }
51 public static Icon Hand { get { return LoadIcon("Hand");} }
52 public static Icon Information { get { return LoadIcon("Information");} }
53 public static Icon Question { get { return LoadIcon("Question");} }
54 public static Icon Warning { get { return LoadIcon("Warning");} }
55 public static Icon WinLogo { get { return LoadIcon("WinLogo");} }
57 private static Icon LoadIcon (string iconName)
59 Hashtable systemIcons = (Hashtable)AppDomain.CurrentDomain.GetData("SYSTEM_ICONS");
61 if (systemIcons == null)
63 systemIcons = LoadSystemIconsFromResource();
64 AppDomain.CurrentDomain.SetData(SYSTEM_ICONS, systemIcons);
67 return (Icon)systemIcons[iconName];
70 private static Hashtable LoadSystemIconsFromResource()
72 string [] iconNames = {
73 "Application", "Asterisk", "Error",
74 "Exclamation", "Hand", "Information",
75 "Question", "Warning", "WinLogo"
78 NameValueCollection config = (NameValueCollection) ConfigurationSettings.GetConfig ("system.drawing/icons");
79 Hashtable icons = new Hashtable(9);
81 for (int i = 0; i < iconNames.Length; i++)
82 icons.Add(iconNames[i], LoadIconFromResource( config[ iconNames[i] ] ));
87 private static Icon LoadIconFromResource(string iconName)
92 java.lang.ClassLoader cl = (java.lang.ClassLoader)
93 AppDomain.CurrentDomain.GetData("GH_ContextClassLoader");
96 java.io.InputStream inputStream = cl.getResourceAsStream(iconName);
97 s = (Stream)vmw.common.IOUtils.getStream(inputStream);
103 return new Icon(new Bitmap(s));