本文整理汇总了Java中java.text.BreakIterator.getLineInstance方法的典型用法代码示例。如果您正苦于以下问题:Java BreakIterator.getLineInstance方法的具体用法?Java BreakIterator.getLineInstance怎么用?Java BreakIterator.getLineInstance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.text.BreakIterator
的用法示例。
在下文中一共展示了BreakIterator.getLineInstance方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: piecesOfEmbeddedLine
import java.text.BreakIterator; //导入方法依赖的package包/类
private List<String> piecesOfEmbeddedLine( String line, int width ) {
List<String> pieces = new ArrayList<String>();
BreakIterator words = BreakIterator.getLineInstance( Locale.US );
words.setText( line );
StringBuilder nextPiece = new StringBuilder();
int start = words.first();
for ( int end = words.next(); end != DONE; start = end, end = words.next() )
nextPiece = processNextWord( line, nextPiece, start, end, width, pieces );
if ( nextPiece.length() > 0 )
pieces.add( nextPiece.toString() );
return pieces;
}
示例2: makeLayoutWindow
import java.text.BreakIterator; //导入方法依赖的package包/类
private void makeLayoutWindow(int localStart) {
int compStart = localStart;
int compLimit = fChars.length;
// If we've already gone past the layout window, format to end of paragraph
if (layoutCount > 0 && !haveLayoutWindow) {
float avgLineLength = Math.max(layoutCharCount / layoutCount, 1);
compLimit = Math.min(localStart + (int)(avgLineLength*EST_LINES), fChars.length);
}
if (localStart > 0 || compLimit < fChars.length) {
if (charIter == null) {
charIter = new CharArrayIterator(fChars);
}
else {
charIter.reset(fChars);
}
if (fLineBreak == null) {
fLineBreak = BreakIterator.getLineInstance();
}
fLineBreak.setText(charIter);
if (localStart > 0) {
if (!fLineBreak.isBoundary(localStart)) {
compStart = fLineBreak.preceding(localStart);
}
}
if (compLimit < fChars.length) {
if (!fLineBreak.isBoundary(compLimit)) {
compLimit = fLineBreak.following(compLimit);
}
}
}
ensureComponents(compStart, compLimit);
haveLayoutWindow = true;
}
示例3: getBreaker
import java.text.BreakIterator; //导入方法依赖的package包/类
/**
* Return break iterator appropriate for the current document.
*
* For non-i18n documents a fast whitespace-based break iterator is used.
*/
private BreakIterator getBreaker() {
Document doc = getDocument();
if ((doc != null) && Boolean.TRUE.equals(
doc.getProperty(AbstractDocument.MultiByteProperty))) {
Container c = getContainer();
Locale locale = (c == null ? Locale.getDefault() : c.getLocale());
return BreakIterator.getLineInstance(locale);
} else {
return new WhitespaceBasedBreakIterator();
}
}
示例4: BreakIteratorTest
import java.text.BreakIterator; //导入方法依赖的package包/类
public BreakIteratorTest()
{
characterBreak = BreakIterator.getCharacterInstance();
wordBreak = BreakIterator.getWordInstance();
lineBreak = BreakIterator.getLineInstance();
sentenceBreak = BreakIterator.getSentenceInstance();
}
示例5: createBreakIterator
import java.text.BreakIterator; //导入方法依赖的package包/类
/**
*
*/
private BreakIterator createBreakIterator() {
if ((breakIterator == null) || (breakIteratorLocale != locale)) {
breakIterator = BreakIterator.getLineInstance(locale);
breakIteratorLocale = locale;
}
return breakIterator;
}
示例6: wrapText
import java.text.BreakIterator; //导入方法依赖的package包/类
/**
*
* @param toWrap
* The string on which the line wrapping process should be done
* @param maxLength
* The maximum length per line
* @return The StringBuffer with the wrapped lines
*/
public static String wrapText(final String toWrap, final int maxLength)
{
if (maxLength == 0) throw new IllegalArgumentException("maxLength must not be 0");
StringBuffer ret = new StringBuffer();
BreakIterator boundary = BreakIterator.getLineInstance();
boundary.setText(toWrap);
int realEnd = BreakIterator.DONE;
int start = boundary.first();
int end = boundary.next();
int lineLength = 0;
while (end != BreakIterator.DONE)
{
int charCount = end - start - 1;
if (charCount > maxLength)
{
realEnd = end;
end = start + maxLength;
}
String word = toWrap.substring(start, end);
lineLength = lineLength + word.length();
if (lineLength >= maxLength)
{
ret.append("\n");
lineLength = word.length();
}
ret.append(word);
if (realEnd == BreakIterator.DONE)
{
start = end;
end = boundary.next();
}
else
{
start = end;
end = realEnd;
realEnd = BreakIterator.DONE;
}
}
return ret.toString();
}
示例7: sync
import java.text.BreakIterator; //导入方法依赖的package包/类
/**
* Synchronize the strategy with its FlowView. Allows the strategy
* to update its state to account for changes in that portion of the
* model represented by the FlowView. Also allows the strategy
* to update the FlowView in response to these changes.
*/
void sync(FlowView fv) {
View lv = getLogicalView(fv);
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();
}
Object shaper = null;
if (c instanceof JComponent) {
shaper = ((JComponent) c).getClientProperty(
TextAttribute.NUMERIC_SHAPING);
}
text.setShaper(shaper);
measurer = new LineBreakMeasurer(text, iter, frc);
// If the children of the FlowView's logical view are GlyphViews, they
// need to have their painters updated.
int n = lv.getViewCount();
for( int i=0; i<n; i++ ) {
View child = lv.getView(i);
if( child instanceof GlyphView ) {
int p0 = child.getStartOffset();
int p1 = child.getEndOffset();
measurer.setPosition(text.toIteratorIndex(p0));
TextLayout layout
= measurer.nextLayout( Float.MAX_VALUE,
text.toIteratorIndex(p1), false );
((GlyphView)child).setGlyphPainter(new GlyphPainter2(layout));
}
}
// Reset measurer.
measurer.setPosition(text.getBeginIndex());
}
示例8: formatText
import java.text.BreakIterator; //导入方法依赖的package包/类
private void formatText(PrintWriter writer, String target, int initialLength) {
BreakIterator boundary = BreakIterator.getLineInstance();
boundary.setText(target);
int start = boundary.first();
int end = boundary.next();
int lineLength = initialLength;
while (end != BreakIterator.DONE) {
// Look at the end and only accept whitespace breaks
char endChar = target.charAt(end - 1);
while (!Character.isWhitespace(endChar)) {
int lastEnd = end;
end = boundary.next();
if (end == BreakIterator.DONE) {
// give up. We are at the end of the string
end = lastEnd;
break;
}
endChar = target.charAt(end - 1);
}
int wordEnd = end;
if (endChar == '\n') {
// trim off the \n since println will do it for us
wordEnd--;
if (wordEnd > 0 && target.charAt(wordEnd - 1) == '\r') {
wordEnd--;
}
} else if (endChar == '\t') {
// figure tabs use 8 characters
lineLength += 7;
}
String word = target.substring(start, wordEnd);
lineLength += word.length();
writer.print(word);
if (endChar == '\n' || endChar == '\r') {
// force end of line
writer.println();
writer.print(" ");
lineLength = 2;
}
start = end;
end = boundary.next();
}
if (lineLength != 0) {
writer.println();
}
}
示例9: formatText
import java.text.BreakIterator; //导入方法依赖的package包/类
static void formatText(PrintWriter writer, String target, int initialLength) {
BreakIterator boundary = BreakIterator.getLineInstance();
boundary.setText(target);
int start = boundary.first();
int end = boundary.next();
int lineLength = initialLength;
while (end != BreakIterator.DONE) {
// Look at the end and only accept whitespace breaks
char endChar = target.charAt(end - 1);
while (!Character.isWhitespace(endChar)) {
int lastEnd = end;
end = boundary.next();
if (end == BreakIterator.DONE) {
// give up. We are at the end of the string
end = lastEnd;
break;
}
endChar = target.charAt(end - 1);
}
int wordEnd = end;
if (endChar == '\n') {
// trim off the \n since println will do it for us
wordEnd--;
if (wordEnd > 0 && target.charAt(wordEnd - 1) == '\r') {
wordEnd--;
}
} else if (endChar == '\t') {
// figure tabs use 8 characters
lineLength += 7;
}
String word = target.substring(start, wordEnd);
lineLength += word.length();
writer.print(word);
if (endChar == '\n' || endChar == '\r') {
// force end of line
writer.println();
writer.print(" ");
lineLength = 2;
}
start = end;
end = boundary.next();
}
if (lineLength != 0) {
writer.println();
}
}
示例10: LineBreakMeasurer
import java.text.BreakIterator; //导入方法依赖的package包/类
/**
* Constructs a <code>LineBreakMeasurer</code> for the specified text.
*
* @param text the text for which this <code>LineBreakMeasurer</code>
* produces <code>TextLayout</code> objects; the text must contain
* at least one character; if the text available through
* <code>iter</code> changes, further calls to this
* <code>LineBreakMeasurer</code> instance are undefined (except,
* in some cases, when <code>insertChar</code> or
* <code>deleteChar</code> are invoked afterward - see below)
* @param frc contains information about a graphics device which is
* needed to measure the text correctly;
* text measurements can vary slightly depending on the
* device resolution, and attributes such as antialiasing; this
* parameter does not specify a translation between the
* <code>LineBreakMeasurer</code> and user space
* @see LineBreakMeasurer#insertChar
* @see LineBreakMeasurer#deleteChar
*/
public LineBreakMeasurer(AttributedCharacterIterator text, FontRenderContext frc) {
this(text, BreakIterator.getLineInstance(), frc);
}
示例11: LineBreakMeasurer
import java.text.BreakIterator; //导入方法依赖的package包/类
/**
* Constructs a {@code LineBreakMeasurer} for the specified text.
*
* @param text the text for which this {@code LineBreakMeasurer}
* produces {@code TextLayout} objects; the text must contain
* at least one character; if the text available through
* {@code iter} changes, further calls to this
* {@code LineBreakMeasurer} instance are undefined (except,
* in some cases, when {@code insertChar} or
* {@code deleteChar} are invoked afterward - see below)
* @param frc contains information about a graphics device which is
* needed to measure the text correctly;
* text measurements can vary slightly depending on the
* device resolution, and attributes such as antialiasing; this
* parameter does not specify a translation between the
* {@code LineBreakMeasurer} and user space
* @see LineBreakMeasurer#insertChar
* @see LineBreakMeasurer#deleteChar
*/
public LineBreakMeasurer(AttributedCharacterIterator text, FontRenderContext frc) {
this(text, BreakIterator.getLineInstance(), frc);
}