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

📄 jlist.java

📁 gcc的组建
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
/* JList.java --   Copyright (C) 2002, 2003, 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;import java.awt.Color;import java.awt.Component;import java.awt.ComponentOrientation;import java.awt.Cursor;import java.awt.Dimension;import java.awt.Font;import java.awt.FontMetrics;import java.awt.Point;import java.awt.Rectangle;import java.awt.event.FocusListener;import java.beans.PropertyChangeEvent;import java.beans.PropertyChangeListener;import java.util.Locale;import java.util.Vector;import javax.accessibility.Accessible;import javax.accessibility.AccessibleComponent;import javax.accessibility.AccessibleContext;import javax.accessibility.AccessibleRole;import javax.accessibility.AccessibleSelection;import javax.accessibility.AccessibleState;import javax.accessibility.AccessibleStateSet;import javax.swing.event.ListDataEvent;import javax.swing.event.ListDataListener;import javax.swing.event.ListSelectionEvent;import javax.swing.event.ListSelectionListener;import javax.swing.plaf.ListUI;import javax.swing.text.Position;/** * <p>This class is a facade over three separate objects: {@link * javax.swing.ListModel}, {@link javax.swing.ListSelectionModel} and * {@link javax.swing.plaf.ListUI}. The facade represents a unified "list" * concept, with independently replacable (possibly client-provided) models * for its contents and its current selection. In addition, each element in * the list is rendered via a strategy class {@link * javax.swing.ListCellRenderer}.</p> * * <p>Lists have many properties, some of which are stored in this class * while others are delegated to the list's model or selection. The * following properties are available:</p> * * <table> * <tr><th>Property                       </th><th>Stored in</th><th>Bound?</th></tr> * <tr><td>accessibleContext              </td><td>list     </td><td>no    </td></tr> * <tr><td>anchorSelectionIndex           </td><td>selection</td><td>no    </td></tr> * <tr><td>cellRenderer                   </td><td>list     </td><td>yes   </td></tr> * <tr><td>dragEnabled                    </td><td>list     </td><td>no    </td></tr> * <tr><td>firstVisibleIndex              </td><td>list     </td><td>no    </td></tr> * <tr><td>fixedCellHeight                </td><td>list     </td><td>yes   </td></tr> * <tr><td>fixedCellWidth                 </td><td>list     </td><td>yes   </td></tr> * <tr><td>lastVisibleIndex               </td><td>list     </td><td>no    </td></tr> * <tr><td>layoutOrientation              </td><td>list     </td><td>yes   </td></tr> * <tr><td>leadSelectionIndex             </td><td>selection</td><td>no    </td></tr> * <tr><td>maxSelectionIndex              </td><td>selection</td><td>no    </td></tr> * <tr><td>minSelectionIndex              </td><td>selection</td><td>no    </td></tr> * <tr><td>model                          </td><td>list     </td><td>yes   </td></tr> * <tr><td>opaque                         </td><td>list     </td><td>no    </td></tr> * <tr><td>preferredScrollableViewportSize</td><td>list     </td><td>no    </td></tr> * <tr><td>prototypeCellValue             </td><td>list     </td><td>yes   </td></tr> * <tr><td>scrollableTracksViewportHeight </td><td>list     </td><td>no    </td></tr> * <tr><td>scrollableTracksViewportWidth  </td><td>list     </td><td>no    </td></tr> * <tr><td>selectedIndex                  </td><td>selection</td><td>no    </td></tr> * <tr><td>selectedIndices                </td><td>selection</td><td>no    </td></tr> * <tr><td>selectedValue                  </td><td>model    </td><td>no    </td></tr> * <tr><td>selectedValues                 </td><td>model    </td><td>no    </td></tr> * <tr><td>selectionBackground            </td><td>list     </td><td>yes   </td></tr> * <tr><td>selectionEmpty                 </td><td>selection</td><td>no    </td></tr> * <tr><td>selectionForeground            </td><td>list     </td><td>yes   </td></tr> * <tr><td>selectionMode                  </td><td>selection</td><td>no    </td></tr> * <tr><td>selectionModel                 </td><td>list     </td><td>yes   </td></tr> * <tr><td>UI                             </td><td>list     </td><td>yes   </td></tr> * <tr><td>UIClassID                      </td><td>list     </td><td>no    </td></tr> * <tr><td>valueIsAdjusting               </td><td>list     </td><td>no    </td></tr> * <tr><td>visibleRowCount                </td><td>list     </td><td>no    </td></tr> * </table>  * * @author Graydon Hoare (graydon@redhat.com) */public class JList extends JComponent implements Accessible, Scrollable{  /**   * Provides accessibility support for <code>JList</code>.   */  protected class AccessibleJList extends AccessibleJComponent    implements AccessibleSelection, PropertyChangeListener,               ListSelectionListener, ListDataListener  {    /**     * Provides accessibility support for list elements in <code>JList</code>s.     */    protected class AccessibleJListChild extends AccessibleContext      implements Accessible, AccessibleComponent    {      /**       * The parent list.       */      JList parent;      /**       * The index in the list for that child.       */      int listIndex;      /**       * The cursor for this list child.       */      // TODO: Testcases show that this class somehow stores state about the      // cursor. I cannot make up though how that could affect      // the actual list.      Cursor cursor = Cursor.getDefaultCursor();      /**       * Creates a new instance of <code>AccessibleJListChild</code>.       *       * @param list the list of which this is an accessible child       * @param index the list index for this child       */      public AccessibleJListChild(JList list, int index)      {        parent = list;        listIndex = index;      }      /**       * Returns the accessible context of this object. Returns       * <code>this</code> since <code>AccessibleJListChild</code>s are their       * own accessible contexts.       *       * @return the accessible context of this object, <code>this</code>       */      public AccessibleContext getAccessibleContext()      {        return this;      }      /**       * Returns the background color for this list child. This returns the       * background of the <code>JList</code> itself since the background       * cannot be set on list children individually       *       * @return the background color for this list child       */      public Color getBackground()      {        return parent.getBackground();      }      /**       * Calling this method has no effect, since the background color cannot be       * set on list children individually.       *       * @param color not used here.       */      public void setBackground(Color color)      {        // Calling this method has no effect, since the background color cannot        // be set on list children individually.      }      /**       * Returns the foreground color for this list child. This returns the       * background of the <code>JList</code> itself since the foreground       * cannot be set on list children individually.       *       * @return the background color for this list child       */      public Color getForeground()      {        return parent.getForeground();      }      /**       * Calling this method has no effect, since the foreground color cannot be       * set on list children individually.       *       * @param color not used here.       */      public void setForeground(Color color)      {        // Calling this method has no effect, since the foreground color cannot        // be set on list children individually.      }      /**       * Returns the cursor for this list child.       *       * @return the cursor for this list child       */      public Cursor getCursor()      {        // TODO: Testcases show that this method returns the cursor that has        // been set by setCursor. I cannot make up though how that could affect        // the actual list.        return cursor;      }      /**       * Sets the cursor for this list child.       */      public void setCursor(Cursor cursor)      {        this.cursor = cursor;        // TODO: Testcases show that this method returns the cursor that has        // been set by setCursor. I cannot make up though how that could affect        // the actual list.      }      /**       * Returns the font of the <code>JList</code> since it is not possible to       * set fonts for list children individually.       *       * @return the font of the <code>JList</code>       */      public Font getFont()      {        return parent.getFont();      }      /**       * Does nothing since it is not possible to set the font on list children       * individually.       *       * @param font not used here       */      public void setFont(Font font)      {        // Does nothing since it is not possible to set the font on list        // children individually.      }      /**       * Returns the font metrics for the specified font. This method forwards       * to the parent <code>JList</code>.        *       * @param font the font for which the font metrics is queried       *       * @return the font metrics for the specified font       */      public FontMetrics getFontMetrics(Font font)      {        return parent.getFontMetrics(font);      }      /**       * Returns <code>true</code> if the parent <code>JList</code> is enabled,       * <code>false</code> otherwise. The list children cannot have an enabled       * flag set individually.       *       * @return <code>true</code> if the parent <code>JList</code> is enabled,       *         <code>false</code> otherwise       */      public boolean isEnabled()      {        return parent.isEnabled();      }      /**       * Does nothing since the enabled flag cannot be set for list children       * individually.       *       * @param b not used here       */      public void setEnabled(boolean b)      {        // Does nothing since the enabled flag cannot be set for list children        // individually.      }      /**       * Returns <code>true</code> if this list child is visible,       * <code>false</code> otherwise. The value of this property depends       * on {@link JList#getFirstVisibleIndex()} and       * {@link JList#getLastVisibleIndex()}.       *       * @return <code>true</code> if this list child is visible,       *         <code>false</code> otherwise       */      public boolean isVisible()      {        return listIndex >= parent.getFirstVisibleIndex()               && listIndex <= parent.getLastVisibleIndex();      }      /**       * The value of the visible property cannot be modified, so this method       * does nothing.       *       * @param b not used here       */      public void setVisible(boolean b)      {        // The value of the visible property cannot be modified, so this method        // does nothing.      }      /**       * Returns <code>true</code> if this list child is currently showing on       * screen and <code>false</code> otherwise. The list child is showing if       * it is visible and if it's parent JList is currently showing.       *       * @return <code>true</code> if this list child is currently showing on       *         screen and <code>false</code> otherwise       */      public boolean isShowing()      {        return isVisible() && parent.isShowing();      }      /**       * Returns <code>true</code> if this list child covers the screen location       * <code>point</code> (relative to the <code>JList</code> coordinate       * system, <code>false</code> otherwise.       *       * @return <code>true</code> if this list child covers the screen location       *         <code>point</code> , <code>false</code> otherwise       */      public boolean contains(Point point)      {        return getBounds().contains(point);      }      /**       * Returns the absolute screen location of this list child.       *       * @return the absolute screen location of this list child       */      public Point getLocationOnScreen()      {        Point loc = getLocation();        SwingUtilities.convertPointToScreen(loc, parent);        return loc;      }      /**       * Returns the screen location of this list child relative to it's parent.       *       * @return the location of this list child relative to it's parent       *       * @see JList#indexToLocation(int)       */      public Point getLocation()      {        return parent.indexToLocation(listIndex);      }      /**       * Does nothing since the screen location cannot be set on list children       * explictitly.       *       * @param point not used here       */      public void setLocation(Point point)      {        // Does nothing since the screen location cannot be set on list children        // explictitly.      }      /**       * Returns the bounds of this list child.       *       * @return the bounds of this list child       *       * @see JList#getCellBounds(int, int)       */      public Rectangle getBounds()      {        return parent.getCellBounds(listIndex, listIndex);      }      /**       * Does nothing since the bounds cannot be set on list children       * individually.       *       * @param rectangle not used here       */      public void setBounds(Rectangle rectangle)      {        // Does nothing since the bounds cannot be set on list children        // individually.

⌨️ 快捷键说明

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