53 |
import javax.swing.event.ListSelectionEvent; |
import javax.swing.event.ListSelectionEvent; |
54 |
import javax.swing.event.ListSelectionListener; |
import javax.swing.event.ListSelectionListener; |
55 |
import javax.swing.plaf.ListUI; |
import javax.swing.plaf.ListUI; |
56 |
|
import javax.swing.text.Position; |
57 |
|
|
58 |
/** |
/** |
59 |
* <p>This class is a facade over three separate objects: {@link |
* <p>This class is a facade over three separate objects: {@link |
1336 |
layoutOrientation = orientation; |
layoutOrientation = orientation; |
1337 |
firePropertyChange("layoutOrientation", old, orientation); |
firePropertyChange("layoutOrientation", old, orientation); |
1338 |
} |
} |
1339 |
|
|
1340 |
|
/** |
1341 |
|
* Returns the bounds of the rectangle that encloses both list cells |
1342 |
|
* with index0 and index1. |
1343 |
|
* |
1344 |
|
* @param index0 the index of the first cell |
1345 |
|
* @param index1 the index of the second cell |
1346 |
|
* |
1347 |
|
* @return the bounds of the rectangle that encloses both list cells |
1348 |
|
* with index0 and index1, <code>null</code> if one of the indices is |
1349 |
|
* not valid |
1350 |
|
*/ |
1351 |
|
public Rectangle getCellBounds(int index0, int index1) |
1352 |
|
{ |
1353 |
|
return ((ListUI) ui).getCellBounds(this, index0, index1); |
1354 |
|
} |
1355 |
|
|
1356 |
|
/** |
1357 |
|
* Returns the next list element (beginning from <code>startIndex</code> |
1358 |
|
* that starts with <code>prefix</code>. Searching is done in the direction |
1359 |
|
* specified by <code>bias</code>. |
1360 |
|
* |
1361 |
|
* @param prefix the prefix to search for in the cell values |
1362 |
|
* @param startIndex the index where to start searching from |
1363 |
|
* @param bias the search direction, either {@link Position.Bias.Forward} |
1364 |
|
* or {@link Position.Bias.Backward} |
1365 |
|
* |
1366 |
|
* @return the index of the found element or -1 if no such element has |
1367 |
|
* been found |
1368 |
|
* |
1369 |
|
* @throws IllegalArgumentException if prefix is <code>null</code> or |
1370 |
|
* startIndex is not valid |
1371 |
|
* |
1372 |
|
* @since 1.4 |
1373 |
|
*/ |
1374 |
|
public int getNextMatch(String prefix, int startIndex, Position.Bias bias) |
1375 |
|
{ |
1376 |
|
if (prefix == null) |
1377 |
|
throw new IllegalArgumentException("The argument 'prefix' must not be" |
1378 |
|
+ " null."); |
1379 |
|
if (startIndex < 0) |
1380 |
|
throw new IllegalArgumentException("The argument 'startIndex' must not" |
1381 |
|
+ " be less than zero."); |
1382 |
|
|
1383 |
|
int size = model.getSize(); |
1384 |
|
if (startIndex > model.getSize()) |
1385 |
|
throw new IllegalArgumentException("The argument 'startIndex' must not" |
1386 |
|
+ " be greater than the number of" |
1387 |
|
+ " elements in the ListModel."); |
1388 |
|
|
1389 |
|
int index = -1; |
1390 |
|
if (bias == Position.Bias.Forward) |
1391 |
|
{ |
1392 |
|
for (int i = startIndex; i < size; i++) |
1393 |
|
{ |
1394 |
|
String item = model.getElementAt(i).toString(); |
1395 |
|
if (item.startsWith(prefix)) |
1396 |
|
{ |
1397 |
|
index = i; |
1398 |
|
break; |
1399 |
|
} |
1400 |
|
} |
1401 |
|
} |
1402 |
|
else |
1403 |
|
{ |
1404 |
|
for (int i = startIndex; i >= 0; i--) |
1405 |
|
{ |
1406 |
|
String item = model.getElementAt(i).toString(); |
1407 |
|
if (item.startsWith(prefix)) |
1408 |
|
{ |
1409 |
|
index = i; |
1410 |
|
break; |
1411 |
|
} |
1412 |
|
} |
1413 |
|
} |
1414 |
|
return index; |
1415 |
|
} |
1416 |
} |
} |