basiclistui.java
来自「Mac OS X 10.4.9 for x86 Source Code gcc」· Java 代码 · 共 703 行 · 第 1/2 页
JAVA
703 行
/* BasicListUI.java -- Copyright (C) 2002, 2004 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., 59 Temple Place, Suite 330, Boston, MA02111-1307 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.Color;import java.awt.Component;import java.awt.Dimension;import java.awt.Graphics;import java.awt.Point;import java.awt.Rectangle;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.JComponent;import javax.swing.JList;import javax.swing.ListCellRenderer;import javax.swing.ListModel;import javax.swing.ListSelectionModel;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.ComponentUI;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 FocusEvents} * from the JList. */ 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. */ void repaintCellFocus() { } } /** * A helper class which listens for {@link ListDataEvent}s generated by * the {@link JList}'s {@link ListModel}. * * @see javax.swing.JList#model */ 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}. */ class ListSelectionHandler implements ListSelectionListener { /** * Called when the list selection changes. * * @param e The event representing the change */ public void valueChanged(ListSelectionEvent e) { } } /** * A helper class which listens for {@link MouseEvent}s * from the {@link JList}. */ 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) { } /** * Called when a mouse button is pressed down on the * {@link JList}. * * @param event The event representing the mouse press */ public void mousePressed(MouseEvent event) { int row = BasicListUI.this.convertYToRow(event.getY()); if (row == -1) return; BasicListUI.this.list.setSelectedIndex(row); } /** * Called when a mouse button is released on * the {@link JList} * * @param event The event representing the mouse press */ public void mouseReleased(MouseEvent event) { } /** * Called when the mouse pointer enters the area bounded * by the {@link JList} * * @param event The event representing the mouse entry */ public void mouseEntered(MouseEvent event) { } /** * Called when the mouse pointer leaves the area bounded * by the {@link JList} * * @param event The event representing the mouse exit */ public void mouseExited(MouseEvent event) { } /** * Called when the mouse pointer moves over the area bounded * by the {@link JList} while a button is held down. * * @param event The event representing the mouse drag */ public void mouseDragged(MouseEvent event) { } /** * Called when the mouse pointer moves over the area bounded * by the {@link JList}. * * @param event The event representing the mouse move */ public void mouseMoved(MouseEvent event) { } } /** * Helper class which listens to {@link PropertyChangeEvent}s * from the {@link JList}. */ class PropertyChangeHandler implements PropertyChangeListener { /** * Called when the {@link JList} changes one of its bound properties. * * @param e The event representing the property change */ public void propertyChange(PropertyChangeEvent e) { if (e.getSource() == BasicListUI.this.list) { if (e.getOldValue() != null && e.getOldValue() instanceof ListModel) ((ListModel) e.getOldValue()).removeListDataListener(BasicListUI.this.listDataListener); if (e.getNewValue() != null && e.getNewValue() instanceof ListModel) ((ListModel) e.getNewValue()).addListDataListener(BasicListUI.this.listDataListener); } BasicListUI.this.damageLayout(); } } /** * Creates a new BasicListUI for the component. * * @param c The component to create a UI for * * @return A new UI */ public static ComponentUI createUI(final JComponent c) { return new BasicListUI(); } /** The current focus listener. */ FocusHandler focusListener; /** The data listener listening to the model. */ ListDataHandler listDataListener; /** The selection listener listening to the selection model. */ ListSelectionHandler listSelectionListener; /** The mouse listener listening to the list. */ MouseInputHandler mouseInputListener; /** The property change listener listening to the list. */ PropertyChangeHandler propertyChangeListener; /** Saved reference to the list this UI was created for. */ JList list; /** The height of a single cell in the list. */ int cellHeight; /** The width of a single cell in the list. */ int cellWidth; /** * An array of varying heights of cells in the list, in cases where each * cell might have a different height. */ int[] cellHeights; /** * A simple counter. When nonzero, indicates that the UI class is out of * date with respect to the underlying list, and must recalculate the * list layout before painting or performing size calculations. */ int updateLayoutStateNeeded; /** * Calculate the height of a particular row. If there is a fixed {@link * #cellHeight}, return it; otherwise return the specific row height * requested from the {@link #cellHeights} array. If the requested row * is invalid, return <code>-1</code>. * * @param row The row to get the height of * * @return The height, in pixels, of the specified row */ int getRowHeight(int row) { if (row < 0 || row >= cellHeights.length) return -1; else if (cellHeight != -1) return cellHeight; else return cellHeights[row]; } /** * Calculate the bounds of a particular cell, considering the upper left * corner of the list as the origin position <code>(0,0)</code>. * * @param l Ignored; calculates over <code>this.list</code> * @param index1 The first row to include in the bounds * @param index2 The last row to incude in the bounds * * @return A rectangle encompassing the range of rows between * <code>index1</code> and <code>index2</code> inclusive */ public Rectangle getCellBounds(JList l, int index1, int index2)
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?