Package java.text

Examples of java.text.BreakIterator$BreakIteratorCache


        // our parents start offset.
        Element parent = getElement().getParentElement();
        int parent0;
        int parent1;
        Container c = getContainer();
        BreakIterator breaker;

        if (parent == null) {
            parent0 = p0;
            parent1 = p1;
        }
        else {
            parent0 = parent.getStartOffset();
            parent1 = parent.getEndOffset();
        }
        if (c != null) {
            breaker = BreakIterator.getLineInstance(c.getLocale());
        }
        else {
            breaker = BreakIterator.getLineInstance();
        }

        Segment s = getText(parent0, parent1);
        int breakPoint;

        // Needed to initialize the Segment.
        s.first();
        breaker.setText(s);

        if (p1 == parent1) {
            // This will most likely return the end, the assumption is
            // that if parent1 == p1, then we are the last portion of
            // a paragraph
            breakPoint = breaker.last();
        }
        else if (p1 + 1 == parent1) {
            // assert(s.count > 1)
            breakPoint = breaker.following(s.offset + s.count - 2);
            if (breakPoint >= s.count + s.offset) {
                breakPoint = breaker.preceding(s.offset + s.count - 1);
            }
        }
        else {
            breakPoint = breaker.preceding(p1 - parent0 + s.offset + 1);
        }

        int retValue = -1;

        if (breakPoint != BreakIterator.DONE) {
View Full Code Here


    IndexedSegment seg = getParagraphElementText(index);
    if (seg == null) {
        return null;
    }
    BreakIterator iterator;
    switch (part) {
    case AccessibleText.WORD:
        iterator = BreakIterator.getWordInstance(getLocale());
        break;
    case AccessibleText.SENTENCE:
        iterator = BreakIterator.getSentenceInstance(getLocale());
        break;
    default:
        return null;
    }
    seg.first();
    iterator.setText(seg);
    int end = iterator.following(index - seg.modelOffset + seg.offset);
    if (end == BreakIterator.DONE) {
        return null;
    }
    if (end > seg.offset + seg.count) {
        return null;
    }
    int begin = iterator.previous();
    if (begin == BreakIterator.DONE ||
        begin >= seg.offset + seg.count) {
        return null;
    }
    seg.modelOffset = seg.modelOffset + begin - seg.offset;
View Full Code Here

            try {
                FontMetrics metrics = getFontMetrics();
                Segment segment = new Segment();
                doc.getText(p0, p1 - p0, segment);
                Container c = getContainer();
                BreakIterator line;
                if (c != null) {
                    line = BreakIterator.getLineInstance(c.getLocale());
                } else {
                    line = BreakIterator.getLineInstance();
                }
                line.setText(segment);
                int start = line.first();
                for (int end = line.next();
                     end != BreakIterator.DONE;
                     start = end, end = line.next()) {
                    if (end > start) {
                        span = Math.max(span,
                            metrics.charsWidth(segment.array, start,
                                               end - start));
                    }
View Full Code Here

        text.setView(lv);

        Container container = fv.getContainer();
        FontRenderContext frc = sun.swing.SwingUtilities2.
                                    getFontRenderContext(container);
        BreakIterator iter;
        Container c = fv.getContainer();
        if (c != null) {
            iter = BreakIterator.getLineInstance(c.getLocale());
        } else {
            iter = BreakIterator.getLineInstance();
View Full Code Here

        if (text == null || text.length() == 0) {
            return new String[0];
        }

        List<String> wordList = new ArrayList<String>();
        BreakIterator boundary = BreakIterator.getWordInstance();
        boundary.setText(text);
        int start = 0;

        for (int end = boundary.next(); end != BreakIterator.DONE;
             start = end, end = boundary.next()) {
            String tmp = text.substring(start, end).trim();
            // Remove characters that are not needed.
            tmp = replace(tmp, "+", "");
            tmp = replace(tmp, "/", "");
            tmp = replace(tmp, "\\", "");
View Full Code Here

            // handle splitting at width character
            if (i > lineStart + width - 1) {
                if (!endOfLine) {
                    int limit = i - lineStart - 1;
                    BreakIterator breaks = BreakIterator.getLineInstance(locale);
                    breaks.setText(buf.substring(lineStart, i));
                    int end = breaks.last();

                    // if the last character in the search string isn't a space,
                    // we can't split on it (looks bad). Search for a previous
                    // break character
                    if (end == limit + 1) {
                        if (!Character.isWhitespace(buf.charAt(lineStart + end))) {
                            end = breaks.preceding(end - 1);
                        }
                    }

                    // if the last character is a space, replace it with a \n
                    if (end != BreakIterator.DONE && end == limit + 1) {
View Full Code Here

      {
        rtlGlyphVectors = null;
        //String locale = System.getProperty("user.language");
        // Character iterator required where character is split over
        // string elements
        BreakIterator it = BreakIterator.getCharacterInstance(Locale.getDefault());
        it.setText(label);

        for (int i = 0; i < label.length();)
        {
          int next = it.next();
          int characterLen = 1;
         
          if (next != BreakIterator.DONE)
          {
            characterLen = next - i;
View Full Code Here

     * Regular Expression:
     *   Before C: [{cased==true}][{wordBoundary!=true}]*
     *   After C: !([{wordBoundary!=true}]*[{cased}])
     */
    private static boolean isFinalCased(String src, int index, Locale locale) {
        BreakIterator wordBoundary = BreakIterator.getWordInstance(locale);
        wordBoundary.setText(src);
        int ch;

        // Look for a preceding 'cased' letter
        for (int i = index; (i >= 0) && !wordBoundary.isBoundary(i);
                i -= Character.charCount(ch)) {

            ch = src.codePointBefore(i);
            if (isCased(ch)) {

                int len = src.length();
                // Check that there is no 'cased' letter after the index
                for (i = index + Character.charCount(src.codePointAt(index));
                        (i < len) && !wordBoundary.isBoundary(i);
                        i += Character.charCount(ch)) {

                    ch = src.codePointAt(i);
                    if (isCased(ch)) {
                        return false;
View Full Code Here

                return null;
            }
        case AccessibleText.WORD:
            try {
                String s = unoObject.getText();
                BreakIterator words = BreakIterator.getWordInstance(getLocale(index));
                words.setText(s);
                int start = words.following(index);
                if (start == BreakIterator.DONE || start >= s.length()) {
                    return null;
                }
                int end = words.following(start);
                if (end == BreakIterator.DONE || end >= s.length()) {
                    return null;
                }
                return s.substring(start, end);
            } catch (IllegalArgumentException e) {
                return null;
            } catch (IndexOutOfBoundsException e) {
                return null;
            }
        case AccessibleText.SENTENCE:
            try {
                String s = unoObject.getText();
                BreakIterator sentence =
                    BreakIterator.getSentenceInstance(getLocale(index));
                sentence.setText(s);
                int start = sentence.following(index);
                if (start == BreakIterator.DONE || start >= s.length()) {
                    return null;
                }
                int end = sentence.following(start);
                if (end == BreakIterator.DONE || end >= s.length()) {
                    return null;
                }
                return s.substring(start, end);
            } catch (IllegalArgumentException e) {
View Full Code Here

                return null;
            }
        case AccessibleText.WORD:
            try {
                String s = unoObject.getText();
                BreakIterator words = BreakIterator.getWordInstance(getLocale(index));
                words.setText(s);
                int end = words.following(index);
                end = words.previous();
                int start = words.previous();
                if (start == BreakIterator.DONE) {
                    return null;
                }
                return s.substring(start, end);
            } catch (IllegalArgumentException e) {
                return null;
            } catch (IndexOutOfBoundsException e) {
                return null;
            }
        case AccessibleText.SENTENCE:
            try {
                String s = unoObject.getText();
                BreakIterator sentence =
                    BreakIterator.getSentenceInstance(getLocale(index));
                sentence.setText(s);
                int end = sentence.following(index);
                end = sentence.previous();
                int start = sentence.previous();
                if (start == BreakIterator.DONE) {
                    return null;
                }
                return s.substring(start, end);
            } catch (IllegalArgumentException e) {
View Full Code Here

TOP

Related Classes of java.text.BreakIterator$BreakIteratorCache

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.