Package java.text

Examples of java.text.BreakIterator$BreakIteratorGetter


    public static TextBlock createTextBlock(final String text, final Font font,
            final Paint paint, final float maxWidth, final int maxLines,
            final TextMeasurer measurer) {

        final TextBlock result = new TextBlock();
        final BreakIterator iterator = BreakIterator.getLineInstance();
        iterator.setText(text);
        int current = 0;
        int lines = 0;
        final int length = text.length();
        while (current < length && lines < maxLines) {
            final int next = nextLineBreak(text, current, maxWidth, iterator,
View Full Code Here


    String[] tokenize(
        final String aText,
        final Locale aLocale)
    {
      List<String> tokens = new ArrayList<String>();
      BreakIterator bi = BreakIterator.getWordInstance(aLocale);
      bi.setText(aText);
      int begin = 0;
      while (bi.next() != BreakIterator.DONE) {
        tokens.add(aText.substring(begin, bi.current()));
        begin = bi.current();
      }
      return tokens.toArray(new String[tokens.size()]);
    }
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 TextBlock createTextBlock(final String text, final Font font,
            final Paint paint, final float maxWidth, final int maxLines,
            final TextMeasurer measurer) {
       
        final TextBlock result = new TextBlock();
        final BreakIterator iterator = BreakIterator.getLineInstance();
        iterator.setText(text);
        int current = 0;
        int lines = 0;
        final int length = text.length();
        while (current < length && lines < maxLines) {
            final int next = nextLineBreak(text, current, maxWidth, iterator,
View Full Code Here

    int getBreakLocation(final Segment s, final FontMetrics fm, final int start, final int end,
            final TabExpander t, final int pos) {
        int offset = s.offset;
        int index = Utilities.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

        assertEquals(-1, Utilities.getPositionBelow(jta, 1, 0));
    }

    void getWordStartTest(final JTextComponent c) {
        AbstractDocument ad = (AbstractDocument) c.getDocument();
        BreakIterator bi = BreakIterator.getWordInstance();
        int length = ad.getLength();
        try {
            bi.setText(ad.getText(0, ad.getLength()));
        } catch (BadLocationException e) {
        }
        int iteratorWordStart = 0;
        bi.first();
        for (int i = 0; i < length; i++) {
            int utilitiesWordStart = 0;
            if (i < length - 1) {
                iteratorWordStart = bi.preceding(i + 1);
            } else {
                bi.last();
                iteratorWordStart = bi.previous();
            }
            try {
                utilitiesWordStart = Utilities.getWordStart(c, i);
            } catch (BadLocationException e) {
            }
View Full Code Here

        getWordStartTest(jtf);
    }

    void getWordEndTest(final JTextComponent c) {
        AbstractDocument ad = (AbstractDocument) c.getDocument();
        BreakIterator bi = BreakIterator.getWordInstance();
        int length = ad.getLength();
        try {
            bi.setText(ad.getText(0, length));
        } catch (BadLocationException e) {
        }
        bi.first();
        for (int i = 0; i < length; i++) {
            int utilitiesWordEnd = 0;
            int iteratorWordEnd = bi.following(i);
            try {
                utilitiesWordEnd = Utilities.getWordEnd(c, i);
            } catch (BadLocationException e) {
            }
            assertEquals(iteratorWordEnd, utilitiesWordEnd);
View Full Code Here

        }
    }

    void getPreviousWordTest(final JTextComponent c) {
        AbstractDocument ad = (AbstractDocument) c.getDocument();
        BreakIterator bi = BreakIterator.getWordInstance();
        int length = ad.getLength();
        String content = null;
        try {
            content = ad.getText(0, ad.getLength());
            bi.setText(content);
        } catch (BadLocationException e) {
        }
        assertNotNull(content);
        bi.first();
        for (int i = 0; i < length; i++) {
            int utilitiesPrevWord = 0;
            int iteratorPrevWord = bi.preceding(i);
            while (iteratorPrevWord > 0
                    && ((content.charAt(iteratorPrevWord) == ' ' || content
                            .charAt(iteratorPrevWord) == '\n') || content
                            .charAt(iteratorPrevWord) == '\t')) {
                iteratorPrevWord = bi.preceding(iteratorPrevWord);
            }
            try {
                utilitiesPrevWord = Utilities.getPreviousWord(c, i);
            } catch (BadLocationException e) {
            }
View Full Code Here

        getPreviousWordTest(jtf);
    }

    void getNextWordTest(final JTextComponent c) {
        AbstractDocument ad = (AbstractDocument) c.getDocument();
        BreakIterator bi = BreakIterator.getWordInstance();
        int length = ad.getLength();
        String content = null;
        try {
            content = ad.getText(0, ad.getLength());
            bi.setText(content);
        } catch (BadLocationException e) {
        }
        assertNotNull(content);
        bi.first();
        for (int i = 0; i < length; i++) {
            int utilitiesNextWord = 0;
            int iteratorNextWord = bi.following(i);
            while (iteratorNextWord < length
                    && ((content.charAt(iteratorNextWord) == ' ' || content
                            .charAt(iteratorNextWord) == '\n') || content
                            .charAt(iteratorNextWord) == '\t')) {
                iteratorNextWord = bi.following(iteratorNextWord);
            }
            try {
                utilitiesNextWord = Utilities.getNextWord(c, i);
            } catch (BadLocationException 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 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

TOP

Related Classes of java.text.BreakIterator$BreakIteratorGetter

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.