+++ /dev/null
-package jp.naist.se.stigmata.ui.swing;\r
-\r
-/*\r
- * $Id$\r
- */\r
-\r
-import java.text.MessageFormat;\r
-import java.util.MissingResourceException;\r
-import java.util.ResourceBundle;\r
-\r
-/**\r
- * This class manages message for display.\r
- * \r
- * @author Haruaki TAMADA\r
- * @version $Revision$ $Date$\r
- */\r
-public class Messages{\r
- private static final String BUNDLE_NAME = "resources.messages";\r
- private static final Messages instance = new Messages();\r
- private final ResourceBundle bundle = ResourceBundle.getBundle(BUNDLE_NAME);\r
-\r
- private Messages(){\r
- }\r
-\r
- public static String getString(String key){\r
- return instance.get(key);\r
- }\r
-\r
- public static String getString(String key, Object... strings){\r
- String v = instance.get(key);\r
-\r
- return MessageFormat.format(v, strings);\r
- }\r
-\r
- public static String[] getStringArray(String key){\r
- return instance.getArray(key);\r
- }\r
-\r
- public static boolean hasString(String key){\r
- return instance.hasValue(key);\r
- }\r
-\r
- private String get(String key){\r
- try{\r
- String value = bundle.getString(key);\r
- int currentIndex = 0;\r
-\r
- // replace "hoge${fugakey}" to "hogefuga"\r
- // when fugakey=fuga was defined.\r
- while((value.indexOf('$', currentIndex) >= 0)){\r
- int index = value.indexOf('$', currentIndex);\r
- if(value.charAt(index + 1) == '$'){\r
- currentIndex = index + 2;\r
- }\r
- else if(value.charAt(index + 1) == '{'){\r
- int last = value.indexOf('}', currentIndex + 1);\r
- String subkey = value.substring(index + 2, last);\r
- if(hasValue(subkey)){\r
- String subvalue = get(subkey);\r
- StringBuilder builder = new StringBuilder();\r
- builder.append(value.substring(0, currentIndex));\r
- builder.append(subvalue);\r
- builder.append(value.substring(last + 1));\r
- currentIndex += subvalue.length() + 1;\r
- value = new String(builder);\r
- }\r
- }\r
- }\r
-\r
- return value;\r
- }catch(MissingResourceException e){\r
- e.printStackTrace();\r
- return "!" + key + "!";\r
- }\r
- }\r
-\r
- private String[] getArray(String key){\r
- String value = get(key);\r
- return value.split(", *");\r
- }\r
-\r
- private boolean hasValue(String key){\r
- try{\r
- bundle.getString(key);\r
- return true;\r
- }catch(MissingResourceException e){\r
- }\r
- return false;\r
- }\r
-}\r