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

Class EjsTool

src/org/opensourcephysics/tools/EjsTool.java:53–591  ·  view source on GitHub ↗

Utility classes to work with Ejs at a high level @author Francisco Esquembre (http://fem.um.es) @version 1.0

Source from the content-addressed store, hash-verified

51 * @version 1.0
52 */
53public class EjsTool {
54 static private final String INFO_FILE = ".Ejs.txt"; //$NON-NLS-1$
55 static public final String GET_MODEL_METHOD = "_getEjsModel"; //$NON-NLS-1$
56 static public final String GET_RESOURCES_METHOD = "_getEjsResources"; //$NON-NLS-1$
57 static public final String GET_APPLET_DIMENSION_METHOD = "_getEjsAppletDimension"; //$NON-NLS-1$
58 // ---- Localization
59 static private Bundle res;
60 static public void setLocale(Locale locale) {
61 res = ResourceLoader.getBundle(null, locale);
62 }
63 static {
64 setLocale(null);
65 }
66
67 static public String getString(String key) {
68 try {
69 return res.getString(key);
70 } catch (MissingResourceException e) {
71 return '!' + key + '!';
72 }
73 }
74
75 // --- End of localization
76
77 /**
78 * Whether a class provides an Ejs model.
79 *
80 * @param _ejsClass Class
81 * @return boolean
82 */
83 static public boolean hasEjsModel(Class<?> _ejsClass) {
84 try {
85 Class<?>[] c = {};
86 java.lang.reflect.Method getModelMethod = _ejsClass.getMethod(GET_MODEL_METHOD, c);
87 return getModelMethod != null;
88 } catch (Exception _exc) {
89 return false;
90 }
91 }
92
93 /**
94 * Returns the preferred dimension for the simulation's main window.
95 *
96 * @param _ejsClass Class
97 * @return boolean
98 */
99 static public java.awt.Dimension getEjsAppletDimension(Class<?> _ejsClass) {
100 try {
101 Class<?>[] c = {};
102 java.lang.reflect.Method getDimensionMethod = _ejsClass.getMethod(GET_APPLET_DIMENSION_METHOD, c);
103 if (getDimensionMethod == null) {
104 return null;
105 }
106 Object[] o = {};
107 return (java.awt.Dimension) getDimensionMethod.invoke(null, o);
108 } catch (Exception _exc) {
109 return null;
110 }

Callers

nothing calls this directly

Calls 1

setLocaleMethod · 0.95

Tested by

no test coverage detected