56 |
import javax.swing.CellRendererPane; |
import javax.swing.CellRendererPane; |
57 |
import javax.swing.JComponent; |
import javax.swing.JComponent; |
58 |
import javax.swing.JList; |
import javax.swing.JList; |
59 |
|
import javax.swing.JViewport; |
60 |
import javax.swing.ListCellRenderer; |
import javax.swing.ListCellRenderer; |
61 |
import javax.swing.ListModel; |
import javax.swing.ListModel; |
62 |
import javax.swing.ListSelectionModel; |
import javax.swing.ListSelectionModel; |
387 |
if (l != list || cellWidth == -1) |
if (l != list || cellWidth == -1) |
388 |
return null; |
return null; |
389 |
|
|
390 |
int lo = Math.min(index1, index2); |
int minIndex = Math.min(index1, index2); |
391 |
int hi = Math.max(index1, index2); |
int maxIndex = Math.max(index1, index2); |
392 |
Point loLoc = indexToLocation(list, lo); |
Point loc = indexToLocation(list, minIndex); |
393 |
Point hiLoc = indexToLocation(list, hi); |
Rectangle bounds = new Rectangle(loc.x, loc.y, cellWidth, |
394 |
Rectangle lobounds = new Rectangle(loLoc.x, loLoc.y, cellWidth, |
getRowHeight(minIndex)); |
|
getRowHeight(lo)); |
|
|
Rectangle hibounds = new Rectangle(hiLoc.x, hiLoc.y, cellWidth, |
|
|
getRowHeight(hi)); |
|
395 |
|
|
396 |
return lobounds.union(hibounds); |
for (int i = minIndex + 1; i <= maxIndex; i++) |
397 |
|
{ |
398 |
|
Point hiLoc = indexToLocation(list, i); |
399 |
|
Rectangle hibounds = new Rectangle(hiLoc.x, hiLoc.y, cellWidth, |
400 |
|
getRowHeight(i)); |
401 |
|
bounds = bounds.union(hibounds); |
402 |
|
} |
403 |
|
|
404 |
|
return bounds; |
405 |
} |
} |
406 |
|
|
407 |
/** |
/** |
645 |
*/ |
*/ |
646 |
public Dimension getPreferredSize(JComponent c) |
public Dimension getPreferredSize(JComponent c) |
647 |
{ |
{ |
648 |
if (list.getModel().getSize() == 0) |
int size = list.getModel().getSize(); |
649 |
|
if (size == 0) |
650 |
return new Dimension(0, 0); |
return new Dimension(0, 0); |
651 |
|
int visibleRows = list.getVisibleRowCount(); |
652 |
|
int layoutOrientation = list.getLayoutOrientation(); |
653 |
Rectangle bounds = getCellBounds(list, 0, list.getModel().getSize() - 1); |
Rectangle bounds = getCellBounds(list, 0, list.getModel().getSize() - 1); |
654 |
return bounds.getSize(); |
Dimension retVal = bounds.getSize(); |
655 |
|
Component parent = list.getParent(); |
656 |
|
if ((visibleRows == -1) && (parent instanceof JViewport)) |
657 |
|
{ |
658 |
|
JViewport viewport = (JViewport) parent; |
659 |
|
|
660 |
|
if (layoutOrientation == JList.HORIZONTAL_WRAP) |
661 |
|
{ |
662 |
|
int h = viewport.getSize().height; |
663 |
|
int cellsPerCol = h / cellHeight; |
664 |
|
int w = size / cellsPerCol * cellWidth; |
665 |
|
retVal = new Dimension(w, h); |
666 |
|
} |
667 |
|
else if (layoutOrientation == JList.VERTICAL_WRAP) |
668 |
|
{ |
669 |
|
int w = viewport.getSize().width; |
670 |
|
int cellsPerRow = Math.max(w / cellWidth, 1); |
671 |
|
int h = size / cellsPerRow * cellHeight; |
672 |
|
retVal = new Dimension(w, h); |
673 |
|
} |
674 |
|
} |
675 |
|
return retVal; |
676 |
} |
} |
677 |
|
|
678 |
/** |
/** |