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

📄 basiclistui.java

📁 JAVA的一些源码 JAVA2 STANDARD EDITION DEVELOPMENT KIT 5.0
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
            height = preferredHeight;        }        else {            Rectangle bounds = getCellBounds(list, lastRow);            if (bounds != null) {                height = bounds.y + bounds.height + insets.bottom;            }            else {                height = 0;            }        }        return new Dimension(width, height);    }    /**     * Selected the previous row and force it to be visible.     *     * @see JList#ensureIndexIsVisible     */    protected void selectPreviousIndex() {        int s = list.getSelectedIndex();        if(s > 0) {            s -= 1;            list.setSelectedIndex(s);            list.ensureIndexIsVisible(s);        }    }    /**     * Selected the previous row and force it to be visible.     *     * @see JList#ensureIndexIsVisible     */    protected void selectNextIndex()    {        int s = list.getSelectedIndex();        if((s + 1) < list.getModel().getSize()) {            s += 1;            list.setSelectedIndex(s);            list.ensureIndexIsVisible(s);        }    }    /**     * Registers the keyboard bindings on the <code>JList</code> that the     * <code>BasicListUI</code> is associated with. This method is called at     * installUI() time.     *     * @see #installUI     */    protected void installKeyboardActions() {	InputMap inputMap = getInputMap(JComponent.WHEN_FOCUSED);	SwingUtilities.replaceUIInputMap(list, JComponent.WHEN_FOCUSED,					   inputMap);        LazyActionMap.installLazyActionMap(list, BasicListUI.class,                                           "List.actionMap");    }    InputMap getInputMap(int condition) {	if (condition == JComponent.WHEN_FOCUSED) {	    InputMap keyMap = (InputMap)DefaultLookup.get(                             list, this, "List.focusInputMap");	    InputMap rtlKeyMap;	    if (isLeftToRight ||		((rtlKeyMap = (InputMap)DefaultLookup.get(list, this,                              "List.focusInputMap.RightToLeft")) == null)) {		    return keyMap;	    } else {		rtlKeyMap.setParent(keyMap);		return rtlKeyMap;	    }	}	return null;    }    /**     * Unregisters keyboard actions installed from     * <code>installKeyboardActions</code>.     * This method is called at uninstallUI() time - subclassess should     * ensure that all of the keyboard actions registered at installUI     * time are removed here.     *     * @see #installUI     */    protected void uninstallKeyboardActions() {	SwingUtilities.replaceUIActionMap(list, null);	SwingUtilities.replaceUIInputMap(list, JComponent.WHEN_FOCUSED, null);    }    /**     * Create and install the listeners for the JList, its model, and its     * selectionModel.  This method is called at installUI() time.     *     * @see #installUI     * @see #uninstallListeners     */    protected void installListeners()    {	TransferHandler th = list.getTransferHandler();	if (th == null || th instanceof UIResource) {	    list.setTransferHandler(defaultTransferHandler);	}	DropTarget dropTarget = list.getDropTarget();	if (dropTarget instanceof UIResource) {	    try {		dropTarget.addDropTargetListener(new ListDropTargetListener());	    } catch (TooManyListenersException tmle) {		// should not happen... swing drop target is multicast	    }	}        focusListener = createFocusListener();        mouseInputListener = createMouseInputListener();        propertyChangeListener = createPropertyChangeListener();        listSelectionListener = createListSelectionListener();        listDataListener = createListDataListener();        list.addFocusListener(focusListener);        if (!DRAG_FIX) {            list.addMouseListener(defaultDragRecognizer);            list.addMouseMotionListener(defaultDragRecognizer);        }        list.addMouseListener(mouseInputListener);        list.addMouseMotionListener(mouseInputListener);        list.addPropertyChangeListener(propertyChangeListener);        list.addKeyListener(getHandler());        ListModel model = list.getModel();        if (model != null) {            model.addListDataListener(listDataListener);        }        ListSelectionModel selectionModel = list.getSelectionModel();        if (selectionModel != null) {            selectionModel.addListSelectionListener(listSelectionListener);        }    }    /**     * Remove the listeners for the JList, its model, and its     * selectionModel.  All of the listener fields, are reset to     * null here.  This method is called at uninstallUI() time,     * it should be kept in sync with installListeners.     *     * @see #uninstallUI     * @see #installListeners     */    protected void uninstallListeners()    {        list.removeFocusListener(focusListener);        if (!DRAG_FIX) {            list.removeMouseListener(defaultDragRecognizer);            list.removeMouseMotionListener(defaultDragRecognizer);        }        list.removeMouseListener(mouseInputListener);        list.removeMouseMotionListener(mouseInputListener);        list.removePropertyChangeListener(propertyChangeListener);        list.removeKeyListener(getHandler());        ListModel model = list.getModel();        if (model != null) {            model.removeListDataListener(listDataListener);        }        ListSelectionModel selectionModel = list.getSelectionModel();        if (selectionModel != null) {            selectionModel.removeListSelectionListener(listSelectionListener);        }        focusListener = null;        mouseInputListener  = null;        listSelectionListener = null;        listDataListener = null;        propertyChangeListener = null;        handler = null;    }    /**     * Initialize JList properties, e.g. font, foreground, and background,     * and add the CellRendererPane.  The font, foreground, and background     * properties are only set if their current value is either null     * or a UIResource, other properties are set if the current     * value is null.     *     * @see #uninstallDefaults     * @see #installUI     * @see CellRendererPane     */    protected void installDefaults()    {        list.setLayout(null);        LookAndFeel.installBorder(list, "List.border");        LookAndFeel.installColorsAndFont(list, "List.background", "List.foreground", "List.font");        LookAndFeel.installProperty(list, "opaque", Boolean.TRUE);        if (list.getCellRenderer() == null) {            list.setCellRenderer((ListCellRenderer)(UIManager.get("List.cellRenderer")));        }        Color sbg = list.getSelectionBackground();        if (sbg == null || sbg instanceof UIResource) {            list.setSelectionBackground(UIManager.getColor("List.selectionBackground"));        }        Color sfg = list.getSelectionForeground();        if (sfg == null || sfg instanceof UIResource) {            list.setSelectionForeground(UIManager.getColor("List.selectionForeground"));        }	Long l = (Long)UIManager.get("List.timeFactor");	timeFactor = (l!=null) ? l.longValue() : 1000L;        updateIsFileList();	isLeftToRight = list.getComponentOrientation().isLeftToRight();    }    private void updateIsFileList() {        boolean b = Boolean.TRUE.equals(list.getClientProperty("List.isFileList"));        if (b != isFileList) {            isFileList = b;            Font oldFont = list.getFont();            if (oldFont == null || oldFont instanceof UIResource) {                Font newFont = UIManager.getFont(b ? "FileChooser.listFont" : "List.font");                if (newFont != null && newFont != oldFont) {                    list.setFont(newFont);                }            }        }    }    /**     * Set the JList properties that haven't been explicitly overridden to     * null.  A property is considered overridden if its current value     * is not a UIResource.     *     * @see #installDefaults     * @see #uninstallUI     * @see CellRendererPane     */    protected void uninstallDefaults()    {        LookAndFeel.uninstallBorder(list);        if (list.getFont() instanceof UIResource) {            list.setFont(null);        }        if (list.getForeground() instanceof UIResource) {            list.setForeground(null);        }        if (list.getBackground() instanceof UIResource) {            list.setBackground(null);        }        if (list.getSelectionBackground() instanceof UIResource) {            list.setSelectionBackground(null);        }        if (list.getSelectionForeground() instanceof UIResource) {            list.setSelectionForeground(null);        }        if (list.getCellRenderer() instanceof UIResource) {            list.setCellRenderer(null);        }	if (list.getTransferHandler() instanceof UIResource) {	    list.setTransferHandler(null);	}    }    /**     * Initializes <code>this.list</code> by calling <code>installDefaults()</code>,     * <code>installListeners()</code>, and <code>installKeyboardActions()</code>     * in order.     *     * @see #installDefaults     * @see #installListeners     * @see #installKeyboardActions     */    public void installUI(JComponent c)    {        list = (JList)c;        layoutOrientation = list.getLayoutOrientation();        rendererPane = new CellRendererPane();        list.add(rendererPane);        columnCount = 1;        installDefaults();        installListeners();        installKeyboardActions();    }    /**     * Uninitializes <code>this.list</code> by calling <code>uninstallListeners()</code>,     * <code>uninstallKeyboardActions()</code>, and <code>uninstallDefaults()</code>     * in order.  Sets this.list to null.     *     * @see #uninstallListeners     * @see #uninstallKeyboardActions     * @see #uninstallDefaults     */    public void uninstallUI(JComponent c)    {        uninstallListeners();        uninstallDefaults();        uninstallKeyboardActions();        cellWidth = cellHeight = -1;        cellHeights = null;        listWidth = listHeight = -1;        list.remove(rendererPane);        rendererPane = null;        list = null;    }    /**     * Returns a new instance of BasicListUI.  BasicListUI delegates are     * allocated one per JList.     *     * @return A new ListUI implementation for the Windows look and feel.     */    public static ComponentUI createUI(JComponent list) {        return new BasicListUI();    }    /**     * Convert a point in <code>JList</code> coordinates to the closest index     * of the cell at that location. To determine if the cell actually     * contains the specified location use a combination of this method and     * <code>getCellBounds</code>.  Returns -1 if the model is empty.     *     * @return The index of the cell at location, or -1.     * @see ListUI#locationToIndex     */    public int locationToIndex(JList list, Point location) {        maybeUpdateLayoutState();        return convertLocationToModel(location.x, location.y);    }    /**     * @return The origin of the index'th cell, null if index is invalid.     * @see ListUI#indexToLocation     */    public Point indexToLocation(JList list, int index) {        maybeUpdateLayoutState();        Rectangle rect = getCellBounds(list, index, index);        if (rect != null) {

⌨️ 快捷键说明

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