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

📄 lwroot.java

📁 Zaval Light-Weight Visual Components Library (LwVCL) is a pure Java alternative to humble AWT-based
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/**
 *     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.awt.event.*;import org.zaval.util.event.*;import org.zaval.util.*;import org.zaval.lw.event.*;/** * This class is a root light weight component that implements LwDesktop interface. * The main purpose of the class to provide connection between native Java AWT library * implementation and light weight components hierarchy. So, on the one hand the class is light * weight components (implements LwContainer interface) and on the other hand this class * inherits Java AWT component (java.awt.Panel). Using the class the light weight library: * <ul> *   <li> *     Has Java AWT events source. The AWT events are transformed by the class to *     appropriate light weight events. *   </li> *   <li> *     Has graphical surface to paint the light weight components hierarchy. *  </li> *   <li> *     Has desktop layers supporting. *  </li> *   <li> *     Has custom properties supporting. For example, the implementation supports *     mouse cursor type property. Use the <code>getProperty</code> and <code>setProperty</code> *     methods to control the property. *  </li> * </ul> * Basing on the description above, to create own lightweight application * you have to use the class as a root light weight container. The sample * below shows the root component usage: * <pre> *   ... *   LwContainer root = new LwRoot(); *   root.getRootLayer().setLwLayout(new LwBorderLayout()); *   LwButton button = new LwButton("Ok"); *   root.getRootLayer().add(LwBorderLayout.CENTER, button); *   ... *   java.awt.Frame frame = java.awt.Frame(); *   frame.setSize(400, 400); *   frame.setLayout(new BorderLayout()); *   frame.add("Center", root); *   frame.setVisible(true); *   ... *   OR *   ... *   Applet applet = new Applet(); *   applet.setLayout(new BorderLayout()); *   applet.add("Center", root); *   ... * </pre> * First of all the sample above uses the root layer component as a light weight container for creating * the light weight hierarchy. The second part shows the usage of the root as a part of Java AWT * frame component and a java applet. * <p> * More easy way is using of LwFrame class that inherits java.awt.Frame and provides the lightweight * top-level container ready to create lightweight hierarchy: * <pre> *   ... *   LwFrame frame = LwFrame(); *   LwContainer root = frame.getRoot(); *   root.setLwLayout(new LwBorderLayout()); *   LwButton button = new LwButton("Ok"); *   root.add(LwBorderLayout.CENTER, button); *   frame.setSize(400, 400); *   frame.setVisible(true); *   ... * </pre> */public class LwRootextends Panelimplements LwDesktop, ComponentListener, MouseListener,           MouseMotionListener, KeyListener, FocusListener,           LwLayout{ /**  * Defines cursor property id. The id should be used as an argument for  * <code>getProperty</code> and <code>setProperty</code> method to control  * native cursor state.  */  public static final int CURSOR_PROPERTY = 1;  private LwPanel proxy;  private LwLayer root;  private LwComponent draggOwner, moveOwner, pressOwner, last;  private int keyCode, pressX, pressY;  private Hashtable layers = new Hashtable (); /**  * Constructs the class instance.  */  public LwRoot()  {    setLayout (null);    addComponentListener  (this);    addFocusListener      (this);    addKeyListener        (this);    addMouseMotionListener(this);    addMouseListener      (this);    proxy = new LwPanel();    proxy.setLwLayout(this);    proxy.setLwParent(this);    root = new LwLayer("root");    proxy.add (root);    proxy.add (new LwWinLayer());    //!!!    // Fix problem with the focus under JDK1.4    //!!!    try {      java.lang.reflect.Method m = getClass().getMethod ("setFocusTraversalKeysEnabled", new Class[] { Boolean.TYPE });      m.invoke (this, new Object[] { Boolean.FALSE } );    }    catch (NoSuchMethodException e) {}    catch (Exception ee) {      ee.printStackTrace();    }  }  public void setLwLayout (LwLayout l) {    throw new RuntimeException();  }  public int getX() {    return proxy.getX();  }  public int getY() {    return proxy.getY();  }  public int getWidth() {    return proxy.getWidth();  }  public int getHeight() {    return proxy.getHeight();  }  public LwLayout getLwLayout () {    return proxy.getLwLayout();  } /**  * Gets the lightweight parent of this component.  * The method always returns <code>null</code>, since the root component cannot have  * a light weight component as a parent, because this component should be used as  * a top-level light weight component.  * @return <code>null</code>.  */  public LwComponent getLwParent() {    return null;  }  /**   * Sets the lightweight parent of this component.   * It is impossible to use the method to define the parent component, because   * the class is used as a top-level parent component. The method will throw   * <code>RuntimeException</code> if you try to call it.   * @param <code>p</code> the parent component of this lightweight component.   */  public void setLwParent(LwComponent p) {    throw new RuntimeException();  }  public LwViewMan getViewMan (boolean b) {    return null;  }  public void setViewMan (LwViewMan v) {    throw new RuntimeException();  }  public Rectangle getVisiblePart() {    return isVisible()?new Rectangle(0, 0, getWidth(), getHeight()):null;  }  public LwComponent getLwComponentAt(int x, int y)  {    LwLayer targetLayer = fal();    if (targetLayer != null)    {/*???      if (last != null && LwToolkit.isAncestorOf(targetLayer, last))      {        Point p = LwToolkit.getAbsLocation(last);        if (x >= p.x && y >= p.y && x < p.x + last.getWidth() && y < p.y + last.getHeight())        {          last = LwEventManager.manager.getEventDestination(last.getLwComponentAt(x - p.x, y - p.y));          if (last != null) return last;        }      }*/      last = LwEventManager.manager.getEventDestination(targetLayer.getLwComponentAt(x, y));      return last;    }    return null;  } /**  * Gets the opaque of this component. If the method returns  * <code>false</code> than the component is transparent, in this case  * <code>update</code> method has not be called during painting process.  * The method allways returns <code>true</code> as result, because this is  * root component.  * @return  <code>true</code> if the component is opaque; otherwise  * <code>false</code>.  */  public boolean isOpaque () {    return false;  }  public Layoutable get(int index) {    return proxy.get(index);  }  public int count() {    return proxy.count();  }  public void add(LwComponent c) {    proxy.add(c);  }  public void add(Object s, LwComponent c) {    proxy.add(s, c);  }  public void insert(int i, Object s, LwComponent d) {    proxy.insert(i, s, d);  }  public void remove(int i) {    if (get(i) == root) throw new RuntimeException ();    proxy.remove(i);  }  public void removeAll() {    throw new RuntimeException ();  }  public int indexOf(LwComponent c) {    return proxy.indexOf(c);  }  public void validate() {    proxy.validate();    super.validate();  }  public void setEnabled (boolean b) {    throw new RuntimeException();  }  public Dimension getPreferredSize() {    return proxy.getPreferredSize();  }  public Insets getInsets() {    return proxy.getInsets();  }  public void update(Graphics g) {    paint(g);  }  public void paint (Graphics g) {    if (getParent() != null && getParent().isVisible()) LwPaintManager.manager.rootPaint(g, proxy);  }  public void paintOnTop(Graphics g) {}  public LwLayer getRootLayer () {    return root;  }  public LwLayer getLayer (Object id) {    return (LwLayer)layers.get(id);  }  public Object[] getLayersIDs ()  {    Object[] ids = new Object[layers.size()];    Enumeration en  = layers.keys();    for (int i=0; i < ids.length; i++) ids[i] = en.nextElement();    return ids;  } /**  * Invoked when component has been hidden.  */  public void componentHidden(ComponentEvent e) {    proxy.setVisible(false);  }

⌨️ 快捷键说明

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