Package com.sun.javatest.tool
Class StringFitter
java.lang.Object
com.sun.javatest.tool.StringFitter
-
Constructor Summary
ConstructorsConstructorDescriptionCreates default StringFitter.Creates a StringFitter with specified FontMetrics.StringFitter
(FontMetrics fm, String replaceString, String splitString) Creates a StringFitter with universal replace string, specified split string and FontMetrics.StringFitter
(FontMetrics fm, String leftReplaceString, String rightReplaceString, 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
(String replaceString, String splitString) Creates a StringFitter with universal replace string and specified split string.StringFitter
(String leftReplaceString, String rightReplaceString, String splitString) Creates a StringFitter with replace strings for beginning and ending of the truncated string and also with specified split string. -
Method Summary
Modifier and TypeMethodDescriptionstatic StringFitter
get or create and get an instance of default StringFitter with "..." for replace strings and "" for split stringget current FontMetricsget current replace string for beginning of truncated stringget current replacing string for middle parts of truncated stringget current replace string for ending of truncated stringget current split stringvoid
set FontMetrics through providing Component that will display truncated stringvoid
set FontMetricsvoid
set replace string for replacing beginning of the truncated stringvoid
Set a string for replacing truncated parts in the middle of truncated string ("..." by default)void
set replace string for replacing ending of the truncated stringvoid
set split stringtruncateBeginning
(String s, int width) Truncate a String to fit into some width.truncateBeginning
(String s, Component c) Truncate a String to fit into Component.truncateEnding
(String s, int width) Truncate a String to fit into some width.truncateEnding
(String s, Component c) Truncate a String to fit into Component.truncateMiddle
(String s, int width) Truncate a String to fit into some width.truncateMiddle
(String s, Component c) Truncate a String to fit into Component.
-
Constructor Details
-
StringFitter
public StringFitter()Creates default StringFitter. Uses current system FontMetrics, "..." for all replace strings and "" for split string -
StringFitter
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
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
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
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(FontMetrics fm, String leftReplaceString, String rightReplaceString, 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 Details
-
getDefaultFitter
get or create and get an instance of default StringFitter with "..." for replace strings and "" for split string -
getMiddleReplaceString
get current replacing string for middle parts of truncated string -
setMiddleReplaceString
Set a string for replacing truncated parts in the middle of truncated string ("..." by default)- Parameters:
s
- new replace string
-
getLeftReplaceString
get current replace string for beginning of truncated string -
setLeftReplaceString
set replace string for replacing beginning of the truncated string- Parameters:
s
- new replace string
-
getRightReplaceString
get current replace string for ending of truncated string -
setRightReplaceString
set replace string for replacing ending of the truncated string- Parameters:
s
- new replace string
-
getSplitString
get current split string -
setSplitString
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()
-
getFontMetrics
get current FontMetrics -
setFontMetrics
set FontMetrics- Parameters:
fm
- new FontMetrics used to calculate widths of strings
-
setFontMetrics
set FontMetrics through providing Component that will display truncated string- Parameters:
c
- Component containing FontMetrics used to calculate widths of strings
-
truncateBeginning
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
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
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
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
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
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
-