Package mars.venus
Class EditorFont
java.lang.Object
mars.venus.EditorFont
Specialized Font class designed to be used by both the
settings menu methods and the Settings class.
- Version:
- July 2007
- Author:
- Pete Sanderson
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enum
Enumeration of the available font styles in the editor. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final int
static final int
static final int
-
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 EditorFont.Style
getStyle
(int flags) Given an int field of flags that represents a font style from theFont
class, returns the correspondingEditorFont.Style
.static EditorFont.Style
Given the name of a font style, returns the correspondingEditorFont.Style
.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
substituteSpacesForTabs
(String string, int tabSize) Handy utility to produce a string that substitutes spaces for all tab characters in the given string.
-
Field Details
-
MIN_SIZE
public static final int MIN_SIZE- See Also:
-
MAX_SIZE
public static final int MAX_SIZE- See Also:
-
DEFAULT_SIZE
public static final int DEFAULT_SIZE- See Also:
-
-
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.
-
getStyle
Given the name of a font style, returns the correspondingEditorFont.Style
. The style name is not case-sensitive.- Parameters:
name
- The name of the font style.- Returns:
- The style with the name given. If the name does not correspond
to a valid style,
EditorFont.Style.DEFAULT
is returned.
-
getStyle
Given an int field of flags that represents a font style from theFont
class, returns the correspondingEditorFont.Style
.- Parameters:
flags
- A combination of style flags from theFont
class.- Returns:
- The style corresponding to the flags given. If the flags do not correspond
to a valid style,
EditorFont.Style.DEFAULT
is returned.
-
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 style is substituted if necessary.size
- String containing font size. The defaults and limits of sizeStringToSizeInt() are substituted if necessary.
-
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
-