Package ca.cgjennings.text
Class LineWrapper
- java.lang.Object
-
- ca.cgjennings.text.LineWrapper
-
public class LineWrapper extends java.lang.ObjectALineWrapperbreaks long strings into multiple lines. It is intended for use with fixed-width code-like text rather than natural language text, although it can be used with any string.- Since:
- 3.0
- Author:
- Chris Jennings
-
-
Constructor Summary
Constructors Constructor Description LineWrapper()Creates a line wrapper with a default configuration.LineWrapper(java.lang.String breakText, int firstWrap, int afterWrap, int tolerance)Creates a new line wrapper with the specified wrapper behaviour.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.StringgetBreakText()Returns the break text.intgetFirstLineWrapLength()Returns the line wrap length for the first line.intgetFollowingLineWrapLength()Returns the line wrap length for lines after the first.intgetWrapLengthTolerance()voidsetBreakText(java.lang.String breakText)Sets the break text.voidsetFirstLineWrapLength(int firstWrap)Sets the line wrap length for the first line.voidsetFollowingLineWrapLength(int afterWrap)voidsetWrapLengthTolerance(int tolerance)java.lang.Stringwrap(java.lang.String s)Breaks a string into multiple lines, if necessary, using the current line-wrapping parameters.
-
-
-
Constructor Detail
-
LineWrapper
public LineWrapper()
Creates a line wrapper with a default configuration. This is equivalent toLineWrapper( null, 78, 78, 4 ).
-
LineWrapper
public LineWrapper(java.lang.String breakText, int firstWrap, int afterWrap, int tolerance)Creates a new line wrapper with the specified wrapper behaviour.- Parameters:
breakText- the text to insert when breaking a line; ifnullthen a newline character (\n) is usedfirstWrap- the optimal length for the first lineafterWrap- the optimal length for lines after the firsttolerance- the amount by which the remaining text must exceed the optimal length before a break is inserted (this allows you to avoid breaking a line when onlytoleranceor fewer characters would appear on the following line)
-
-
Method Detail
-
getBreakText
public java.lang.String getBreakText()
Returns the break text.- Returns:
- the text inserted between wrapped lines
-
setBreakText
public void setBreakText(java.lang.String breakText)
Sets the break text.- Parameters:
breakText- the non-null text inserted between wrapped lines
-
getFirstLineWrapLength
public int getFirstLineWrapLength()
Returns the line wrap length for the first line.- Returns:
- the ideal line length
-
setFirstLineWrapLength
public void setFirstLineWrapLength(int firstWrap)
Sets the line wrap length for the first line.- Parameters:
firstWrap- the positive ideal line length
-
getFollowingLineWrapLength
public int getFollowingLineWrapLength()
Returns the line wrap length for lines after the first.- Returns:
- the ideal line length
-
setFollowingLineWrapLength
public void setFollowingLineWrapLength(int afterWrap)
-
getWrapLengthTolerance
public int getWrapLengthTolerance()
-
setWrapLengthTolerance
public void setWrapLengthTolerance(int tolerance)
-
wrap
public java.lang.String wrap(java.lang.String s)
Breaks a string into multiple lines, if necessary, using the current line-wrapping parameters. If the string needs no breaking, the original string is returned. Otherwise, a copy of the string is returned that has the current break text inserted at the selected break points.- Parameters:
s- the string to wrap into lines- Returns:
- the wrapped string
-
-