Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 package com.generalrobotix.ui.util;
00011
00012 import java.util.Locale;
00013 import java.util.ResourceBundle;
00014 import com.generalrobotix.ui.util.GrxDebugUtil;
00015
00016 public class MessageBundle {
00017 private static MessageBundle this_;
00018 protected static ResourceBundle messages_;
00019
00020 private MessageBundle() {
00021 messages_ =
00022 ResourceBundle.getBundle("com.generalrobotix.messages", Locale.US);
00023 }
00024
00025 private MessageBundle(Locale locale) {
00026 messages_ = ResourceBundle.getBundle("com.generalrobotix.messages", locale);
00027 }
00028
00029 public static final void setLocale(Locale locale) {
00030 if (this_ == null) {
00031 this_ = new MessageBundle(locale);
00032 } else {
00033 messages_ =
00034 ResourceBundle.getBundle("com.generalrobotix.messages", locale);
00035 }
00036 }
00037
00038 public static final void setLocale(String language, String country) {
00039 if (this_ == null) {
00040 this_ = new MessageBundle(new Locale(language, country));
00041 } else {
00042 messages_ =
00043 ResourceBundle.getBundle(
00044 "com.generalrobotix.messages",
00045 new Locale(language, country)
00046 );
00047 }
00048 }
00049
00050 public static final String get(String key) {
00051 if (this_ == null) {
00052 this_ = new MessageBundle(Locale.getDefault());
00053 }
00054 try{
00055 return messages_.getString(key);
00056 }catch(Exception e){
00057 try{
00058 GrxDebugUtil.println("not found " + key + "in messages_(defaultlocale).properties");
00059 return ResourceBundle.getBundle("com.generalrobotix.messages", Locale.US).getString(key);
00060 }catch(Exception e1){
00061 GrxDebugUtil.println("not found " + key + "in messages_en.properties");
00062 return "";
00063 }
00064 }
00065 }
00066
00067 public static final ResourceBundle getMessages() { return messages_; }
00068 }