< prev index next >

src/java.desktop/share/classes/javax/swing/plaf/basic/BasicListUI.java

Print this page

        

*** 2132,2141 **** --- 2132,2144 ---- ListSelectionModel lsm = list.getSelectionModel(); int lead = adjustIndex(lsm.getLeadSelectionIndex(), list); Rectangle leadRect = (lead==-1) ? new Rectangle() : list.getCellBounds(lead, lead); + if (leadRect == null) { + return index; + } if (list.getLayoutOrientation() == JList.VERTICAL_WRAP && list.getVisibleRowCount() <= 0) { if (!list.getComponentOrientation().isLeftToRight()) { direction = -direction; }
*** 2145,2177 **** // left visRect.x = leadRect.x + leadRect.width - visRect.width; Point p = new Point(visRect.x - 1, leadRect.y); index = list.locationToIndex(p); Rectangle cellBounds = list.getCellBounds(index, index); ! if (visRect.intersects(cellBounds)) { p.x = cellBounds.x - 1; index = list.locationToIndex(p); cellBounds = list.getCellBounds(index, index); } // this is necessary for right-to-left orientation only ! if (cellBounds.y != leadRect.y) { p.x = cellBounds.x + cellBounds.width; index = list.locationToIndex(p); } } else { // right visRect.x = leadRect.x; Point p = new Point(visRect.x + visRect.width, leadRect.y); index = list.locationToIndex(p); Rectangle cellBounds = list.getCellBounds(index, index); ! if (visRect.intersects(cellBounds)) { p.x = cellBounds.x + cellBounds.width; index = list.locationToIndex(p); cellBounds = list.getCellBounds(index, index); } ! if (cellBounds.y != leadRect.y) { p.x = cellBounds.x - 1; index = list.locationToIndex(p); } } } --- 2148,2180 ---- // left visRect.x = leadRect.x + leadRect.width - visRect.width; Point p = new Point(visRect.x - 1, leadRect.y); index = list.locationToIndex(p); Rectangle cellBounds = list.getCellBounds(index, index); ! if (cellBounds != null && visRect.intersects(cellBounds)) { p.x = cellBounds.x - 1; index = list.locationToIndex(p); cellBounds = list.getCellBounds(index, index); } // this is necessary for right-to-left orientation only ! if (cellBounds != null && cellBounds.y != leadRect.y) { p.x = cellBounds.x + cellBounds.width; index = list.locationToIndex(p); } } else { // right visRect.x = leadRect.x; Point p = new Point(visRect.x + visRect.width, leadRect.y); index = list.locationToIndex(p); Rectangle cellBounds = list.getCellBounds(index, index); ! if (cellBounds != null && visRect.intersects(cellBounds)) { p.x = cellBounds.x + cellBounds.width; index = list.locationToIndex(p); cellBounds = list.getCellBounds(index, index); } ! if (cellBounds != null && cellBounds.y != leadRect.y) { p.x = cellBounds.x - 1; index = list.locationToIndex(p); } } }
*** 2188,2205 **** p.y = visRect.y; index = list.locationToIndex(p); Rectangle cellBounds = list.getCellBounds(index, index); // go one cell down if first visible cell doesn't fit // into adjasted visible rectangle ! if (cellBounds.y < visRect.y) { p.y = cellBounds.y + cellBounds.height; index = list.locationToIndex(p); cellBounds = list.getCellBounds(index, index); } // if index isn't less then lead // try to go to cell previous to lead ! if (cellBounds.y >= leadRect.y) { p.y = leadRect.y - 1; index = list.locationToIndex(p); } } } --- 2191,2208 ---- p.y = visRect.y; index = list.locationToIndex(p); Rectangle cellBounds = list.getCellBounds(index, index); // go one cell down if first visible cell doesn't fit // into adjasted visible rectangle ! if (cellBounds != null && cellBounds.y < visRect.y) { p.y = cellBounds.y + cellBounds.height; index = list.locationToIndex(p); cellBounds = list.getCellBounds(index, index); } // if index isn't less then lead // try to go to cell previous to lead ! if (cellBounds != null && cellBounds.y >= leadRect.y) { p.y = leadRect.y - 1; index = list.locationToIndex(p); } } }
*** 2210,2221 **** visRect.y + visRect.height - 1); index = list.locationToIndex(p); Rectangle cellBounds = list.getCellBounds(index, index); // go up one cell if last visible cell doesn't fit // into visible rectangle ! if (cellBounds.y + cellBounds.height > ! visRect.y + visRect.height) { p.y = cellBounds.y - 1; index = list.locationToIndex(p); cellBounds = list.getCellBounds(index, index); index = Math.max(index, lead); } --- 2213,2226 ---- visRect.y + visRect.height - 1); index = list.locationToIndex(p); Rectangle cellBounds = list.getCellBounds(index, index); // go up one cell if last visible cell doesn't fit // into visible rectangle ! if (cellBounds != null && ! cellBounds.y + cellBounds.height > ! visRect.y + visRect.height) ! { p.y = cellBounds.y - 1; index = list.locationToIndex(p); cellBounds = list.getCellBounds(index, index); index = Math.max(index, lead); }
*** 2227,2251 **** p.y = visRect.y + visRect.height - 1; index = list.locationToIndex(p); cellBounds = list.getCellBounds(index, index); // go one cell up if last visible cell doesn't fit // into adjasted visible rectangle ! if (cellBounds.y + cellBounds.height > ! visRect.y + visRect.height) { p.y = cellBounds.y - 1; index = list.locationToIndex(p); cellBounds = list.getCellBounds(index, index); } // if index isn't greater then lead // try to go to cell next after lead ! if (cellBounds.y <= leadRect.y) { p.y = leadRect.y + leadRect.height; index = list.locationToIndex(p); } } } } return index; } private void changeSelection(JList<?> list, int type, int index, int direction) { --- 2232,2259 ---- p.y = visRect.y + visRect.height - 1; index = list.locationToIndex(p); cellBounds = list.getCellBounds(index, index); // go one cell up if last visible cell doesn't fit // into adjasted visible rectangle ! if (cellBounds != null && ! cellBounds.y + cellBounds.height > ! visRect.y + visRect.height) ! { p.y = cellBounds.y - 1; index = list.locationToIndex(p); cellBounds = list.getCellBounds(index, index); } // if index isn't greater then lead // try to go to cell next after lead ! if (cellBounds != null && cellBounds.y <= leadRect.y) { p.y = leadRect.y + leadRect.height; index = list.locationToIndex(p); } } } } + return index; } private void changeSelection(JList<?> list, int type, int index, int direction) {
*** 2308,2344 **** cellBounds.x + cellBounds.width - visRect.width); int startIndex = list.locationToIndex(new Point(x, cellBounds.y)); Rectangle startRect = list.getCellBounds(startIndex, startIndex); ! if (startRect.x < x && startRect.x < cellBounds.x) { startRect.x += startRect.width; startIndex = list.locationToIndex(startRect.getLocation()); startRect = list.getCellBounds(startIndex, startIndex); } cellBounds = startRect; } cellBounds.width = visRect.width; } else { if (direction > 0) { // left for right-to-left int x = cellBounds.x + visRect.width; int rightIndex = list.locationToIndex(new Point(x, cellBounds.y)); Rectangle rightRect = list.getCellBounds(rightIndex, rightIndex); if (rightRect.x + rightRect.width > x && rightRect.x > cellBounds.x) { rightRect.width = 0; } cellBounds.x = Math.max(0, rightRect.x + rightRect.width - visRect.width); cellBounds.width = visRect.width; } else { cellBounds.x += Math.max(0, cellBounds.width - visRect.width); // adjust width to fit into visible rectangle cellBounds.width = Math.min(cellBounds.width, --- 2316,2357 ---- cellBounds.x + cellBounds.width - visRect.width); int startIndex = list.locationToIndex(new Point(x, cellBounds.y)); Rectangle startRect = list.getCellBounds(startIndex, startIndex); ! if (startRect != null && ! startRect.x < x && startRect.x < cellBounds.x) { startRect.x += startRect.width; startIndex = list.locationToIndex(startRect.getLocation()); startRect = list.getCellBounds(startIndex, startIndex); } cellBounds = startRect; } + if (cellBounds != null) { cellBounds.width = visRect.width; } + } else { if (direction > 0) { // left for right-to-left int x = cellBounds.x + visRect.width; int rightIndex = list.locationToIndex(new Point(x, cellBounds.y)); Rectangle rightRect = list.getCellBounds(rightIndex, rightIndex); + if (rightRect != null) { if (rightRect.x + rightRect.width > x && rightRect.x > cellBounds.x) { rightRect.width = 0; } cellBounds.x = Math.max(0, rightRect.x + rightRect.width - visRect.width); cellBounds.width = visRect.width; } + } else { cellBounds.x += Math.max(0, cellBounds.width - visRect.width); // adjust width to fit into visible rectangle cellBounds.width = Math.min(cellBounds.width,
*** 2357,2384 **** cellBounds.y + cellBounds.height - visRect.height); int startIndex = list.locationToIndex(new Point(cellBounds.x, y)); Rectangle startRect = list.getCellBounds(startIndex, startIndex); ! if (startRect.y < y && startRect.y < cellBounds.y) { startRect.y += startRect.height; startIndex = list.locationToIndex(startRect.getLocation()); startRect = list.getCellBounds(startIndex, startIndex); } cellBounds = startRect; cellBounds.height = visRect.height; } else { // adjust height to fit into visible rectangle cellBounds.height = Math.min(cellBounds.height, visRect.height); } } list.scrollRectToVisible(cellBounds); } } private int getNextColumnIndex(JList<?> list, BasicListUI ui, int amount) { if (list.getLayoutOrientation() != JList.VERTICAL) { int index = adjustIndex(list.getLeadSelectionIndex(), list); --- 2370,2402 ---- cellBounds.y + cellBounds.height - visRect.height); int startIndex = list.locationToIndex(new Point(cellBounds.x, y)); Rectangle startRect = list.getCellBounds(startIndex, startIndex); ! if (startRect != null && ! startRect.y < y && startRect.y < cellBounds.y) { startRect.y += startRect.height; startIndex = list.locationToIndex(startRect.getLocation()); startRect = list.getCellBounds(startIndex, startIndex); } cellBounds = startRect; + if (cellBounds != null) { cellBounds.height = visRect.height; } + } else { // adjust height to fit into visible rectangle cellBounds.height = Math.min(cellBounds.height, visRect.height); } } + if (cellBounds != null) { list.scrollRectToVisible(cellBounds); } } + } private int getNextColumnIndex(JList<?> list, BasicListUI ui, int amount) { if (list.getLayoutOrientation() != JList.VERTICAL) { int index = adjustIndex(list.getLeadSelectionIndex(), list);
< prev index next >