/[classpath]/classpath/javax/swing/text/Utilities.java
ViewVC logotype

Diff of /classpath/javax/swing/text/Utilities.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.10 by abalkiss, Thu Sep 22 19:04:48 2005 UTC revision 1.11 by abalkiss, Thu Sep 22 20:17:08 2005 UTC
# Line 354  public class Utilities Line 354  public class Utilities
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  }  }

Legend:
Removed from v.1.10  
changed lines
  Added in v.1.11

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26