Debian Codegraph @

src/com/jidesoft/plaf/basic/BasicCheckBoxListUI.java

raw
1 /*
2 * @(#)BasicCheckBoxListUI.java 3/18/2009
3 *
4 * Copyright 2002 - 2009 JIDE Software Inc. All rights reserved.
5 *
6 */
7
8 package com.jidesoft.plaf.basic;
9
10 import javax.swing.*;
11 import javax.swing.plaf.ComponentUI;
12 import javax.swing.plaf.basic.BasicListUI;
13 import java.awt.*;
14
15 public class BasicCheckBoxListUI extends BasicListUI {
16 public BasicCheckBoxListUI() {
17 }
18
19 @SuppressWarnings({"UnusedDeclaration"})
20 public static ComponentUI createUI(JComponent c) {
21 return new BasicCheckBoxListUI();
22 }
23
24 @Override
25 public int locationToIndex(JList aList, Point location) {
26 int index = super.locationToIndex(aList, location);
27 int size = list.getModel().getSize();
28 if (index < size - 1) {
29 return index;
30 }
31
32 // To avoid the behavior that clicking on the blank area selects the last item in the list.
33 int y = location.y;
34 Insets insets = list.getInsets();
35 int maxRow = size - 1; // it is only valid for JList.VERTICAL scenario, no good solution for other orientations
36 int row;
37 if (cellHeights == null) {
38 row = (cellHeight == 0) ? 0 :
39 ((y - insets.top) / cellHeight);
40 }
41 else if (size > cellHeights.length) {
42 return index;
43 }
44 else {
45 int rowYOffset = insets.top;
46 for (row = 0; row < size; row++) {
47 if (y >= rowYOffset && y < rowYOffset + cellHeights[row]) {
48 break;
49 }
50 rowYOffset += cellHeights[row];
51 }
52 }
53 if (row > maxRow) {
54 return -1;
55 }
56 else {
57 return index;
58 }
59 }
60 }