1 /*
   2  * Copyright (c) 1997, 2006, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package javax.swing.plaf;
  27 
  28 import javax.swing.JList;
  29 import java.awt.Point;
  30 import java.awt.Rectangle;
  31 
  32 
  33 /**
  34  * The {@code JList} pluggable look and feel delegate.
  35  *
  36  * @author Hans Muller
  37  */
  38 
  39 public abstract class ListUI extends ComponentUI
  40 {
  41     /**
  42      * Returns the cell index in the specified {@code JList} closest to the
  43      * given location in the list's coordinate system. To determine if the
  44      * cell actually contains the specified location, compare the point against
  45      * the cell's bounds, as provided by {@code getCellBounds}.
  46      * This method returns {@code -1} if the list's model is empty.
  47      *
  48      * @param list the list
  49      * @param location the coordinates of the point
  50      * @return the cell index closest to the given location, or {@code -1}
  51      * @throws NullPointerException if {@code location} is null
  52      */
  53     public abstract int locationToIndex(JList list, Point location);
  54 
  55 
  56     /**
  57      * Returns the origin in the given {@code JList}, of the specified item,
  58      * in the list's coordinate system.
  59      * Returns {@code null} if the index isn't valid.
  60      *
  61      * @param list the list
  62      * @param index the cell index
  63      * @return the origin of the cell, or {@code null}
  64      */
  65     public abstract Point indexToLocation(JList list, int index);
  66 
  67 
  68     /**
  69      * Returns the bounding rectangle, in the given list's coordinate system,
  70      * for the range of cells specified by the two indices.
  71      * The indices can be supplied in any order.
  72      * <p>
  73      * If the smaller index is outside the list's range of cells, this method
  74      * returns {@code null}. If the smaller index is valid, but the larger
  75      * index is outside the list's range, the bounds of just the first index
  76      * is returned. Otherwise, the bounds of the valid range is returned.
  77      *
  78      * @param list the list
  79      * @param index1 the first index in the range
  80      * @param index2 the second index in the range
  81      * @return the bounding rectangle for the range of cells, or {@code null}
  82      */
  83     public abstract Rectangle getCellBounds(JList list, int index1, int index2);
  84 }