Package java.text

Examples of java.text.BreakIterator$BreakIteratorCache


    String stripped = m.group(2);

    p = Pattern.compile("^\\p{Blank}*\\**\\p{Blank}*", Pattern.MULTILINE);
    String bareComment = p.matcher(stripped).replaceAll("");

    BreakIterator iterator = BreakIterator.getSentenceInstance();
    iterator.setText(bareComment);
    int firstSentenceEnd = iterator.next();
    if (firstSentenceEnd == BreakIterator.DONE) {
      summary.append(bareComment);
    } else {
      summary.append(bareComment.substring(0, firstSentenceEnd));
    }
View Full Code Here


        return new AccessibleAWTTextComponent();
    }

    private String getLine(int index) {
        String result = null;
        BreakIterator bi = BreakIterator.getSentenceInstance();
        bi.setText(getText());
        int end = bi.following(index);
        int start = bi.preceding(end - 1);
        try {
            result = document.getText(start, end - start);
        } catch (BadLocationException e) {
            e.printStackTrace();
        }
View Full Code Here

        }
        return s;
    }

    private int getWordEnd(final int pos) throws BadLocationException {
        BreakIterator bi = BreakIterator.getWordInstance();
        int length = document.getLength();
        if (pos < 0 || pos > length) {
            throwException("No word at " + pos, pos);
        }
        String content = document.getText(0, length);
        bi.setText(content);
        return (pos < bi.last()) ? bi.following(pos) : pos;
    }
View Full Code Here

        bi.setText(content);
        return (pos < bi.last()) ? bi.following(pos) : pos;
    }

    private int getWordStart(final int pos) throws BadLocationException {
        BreakIterator bi = BreakIterator.getWordInstance();
        int length = document.getLength();
        if (pos < 0 || pos > length) {
            throwException("No word at " + pos, pos);
        }
        String content = null;
        content = document.getText(0, length);
        bi.setText(content);
        int iteratorWordStart = pos;
        if (pos < length - 1) {
            iteratorWordStart = bi.preceding(pos + 1);
        } else {
            bi.last();
            iteratorWordStart = bi.previous();
        }
        return iteratorWordStart;
    }
View Full Code Here

                    } catch (final BadLocationException e) {
                        return null;
                    }
                    return (offset < 0) ? null : getWord(offset);
                case AccessibleText.SENTENCE:
                    BreakIterator bi = BreakIterator.getSentenceInstance();
                    bi.setText(getText());
                    offset = bi.preceding(index);
                    offset = bi.previous() + 1;
                    return (offset < 0) ? null : getLine(offset);
                default:
                    return null;
            }
        }
View Full Code Here

              else
              {
                // Get a BreakIterator.  Note that this code doesn't
                // really work for multi-lingual pages (e.g., an English
                // page that contains some Japanese text).
                BreakIterator breaks = BreakIterator.getLineInstance(
                  context.getViewRoot().getLocale());
                breaks.setText(textString);

                _writeTextWithBreaks(context, breaks, textString, columns);
              }
            } // endif wrapping on
            else
View Full Code Here

              else
              {
                // Get a BreakIterator.  Note that this code doesn't
                // really work for multi-lingual pages (e.g., an English
                // page that contains some Japanese text).
                BreakIterator breaks = BreakIterator.getLineInstance(
                  context.getViewRoot().getLocale());
                breaks.setText(textString);

                _writeTextWithBreaks(context, breaks, textString, columns);
              }
            } // endif wrapping on
            else
View Full Code Here


    public static final int getNextWord(final Document doc, final int pos)
        throws BadLocationException {

        BreakIterator bi = BreakIterator.getWordInstance();
        int length = doc.getLength();
        if (pos < 0 || pos > length) {
            throwException("No more words", pos);
        }
        String content = null;

        content = doc.getText(0, doc.getLength());
        bi.setText(content);

        int iteratorNextWord = bi.following(pos);
        while (iteratorNextWord < length
             && ((content.charAt(iteratorNextWord) == ' '
             || content.charAt(iteratorNextWord) == '\n')
             || content.charAt(iteratorNextWord) == '\t')) {
             iteratorNextWord = bi.following(iteratorNextWord);
        }
        if (iteratorNextWord == length) {
             iteratorNextWord = 0;
        }
        return iteratorNextWord;
View Full Code Here

    }

    public static final int getPreviousWord(final Document doc, final int pos)
        throws BadLocationException  {

        BreakIterator bi = BreakIterator.getWordInstance();
        int length = doc.getLength();
        if (pos < 0 || pos > length) {
            throwException("No more words", pos);
        }
        String content = null;

        content = doc.getText(0, doc.getLength());
        bi.setText(content);

        int iteratorPrevWord = bi.preceding(pos);
        while (iteratorPrevWord > 0
                && ((content.charAt(iteratorPrevWord) == ' '
                    || content.charAt(iteratorPrevWord) == '\n')
                    || content.charAt(iteratorPrevWord) == '\t')) {
            iteratorPrevWord = bi.preceding(iteratorPrevWord);
        }
        return iteratorPrevWord == -1 ? 0 : iteratorPrevWord;
    }
View Full Code Here

        int offset = s.offset;
        int index = TextUtils.getTabbedTextOffset(s, fm, start, end, t, pos,
                false);
        int fullIndex = offset +  index;

        BreakIterator bi = BreakIterator.getWordInstance();
        bi.setText(s);
        if (bi.last() <= fullIndex) {
            return bi.last() - offset;
        }
        if (bi.isBoundary(fullIndex)) {
            return Character.isWhitespace(s.array[fullIndex])
                   ? index + 1 : index;
        }
        int prev = bi.preceding(fullIndex);
        if (prev == bi.first()) {
            return index;
        }
        return prev - offset;
    }
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.