Package ca.cgjennings.layout
Class TextStyle
- java.lang.Object
-
- ca.cgjennings.layout.TextStyle
-
public class TextStyle extends java.lang.ObjectA combination ofTextAttributes that represents a particular style of text (a heading, for example).- Author:
- Chris Jennings
-
-
Field Summary
Fields Modifier and Type Field Description static TextStyleBOLD_STYLEA shared instance of a style that will render bold text.static TextStyleCOLOR_BLACKStandard colours.static TextStyleCOLOR_BLUEstatic TextStyleCOLOR_BROWNstatic TextStyleCOLOR_DKGREYstatic TextStyleCOLOR_GREENstatic TextStyleCOLOR_GREYstatic TextStyleCOLOR_LTGREYstatic TextStyleCOLOR_ORANGEstatic TextStyleCOLOR_PURPLEstatic TextStyleCOLOR_REDstatic TextStyleCOLOR_WHITEstatic TextStyleCOLOR_YELLOWstatic TextStyleITALIC_STYLEA shared instance of a style that will render italic text.static TextStyleJUSTIFYA shared instance of a style that will enable justification.static TextStyleKERNING_OFFA shared instance of a style that will disable kerning of text.static TextStyleKERNING_ONA shared instance of a style that will enable kerning of text.static TextStyleLIGATURES_OFFA shared instance of a style that will disable optional ligature replacement.static TextStyleLIGATURES_ONA shared instance of a style that will enable optional ligature replacement.static TextStylePLAIN_STYLEA shared instance of a style that will render "plain" text, removing any italic and bold effects.static TextStyleSANSSERIF_STYLEA shared instance of a style that will render sans serif text.static TextStyleSERIF_STYLEA shared instance of a style that will render serif text.static TextStyleSTRIKETHROUGH_STYLEA shared instance of a style that will render struck out text.static TextStyleSUBSCRIPT_STYLEA shared instance of a style that will render subscript text.static TextStyleSUPERSCRIPT_STYLEA shared instance of a style that will render superscript text.static TextStyleTYPEWRITER_STYLEA shared instance of a style that will render sans serif text.static TextStyleUNDERLINE_STYLEA shared instance of a style that will render underlined text.static TextStyleUPRIGHT_STYLE
-
Constructor Summary
Constructors Constructor Description TextStyle()Create a new, empty style.TextStyle(java.awt.font.TextAttribute attr, java.lang.Object styleValue)Create a new style which initially consists of a single style.TextStyle(java.lang.Object... listOfAttributesAndStyles)Create a new style which initially consists of the specified styles.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidadd(TextStyle sourceStyle)Add all the attributes of thesourceStyleto this style.voidadd(java.awt.font.TextAttribute attr, java.lang.Object styleValue)Add a newTextAttributeto this style.voidadd(java.lang.Object... listOfAttributesAndStyles)Add an arbitrarily long sequence of styles and values.voidapplyStyle(java.text.AttributedString s)Apply a style to all characters in anAttributedString.voidapplyStyle(java.text.AttributedString s, int beginPos, int endPos)Apply this style to a range of characters in anAttributedString.booleancontains(java.awt.font.TextAttribute attr)Returns whether the specified attribute is a member of this style.java.lang.Objectget(java.awt.font.TextAttribute attr)Get the value for aTextAttributein this style.voidremove(java.awt.font.TextAttribute attr)Remove aTextAttributefrom the style.java.lang.StringtoString()
-
-
-
Field Detail
-
SERIF_STYLE
public static final TextStyle SERIF_STYLE
A shared instance of a style that will render serif text. If this instance is modified, everyone using it is also affected.
-
SANSSERIF_STYLE
public static final TextStyle SANSSERIF_STYLE
A shared instance of a style that will render sans serif text. If this instance is modified, everyone using it is also affected.
-
TYPEWRITER_STYLE
public static final TextStyle TYPEWRITER_STYLE
A shared instance of a style that will render sans serif text. If this instance is modified, everyone using it is also affected.
-
BOLD_STYLE
public static final TextStyle BOLD_STYLE
A shared instance of a style that will render bold text. If this instance is modified, everyone using it is also affected.
-
ITALIC_STYLE
public static final TextStyle ITALIC_STYLE
A shared instance of a style that will render italic text. If this instance is modified, everyone using it is also affected.
-
UPRIGHT_STYLE
public static final TextStyle UPRIGHT_STYLE
-
SUPERSCRIPT_STYLE
public static final TextStyle SUPERSCRIPT_STYLE
A shared instance of a style that will render superscript text. If this instance is modified, everyone using it is also affected.
-
SUBSCRIPT_STYLE
public static final TextStyle SUBSCRIPT_STYLE
A shared instance of a style that will render subscript text. If this instance is modified, everyone using it is also affected.
-
STRIKETHROUGH_STYLE
public static final TextStyle STRIKETHROUGH_STYLE
A shared instance of a style that will render struck out text. If this instance is modified, everyone using it is also affected.
-
UNDERLINE_STYLE
public static final TextStyle UNDERLINE_STYLE
A shared instance of a style that will render underlined text. If this instance is modified, everyone using it is also affected.
-
KERNING_ON
public static final TextStyle KERNING_ON
A shared instance of a style that will enable kerning of text. If this instance is modified, everyone using it is also affected.
-
KERNING_OFF
public static final TextStyle KERNING_OFF
A shared instance of a style that will disable kerning of text. If this instance is modified, everyone using it is also affected.
-
LIGATURES_ON
public static final TextStyle LIGATURES_ON
A shared instance of a style that will enable optional ligature replacement. If this instance is modified, everyone using it is also affected.
-
LIGATURES_OFF
public static final TextStyle LIGATURES_OFF
A shared instance of a style that will disable optional ligature replacement. If this instance is modified, everyone using it is also affected.
-
JUSTIFY
public static final TextStyle JUSTIFY
A shared instance of a style that will enable justification. If this instance is modified, everyone using it is also affected.
-
PLAIN_STYLE
public static final TextStyle PLAIN_STYLE
A shared instance of a style that will render "plain" text, removing any italic and bold effects.
-
COLOR_BLACK
public static final TextStyle COLOR_BLACK
Standard colours.
-
COLOR_WHITE
public static final TextStyle COLOR_WHITE
-
COLOR_LTGREY
public static final TextStyle COLOR_LTGREY
-
COLOR_GREY
public static final TextStyle COLOR_GREY
-
COLOR_DKGREY
public static final TextStyle COLOR_DKGREY
-
COLOR_RED
public static final TextStyle COLOR_RED
-
COLOR_ORANGE
public static final TextStyle COLOR_ORANGE
-
COLOR_YELLOW
public static final TextStyle COLOR_YELLOW
-
COLOR_GREEN
public static final TextStyle COLOR_GREEN
-
COLOR_BLUE
public static final TextStyle COLOR_BLUE
-
COLOR_PURPLE
public static final TextStyle COLOR_PURPLE
-
COLOR_BROWN
public static final TextStyle COLOR_BROWN
-
-
Constructor Detail
-
TextStyle
public TextStyle()
Create a new, empty style.
-
TextStyle
public TextStyle(java.lang.Object... listOfAttributesAndStyles)
Create a new style which initially consists of the specified styles.
-
TextStyle
public TextStyle(java.awt.font.TextAttribute attr, java.lang.Object styleValue)Create a new style which initially consists of a single style. This may optimize internal storage for a style with only a single member, but does not preclude adding additional members later.
-
-
Method Detail
-
add
public void add(java.awt.font.TextAttribute attr, java.lang.Object styleValue)Add a newTextAttributeto this style.
-
add
public void add(java.lang.Object... listOfAttributesAndStyles)
Add an arbitrarily long sequence of styles and values. The sequence of arguments must come in pairs ofTextAttributes followed byObjectvalues.
-
add
public void add(TextStyle sourceStyle)
Add all the attributes of thesourceStyleto this style.
-
get
public java.lang.Object get(java.awt.font.TextAttribute attr)
Get the value for aTextAttributein this style. Returnsnullif the attribute has not been specified.
-
remove
public void remove(java.awt.font.TextAttribute attr)
Remove aTextAttributefrom the style.
-
contains
public boolean contains(java.awt.font.TextAttribute attr)
Returns whether the specified attribute is a member of this style.
-
applyStyle
public void applyStyle(java.text.AttributedString s, int beginPos, int endPos)Apply this style to a range of characters in anAttributedString.- Parameters:
s- the string to the apply the attributes of the style tobeginPos- the index of the first character in the rangeendPos- the index one past the last character in the range
-
applyStyle
public void applyStyle(java.text.AttributedString s)
Apply a style to all characters in anAttributedString.
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-