614 |
|
|
615 |
// TODO: Implement the remaining methods of this class. |
// TODO: Implement the remaining methods of this class. |
616 |
} |
} |
617 |
|
|
618 |
|
/** |
619 |
|
* Create a new AccessibleJList. |
620 |
|
*/ |
621 |
|
public AccessibleJList() |
622 |
|
{ |
623 |
|
// Nothing to do here. |
624 |
|
} |
625 |
|
|
626 |
/** |
/** |
627 |
* Returns the number of selected accessible children. |
* Returns the number of selected accessible children. |
923 |
|
|
924 |
/** |
/** |
925 |
* This property specifies a foreground color for the selected cells in |
* This property specifies a foreground color for the selected cells in |
926 |
* the list. When {@link ListCellRenderer.getListCellRendererComponent} |
* the list. When {@link ListCellRenderer#getListCellRendererComponent} |
927 |
* is called with a selected cell object, the component returned will |
* is called with a selected cell object, the component returned will |
928 |
* have its "foreground" set to this color. |
* have its "foreground" set to this color. |
929 |
*/ |
*/ |
931 |
|
|
932 |
/** |
/** |
933 |
* This property specifies a background color for the selected cells in |
* This property specifies a background color for the selected cells in |
934 |
* the list. When {@link ListCellRenderer.getListCellRendererComponent} |
* the list. When {@link ListCellRenderer#getListCellRendererComponent} |
935 |
* is called with a selected cell object, the component returned will |
* is called with a selected cell object, the component returned will |
936 |
* have its "background" property set to this color. |
* have its "background" property set to this color. |
937 |
*/ |
*/ |
958 |
/** |
/** |
959 |
* This property indicates a <em>preference</em> for the number of rows |
* This property indicates a <em>preference</em> for the number of rows |
960 |
* displayed in the list, and will scale the |
* displayed in the list, and will scale the |
961 |
* {@link #preferredScrollableViewportSize} property accordingly. The actual |
* {@link #getPreferredScrollableViewportSize} property accordingly. The actual |
962 |
* number of displayed rows, when the list is placed in a real {@link |
* number of displayed rows, when the list is placed in a real {@link |
963 |
* Viewport} or other component, may be greater or less than this number. |
* JViewport} or other component, may be greater or less than this number. |
964 |
*/ |
*/ |
965 |
int visibleRowCount; |
int visibleRowCount; |
966 |
|
|
1012 |
event.getValueIsAdjusting()); |
event.getValueIsAdjusting()); |
1013 |
JList.this.repaint(); |
JList.this.repaint(); |
1014 |
} |
} |
1015 |
}; |
} |
1016 |
|
|
1017 |
/** |
/** |
1018 |
* Shared ListListener instance, subscribed to both the current {@link |
* Shared ListListener instance, subscribed to both the current {@link |
1179 |
/** |
/** |
1180 |
* Sets the value of the {@link #visibleRowCount} property. |
* Sets the value of the {@link #visibleRowCount} property. |
1181 |
* |
* |
1182 |
* @param visibleRowCount The new property value |
* @param vc The new property value |
1183 |
*/ |
*/ |
1184 |
public void setVisibleRowCount(int vc) |
public void setVisibleRowCount(int vc) |
1185 |
{ |
{ |
1305 |
|
|
1306 |
/** |
/** |
1307 |
* Returns the list index of the upper left or upper right corner of the |
* Returns the list index of the upper left or upper right corner of the |
1308 |
* {@link #visibleRect} property, depending on the {@link |
* visible rectangle of this list, depending on the {@link |
1309 |
* #componentOrientation} property. |
* Component#getComponentOrientation} property. |
1310 |
* |
* |
1311 |
* @return The index of the first visible list cell, or <code>-1</code> |
* @return The index of the first visible list cell, or <code>-1</code> |
1312 |
* if none is visible. |
* if none is visible. |
1327 |
* |
* |
1328 |
* @return index of the cell to which specified location is closest to. |
* @return index of the cell to which specified location is closest to. |
1329 |
*/ |
*/ |
1330 |
public int locationToIndex(Point location) { |
public int locationToIndex(Point location) |
1331 |
|
{ |
1332 |
return getUI().locationToIndex(this, location); |
return getUI().locationToIndex(this, location); |
1333 |
} |
} |
1334 |
|
|
1338 |
* |
* |
1339 |
* @return location of the cell located at the specified index in the list. |
* @return location of the cell located at the specified index in the list. |
1340 |
*/ |
*/ |
1341 |
public Point indexToLocation(int index){ |
public Point indexToLocation(int index) |
1342 |
return getCellBounds(index, index).getLocation(); |
{ |
1343 |
|
return getUI().indexToLocation(this, index); |
1344 |
} |
} |
1345 |
|
|
1346 |
/** |
/** |
1347 |
* Returns the list index of the lower right or lower left corner of the |
* Returns the list index of the lower right or lower left corner of the |
1348 |
* {@link #visibleRect} property, depending on the {@link |
* visible rectangle of this list, depending on the {@link |
1349 |
* #componentOrientation} property. |
* Component#getComponentOrientation} property. |
1350 |
* |
* |
1351 |
* @return The index of the last visible list cell, or <code>-1</code> |
* @return The index of the last visible list cell, or <code>-1</code> |
1352 |
* if none is visible. |
* if none is visible. |
1369 |
* selected. |
* selected. |
1370 |
* |
* |
1371 |
* @return An array of model indices, each of which is selected according |
* @return An array of model indices, each of which is selected according |
1372 |
* to the {@link #selection} property |
* to the {@link #getSelectedValues} property |
1373 |
*/ |
*/ |
1374 |
public int[] getSelectedIndices() |
public int[] getSelectedIndices() |
1375 |
{ |
{ |
1384 |
n++; |
n++; |
1385 |
int [] v = new int[n]; |
int [] v = new int[n]; |
1386 |
j = 0; |
j = 0; |
1387 |
for (i = lo; i < hi; ++i) |
for (i = lo; i <= hi; ++i) |
1388 |
if (selectionModel.isSelectedIndex(i)) |
if (selectionModel.isSelectedIndex(i)) |
1389 |
v[j++] = i; |
v[j++] = i; |
1390 |
return v; |
return v; |
1414 |
* @return The first selected element, or <code>null</code> if no element |
* @return The first selected element, or <code>null</code> if no element |
1415 |
* is selected. |
* is selected. |
1416 |
* |
* |
1417 |
* @see getSelectedValues |
* @see #getSelectedValues |
1418 |
*/ |
*/ |
1419 |
public Object getSelectedValue() |
public Object getSelectedValue() |
1420 |
{ |
{ |
1430 |
* |
* |
1431 |
* @return An array containing all the selected values |
* @return An array containing all the selected values |
1432 |
* |
* |
1433 |
* @see getSelectedValue |
* @see #setSelectedValue |
1434 |
*/ |
*/ |
1435 |
public Object[] getSelectedValues() |
public Object[] getSelectedValues() |
1436 |
{ |
{ |
1589 |
} |
} |
1590 |
|
|
1591 |
/** |
/** |
1592 |
* Sets the value of the {@link #celLRenderer} property. |
* Sets the value of the {@link #getCellRenderer} property. |
1593 |
* |
* |
1594 |
* @param renderer The new property value |
* @param renderer The new property value |
1595 |
*/ |
*/ |
1763 |
|
|
1764 |
public AccessibleContext getAccessibleContext() |
public AccessibleContext getAccessibleContext() |
1765 |
{ |
{ |
1766 |
return null; |
return new AccessibleJList(); |
1767 |
} |
} |
1768 |
|
|
1769 |
/** |
/** |
1770 |
* Returns a size indicating how much space this list would like to |
* Returns a size indicating how much space this list would like to |
1771 |
* consume, when contained in a scrollable viewport. This is part of the |
* consume, when contained in a scrollable viewport. This is part of the |
1772 |
* {@link Scrollable} interface, which interacts with {@link |
* {@link Scrollable} interface, which interacts with {@link |
1773 |
* ScrollPaneLayout} and {@link Viewport} to define scrollable objects. |
* ScrollPaneLayout} and {@link JViewport} to define scrollable objects. |
1774 |
* |
* |
1775 |
* @return The preferred size |
* @return The preferred size |
1776 |
*/ |
*/ |
1780 |
//return the value from getPreferredSize. The current ListUI is |
//return the value from getPreferredSize. The current ListUI is |
1781 |
//expected to override getPreferredSize to return an appropriate value. |
//expected to override getPreferredSize to return an appropriate value. |
1782 |
if (getLayoutOrientation() != VERTICAL) |
if (getLayoutOrientation() != VERTICAL) |
1783 |
return getPreferredSize(); |
return getPreferredSize(); |
1784 |
|
|
1785 |
|
int size = getModel().getSize(); |
1786 |
|
|
1787 |
|
// Trivial case: if fixedCellWidth and fixedCellHeight were set |
1788 |
|
// just use them |
1789 |
if (fixedCellHeight != -1 && fixedCellWidth != -1) |
if (fixedCellHeight != -1 && fixedCellWidth != -1) |
1790 |
return new Dimension(fixedCellWidth, getModel().getSize() * |
return new Dimension(fixedCellWidth, size * fixedCellHeight); |
1791 |
fixedCellHeight); |
|
1792 |
|
// If the model is empty we use 16 * the number of visible rows |
1793 |
|
// for the height and either fixedCellWidth (if set) or 256 |
1794 |
|
// for the width |
1795 |
|
if (size == 0) |
1796 |
|
{ |
1797 |
|
if (fixedCellWidth == -1) |
1798 |
|
return new Dimension(256, 16 * getVisibleRowCount()); |
1799 |
|
else |
1800 |
|
return new Dimension(fixedCellWidth, 16 * getVisibleRowCount()); |
1801 |
|
} |
1802 |
|
|
1803 |
int prefWidth, prefHeight; |
// Calculate the width: if fixedCellWidth was set use that, otherwise |
1804 |
|
// use the preferredWidth |
1805 |
|
int prefWidth; |
1806 |
if (fixedCellWidth != -1) |
if (fixedCellWidth != -1) |
1807 |
prefWidth = fixedCellWidth; |
prefWidth = fixedCellWidth; |
1808 |
else |
else |
1809 |
{ |
prefWidth = getPreferredSize().width; |
1810 |
prefWidth = 0; |
|
1811 |
int size = getModel().getSize(); |
// Calculate the height: if fixedCellHeight was set use that, otherwise |
1812 |
for (int i = 0; i < size; i++) |
// use the height of the first row multiplied by the number of visible |
1813 |
if (getCellBounds(i, i).width > prefWidth) |
// rows |
1814 |
prefWidth = getCellBounds(i, i).width; |
int prefHeight; |
|
} |
|
|
|
|
|
if (getModel().getSize() == 0 && fixedCellWidth == -1) |
|
|
return new Dimension(256, 16 * getVisibleRowCount()); |
|
|
else if (getModel().getSize() == 0) |
|
|
return new Dimension (fixedCellWidth, 16 * getVisibleRowCount()); |
|
|
|
|
1815 |
if (fixedCellHeight != -1) |
if (fixedCellHeight != -1) |
1816 |
prefHeight = fixedCellHeight; |
prefHeight = fixedCellHeight; |
1817 |
else |
else |
1818 |
{ |
prefHeight = getVisibleRowCount() * getCellBounds(0, 0).height; |
1819 |
prefHeight = getVisibleRowCount() * getCellBounds |
|
|
(getFirstVisibleIndex(), getFirstVisibleIndex()).height; |
|
|
} |
|
1820 |
return new Dimension (prefWidth, prefHeight); |
return new Dimension (prefWidth, prefHeight); |
1821 |
} |
} |
1822 |
|
|
1947 |
} |
} |
1948 |
|
|
1949 |
/** |
/** |
1950 |
* Gets the value of the {@link #scrollableTracksViewportWidth} property. |
* Gets the value of the <code>scrollableTracksViewportWidth</code> property. |
1951 |
* |
* |
1952 |
* @return <code>true</code> if the viewport is larger (horizontally) |
* @return <code>true</code> if the viewport is larger (horizontally) |
1953 |
* than the list and the list should be expanded to fit the viewport; |
* than the list and the list should be expanded to fit the viewport; |
1972 |
} |
} |
1973 |
|
|
1974 |
/** |
/** |
1975 |
* Gets the value of the {@link #scrollableTracksViewportWidth} property. |
* Gets the value of the </code>scrollableTracksViewportWidth</code> property. |
1976 |
* |
* |
1977 |
* @return <code>true</code> if the viewport is larger (vertically) |
* @return <code>true</code> if the viewport is larger (vertically) |
1978 |
* than the list and the list should be expanded to fit the viewport; |
* than the list and the list should be expanded to fit the viewport; |
2124 |
*/ |
*/ |
2125 |
public Rectangle getCellBounds(int index0, int index1) |
public Rectangle getCellBounds(int index0, int index1) |
2126 |
{ |
{ |
2127 |
return ((ListUI) ui).getCellBounds(this, index0, index1); |
return getUI().getCellBounds(this, index0, index1); |
2128 |
} |
} |
2129 |
|
|
2130 |
/** |
/** |
2134 |
* |
* |
2135 |
* @param prefix the prefix to search for in the cell values |
* @param prefix the prefix to search for in the cell values |
2136 |
* @param startIndex the index where to start searching from |
* @param startIndex the index where to start searching from |
2137 |
* @param bias the search direction, either {@link Position.Bias.Forward} |
* @param bias the search direction, either {@link Position.Bias#Forward} |
2138 |
* or {@link Position.Bias.Backward} |
* or {@link Position.Bias#Backward} |
2139 |
* |
* |
2140 |
* @return the index of the found element or -1 if no such element has |
* @return the index of the found element or -1 if no such element has |
2141 |
* been found |
* been found |