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

📄 lwroot.java

📁 Zaval Light-Weight Visual Components Library (LwVCL) is a pure Java alternative to humble AWT-based
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
 /**  * Invoked when component has been moved.  */  public void componentMoved(ComponentEvent e) {}  public void reshape(int x, int y, int w, int h) {    super.reshape(x, y, w, h);    proxy.setSize(w, h);  } /**  * Invoked when component has been resized.  */  public void componentResized(ComponentEvent e) {} /**  * Invoked when component has been shown.  */  public void componentShown(ComponentEvent e) {    proxy.setVisible(true);  } /**  * Returns whether this component can be traversed using Tab or Shift-Tab keyboard  * focus traversal. If this method returns "false", this component may still  * request the keyboard focus using requestFocus(), but it will not automatically  * be assigned focus during tab traversal.  */  public boolean isFocusTraversable() {    return true;  } /**  * Sets the opaque of this component. Use <code> false </code>  * argument value to make a transparent component from this component.  * The method usage has not any effect, because the root component has to  * be always opaque.  * @param  <code>b</code> the opaque flag.  */  public void setOpaque (boolean b) {    throw new RuntimeException();  }  public Point getOrigin () {    return null;  }  public Point getLayoutOffset() {    return new Point();  } /**  * Invoked when a component gains the keyboard focus.  */  public void focusGained(FocusEvent e)  {    LwLayer activeLayer = fal();    if (activeLayer != null) activeLayer.setupFocus();  } /**  * Invoked when a component loses the keyboard focus.  */  public void focusLost(FocusEvent e) {    LwLayer activeLayer = fal();    if (activeLayer != null) activeLayer.releaseFocus();  } /**  * Invoked when the mouse has been clicked on a component.  */  public void mouseClicked(MouseEvent e) {} /**  * Invoked when the mouse enters a component.  */  public void mouseEntered(MouseEvent e)  {    if (draggOwner == null)    {      LwComponent d = getLwComponentAt(e.getX(), e.getY());      if (isEventable(d)){        moveOwner = d;        fme(d, LwMouseEvent.MOUSE_ENTERED, e);      }    }  } /**  * Invoked when the mouse exits a component.  */  public void mouseExited(MouseEvent e)  {    if (moveOwner != null && draggOwner == null)    {      LwComponent p = moveOwner;      moveOwner = null;      fme(p, LwMouseEvent.MOUSE_EXITED, e);    }  } /**  * Invoked when a mouse button has been pressed on a component.  */  public void mousePressed(MouseEvent e)  {    pressX = e.getX();    pressY = e.getY();    for (int i=proxy.count()-1; i>=0; i--)    {      LwLayer l = (LwLayer)proxy.get(i);      l.mousePressed(pressX, pressY, e.getModifiers());      if (l.isActive()) break;    }    LwComponent d = getLwComponentAt(pressX, pressY);    if (isEventable(d))    {      pressOwner = d;      fme(d, LwMouseEvent.MOUSE_PRESSED, e);    }  } /**  * Invoked when a mouse button has been released on a component.  */  public void mouseReleased(MouseEvent e)  {    int x = e.getX(), y = e.getY();    int m = e.getModifiers();    boolean drag = (draggOwner != null);    if (drag)    {      fmme(draggOwner, LwMouseMotionEvent.MOUSE_ENDDRAGGED, x, y, m);      draggOwner = null;    }    LwComponent po = pressOwner;    if (pressOwner != null)    {      fme(pressOwner, LwMouseEvent.MOUSE_RELEASED, e);      if (!drag) fme(pressOwner, LwMouseEvent.MOUSE_CLICKED, e);      pressOwner = null;    }    if (drag || (po != null && po != moveOwner))    {      LwComponent nd = getLwComponentAt(x, y);      if (nd != moveOwner)      {        if (moveOwner != null) fme(moveOwner, LwMouseEvent.MOUSE_EXITED, e);        if (isEventable(nd))        {          moveOwner = nd;          fme(nd, LwMouseEvent.MOUSE_ENTERED, e);        }      }    }  } /**  * Invoked when a key has been pressed.  */  public void keyPressed(KeyEvent e)  {    for (int i=proxy.count()-1; i>=0; i--)    {      LwLayer l = (LwLayer)proxy.get(i);      l.keyPressed(e.getKeyCode(), e.getModifiers());      if (l.isActive()) break;    }    LwComponent focusOwner = LwFocusManager.manager.getFocusOwner();    if (focusOwner != null)    {      keyCode = e.getKeyCode();      fke (focusOwner, LwKeyEvent.KEY_PRESSED, e);    }  } /**  * Invoked when a key has been released.  */  public void keyReleased(KeyEvent e)  {    LwComponent focusOwner = LwFocusManager.manager.getFocusOwner();    if (focusOwner != null)      fke(focusOwner, LwKeyEvent.KEY_RELEASED, e);  } /**  * Invoked when a key has been typed.  * This event occurs when a key press is followed by a key release.  */  public void keyTyped(KeyEvent e) {    LwComponent focusOwner = LwFocusManager.manager.getFocusOwner();    if (focusOwner != null) fke(focusOwner, LwKeyEvent.KEY_TYPED, e);  } /**  * Invoked when the mouse button has been moved on a component  * (with no buttons no down).  */  public void mouseMoved(MouseEvent e)  {    int x = e.getX(), y = e.getY();    LwComponent d = getLwComponentAt(x, y);    int m = e.getModifiers();    if (moveOwner != null)    {       if (d != moveOwner)       {         LwComponent old = moveOwner;         moveOwner = null;         fme(old, LwMouseEvent.MOUSE_EXITED, e);         if (isEventable(d))         {           moveOwner = d;           fme(moveOwner, LwMouseEvent.MOUSE_ENTERED, e);         }       }       else       {         if (isEventable(d)) fmme(d, LwMouseMotionEvent.MOUSE_MOVED, x, y, m);       }    }    else    if (isEventable(d))    {      moveOwner = d;      fme(d, LwMouseEvent.MOUSE_ENTERED, e);    }  } /**  * Invoked when a mouse button is pressed on a component and then  * dragged. Mouse drag events will continue to be delivered to  * the component where the first originated until the mouse button is  * released (regardless of whether the mouse position is within the  * bounds of the component).  */  public void mouseDragged(MouseEvent e)  {    int m = e.getModifiers() | InputEvent.BUTTON1_MASK;    int x = e.getX(), y = e.getY();    if (draggOwner == null)    {      LwComponent d = (moveOwner == null)?getLwComponentAt(pressX, pressY):moveOwner;      if (isEventable(d))      {        draggOwner = d;        fmme(draggOwner, LwMouseMotionEvent.MOUSE_STARTDRAGGED, pressX, pressY, m);        if (pressX != x || pressY != y)          fmme(draggOwner, LwMouseMotionEvent.MOUSE_DRAGGED, x, y, m);      }    }    else fmme(draggOwner, LwMouseMotionEvent.MOUSE_DRAGGED, x, y, m);  }  public void componentAdded(Object id, Layoutable lw, int index)  {    LwLayer l = (LwLayer)lw;    if (layers.get(l.getID()) != null) throw new RuntimeException();    layers.put (l.getID(), lw);  }  public void componentRemoved(Layoutable lw, int index) {    layers.remove(((LwLayer)lw).getID());  }  public Dimension calcPreferredSize(LayoutContainer target) {    return new Dimension ();  }  public void layout(LayoutContainer target)  {    int w = getWidth(), h = getHeight();    for (int i=0;i<target.count();i++)    {      Layoutable l = target.get(i);      l.setSize(w, h);    }  }  public Object getProperty (int id) {    if (id == CURSOR_PROPERTY) return getCursor();    else throw new IllegalArgumentException();  }  public void setProperty (int id, Object value) {    if (id == CURSOR_PROPERTY) setCursor((Cursor)value);    else throw new IllegalArgumentException();  }  public boolean canHaveFocus () {    return false;  }  /*[fire key event]*/  private final void  fke(LwComponent target, int id, KeyEvent e)  {    KE_STUB.reset(target, id, keyCode, e.getKeyChar(), e.getModifiers());    LwEventManager.manager.perform (KE_STUB);  }  /*[fire mouse event]*/  private final void fme(LwComponent target, int id, MouseEvent e) {    ME_STUB.reset(target, id, e.getX(), e.getY(), e.getModifiers(), e.getClickCount());    LwEventManager.manager.perform(ME_STUB);  }  /*[fire mouse motion event]*/  private final void fmme (LwComponent target, int id, int ax, int ay, int m) {    MME_STUB.reset(target, id, ax, ay, m, 0);    LwEventManager.manager.perform (MME_STUB);  }  /*[find active layer]*/  private final LwLayer fal()  {    for (int i=proxy.count()-1; i>=0; i--)    {      LwLayer targetLayer = (LwLayer)proxy.get(i);      if (targetLayer.isActive()) return targetLayer;    }    return null;  }  private static final boolean isEventable(LwComponent c) {    return c != null && c.isEnabled();  }  private LwKeyEvent         KE_STUB  = new LwKeyEvent        (this, LwKeyEvent.KEY_PRESSED, 0, 'x', 0);  private LwMouseEvent       ME_STUB  = new LwMouseEvent      (this, LwMouseEvent.MOUSE_PRESSED, 0, 0, 0, 1);  private LwMouseMotionEvent MME_STUB = new LwMouseMotionEvent(this, LwMouseMotionEvent.MOUSE_MOVED, 0, 0, 0);}

⌨️ 快捷键说明

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