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

📄 basiclistui.java

📁 gcc的组建
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
/* BasicListUI.java --   Copyright (C) 2002, 2004, 2005 Free Software Foundation, Inc.This file is part of GNU Classpath.GNU Classpath is free software; you can redistribute it and/or modifyit under the terms of the GNU General Public License as published bythe Free Software Foundation; either version 2, or (at your option)any later version.GNU Classpath is distributed in the hope that it will be useful, butWITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNUGeneral Public License for more details.You should have received a copy of the GNU General Public Licensealong with GNU Classpath; see the file COPYING.  If not, write to theFree Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA02110-1301 USA.Linking this library statically or dynamically with other modules ismaking a combined work based on this library.  Thus, the terms andconditions of the GNU General Public License cover the wholecombination.As a special exception, the copyright holders of this library give youpermission to link this library with independent modules to produce anexecutable, regardless of the license terms of these independentmodules, and to copy and distribute the resulting executable underterms of your choice, provided that you also meet, for each linkedindependent module, the terms and conditions of the license of thatmodule.  An independent module is a module which is not derived fromor based on this library.  If you modify this library, you may extendthis exception to your version of the library, but you are notobligated to do so.  If you do not wish to do so, delete thisexception statement from your version. */package javax.swing.plaf.basic;import java.awt.Component;import java.awt.Dimension;import java.awt.Graphics;import java.awt.Point;import java.awt.Rectangle;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.awt.event.ComponentAdapter;import java.awt.event.ComponentEvent;import java.awt.event.ComponentListener;import java.awt.event.FocusEvent;import java.awt.event.FocusListener;import java.awt.event.MouseEvent;import java.beans.PropertyChangeEvent;import java.beans.PropertyChangeListener;import javax.swing.AbstractAction;import javax.swing.ActionMap;import javax.swing.CellRendererPane;import javax.swing.DefaultListSelectionModel;import javax.swing.InputMap;import javax.swing.JComponent;import javax.swing.JList;import javax.swing.JViewport;import javax.swing.KeyStroke;import javax.swing.ListCellRenderer;import javax.swing.ListModel;import javax.swing.ListSelectionModel;import javax.swing.LookAndFeel;import javax.swing.UIDefaults;import javax.swing.UIManager;import javax.swing.event.ListDataEvent;import javax.swing.event.ListDataListener;import javax.swing.event.ListSelectionEvent;import javax.swing.event.ListSelectionListener;import javax.swing.event.MouseInputListener;import javax.swing.plaf.ActionMapUIResource;import javax.swing.plaf.ComponentUI;import javax.swing.plaf.InputMapUIResource;import javax.swing.plaf.ListUI;/** * The Basic Look and Feel UI delegate for the  * JList. */public class BasicListUI extends ListUI{  /**   * A helper class which listens for {@link ComponentEvent}s from   * the JList.   */  private class ComponentHandler extends ComponentAdapter {    /**     * Called when the component is hidden. Invalidates the internal     * layout.     */    public void componentResized(ComponentEvent ev) {      BasicListUI.this.damageLayout();    }  }  /**   * A helper class which listens for {@link FocusEvent}s   * from the JList.   */  public class FocusHandler implements FocusListener  {    /**     * Called when the JList acquires focus.     *     * @param e The FocusEvent representing focus acquisition     */    public void focusGained(FocusEvent e)    {      repaintCellFocus();    }    /**     * Called when the JList loses focus.     *     * @param e The FocusEvent representing focus loss     */    public void focusLost(FocusEvent e)    {      repaintCellFocus();    }    /**     * Helper method to repaint the focused cell's      * lost or acquired focus state.     */    protected void repaintCellFocus()    {      // TODO: Implement this properly.    }  }  /**   * A helper class which listens for {@link ListDataEvent}s generated by   * the {@link JList}'s {@link ListModel}.   *   * @see javax.swing.JList#getModel()   */  public class ListDataHandler implements ListDataListener  {    /**     * Called when a general change has happened in the model which cannot     * be represented in terms of a simple addition or deletion.     *     * @param e The event representing the change     */    public void contentsChanged(ListDataEvent e)    {      BasicListUI.this.damageLayout();    }    /**     * Called when an interval of objects has been added to the model.     *     * @param e The event representing the addition     */    public void intervalAdded(ListDataEvent e)    {      BasicListUI.this.damageLayout();    }    /**     * Called when an inteval of objects has been removed from the model.     *     * @param e The event representing the removal     */    public void intervalRemoved(ListDataEvent e)    {      BasicListUI.this.damageLayout();    }  }  /**   * A helper class which listens for {@link ListSelectionEvent}s   * from the {@link JList}'s {@link ListSelectionModel}.   */  public class ListSelectionHandler implements ListSelectionListener  {    /**     * Called when the list selection changes.       *     * @param e The event representing the change     */    public void valueChanged(ListSelectionEvent e)    {      int index1 = e.getFirstIndex();      int index2 = e.getLastIndex();      Rectangle damaged = getCellBounds(list, index1, index2);      list.repaint(damaged);    }  }  /**   * This class is used to mimmic the behaviour of the JDK when registering   * keyboard actions.  It is the same as the private class used in JComponent   * for the same reason.  This class receives an action event and dispatches   * it to the true receiver after altering the actionCommand property of the   * event.   */  private static class ActionListenerProxy    extends AbstractAction  {    ActionListener target;    String bindingCommandName;    public ActionListenerProxy(ActionListener li,                                String cmd)    {      target = li;      bindingCommandName = cmd;    }    public void actionPerformed(ActionEvent e)    {      ActionEvent derivedEvent = new ActionEvent(e.getSource(),                                                 e.getID(),                                                 bindingCommandName,                                                 e.getModifiers());      target.actionPerformed(derivedEvent);    }  }    class ListAction extends AbstractAction  {    public void actionPerformed (ActionEvent e)    {      int lead = list.getLeadSelectionIndex();      int max = list.getModel().getSize() - 1;      DefaultListSelectionModel selModel = (DefaultListSelectionModel)list.getSelectionModel();      String command = e.getActionCommand();      // Do nothing if list is empty      if (max == -1)        return;            if (command.equals("selectNextRow"))        {          selectNextIndex();        }      else if (command.equals("selectPreviousRow"))        {          selectPreviousIndex();        }      else if (command.equals("clearSelection"))        {          list.clearSelection();        }      else if (command.equals("selectAll"))        {          list.setSelectionInterval(0, max);          // this next line is to restore the lead selection index to the old          // position, because select-all should not change the lead index          list.addSelectionInterval(lead, lead);        }      else if (command.equals("selectLastRow"))        {          list.setSelectedIndex(list.getModel().getSize() - 1);         }      else if (command.equals("selectLastRowChangeLead"))        {          selModel.moveLeadSelectionIndex(list.getModel().getSize() - 1);        }      else if (command.equals("scrollDownExtendSelection"))        {          int target;          if (lead == list.getLastVisibleIndex())            {              target = Math.min                (max, lead + (list.getLastVisibleIndex() -                    list.getFirstVisibleIndex() + 1));            }          else            target = list.getLastVisibleIndex();          selModel.setLeadSelectionIndex(target);        }      else if (command.equals("scrollDownChangeLead"))        {          int target;          if (lead == list.getLastVisibleIndex())            {              target = Math.min                (max, lead + (list.getLastVisibleIndex() -                    list.getFirstVisibleIndex() + 1));            }          else            target = list.getLastVisibleIndex();          selModel.moveLeadSelectionIndex(target);        }      else if (command.equals("scrollUpExtendSelection"))        {          int target;          if (lead == list.getFirstVisibleIndex())            {              target = Math.max                 (0, lead - (list.getLastVisibleIndex() -                     list.getFirstVisibleIndex() + 1));            }          else            target = list.getFirstVisibleIndex();          selModel.setLeadSelectionIndex(target);        }      else if (command.equals("scrollUpChangeLead"))        {          int target;          if (lead == list.getFirstVisibleIndex())            {              target = Math.max                 (0, lead - (list.getLastVisibleIndex() -                     list.getFirstVisibleIndex() + 1));            }          else            target = list.getFirstVisibleIndex();          selModel.moveLeadSelectionIndex(target);        }      else if (command.equals("selectNextRowExtendSelection"))        {          selModel.setLeadSelectionIndex(Math.min(lead + 1,max));        }      else if (command.equals("selectFirstRow"))        {          list.setSelectedIndex(0);        }      else if (command.equals("selectFirstRowChangeLead"))          {            selModel.moveLeadSelectionIndex(0);          }      else if (command.equals("selectFirstRowExtendSelection"))        {          selModel.setLeadSelectionIndex(0);        }      else if (command.equals("selectPreviousRowExtendSelection"))        {          selModel.setLeadSelectionIndex(Math.max(0,lead - 1));        }      else if (command.equals("scrollUp"))        {          int target;          if (lead == list.getFirstVisibleIndex())            {              target = Math.max                 (0, lead - (list.getLastVisibleIndex() -                     list.getFirstVisibleIndex() + 1));            }          else            target = list.getFirstVisibleIndex();          list.setSelectedIndex(target);                  }      else if (command.equals("selectLastRowExtendSelection"))        {          selModel.setLeadSelectionIndex(list.getModel().getSize() - 1);        }      else if (command.equals("scrollDown"))        {          int target;          if (lead == list.getLastVisibleIndex())            {              target = Math.min                (max, lead + (list.getLastVisibleIndex() -                    list.getFirstVisibleIndex() + 1));            }          else            target = list.getLastVisibleIndex();          list.setSelectedIndex(target);        }      else if (command.equals("selectNextRowChangeLead"))          {            if (selModel.getSelectionMode() != ListSelectionModel.MULTIPLE_INTERVAL_SELECTION)              selectNextIndex();            else              {                selModel.moveLeadSelectionIndex(Math.min(max, lead + 1));              }          }      else if (command.equals("selectPreviousRowChangeLead"))        {          if (selModel.getSelectionMode() != ListSelectionModel.MULTIPLE_INTERVAL_SELECTION)            selectPreviousIndex();          else            {              selModel.moveLeadSelectionIndex(Math.max(0, lead - 1));            }        }            else if (command.equals("addToSelection"))        {          list.addSelectionInterval(lead, lead);        }      else if (command.equals("extendTo"))        {          selModel.setSelectionInterval(selModel.getAnchorSelectionIndex(),                                        lead);        }      else if (command.equals("toggleAndAnchor"))        {          if (!list.isSelectedIndex(lead))            list.addSelectionInterval(lead, lead);          else            list.removeSelectionInterval(lead, lead);          selModel.setAnchorSelectionIndex(lead);        }      else         {          // DEBUG: uncomment the following line to print out           // key bindings that aren't implemented yet                    // System.out.println ("not implemented: "+e.getActionCommand());        }            list.ensureIndexIsVisible(list.getLeadSelectionIndex());    }  }       /**   * A helper class which listens for {@link MouseEvent}s    * from the {@link JList}.   */  public class MouseInputHandler implements MouseInputListener  {    /**     * Called when a mouse button press/release cycle completes     * on the {@link JList}     *     * @param event The event representing the mouse click     */    public void mouseClicked(MouseEvent event)    {      Point click = event.getPoint();      int index = locationToIndex(list, click);      if (index == -1)        return;      if (event.isShiftDown())        {          if (list.getSelectionMode() == ListSelectionModel.SINGLE_SELECTION)            list.setSelectedIndex(index);          else if (list.getSelectionMode() ==                    ListSelectionModel.SINGLE_INTERVAL_SELECTION)            // COMPAT: the IBM VM is compatible with the following line of code.            // However, compliance with Sun's VM would correspond to replacing             // getAnchorSelectionIndex() with getLeadSelectionIndex().This is             // both unnatural and contradictory to the way they handle other             // similar UI interactions.            list.setSelectionInterval(list.getAnchorSelectionIndex(), index);          else            // COMPAT: both Sun and IBM are compatible instead with:            // list.setSelectionInterval            //     (list.getLeadSelectionIndex(),index);            // Note that for IBM this is contradictory to what they did in             // the above situation for SINGLE_INTERVAL_SELECTION.              // The most natural thing to do is the following:

⌨️ 快捷键说明

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