/[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.14 by rabbit78, Thu Oct 6 20:16:32 2005 UTC revision 1.15 by abalkiss, Tue Oct 25 17:38:08 2005 UTC
# Line 486  public class Utilities Line 486  public class Utilities
486            }            }
487        }        }
488    }    }
489      
490      /**
491       * Determine where to break the text in the given Segment, attempting to find
492       * a word boundary.
493       * @param s the Segment that holds the text
494       * @param metrics the font metrics used for calculating the break point
495       * @param x0 starting view location representing the start of the text
496       * @param x the target view location
497       * @param e the TabExpander used for expanding tabs (if this is null tabs
498       * are expanded to 1 space)
499       * @param startOffset the offset in the Document of the start of the text
500       * @return the offset at which we should break the text
501       */
502      public static final int getBreakLocation(Segment s, FontMetrics metrics,
503                                               int x0, int x, TabExpander e,
504                                               int startOffset)
505      {
506        int mark = Utilities.getTabbedTextOffset(s, metrics, x0, x, e, startOffset);
507        BreakIterator breaker = BreakIterator.getWordInstance();
508        breaker.setText(s.toString());
509        
510        // If mark is equal to the end of the string, just use that position
511        if (mark == s.count)
512          return mark;
513        
514        // Try to find a word boundary previous to the mark at which we
515        // can break the text
516        int preceding = breaker.preceding(mark + 1);
517        
518        if (preceding != 0)
519          return preceding;
520        else
521          // If preceding is 0 we couldn't find a suitable word-boundary so
522          // just break it on the character boundary
523          return mark;
524      }
525  }  }

Legend:
Removed from v.1.14  
changed lines
  Added in v.1.15

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