⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lwmanager.java

📁 Zaval Light-Weight Visual Components Library (LwVCL) is a pure Java alternative to humble AWT-based
💻 JAVA
字号:
/**
 *     Caption: Zaval Light-Weight Visual Components Library
 *     $Revision: 2.79 $
 *     $Date: 2003/08/22 11:24:16 $
 *
 *     @author:     Andrei Vishnevsky
 *     @version:    3.50
 *
 * Zaval Light-Weight Visual Components Library (LwVCL) is a pure Java
 * alternative to humble AWT-based and SWING-based GUI interfaces for
 * wide ranges of platforms, including J2SE, PersonalJava and J2ME.
 *
 * Designed as light-weight but, alternatively to Swing, built separately
 * from AWT (not on top of the java.awt library like Swing), the LwVCL is
 * the good alternative to highly performant, memory-efficient, flexible
 * GUI solution for embedded, stand-alone and applet applications.
 *
 * For more info on this product read Zaval Light-Weight Visual Components Library Tutorial
 * (It comes within this package).
 * The latest product version is always available from the product's homepage:
 * http://www.zaval.org/products/lwvcl/
 * and from the SourceForge:
 * http://sourceforge.net/projects/zaval0003/
 *
 * Contacts:
 *   Support : support@zaval.org
 *   Change Requests : change-request@zaval.org
 *   Feedback : feedback@zaval.org
 *   Other : info@zaval.org
 *
 * Copyright (C) 2001-2003  Zaval Creative Engineering Group (http://www.zaval.org)
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * (version 2) as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 *
 */
package org.zaval.lw;import java.awt.*;import java.util.*;import java.lang.reflect.*;import org.zaval.lw.event.*;import org.zaval.util.*;/** * This manager is a core for deploying the library that does following: * <ul> *   <li> *     Initilizes the light wight library. The manager reads light weight properties *     file (that is stored in "org/zaval/lw/rs/lw.properties" file) and basing on the *     information creates lightweight managers and static objects. *   </li> *   <li> *     Initilizes the extension light wight library. The manager tries to read lwvcl extension *     properties file (that is stored in "org/zaval/lw/rs/lwext.properties" file) and *     creates extension managers and static objects. The extension can be absent. *   </li> *   <li> *     Provides ability to get static object by a key. *   </li> * </ul> */public class LwManager{ /**  * The field is used to store all static objects.  */  protected static Hashtable staticObjects;  protected static String    version; /**  * Gets the static object by the specified key.  * @param <code>key</code> the specified key.  * @return a static object.  */  public static Object getStaticObject(String key) {    return staticObjects.get(key);  } /**  * Gets a static object by the specified key as LwView class.  * @param <code>key</code> the specified key.  * @return a static object.  */  public static LwView getView(String key) {    return (LwView)staticObjects.get(key);  } /**  * Gets a static object by the specified key as LwLayout class.  * @param <code>key</code> the specified key.  * @return a static object.  */  public static LwLayout getLwLayout(String key) {    return (LwLayout)staticObjects.get(key);  } /**  * Gets the library version.  * @return the library version.  */  public static String getVersion () {    return version;  } /**  * Loads objects by the specified key of the specified properties set into static objects  * table.  * @param <code>key</code> the specified key that defines set of objects that should be  * loaded.  * @param <code>props</code> the specified properties.  */  public static void loadObjects(String key, Properties props)  throws Exception  {    loadObjects(key, props, staticObjects);  }  private static void loadObjects(String key, Properties props, Hashtable res)  throws Exception  {      String val = props.getProperty(key);      if (val != null)      {        StringTokenizer st = new StringTokenizer(val, ",");        for (int i=0; st.hasMoreTokens(); i++)        {          Object m         = null;          String token     = st.nextToken();          String className = props.getProperty(key + "." + token + ".cl" );          String keyName   = props.getProperty(key + "." + token + ".key");          if (className.indexOf ('@') == 0) m = staticObjects == null?res.get(className.substring(1)):getStaticObject(className.substring(1));          else          {            String constructorArg = props.getProperty(key + "." + token + ".arg" );            Class  classInstance  = Class.forName(className.indexOf('.')>0?className:PACKAGE_NAME + className);    	    if (constructorArg == null) m = classInstance.newInstance();            else            {              StringTokenizer args       = new StringTokenizer(constructorArg, ",");              Class[]         argsTypes  = new Class [args.countTokens()];              Object[]        argsValues = new Object[argsTypes.length];              for (int j = 0; args.hasMoreTokens(); j++)              {                String arg = args.nextToken().trim();                if (arg.indexOf("\"")==0)                {                  argsTypes [j] = String.class;                  argsValues[j] = arg.substring(1, arg.length() - 1);                }                else                if (arg.equals("true") || arg.equals("false"))                {                  argsTypes [j] = Boolean.TYPE;                  argsValues[j] = new Boolean(arg);                }                else                if (arg.indexOf('@') == 0)                {                  argsValues[j] = staticObjects == null?res.get(arg.substring(1)):getStaticObject(arg.substring(1));                  argsTypes [j] = argsValues[j].getClass();                }                else                {                  argsTypes [j] = Integer.TYPE;                  argsValues[j] = new Integer(arg);                }              }              Constructor classMaker = classInstance.getConstructor(argsTypes);              m = classMaker.newInstance(argsValues);            }          }          res.put(keyName == null?token:keyName, m);        }     }  }  private static String PACKAGE_NAME;  static {    PACKAGE_NAME = (new LwManager()).getClass().getName();    int index = PACKAGE_NAME.lastIndexOf('.');    PACKAGE_NAME =(index > 0)?PACKAGE_NAME.substring(0, index+1):"";    try {      staticObjects = new Hashtable();      Properties props = LwToolkit.getProperties("rs/lw.properties");      if (props == null) throw new RuntimeException("Properties file not found.");      version = props.getProperty("lwvcl.ver");      Properties extProps = LwToolkit.getProperties("rs/lwext.properties");      LwEventManager.manager = ((LwEventManager)Class.forName(PACKAGE_NAME + props.getProperty("man.event.cl")).newInstance());      staticObjects.put ("event", LwEventManager.manager);      loadObjects("man", props, staticObjects);      if (extProps != null) loadObjects("man", extProps, staticObjects);      for (Enumeration en = staticObjects.elements();en.hasMoreElements();)      {        Object manager = en.nextElement();        Field field = manager.getClass().getField("manager");        field.set(manager, manager);        if (manager instanceof EventListener) LwEventManager.manager.addXXXListener((EventListener)manager);      }      loadObjects("obj", props, staticObjects);      if (extProps != null) loadObjects("obj", extProps, staticObjects);    }    catch (Exception e) {      e.printStackTrace();    }  }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -