354 |
} |
} |
355 |
return 0; |
return 0; |
356 |
} |
} |
357 |
|
|
358 |
|
/** |
359 |
|
* Finds the start of a word for the given location. |
360 |
|
* @param c the text component |
361 |
|
* @param offs the offset location |
362 |
|
* @return the location of the word beginning |
363 |
|
* @throws BadLocationException if the offset location is invalid |
364 |
|
*/ |
365 |
|
public static final int getWordStart(JTextComponent c, int offs) |
366 |
|
throws BadLocationException |
367 |
|
{ |
368 |
|
if (offs < 0 || offs >= c.getText().length()) |
369 |
|
throw new BadLocationException("invalid offset specified", offs); |
370 |
|
|
371 |
|
String text = c.getText(); |
372 |
|
BreakIterator wb = BreakIterator.getWordInstance(); |
373 |
|
wb.setText(text); |
374 |
|
if (wb.isBoundary(offs)) |
375 |
|
return offs; |
376 |
|
return wb.preceding(offs); |
377 |
|
} |
378 |
|
|
379 |
|
/** |
380 |
|
* Finds the end of a word for the given location. |
381 |
|
* @param c the text component |
382 |
|
* @param offs the offset location |
383 |
|
* @return the location of the word end |
384 |
|
* @throws BadLocationException if the offset location is invalid |
385 |
|
*/ |
386 |
|
public static final int getWordEnd(JTextComponent c, int offs) |
387 |
|
throws BadLocationException |
388 |
|
{ |
389 |
|
if (offs < 0 || offs >= c.getText().length()) |
390 |
|
throw new BadLocationException("invalid offset specified", offs); |
391 |
|
|
392 |
|
String text = c.getText(); |
393 |
|
BreakIterator wb = BreakIterator.getWordInstance(); |
394 |
|
wb.setText(text); |
395 |
|
return wb.following(offs); |
396 |
|
} |
397 |
} |
} |