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

📄 lwlist.java

📁 Zaval Light-Weight Visual Components Library (LwVCL) is a pure Java alternative to humble AWT-based
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
    * object that is selection index.    * @param <code>l</code> the specified listener.    */    public void addSelectionListener(LwActionListener l)  {      if (support == null) support = new LwActionSupport();      support.addListener(l);    }   /**    * Removes the specified selection listener so it no longer receives selection events    * from this list component.    * @param <code>l</code> the specified listener.    */    public void removeSelectionListener(LwActionListener l)  {      if (support != null) support.removeListener(l);    }   /**    * Paints this component. The method is overrided to paint the list item selection rectangle.    * @param <code>g</code> the graphics context to be used for painting.    */    public /*C#override*/ void paintOnTop(Graphics g) {      if (!hasInputFocus()) drawSelMarker(g);      if (hasFocus()) drawPosMarker(g);    }   /**    * Invoked to paint selection marker.    * @param <code>g</code> the graphics context to be used for painting.    */    protected void drawSelMarker(Graphics g)    {       if (selectedIndex >= 0)       {         LwComponent c = getSelected();         LwToolkit.drawMarker(g, c.getX(), c.getY(), c.getWidth(), c.getHeight(), getBackground(), selectColor);       }    }   /**    * Invoked to paint position marker.    * @param <code>g</code> the graphics context to be used for painting.    */    protected void drawPosMarker(Graphics g)    {       int offset = controller.getOffset();       if (offset >= 0)       {         LwComponent c = (LwComponent)get(offset);         g.setColor(posRectColor);         g.drawRect(c.getX(), c.getY(), c.getWidth()-1, c.getHeight()-1);       }    }    public /*C#virtual*/ void mouseClicked(LwMouseEvent e) {}    public /*C#virtual*/ void mouseEntered(LwMouseEvent e) {}    public /*C#virtual*/ void mouseExited(LwMouseEvent e)  {}    public /*C#virtual*/ void mousePressed(LwMouseEvent e)    {      if (LwToolkit.isActionMask(e.getMask()))      {        int index = LwToolkit.getDirectCompAt(e.getX(), e.getY(), this);        if (index >= 0)        {          controller.setOffset(index);          select(index);        }      }    }    public /*C#virtual*/ void mouseReleased(LwMouseEvent e) {}    public /*C#virtual*/ void keyPressed(LwKeyEvent e)    {      if (posInfo.getMaxOffset() > 0)      {        boolean isCtrl = (e.getMask() &  KeyEvent.CTRL_MASK) > 0;        switch(e.getKeyCode())        {          case KeyEvent.VK_END :  if (isCtrl) controller.setOffset(controller.getMaxOffset());                                  else        controller.seekLineTo(PosController.END);                                  break;          case KeyEvent.VK_HOME:  if (isCtrl) controller.setOffset(0);                                  else        controller.seekLineTo(PosController.BEG);                                  break;          case KeyEvent.VK_RIGHT: controller.seek(1); break;          case KeyEvent.VK_DOWN:  controller.seekLineTo(PosController.DOWN); break;          case KeyEvent.VK_LEFT:  controller.seek(-1); break;          case KeyEvent.VK_UP:    controller.seekLineTo(PosController.UP); break;          case KeyEvent.VK_PAGE_UP  : controller.seek(pageSize(-1));  break;          case KeyEvent.VK_PAGE_DOWN: controller.seek(pageSize(1)); break;        }      }    }    public /*C#virtual*/ void keyReleased(LwKeyEvent e){}    public /*C#virtual*/ void keyTyped(LwKeyEvent e)   {}    public /*C#virtual*/ void focusGained(LwFocusEvent e)    {      int o = controller.getOffset();      if (o >= 0 && o == selectedIndex) input = (LwComponent)get(controller.getOffset());      else input=null;    }    public /*C#virtual*/ void focusLost(LwFocusEvent e) {}    public /*C#virtual*/ boolean catchInput (LwComponent child)    {      boolean b = input != null && LwToolkit.isAncestorOf(input, child);      if (b && !hasInputFocus() && !hasFocus()) input = null;      return (input == null || !b);    }    public /*C#virtual*/ void posChanged(PosEvent e)    {      int off = controller.getOffset();      select(off);      repaint();      input = (controller.getOffset() >= 0)?(LwComponent)get(off):null;    }    public /*C#override*/ void insert(int i, Object s, LwComponent d)    {      int offset = controller.getOffset();      super.insert(i, s, d);      if (offset >= 0 && offset >= i)      {        clearSelection();        controller.clearPos();        offset = offset == i?offset:offset+1;        controller.setOffset(offset);      }      //if (csupport != null) csupport.perform(new LwContainerEvent(d, this, LwContainerEvent.COMP_ADDED));    }    public /*C#override*/ void remove(int i)    {      int offset = controller.getOffset();      super.remove(i);      if (offset >= 0)      {        if (count() == 0 || offset >= i)        {          clearSelection();          controller.clearPos();        }        if (count() > 0 && offset >= i)        {          offset = offset == i?offset:offset-1;          controller.setOffset(offset);        }      }    }    public /*C#override*/ void removeAll()    {      clearSelection();      controller.clearPos();      super.removeAll();    }    public Point getSOLocation () {      return getLayoutOffset();    }    public void setSOLocation (int x, int y)    {      if (x != dx || y != dy)      {        dx = x;        dy = y;        vrp();      }    }    public Dimension getSOSize() {      return getPreferredSize();    }    public void setScrollMan (ScrollMan m) {      man = m;    }    public boolean moveContent() {      return true;    }    public /*C#override*/ Point getLayoutOffset()  {      return new Point(dx, dy);    }   /**    * Gets the selected item component.    * @return a selected item component.    */    public LwComponent getSelected() {      return selectedIndex < 0?null:(LwComponent)get(selectedIndex);    }   /**    * Creates and fires appropriate selection event for list of selection listeners.    * @param <code>from</code> the selected item index.    */    protected /*C#virtual*/ void perform(int from) {      if (support != null) support.perform(new LwActionEvent(this, new Integer(from)));    }   /**    * Notifies the scroll manager that an item component at the specified index should be fully    * visible. The scroll manager should scrolls the list view to make the component fully    * visible if it is necessary.    * @param <code>index</code> the specified index.    * @return <code>true</code> if the item component has not been fully visible; <code>false</code>    * otherwise.    */    protected /*C#virtual*/ boolean notifyScrollMan(int index)    {      if (index >= 0)      {        LwComponent c = (LwComponent)get(index);        Point p = LwToolkit.calcOrigin (c.getX() - dx, c.getY()- dy, c.getWidth(), c.getHeight(), dx, dy, this);        if (p.x != dx || p.y != dy)        {          if (man != null) man.scrollObjMoved(p.x, p.y);          else             setSOLocation(p.x, p.y);          return true;        }      }      return false;    }   /**    * Returns the page size for the specified direction.    * @param <code>d</code> the specified direction. Use <code>-1</code> value to specify bottom-up direction and    * <code>1</code> value to specify up-bottom direction.    * @return a page size.    */    protected /*C#virtual*/ int pageSize(int d)    {      int offset = controller.getOffset();      if (offset >= 0)      {        Rectangle vp = getVisiblePart();        int sum = 0, i = 0;        for (i=offset; i>=0 && i<=controller.getMaxOffset() && sum<vp.height; i+=d)          sum += get(i).getHeight();        return i - offset - d;      }      return 0;    }    protected /*C#override*/ LwLayout getDefaultLayout() {      return new LwListLayout();    }    private boolean clearSelection()    {      if (selectedIndex >= 0)      {        int prev = selectedIndex;        selectedIndex = -1;        return true;      }      return false;    }   private boolean hasInputFocus()  {     return input != null && LwToolkit.isAncestorOf(input, LwFocusManager.manager.getFocusOwner());   }}

⌨️ 快捷键说明

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