use of java.text.BreakIterator in project lucene-solr by apache.
the class TestCustomSeparatorBreakIterator method testSliceEnd.
public void testSliceEnd() throws Exception {
BreakIterator expected = BreakIterator.getSentenceInstance(Locale.ROOT);
BreakIterator actual = new CustomSeparatorBreakIterator(randomSeparator());
assertSameBreaks("a000", 0, 1, expected, actual);
assertSameBreaks("ab000", 0, 1, expected, actual);
assertSameBreaks("abc000", 0, 1, expected, actual);
assertSameBreaks("000", 0, 0, expected, actual);
}
use of java.text.BreakIterator in project lucene-solr by apache.
the class TestCustomSeparatorBreakIterator method testSliceStart.
public void testSliceStart() throws Exception {
BreakIterator expected = BreakIterator.getSentenceInstance(Locale.ROOT);
BreakIterator actual = new CustomSeparatorBreakIterator(randomSeparator());
assertSameBreaks("000a", 3, 1, expected, actual);
assertSameBreaks("000ab", 3, 2, expected, actual);
assertSameBreaks("000abc", 3, 3, expected, actual);
assertSameBreaks("000", 3, 0, expected, actual);
}
use of java.text.BreakIterator in project lucene-solr by apache.
the class TestCustomSeparatorBreakIterator method testFirstPosition.
/** the current position must be ignored, initial position is always first() */
public void testFirstPosition() throws Exception {
BreakIterator expected = BreakIterator.getSentenceInstance(Locale.ROOT);
BreakIterator actual = new CustomSeparatorBreakIterator(randomSeparator());
assertSameBreaks("000ab000", 3, 2, 4, expected, actual);
}
use of java.text.BreakIterator in project beast-mcmc by beast-dev.
the class TextUtil method wrapText.
// auto wrap string by given a JComp and the length limit
public static String wrapText(String someText, JComponent jComp, int lenLimit) {
BreakIterator iterator = BreakIterator.getWordInstance(Locale.getDefault());
iterator.setText(someText);
int start = iterator.first();
int end = iterator.next();
FontMetrics fm = jComp.getFontMetrics(jComp.getFont());
String s = "<html>";
int len = 0;
while (end != BreakIterator.DONE) {
String word = someText.substring(start, end);
if (len + fm.stringWidth(word) > lenLimit) {
s += "<br> ";
len = fm.stringWidth(word);
} else {
len += fm.stringWidth(word);
}
s += word;
start = end;
end = iterator.next();
}
s += "</html>";
return s;
}
Aggregations