Package com.sun.javatest.tool
Class StringFitter
- java.lang.Object
-
- com.sun.javatest.tool.StringFitter
-
public class StringFitter extends java.lang.Object
-
-
Constructor Summary
Constructors Constructor Description StringFitter()
Creates default StringFitter.StringFitter(java.awt.FontMetrics fm)
Creates a StringFitter with specified FontMetrics.StringFitter(java.awt.FontMetrics fm, java.lang.String replaceString, java.lang.String splitString)
Creates a StringFitter with universal replace string, specified split string and FontMetrics.StringFitter(java.awt.FontMetrics fm, java.lang.String leftReplaceString, java.lang.String rightReplaceString, java.lang.String splitString)
Creates a StringFitter with replace strings for beginning and ending of the truncated string and also with specified split string and FontMetrics.StringFitter(java.lang.String replaceString, java.lang.String splitString)
Creates a StringFitter with universal replace string and specified split string.StringFitter(java.lang.String leftReplaceString, java.lang.String rightReplaceString, java.lang.String splitString)
Creates a StringFitter with replace strings for beginning and ending of the truncated string and also with specified split string.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static StringFitter
getDefaultFitter()
get or create and get an instance of default StringFitter with "..." for replace strings and "" for split stringjava.awt.FontMetrics
getFontMetrics()
get current FontMetricsjava.lang.String
getLeftReplaceString()
get current replace string for beginning of truncated stringjava.lang.String
getMiddleReplaceString()
get current replacing string for middle parts of truncated stringjava.lang.String
getRightReplaceString()
get current replace string for ending of truncated stringjava.lang.String
getSplitString()
get current split stringvoid
setFontMetrics(java.awt.Component c)
set FontMetrics through providing Component that will display truncated stringvoid
setFontMetrics(java.awt.FontMetrics fm)
set FontMetricsvoid
setLeftReplaceString(java.lang.String s)
set replace string for replacing beginning of the truncated stringvoid
setMiddleReplaceString(java.lang.String s)
Set a string for replacing truncated parts in the middle of truncated string ("..." by default)void
setRightReplaceString(java.lang.String s)
set replace string for replacing ending of the truncated stringvoid
setSplitString(java.lang.String s)
set split stringjava.lang.String
truncateBeginning(java.lang.String s, int width)
Truncate a String to fit into some width.java.lang.String
truncateBeginning(java.lang.String s, java.awt.Component c)
Truncate a String to fit into Component.java.lang.String
truncateEnding(java.lang.String s, int width)
Truncate a String to fit into some width.java.lang.String
truncateEnding(java.lang.String s, java.awt.Component c)
Truncate a String to fit into Component.java.lang.String
truncateMiddle(java.lang.String s, int width)
Truncate a String to fit into some width.java.lang.String
truncateMiddle(java.lang.String s, java.awt.Component c)
Truncate a String to fit into Component.
-
-
-
Constructor Detail
-
StringFitter
public StringFitter()
Creates default StringFitter. Uses current system FontMetrics, "..." for all replace strings and "" for split string
-
StringFitter
public StringFitter(java.lang.String replaceString, java.lang.String splitString)
Creates a StringFitter with universal replace string and specified split string. Uses current system FontMetrics.- Parameters:
replaceString
- an universal string for replacing truncated parts. It is used to replace beginning, ending and middle partssplitString
- a string to provide discrete truncation. E.g. if split string is "/" - string "/some/long/file/path/that/needs/to/be/fit" will become "/some/long/file/path/..." and not "/some/long/file/path/th..." after truncateEnding()
-
StringFitter
public StringFitter(java.lang.String leftReplaceString, java.lang.String rightReplaceString, java.lang.String splitString)
Creates a StringFitter with replace strings for beginning and ending of the truncated string and also with specified split string. Uses current system FontMetrics. This constructor is useful if it is needed to make different behavior when truncating from the beginning and from the ending- Parameters:
leftReplaceString
- a string for replacing truncated parts in the beginning of the truncated string. If rightReplaceString and leftReplaceString are equal leftReplaceString is used to replace middle parts too. A concatenation of two replace strings is used otherwise.rightReplaceString
- a string for replacing truncated parts in the ending of the truncated string. If rightReplaceString and leftReplaceString are equal leftReplaceString is used to replace middle parts too. A concatenation of two replace strings is used otherwise.splitString
- a string to provide discrete truncation. E.g. if split string is "/" - string "/some/long/file/path/that/needs/to/be/fit" will become "/some/long/file/path/..." and not "/some/long/file/path/th..." after truncateEnding()
-
StringFitter
public StringFitter(java.awt.FontMetrics fm)
Creates a StringFitter with specified FontMetrics. Uses "..." for all replace strings and "" for split string- Parameters:
fm
- FontMetrics to use in this StringFitter. Current system FontMetrics is used if it is null
-
StringFitter
public StringFitter(java.awt.FontMetrics fm, java.lang.String replaceString, java.lang.String splitString)
Creates a StringFitter with universal replace string, specified split string and FontMetrics.- Parameters:
fm
- FontMetrics to use in this StringFitter. Current system FontMetrics is used if it is nullreplaceString
- an universal string for replacing truncated parts. It is used to replace beginning, ending and middle partssplitString
- a string to provide discrete truncation. E.g. if split string is "/" - string "/some/long/file/path/that/needs/to/be/fit" will become "/some/long/file/path/..." and not "/some/long/file/path/th..." after truncateEnding()
-
StringFitter
public StringFitter(java.awt.FontMetrics fm, java.lang.String leftReplaceString, java.lang.String rightReplaceString, java.lang.String splitString)
Creates a StringFitter with replace strings for beginning and ending of the truncated string and also with specified split string and FontMetrics. This constructor is useful if it is needed to make different behavior when truncating from the beginning and from the ending- Parameters:
fm
- FontMetrics to use in this StringFitter. Current system FontMetrics is used if it is nullleftReplaceString
- a string for replacing truncated parts in the beginning of the truncated string. If rightReplaceString and leftReplaceString are equal leftReplaceString is used to replace middle parts too. A concatenation of two replace strings is used otherwise.rightReplaceString
- a string for replacing truncated parts in the ending of the truncated string. If rightReplaceString and leftReplaceString are equal leftReplaceString is used to replace middle parts too. A concatenation of two replace strings is used otherwise.splitString
- a string to provide discrete truncation. E.g. if split string is "/" - string "/some/long/file/path/that/needs/to/be/fit" will become "/some/long/file/path/..." and not "/some/long/file/path/th..." after truncateEnding()
-
-
Method Detail
-
getDefaultFitter
public static StringFitter getDefaultFitter()
get or create and get an instance of default StringFitter with "..." for replace strings and "" for split string
-
getMiddleReplaceString
public java.lang.String getMiddleReplaceString()
get current replacing string for middle parts of truncated string
-
setMiddleReplaceString
public void setMiddleReplaceString(java.lang.String s)
Set a string for replacing truncated parts in the middle of truncated string ("..." by default)- Parameters:
s
- new replace string
-
getLeftReplaceString
public java.lang.String getLeftReplaceString()
get current replace string for beginning of truncated string
-
getRightReplaceString
public java.lang.String getRightReplaceString()
get current replace string for ending of truncated string
-
getSplitString
public java.lang.String getSplitString()
get current split string
-
getFontMetrics
public java.awt.FontMetrics getFontMetrics()
get current FontMetrics
-
setLeftReplaceString
public void setLeftReplaceString(java.lang.String s)
set replace string for replacing beginning of the truncated string- Parameters:
s
- new replace string
-
setRightReplaceString
public void setRightReplaceString(java.lang.String s)
set replace string for replacing ending of the truncated string- Parameters:
s
- new replace string
-
setSplitString
public void setSplitString(java.lang.String s)
set split string- Parameters:
s
- a string to provide discrete truncation. E.g. if split string is "/" - string "/some/long/file/path/that/needs/to/be/fit" will become "/some/long/file/path/..." and not "/some/long/file/path/th..." after truncateEnding()
-
setFontMetrics
public void setFontMetrics(java.awt.FontMetrics fm)
set FontMetrics- Parameters:
fm
- new FontMetrics used to calculate widths of strings
-
setFontMetrics
public void setFontMetrics(java.awt.Component c)
set FontMetrics through providing Component that will display truncated string- Parameters:
c
- Component containing FontMetrics used to calculate widths of strings
-
truncateBeginning
public java.lang.String truncateBeginning(java.lang.String s, java.awt.Component c)
Truncate a String to fit into Component. The string is truncated from the beginning- Parameters:
s
- a String to truncatec
- Component that will contains String s
-
truncateBeginning
public java.lang.String truncateBeginning(java.lang.String s, int width)
Truncate a String to fit into some width. The string is truncated from the beginning- Parameters:
s
- a String to truncatewidth
- available space for the string
-
truncateEnding
public java.lang.String truncateEnding(java.lang.String s, java.awt.Component c)
Truncate a String to fit into Component. The string is truncated from the ending- Parameters:
s
- a String to truncatec
- Component that will contains String s
-
truncateEnding
public java.lang.String truncateEnding(java.lang.String s, int width)
Truncate a String to fit into some width. The string is truncated from the ending.- Parameters:
s
- a String to truncatewidth
- available space for the string
-
truncateMiddle
public java.lang.String truncateMiddle(java.lang.String s, java.awt.Component c)
Truncate a String to fit into Component. The string is truncated from the middle- Parameters:
s
- a String to truncatec
- Component that will contains String s
-
truncateMiddle
public java.lang.String truncateMiddle(java.lang.String s, int width)
Truncate a String to fit into some width. The string is truncated from the middle- Parameters:
s
- a String to truncatewidth
- available space for the string
-
-