Class TitleGenerator

  • All Implemented Interfaces:
    Serializable

    public class TitleGenerator
    extends Object
    implements Serializable
    A simple helper class for generating titles for frames and dialogs.
    Author:
    fracpete (fracpete at waikato dot ac dot nz)
    See Also:
    Serialized Form
    • Field Detail

      • DEFAULT_MAX_CHARS

        public static final int DEFAULT_MAX_CHARS
        the default max chars.
        See Also:
        Constant Field Values
      • m_Title

        protected String m_Title
        the base title.
      • m_Split

        protected boolean m_Split
        whether to split the full filename into path and filename.
      • m_Shortening

        protected ShorteningType m_Shortening
        whether to shorten the file (or parent).
      • m_MaxChars

        protected int m_MaxChars
        the maximum chars for shortening.
      • m_Enabled

        protected boolean m_Enabled
        whether the generator is enabled.
    • Constructor Detail

      • TitleGenerator

        public TitleGenerator​(String title,
                              boolean split)
        Initializes the generator. Uses no shortening.
        Parameters:
        title - the base title.
        split - whether to split the filename into path/name
      • TitleGenerator

        public TitleGenerator​(String title,
                              boolean split,
                              ShorteningType shortening)
        Initializes the generator. Uses the specified shortening with DEFAULT_MAX_CHARS.
        Parameters:
        title - the base title.
        split - whether to split the filename into path/name
        shortening - how to shorten the filename (if at all)
      • TitleGenerator

        public TitleGenerator​(String title,
                              boolean split,
                              ShorteningType shortening,
                              int maxChars)
        Initializes the generator.
        Parameters:
        title - the base title.
        split - whether to split the filename into path/name
        shortening - how to shorten the filename (if at all)
        maxChars - the maximum number of characters for the shortened filename
    • Method Detail

      • setTitle

        public void setTitle​(String value)
        Sets the base title.
        Parameters:
        value - the title
      • getTitle

        public String getTitle()
        Returns the base title.
        Returns:
        the title
      • getSplit

        public boolean getSplit()
        Returns whether the filename is split into path and name part.
        Returns:
        true if split
      • getShortening

        public ShorteningType getShortening()
        Returns how the file is being shortened.
        Returns:
        the shortening type
      • getMaxChars

        public int getMaxChars()
        Returns the maximum number of characters used for shortening the filename.
        Returns:
        the max chars
        See Also:
        getShortening()
      • setEnabled

        public void setEnabled​(boolean value)
        Sets whether the generator is enabled.
        Parameters:
        value - true if enabled
      • isEnabled

        public boolean isEnabled()
        Returns whether the generator is enabled.
        Returns:
        true if enabled
      • generate

        public String generate()
        Generates the default title.
        Returns:
        the generated title
      • generate

        public String generate​(boolean modified)
        Generates the default title.
        Parameters:
        modified - whether the data is modified
        Returns:
        the generated title
      • generate

        public String generate​(String filename)
        Generates a title for the given file.
        Parameters:
        filename - the file to generate the title for, can be null
        Returns:
        the generated title
      • generate

        public String generate​(String filename,
                               boolean modified)
        Generates a title for the given file.
        Parameters:
        filename - the file to generate the title for, can be null
        modified - whether the file is modified
        Returns:
        the generated title
      • generate

        public String generate​(File file)
        Generates a title for the given file.
        Parameters:
        file - the file to generate the title for, can be null
        Returns:
        the generated title
      • generate

        public String generate​(File file,
                               boolean modified)
        Generates a title for the given file.
        Parameters:
        file - the file to generate the title for, can be null
        modified - whether the file is modified
        Returns:
        the generated title
      • generateAny

        public String generateAny​(String subtitle)
        Generates a title for the given sub-title. Does not apply a split.
        Parameters:
        subtitle - the sub-title to generate the title for, can be null
        Returns:
        the generated title
      • generateAny

        public String generateAny​(String subtitle,
                                  boolean modified)
        Generates a title for the given sub-title. Does not apply a split.
        Parameters:
        subtitle - the sub-title to generate the title for, can be null
        modified - whether the user interface is modified
        Returns:
        the generated title