Package ca.cgjennings.layout
Class TextStyle
- java.lang.Object
-
- ca.cgjennings.layout.TextStyle
-
public class TextStyle extends java.lang.Object
A combination ofTextAttribute
s that represents a particular style of text (a heading, for example).- Author:
- Chris Jennings
-
-
Field Summary
Fields Modifier and Type Field Description static TextStyle
BOLD_STYLE
A shared instance of a style that will render bold text.static TextStyle
COLOR_BLACK
Standard colours.static TextStyle
COLOR_BLUE
static TextStyle
COLOR_BROWN
static TextStyle
COLOR_DKGREY
static TextStyle
COLOR_GREEN
static TextStyle
COLOR_GREY
static TextStyle
COLOR_LTGREY
static TextStyle
COLOR_ORANGE
static TextStyle
COLOR_PURPLE
static TextStyle
COLOR_RED
static TextStyle
COLOR_WHITE
static TextStyle
COLOR_YELLOW
static TextStyle
ITALIC_STYLE
A shared instance of a style that will render italic text.static TextStyle
JUSTIFY
A shared instance of a style that will enable justification.static TextStyle
KERNING_OFF
A shared instance of a style that will disable kerning of text.static TextStyle
KERNING_ON
A shared instance of a style that will enable kerning of text.static TextStyle
LIGATURES_OFF
A shared instance of a style that will disable optional ligature replacement.static TextStyle
LIGATURES_ON
A shared instance of a style that will enable optional ligature replacement.static TextStyle
PLAIN_STYLE
A shared instance of a style that will render "plain" text, removing any italic and bold effects.static TextStyle
SANSSERIF_STYLE
A shared instance of a style that will render sans serif text.static TextStyle
SERIF_STYLE
A shared instance of a style that will render serif text.static TextStyle
STRIKETHROUGH_STYLE
A shared instance of a style that will render struck out text.static TextStyle
SUBSCRIPT_STYLE
A shared instance of a style that will render subscript text.static TextStyle
SUPERSCRIPT_STYLE
A shared instance of a style that will render superscript text.static TextStyle
TYPEWRITER_STYLE
A shared instance of a style that will render sans serif text.static TextStyle
UNDERLINE_STYLE
A shared instance of a style that will render underlined text.static TextStyle
UPRIGHT_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 void
add(TextStyle sourceStyle)
Add all the attributes of thesourceStyle
to this style.void
add(java.awt.font.TextAttribute attr, java.lang.Object styleValue)
Add a newTextAttribute
to this style.void
add(java.lang.Object... listOfAttributesAndStyles)
Add an arbitrarily long sequence of styles and values.void
applyStyle(java.text.AttributedString s)
Apply a style to all characters in anAttributedString
.void
applyStyle(java.text.AttributedString s, int beginPos, int endPos)
Apply this style to a range of characters in anAttributedString
.boolean
contains(java.awt.font.TextAttribute attr)
Returns whether the specified attribute is a member of this style.java.lang.Object
get(java.awt.font.TextAttribute attr)
Get the value for aTextAttribute
in this style.void
remove(java.awt.font.TextAttribute attr)
Remove aTextAttribute
from the style.java.lang.String
toString()
-
-
-
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 newTextAttribute
to 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 ofTextAttribute
s followed byObject
values.
-
add
public void add(TextStyle sourceStyle)
Add all the attributes of thesourceStyle
to this style.
-
get
public java.lang.Object get(java.awt.font.TextAttribute attr)
Get the value for aTextAttribute
in this style. Returnsnull
if the attribute has not been specified.
-
remove
public void remove(java.awt.font.TextAttribute attr)
Remove aTextAttribute
from 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:
toString
in classjava.lang.Object
-
-