31 import java.awt.event.AdjustmentEvent; |
31 import java.awt.event.AdjustmentEvent; |
32 import java.util.List; |
32 import java.util.List; |
33 import java.util.ArrayList; |
33 import java.util.ArrayList; |
34 import java.util.Iterator; |
34 import java.util.Iterator; |
35 import sun.awt.motif.X11FontMetrics; |
35 import sun.awt.motif.X11FontMetrics; |
36 import java.util.logging.*; |
36 import sun.util.logging.PlatformLogger; |
37 |
37 |
38 // FIXME: implement multi-select |
38 // FIXME: implement multi-select |
39 /* |
39 /* |
40 * Class to paint a list of items, possibly with scrollbars |
40 * Class to paint a list of items, possibly with scrollbars |
41 * This class paints all items with the same font |
41 * This class paints all items with the same font |
42 * For now, this class manages the list of items and painting thereof, but not |
42 * For now, this class manages the list of items and painting thereof, but not |
43 * posting of Item or ActionEvents |
43 * posting of Item or ActionEvents |
44 */ |
44 */ |
45 public class ListHelper implements XScrollbarClient { |
45 public class ListHelper implements XScrollbarClient { |
46 private static final Logger log = Logger.getLogger("sun.awt.X11.ListHelper"); |
46 private static final PlatformLogger log = PlatformLogger.getLogger("sun.awt.X11.ListHelper"); |
47 |
47 |
48 private final int FOCUS_INSET = 1; |
48 private final int FOCUS_INSET = 1; |
49 |
49 |
50 private final int BORDER_WIDTH; // Width of border drawn around the list |
50 private final int BORDER_WIDTH; // Width of border drawn around the list |
51 // of items |
51 // of items |
261 int getItemHeight() { |
261 int getItemHeight() { |
262 return fm.getHeight() + (2*TEXT_SPACE); |
262 return fm.getHeight() + (2*TEXT_SPACE); |
263 } |
263 } |
264 |
264 |
265 public int y2index(int y) { |
265 public int y2index(int y) { |
266 if (log.isLoggable(Level.FINE)) { |
266 if (log.isLoggable(PlatformLogger.FINE)) { |
267 log.fine("y=" + y +", firstIdx=" + firstDisplayedIndex() +", itemHeight=" + getItemHeight() |
267 log.fine("y=" + y +", firstIdx=" + firstDisplayedIndex() +", itemHeight=" + getItemHeight() |
268 + ",item_margin=" + ITEM_MARGIN); |
268 + ",item_margin=" + ITEM_MARGIN); |
269 } |
269 } |
270 // See 6243382 for more information |
270 // See 6243382 for more information |
271 int newIdx = firstDisplayedIndex() + ((y - 2*ITEM_MARGIN) / (getItemHeight() + 2*ITEM_MARGIN)); |
271 int newIdx = firstDisplayedIndex() + ((y - 2*ITEM_MARGIN) / (getItemHeight() + 2*ITEM_MARGIN)); |