MCPcopy Create free account
hub / github.com/OpenSourcePhysics/osp / LaunchRes

Class LaunchRes

src/org/opensourcephysics/tools/LaunchRes.java:23–102  ·  view source on GitHub ↗

String resources for launcher classes.

Source from the content-addressed store, hash-verified

21 * String resources for launcher classes.
22 */
23public class LaunchRes {
24 // static fields
25 static Locale resourceLocale = Locale.ENGLISH;
26 static final String BUNDLE_NAME = "org.opensourcephysics.resources.tools.launcher"; //$NON-NLS-1$
27 static Bundle res;
28 static PropertyChangeSupport support = new SwingPropertyChangeSupport(new LaunchRes());
29
30 static {
31 String language = Locale.getDefault().getLanguage();
32 resourceLocale = Locale.ENGLISH;
33 for (Locale locale : OSPRuntime.getInstalledLocales()) {
34 if (locale.getLanguage().equals(language)) {
35 resourceLocale = locale;
36 break;
37 }
38 }
39 res = ResourceLoader.getBundle(BUNDLE_NAME, resourceLocale);
40 }
41
42 /**
43 * Sets the locale.
44 *
45 * @param loc the locale
46 */
47 public static void setLocale(Locale loc) {
48 if (resourceLocale == loc) {
49 return;
50 }
51 Locale prev = resourceLocale;
52 resourceLocale = loc;
53 // get the new resource bundle
54 res = ResourceLoader.getBundle(BUNDLE_NAME, resourceLocale);
55 support.firePropertyChange(ToolsRes.OSP_PROPERTY_LOCALE, prev, resourceLocale); //$NON-NLS-1$
56 ToolsRes.setLocale(loc);
57 }
58
59 /**
60 * Private constructor to prevent instantiation.
61 */
62 private LaunchRes() { /* empty block */
63 }
64
65 /**
66 * Gets the localized value of a string. If no localized value is found, the key
67 * is returned surrounded by exclamation points.
68 *
69 * @param key the string to localize
70 * @return the localized string
71 */
72 static String getString(String key) {
73 try {
74 return res.getString(key);
75 } catch (MissingResourceException ex) {
76 return "!" + key + "!"; //$NON-NLS-1$ //$NON-NLS-2$
77 }
78 }
79
80 /**

Callers

nothing calls this directly

Calls 5

getInstalledLocalesMethod · 0.95
getBundleMethod · 0.95
getLanguageMethod · 0.80
equalsMethod · 0.65
getDefaultMethod · 0.45

Tested by

no test coverage detected