Class StringFitter

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

public class StringFitter extends Object
  • Constructor Details

    • StringFitter

      public StringFitter()
      Creates default StringFitter. Uses current system FontMetrics, "..." for all replace strings and "" for split string
    • StringFitter

      public StringFitter(String replaceString, 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(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. 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(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(FontMetrics fm, String replaceString, 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(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 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 Details

    • 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 String getMiddleReplaceString()
      get current replacing string for middle parts of truncated string
    • setMiddleReplaceString

      public void setMiddleReplaceString(String s)
      Set a string for replacing truncated parts in the middle of truncated string ("..." by default)
      Parameters:
      s - new replace string
    • getLeftReplaceString

      public String getLeftReplaceString()
      get current replace string for beginning of truncated string
    • setLeftReplaceString

      public void setLeftReplaceString(String s)
      set replace string for replacing beginning of the truncated string
      Parameters:
      s - new replace string
    • getRightReplaceString

      public String getRightReplaceString()
      get current replace string for ending of truncated string
    • setRightReplaceString

      public void setRightReplaceString(String s)
      set replace string for replacing ending of the truncated string
      Parameters:
      s - new replace string
    • getSplitString

      public String getSplitString()
      get current split string
    • setSplitString

      public void setSplitString(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()
    • getFontMetrics

      public FontMetrics getFontMetrics()
      get current FontMetrics
    • setFontMetrics

      public void setFontMetrics(FontMetrics fm)
      set FontMetrics
      Parameters:
      fm - new FontMetrics used to calculate widths of strings
    • setFontMetrics

      public void setFontMetrics(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 String truncateBeginning(String s, 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 String truncateBeginning(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 String truncateEnding(String s, 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 String truncateEnding(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 String truncateMiddle(String s, 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 String truncateMiddle(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