Source Code Cross Referenced for I18N.java in  » GIS » openjump » com » vividsolutions » jump » 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 » GIS » openjump » com.vividsolutions.jump 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * The Unified Mapping Platform (JUMP) is an extensible, interactive GUI 
003:         * for visualizing and manipulating spatial features with geometry and attributes.
004:         *
005:         * Copyright (C) 2003 Vivid Solutions
006:         * 
007:         * This program is free software; you can redistribute it and/or
008:         * modify it under the terms of the GNU General Public License
009:         * as published by the Free Software Foundation; either version 2
010:         * of the License, or (at your option) any later version.
011:         * 
012:         * This program is distributed in the hope that it will be useful,
013:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
014:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
015:         * GNU General Public License for more details.
016:         * 
017:         * You should have received a copy of the GNU General Public License
018:         * along with this program; if not, write to the Free Software
019:         * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
020:         * 
021:         * For more information, contact:
022:         *
023:         * Vivid Solutions
024:         * Suite #1A
025:         * 2328 Government Street
026:         * Victoria BC  V8T 5G5
027:         * Canada
028:         *
029:         * (250)385-6040
030:         * www.vividsolutions.com
031:         */
032:        package com.vividsolutions.jump;
033:
034:        import java.text.MessageFormat;
035:        import java.util.Hashtable;
036:        import java.util.ResourceBundle;
037:        import java.util.Locale;
038:
039:        import com.vividsolutions.jump.workbench.JUMPWorkbench;
040:
041:        import org.apache.log4j.Logger;
042:
043:        /**
044:         * Singleton for the Internationalization (I18N)
045:         * <pre>
046:         * [1] HOWTO TRANSLATE JUMP IN MY OWN LANGUAGE
047:         *  Copy theses files and add the locales extension for your language and country instead of the *.
048:         *  - resources/jump_*.properties
049:         *  - com/vividsolutions/jump/workbench/ui/plugin/KeyboardPlugIn_*.html
050:         *
051:         * [2] HOWTO TRANSLATE MY PLUGIN AND GIVE THE ABILITY TO TRANSLATE IT
052:         *  Use theses methods to use your own *.properties files :
053:         *  [Michael Michaud 2007-03-23] the 3 following methods have been deactivated
054:         *  com.vividsolutions.jump.I18N#setPlugInRessource(String, String)
055:         *  com.vividsolutions.jump.I18N#get(String, String)
056:         *  com.vividsolutions.jump.I18N#getMessage(String, String, Object[])
057:         *  you still can use plugInsResourceBundle (as in Pirol's plugin)
058:         *  
059:         *  And use jump standard menus
060:         *  </pre>
061:         *
062:         * Code example : [Michael Michaud 2007-03-23 : the following code example
063:         * is no more valid and has to be changed]
064:         * 
065:         * <pre>
066:         * public class PrintPlugIn extends AbstractPlugIn
067:         *  {
068:         *    private String name = "print";
069:         *
070:         * public void initialize(PlugInContext context) throws Exception
071:         * {
072:         *   I18N.setPlugInRessource(name, "org.agil.core.jump.plugin.print");
073:         *   context.getFeatureInstaller().addMainMenuItem(this,
074:         *                                                 new String[]
075:         *                                                 {MenuNames.TOOLS,I18N.get(name, "print")},
076:         *                                                 I18N.get(name, "print"), false, null, null);
077:         * }
078:         * ...
079:         * </pre>
080:         * 
081:         * <pre>
082:         * TODO :I18N (1) Improve translations
083:         * TODO :I18N (2) Separate config (customization) and I18N
084:         * TODO :I18N (3) Explore and discuss about I18N integration and Jakarta Common Ressources
085:         * (using it as a ressource interface)
086:         * </pre>
087:         * 
088:         * @author Basile Chandesris - <chandesris@pt-consulting.lu>
089:         * 
090:         * @see com.vividsolutions.jump.workbench.ui.MenuNames 
091:         * @see com.vividsolutions.jump.workbench.ui.VTextIcon text rotation
092:         */
093:        public final class I18N {
094:
095:            private static final Logger LOG = Logger.getLogger(I18N.class);
096:
097:            // [Michael Michaud 2007-03-23] removed SingletonHolder internal class
098:            // 1 - getInstance is enough to guarantee I18N instance unicity
099:            // 2 - I18N should not be instanciated as the class has only static methods
100:            private static final I18N instance = new I18N();
101:
102:            // use 'jump<locale>.properties' i18n mapping file
103:            // STanner changed the place where are stored bundles. Now are in /language
104:            // public static ResourceBundle rb = ResourceBundle.getBundle("com.vividsolutions.jump.jump");
105:            public static ResourceBundle rb = ResourceBundle
106:                    .getBundle("language/jump");
107:
108:            // [Michael Michaud 2007-03-23] plugInsResourceBundle is deactivated because all the methods
109:            // using it have been deactivated.
110:            // [sstein] activated again since Pirol does use it
111:            public static Hashtable plugInsResourceBundle = new Hashtable();
112:
113:            private I18N() {
114:                super ();
115:            }
116:
117:            public static I18N getInstance() {
118:                //[Michael Michaud 2007-03-04] guarantee I18N instance unicity without
119:                // creating a SingletonHolder inner class instance
120:                return (instance == null) ? new I18N() : instance;
121:                // return SingletonHolder._singleton;
122:            }
123:
124:            /**
125:             * Load file specified in command line (-i18n lang_country)
126:             * (lang_country :language 2 letters + "_" + country 2 letters)
127:             * Tries first to extract lang and country, and if only lang
128:             * is specified, loads the corresponding resource bundle.
129:             * @param langcountry
130:             */
131:            public static void loadFile(final String langcountry) {
132:                // [Michael Michaud 2007-03-04] handle the case where lang is the only
133:                // variable instead of catching an ArrayIndexOutOfBoundsException
134:                String[] lc = langcountry.split("_");
135:                Locale locale = Locale.getDefault();
136:                if (lc.length > 1) {
137:                    LOG.debug("lang:" + lc[0] + " " + "country:" + lc[1]);
138:                    locale = new Locale(lc[0], lc[1]);
139:                } else if (lc.length > 0) {
140:                    LOG.debug("lang:" + lc[0]);
141:                    locale = new Locale(lc[0]);
142:                } else {
143:                    LOG
144:                            .debug(langcountry
145:                                    + " is an illegal argument to define lang [and country]");
146:                }
147:                rb = ResourceBundle.getBundle("language/jump", locale);
148:            }
149:
150:            /**
151:             * Process text with the locale 'jump_<locale>.properties' file
152:             * @param label
153:             * @return i18n label
154:             * [Michael Michaud 2007-03-23] If no resourcebundle is found, returns a default string
155:             * which is the last part of the label
156:             */
157:            public static String get(final String label) {
158:                try {
159:                    return rb.getString(label);
160:                } catch (java.util.MissingResourceException e) {
161:                    String[] labelpath = label.split("\\.");
162:                    LOG
163:                            .debug("No resource bundle or no translation found for the key : "
164:                                    + label);
165:                    return labelpath[labelpath.length - 1];
166:                }
167:            }
168:
169:            /**
170:             * Get the short signature for locale 
171:             * (letters extension :language 2 letters + "_" + country 2 letters)
172:             * @return string signature for locale
173:             */
174:            public static String getLocale() {
175:                return rb.getLocale().getLanguage() + "_"
176:                        + rb.getLocale().getCountry();
177:            }
178:
179:            /**
180:             * Get the short signature for language 
181:             * (letters extension :language 2 letters)
182:             * @return string signature for language
183:             */
184:            public static String getLanguage() {
185:                if (JUMPWorkbench.I18N_SETLOCALE == "") {
186:                    // No locale has been specified at startup: choose default locale
187:                    return rb.getLocale().getLanguage();
188:                } else {
189:                    return JUMPWorkbench.I18N_SETLOCALE.split("_")[0];
190:                }
191:            }
192:
193:            /**
194:             * Process text with the locale 'jump_<locale>.properties' file
195:             * If no resourcebundle is found, returns default string contained
196:             * inside com.vividsolutions.jump.jump
197:             * @param label with argument insertion : {0} 
198:             * @param objects
199:             * @return i18n label
200:             */
201:            public static String getMessage(final String label,
202:                    final Object[] objects) {
203:                try {
204:                    final MessageFormat mformat = new MessageFormat(rb
205:                            .getString(label));
206:                    return mformat.format(objects);
207:                } catch (java.util.MissingResourceException e) {
208:                    final String[] labelpath = label.split("\\.");
209:                    LOG.warn(e.getMessage()
210:                            + " no default value, the resource key is used: "
211:                            + labelpath[labelpath.length - 1]);
212:                    final MessageFormat mformat = new MessageFormat(
213:                            labelpath[labelpath.length - 1]);
214:                    return mformat.format(objects);
215:                }
216:            }
217:
218:            /**
219:             * Process text with the locale 'pluginName_<locale>.properties' file
220:             * 
221:             * @param pluginName (path + name)
222:             * @param label
223:             * @return i18n label
224:             */
225:            /*
226:            public static String get(String pluginName, String label)
227:            {
228:                if (LOG.isDebugEnabled()){
229:                    LOG.debug(I18N.plugInsResourceBundle.get(pluginName)+" "+label
230:                        + ((ResourceBundle)I18N.plugInsResourceBundle
231:                                .get(pluginName))
232:                                .getString(label));
233:                }
234:                return ((ResourceBundle)I18N.plugInsResourceBundle
235:                            .get(pluginName))
236:                            .getString(label);
237:            }
238:             */
239:
240:            /**
241:             * Process text with the locale 'pluginName_<locale>.properties' file
242:             * 
243:             * @param pluginName (path + name)
244:             * @param label with argument insertion : {0} 
245:             * @param objects
246:             * @return i18n label
247:             */
248:            /*
249:             public static String getMessage(String pluginName, String label, Object[] objects)
250:             {
251:                 MessageFormat mf = new MessageFormat(((ResourceBundle)I18N.plugInsResourceBundle
252:                                                     .get(pluginName))
253:                                                     .getString(label));
254:                 return mf.format(objects);
255:             }
256:             */
257:
258:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.