Source Code Cross Referenced for ResourceBundleUtil.java in  » Swing-Library » substance-look-feel » contrib » ch » randelshofer » quaqua » util » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Swing Library » substance look feel » contrib.ch.randelshofer.quaqua.util 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * @(#)ResourceBundleUtil.java  1.3.3  2005-11-07
003:         *
004:         * Copyright (c) 2000-2005 Werner Randelshofer
005:         * Staldenmattweg 2, CH-6405 Immensee, Switzerland
006:         * All rights reserved.
007:         *
008:         * This software is the confidential and proprietary information of
009:         * Werner Randelshofer. ("Confidential Information").  You shall not
010:         * disclose such Confidential Information and shall use it only in
011:         * accordance with the terms of the license agreement you entered into
012:         * with Werner Randelshofer.
013:         */
014:        package contrib.ch.randelshofer.quaqua.util;
015:
016:        import java.util.*;
017:        import javax.swing.KeyStroke;
018:        import javax.swing.UIManager;
019:        import javax.swing.ImageIcon;
020:        import java.text.MessageFormat;
021:        import java.net.URL;
022:
023:        /**
024:         * This is a convenience wrapper for accessing resources stored in a ResourceBundle.
025:         *
026:         * @author  Werner Randelshofer, Staldenmattweg 2, CH-6405 Immensee, Switzerland
027:         * @version 1,3.3 2005-11-07 Method getLocale added.
028:         * <br>1.3.2 2004-05-02 Method getLAFBundle without Locale as parameter
029:         * added.
030:         * <br>1.3.1 2002-07-30 Method getLAFBundle now takes a Locale as
031:         * an additional parameter.
032:         * <br>1.3 2001-10-10   The default resource name changed from 'name_Metal'
033:         *                            to 'name'.
034:         * <br>      1.2 2001-07-23   Adaptation to JDK 1.3 in progress.
035:         * <br>      1.0 2000-06-10   Created.
036:         */
037:        public class ResourceBundleUtil {
038:            /** The wrapped resource bundle. */
039:            private ResourceBundle resource;
040:
041:            /**
042:             * Creates a new ResouceBundleUtil which wraps
043:             * the provided resource bundle.
044:             */
045:            public ResourceBundleUtil(ResourceBundle r) {
046:                resource = r;
047:            }
048:
049:            /**
050:             * Get a String from the ResourceBundle.
051:             * <br>Convenience method to save casting.
052:             *
053:             * @param key The key of the property.
054:             * @return The value of the property. Returns the key
055:             *          if the property is missing.
056:             */
057:            public String getString(String key) {
058:                try {
059:                    return resource.getString(key);
060:                } catch (MissingResourceException e) {
061:                    return '-' + key + '-';
062:                }
063:            }
064:
065:            /**
066:             * Get an image icon from the ResourceBundle.
067:             * <br>Convenience method .
068:             *
069:             * @param key The key of the property.
070:             * @return The value of the property. Returns null
071:             *          if the property is missing.
072:             */
073:            public ImageIcon getImageIcon(String key, Class baseClass) {
074:                try {
075:                    String rsrcName = resource.getString(key);
076:                    if (rsrcName.equals("")) {
077:                        return null;
078:                    }
079:                    URL url = baseClass.getResource(rsrcName);
080:                    return (url == null) ? null : new ImageIcon(url);
081:                } catch (MissingResourceException e) {
082:                    return null;
083:                }
084:            }
085:
086:            /**
087:             * Get a Mnemonic from the ResourceBundle.
088:             * <br>Convenience method.
089:             *
090:             * @param key The key of the property.
091:             * @return The first char of the value of the property.
092:             *          Returns '\0' if the property is missing.
093:             */
094:            public char getMnemonic(String key) {
095:                String s = resource.getString(key);
096:                return (s == null || s.length() == 0) ? '\0' : s.charAt(0);
097:            }
098:
099:            /**
100:             * Get a Mnemonic from the ResourceBundle.
101:             * <br>Convenience method.
102:             *
103:             * @param key The key of the property. This method appends "Mnem" to the key.
104:             * @return The first char of the value of the property.
105:             *          Returns '\0' if the property is missing.
106:             */
107:            public char getMnem(String key) {
108:                String s = resource.getString(key + "Mnem");
109:                return (s == null || s.length() == 0) ? '\0' : s.charAt(0);
110:            }
111:
112:            /**
113:             * Get a KeyStroke from the ResourceBundle.
114:             * <BR>Convenience method.
115:             *
116:             * @param key The key of the property.
117:             * @return <code>javax.swing.KeyStroke.getKeyStroke(value)</code>.
118:             *          Returns null if the property is missing.
119:             */
120:            public KeyStroke getKeyStroke(String key) {
121:                KeyStroke ks = null;
122:                try {
123:                    String s = resource.getString(key);
124:                    ks = (s == null) ? (KeyStroke) null : KeyStroke
125:                            .getKeyStroke(s);
126:                } catch (NoSuchElementException e) {
127:                }
128:                return ks;
129:            }
130:
131:            /**
132:             * Get a KeyStroke from the ResourceBundle.
133:             * <BR>Convenience method.
134:             *
135:             * @param key The key of the property. This method adds "Acc" to the key.
136:             * @return <code>javax.swing.KeyStroke.getKeyStroke(value)</code>.
137:             *          Returns null if the property is missing.
138:             */
139:            public KeyStroke getAcc(String key) {
140:                KeyStroke ks = null;
141:                try {
142:                    String s = resource.getString(key + "Acc");
143:                    ks = (s == null) ? (KeyStroke) null : KeyStroke
144:                            .getKeyStroke(s);
145:                } catch (NoSuchElementException e) {
146:                }
147:                return ks;
148:            }
149:
150:            public String getFormatted(String key, Object argument) {
151:                return MessageFormat.format(resource.getString(key),
152:                        new Object[] { argument });
153:            }
154:
155:            public String getFormatted(String key, Object[] arguments) {
156:                return MessageFormat.format(resource.getString(key), arguments);
157:            }
158:
159:            public Locale getLocale() {
160:                return resource.getLocale();
161:            }
162:
163:            /**
164:             * Get the appropriate ResourceBundle subclass.
165:             *
166:             * @see java.util.ResourceBundle
167:             */
168:            public static ResourceBundleUtil getBundle(String baseName)
169:                    throws MissingResourceException {
170:                return new ResourceBundleUtil(ResourceBundle.getBundle(
171:                        baseName, Locale.getDefault()));
172:            }
173:
174:            /**
175:             * Get the appropriate ResourceBundle subclass.
176:             * The baseName is extended by the Swing Look and Feel ID
177:             * and by the Locale code returned by Locale.getDefault().
178:             *
179:             * The default Look and Feel ID is Metal.
180:             *
181:             * @see java.util.ResourceBundle
182:             */
183:            public static ResourceBundleUtil getLAFBundle(String baseName)
184:                    throws MissingResourceException {
185:                return getLAFBundle(baseName, Locale.getDefault());
186:            }
187:
188:            /**
189:             * Get the appropriate ResourceBundle subclass.
190:             * The baseName is extended by the Swing Look and Feel ID
191:             * and by the Locale code.
192:             *
193:             * The default Look and Feel ID is Metal.
194:             *
195:             * @see java.util.ResourceBundle
196:             */
197:            public static ResourceBundleUtil getLAFBundle(String baseName,
198:                    Locale locale) throws MissingResourceException {
199:                ResourceBundleUtil r;
200:                try {
201:                    r = new ResourceBundleUtil(ResourceBundle
202:                            .getBundle(baseName + "_"
203:                                    + UIManager.getLookAndFeel().getID(),
204:                                    locale));
205:                } catch (MissingResourceException e) {
206:                    r = new ResourceBundleUtil(ResourceBundle.getBundle(
207:                            baseName, locale));
208:                }
209:                return r;
210:            }
211:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.