home *** CD-ROM | disk | FTP | other *** search
- package asp.util;
-
- import java.awt.Component;
- import java.util.Hashtable;
- import java.util.ResourceBundle;
-
- public class ResourceUtil {
- public static final String RESBASE_ASPWIZ = "asp.wizard.res";
- public static final String RESBASE_ASPCOMP = "asp.nfx.res";
- private static Hashtable _resourceUtilDictionary = new Hashtable();
- ResourceBundle _rb;
-
- public static ResourceUtil getResourceUtil(String resourceBase, Class classOfPanel) throws EResourceUtil {
- ResourceUtil ru = null;
- if (classOfPanel != null) {
- ru = (ResourceUtil)_resourceUtilDictionary.get(classOfPanel);
- if (ru == null) {
- ru = new ResourceUtil(resourceBase, classOfPanel);
- _resourceUtilDictionary.put(classOfPanel, ru);
- }
- }
-
- return ru;
- }
-
- public ResourceUtil(String resourceBase, Class componentClass) throws EResourceUtil {
- if (componentClass == null) {
- throw new EResourceUtil("ResourceTool needs to know the resource user class");
- } else {
- String bundleName = (resourceBase != null ? resourceBase + "." : "") + "Resource" + getRightToLastDot(componentClass.getName());
- this._rb = ResourceBundle.getBundle(bundleName);
- }
- }
-
- public static String getResourceString(String resourceBase, Class classOfPanel, String key) {
- ResourceUtil ru = null;
- String rs = "";
-
- try {
- ru = getResourceUtil(resourceBase, classOfPanel);
- if (ru != null) {
- rs = ru.getString(key);
- }
- } catch (EResourceUtil var5) {
- }
-
- return rs;
- }
-
- public String getString(String key) {
- return this._rb != null ? this._rb.getString(key) : null;
- }
-
- public String getString(String key, String defstr) {
- String result = this.getString(key);
- if (result == null) {
- result = defstr;
- }
-
- return result;
- }
-
- public static String getString(String key, Component child) {
- while(child != null && !(child instanceof ResourceUtilOwner)) {
- child = child.getParent();
- }
-
- return child != null ? ((ResourceUtilOwner)child).getResourceUtil().getString(key) : null;
- }
-
- public char getMnemonic(String key) {
- char result = 0;
- if (key != null) {
- String resStr = this.getString(key + ".mnemonic");
- if (resStr != null && resStr.length() > 0) {
- result = resStr.charAt(0);
- }
- }
-
- return result;
- }
-
- private static String getRightToLastDot(String str) {
- String result = null;
- if (str != null) {
- int dotloc = str.lastIndexOf(46);
- result = dotloc != -1 ? str.substring(dotloc + 1) : str;
- }
-
- return result;
- }
-
- public String getComponentString(Component comp) {
- String result = "";
- if (comp != null) {
- String classname = getRightToLastDot(comp.getClass().getName());
- String reskey = classname + '.' + comp.getName();
- result = this.getString(reskey);
- }
-
- return result;
- }
- }
-