Package mars.util
Class EditorFont
java.lang.Object
mars.util.EditorFont
Specialized Font class designed to be used by both the settings menu methods
and the Settings class.
- Version:
- July 2007
- Author:
- Pete Sanderson
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic Font
createFontFromStringValues(String family, String style, String size)
Creates a new Font object based on the given String specifications.static String[]
Obtain an array of all available font family names.static String[]
Obtain an array of common font family names.static String[]
Get array containing String values for font style names.static String
sizeIntToSizeString(int size)
Given an int representing font size, returns corresponding string.static int
sizeStringToSizeInt(String size)
Given a String representing font size, returns corresponding int.static String
styleIntToStyleString(int style)
Given an int that represents a font style from the Font class, returns the corresponding String.static int
styleStringToStyleInt(String style)
Given a string that represents a font style, returns the corresponding final int defined in Font: PLAIN, BOLD, ITALIC.static String
substituteSpacesForTabs(String string)
static String
substituteSpacesForTabs(String string, int tabSize)
Handy utility to produce a string that substitutes spaces for all tab characters in the given string.
-
Field Details
-
DEFAULT_STYLE_STRING
-
DEFAULT_STYLE_INT
public static final int DEFAULT_STYLE_INT -
MIN_SIZE
public static final int MIN_SIZE- See Also:
- Constant Field Values
-
MAX_SIZE
public static final int MAX_SIZE- See Also:
- Constant Field Values
-
DEFAULT_SIZE
public static final int DEFAULT_SIZE- See Also:
- Constant Field Values
-
-
Constructor Details
-
EditorFont
public EditorFont()
-
-
Method Details
-
getCommonFamilies
Obtain an array of common font family names. These are guaranteed to be available at runtime, as they were checked against the local GraphicsEnvironment.- Returns:
- Array of strings, each is a common and available font family name.
-
getAllFamilies
Obtain an array of all available font family names. These are guaranteed to be available at runtime, as they come from the local GraphicsEnvironment.- Returns:
- Array of strings, each is an available font family name.
-
getFontStyleStrings
Get array containing String values for font style names. -
styleStringToStyleInt
Given a string that represents a font style, returns the corresponding final int defined in Font: PLAIN, BOLD, ITALIC. It is not case-sensitive.- Parameters:
style
- String representing the font style name- Returns:
- The int value of the corresponding Font style constant. If the string does not match any style name, returns Font.PLAIN.
-
styleIntToStyleString
Given an int that represents a font style from the Font class, returns the corresponding String.- Parameters:
style
- Must be one of Font.PLAIN, Font.BOLD, Font.ITALIC.- Returns:
- The String representation of that style. If the parameter is not one of the above, returns "Plain".
-
sizeIntToSizeString
Given an int representing font size, returns corresponding string.- Parameters:
size
- Int representing size.- Returns:
- String value of parameter, unless it is less than MIN_SIZE (returns MIN_SIZE as String) or greater than MAX_SIZE (returns MAX_SIZE as String).
-
sizeStringToSizeInt
Given a String representing font size, returns corresponding int.- Parameters:
size
- String representing size.- Returns:
- int value of parameter, unless it is less than MIN_SIZE (returns MIN_SIZE) or greater than MAX_SIZE (returns MAX_SIZE). If the string cannot be parsed as a decimal integer, it returns DEFAULT_SIZE.
-
createFontFromStringValues
Creates a new Font object based on the given String specifications. This is different than Font's constructor, which requires ints for style and size. It assures that defaults and size limits are applied when necessary.- Parameters:
family
- String containing font family.style
- String containing font style. A list of available styles can be obtained from getFontStyleStrings(). The default of styleStringToStyleInt() is substituted if necessary.size
- String containing font size. The defaults and limits of sizeStringToSizeInt() are substituted if necessary.
-
substituteSpacesForTabs
-
substituteSpacesForTabs
Handy utility to produce a string that substitutes spaces for all tab characters in the given string. The number of spaces generated is based on the position of the tab character and the specified tab size.- Parameters:
string
- The original stringtabSize
- The number of spaces each tab character represents- Returns:
- New string in which spaces are substituted for tabs
- Throws:
NullPointerException
- if string is null
-