Source Code Cross Referenced for LocaleSupport.java in  » Swing-Library » abeille-forms-designer » org » netbeans » editor » 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 » abeille forms designer » org.netbeans.editor 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *                 Sun Public License Notice
003:         * 
004:         * The contents of this file are subject to the Sun Public License
005:         * Version 1.0 (the "License"). You may not use this file except in
006:         * compliance with the License. A copy of the License is available at
007:         * http://www.sun.com/
008:         * 
009:         * The Original Code is NetBeans. The Initial Developer of the Original
010:         * Code is Sun Microsystems, Inc. Portions Copyright 1997-2000 Sun
011:         * Microsystems, Inc. All Rights Reserved.
012:         */
013:
014:        package org.netbeans.editor;
015:
016:        import java.util.ArrayList;
017:        import java.util.Arrays;
018:        import java.util.HashMap;
019:        import java.util.MissingResourceException;
020:
021:        /**
022:         * All the strings that should be localized will go through this place. Multiple
023:         * custom localizers can be registered. The strings already retrieved are cached
024:         * for the faster performance.
025:         * 
026:         * @author Miloslav Metelka
027:         * @version 1.00
028:         */
029:
030:        public class LocaleSupport {
031:
032:            private static final String NULL_STRING = new String();
033:
034:            /** Cache for the retrieved strings */
035:            private static final HashMap cache = new HashMap(503);
036:
037:            private static Localizer[] localizers = new Localizer[0];
038:
039:            /**
040:             * Add a new localizer to the localizer array. The array of localizers is
041:             * tracked from the lastly added localizer to the firstly added one until
042:             * the translation for the given key is found.
043:             * 
044:             * @param localizer
045:             *            localizer to add to the localizer array.
046:             */
047:            public static void addLocalizer(Localizer localizer) {
048:                ArrayList ll = new ArrayList(Arrays.asList(localizers));
049:                ll.add(localizer);
050:                Localizer[] la = new Localizer[ll.size()];
051:                ll.toArray(la);
052:                localizers = la;
053:
054:                cache.clear();
055:            }
056:
057:            /**
058:             * Remove the existing localizer from the localizer array.
059:             * 
060:             * @param localizer
061:             *            localizer to remove.
062:             */
063:            public static void removeLocalizer(Localizer localizer) {
064:                ArrayList ll = new ArrayList(Arrays.asList(localizers));
065:                ll.remove(localizer);
066:                Localizer[] la = new Localizer[ll.size()];
067:                ll.toArray(la);
068:                localizers = la;
069:
070:                cache.clear();
071:            }
072:
073:            /**
074:             * Get the localized string for the given key using the registered
075:             * localizers.
076:             * 
077:             * @param key
078:             *            key to translate to localized string.
079:             * @return localized string or null if there's no localization.
080:             */
081:            public static synchronized String getString(String key) {
082:                String ret = (String) cache.get(key);
083:                if (ret == null) {
084:                    for (int i = localizers.length - 1; i >= 0; i--) {
085:
086:                        // Try to find a return value
087:                        try {
088:                            ret = localizers[i].getString(key);
089:                        } catch (MissingResourceException e) { // localizers are often
090:                            // bundles
091:                            ret = null;
092:                        }
093:
094:                        if (ret != null) {
095:                            break;
096:                        }
097:                    }
098:
099:                    if (ret == null) {
100:                        ret = NULL_STRING;
101:                    }
102:                    cache.put(key, ret);
103:                }
104:
105:                return (ret != NULL_STRING) ? ret : null;
106:            }
107:
108:            /**
109:             * Get the localized string or the default value if no translation for the
110:             * given key exists.
111:             * 
112:             * @param key
113:             *            key to translate to localized string.
114:             * @param defaultValue
115:             *            default value to be returned in case no localized string is
116:             *            found for the given key.
117:             */
118:            public static String getString(String key, String defaultValue) {
119:                String ret = getString(key);
120:                return (ret != null) ? ret : defaultValue;
121:            }
122:
123:            /**
124:             * Get the localized character or the default value if no translation for
125:             * the given key exists. This method is mainly usable for getting localized
126:             * mnemonics.
127:             * 
128:             * @param key
129:             *            key to translate to localized character.
130:             * @param defaultValue
131:             *            default value to be returned in case no localized character is
132:             *            found for the given key.
133:             */
134:            public static char getChar(String key, char defaultValue) {
135:                String value = getString(key);
136:                if (value == null || value.length() < 1)
137:                    return defaultValue;
138:                return value.charAt(0);
139:            }
140:
141:            /**
142:             * Translates the keys to the localized strings. There can be multiple
143:             * localizers registered in the locale support.
144:             */
145:            public interface Localizer {
146:
147:                /**
148:                 * Translate the key to the localized string.
149:                 * 
150:                 * @param key
151:                 *            key to translate to the localized string.
152:                 */
153:                public String getString(String key);
154:
155:            }
156:
157:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.