本文整理汇总了Java中org.apache.commons.text.WordUtils.wrap方法的典型用法代码示例。如果您正苦于以下问题:Java WordUtils.wrap方法的具体用法?Java WordUtils.wrap怎么用?Java WordUtils.wrap使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.text.WordUtils
的用法示例。
在下文中一共展示了WordUtils.wrap方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: LineBreaker
import org.apache.commons.text.WordUtils; //导入方法依赖的package包/类
public LineBreaker(String text, int wrapLength)
{
String wrappedText = WordUtils.wrap(text, wrapLength);
String[] lines = wrappedText.split(System.lineSeparator());
for(String line : lines)
{
Label lineLabel = new Label(line, Settings.DEFAULT_SKIN);
this.add(lineLabel);
this.row();
}
this.pack();
}
示例2: getDcTitle
import org.apache.commons.text.WordUtils; //导入方法依赖的package包/类
/**
* Perform renderer-specific name reformatting:<p>
* Truncating and wrapping see {@code TextWrap}<br>
* Character substitution see {@code CharMap}
*
* @param name Original name
* @param suffix Additional media information
* @param dlna The actual DLNA resource
* @return Reformatted name
*/
public String getDcTitle(String name, String suffix, DLNAResource dlna) {
// Wrap + truncate
int len = 0;
if (lineWidth > 0 && (name.length() + suffix.length()) > lineWidth) {
int suffix_len = dots.length() + suffix.length();
if (lineHeight == 1) {
len = lineWidth - suffix_len;
} else {
// Wrap
int i = dlna.isFolder() ? 0 : indent;
String newline = "\n" + (dlna.isFolder() ? "" : inset);
name = name.substring(0, i + (i < name.length() && Character.isWhitespace(name.charAt(i)) ? 1 : 0))
+ WordUtils.wrap(name.substring(i) + suffix, lineWidth - i, newline, true);
len = lineWidth * lineHeight;
if (len != 0 && name.length() > len) {
len = name.substring(0, name.length() - lineWidth).lastIndexOf(newline) + newline.length();
name = name.substring(0, len) + name.substring(len, len + lineWidth).replace(newline, " ");
len += (lineWidth - suffix_len - i);
} else {
len = -1; // done
}
}
if (len > 0) {
// Truncate
name = name.substring(0, len).trim() + dots;
}
}
if (len > -1) {
name += suffix;
}
// Substitute
for (String s : charMap.keySet()) {
String repl = charMap.get(s).replaceAll("###e", "");
name = name.replaceAll(s, repl);
}
return name;
}