com.sun.javatest.tool
Class StringFitter

java.lang.Object
  extended by com.sun.javatest.tool.StringFitter

public class StringFitter
extends java.lang.Object


Constructor Summary
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
static StringFitter getDefaultFitter()
          get or create and get an instance of default StringFitter with "..." for replace strings and "" for split string
 java.awt.FontMetrics getFontMetrics()
          get current FontMetrics
 java.lang.String getLeftReplaceString()
          get current replace string for beginning of truncated string
 java.lang.String getMiddleReplaceString()
          get current replacing string for middle parts of truncated string
 java.lang.String getRightReplaceString()
          get current replace string for ending of truncated string
 java.lang.String getSplitString()
          get current split string
 void setFontMetrics(java.awt.Component c)
          set FontMetrics through providing Component that will display truncated string
 void setFontMetrics(java.awt.FontMetrics fm)
          set FontMetrics
 void setLeftReplaceString(java.lang.String s)
          set replace string for replacing beginning of the truncated string
 void 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 string
 void setSplitString(java.lang.String s)
          set split string
 java.lang.String truncateBeginning(java.lang.String s, java.awt.Component c)
          Truncate a String to fit into Component.
 java.lang.String truncateBeginning(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 truncateEnding(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.
 java.lang.String truncateMiddle(java.lang.String s, int width)
          Truncate a String to fit into some width.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

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 parts
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.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 null
replaceString - an universal string for replacing truncated parts. It is used to replace beginning, ending and middle parts
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,
                    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 null
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()
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 truncate
c - 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 truncate
width - 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 truncate
c - 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 truncate
width - 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 truncate
c - 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 truncate
width - available space for the string


Copyright (c) 1996, 2010, Oracle and/or its affiliates. All rights reserved.