Client API. The Codename One framework your app is built on: this runs on the device, not in a backend.
public final class TextStyle
- Object
- TextStyle
Immutable character formatting for a run of text. Sizes are in points and colors are 24 bit RGB values.
A style is changed by deriving a new one, never in place:
// com.codename1.ui.editor has a TextStyle too, hence the full name
com.codename1.wordprocessing.TextStyle heading =
com.codename1.wordprocessing.TextStyle.DEFAULT.withSize(18).withBold(true);
Log.p("heading at " + heading.size + "pt");Fields
Constructors
Methods
public TextStyle withFont(String value) | A copy with a different font family. |
public TextStyle withSize(float value) | A copy with a different size. |
public TextStyle withColor(int value) | A copy with a different text color. |
public TextStyle withBackground(int value) | A copy with a different highlight. |
public TextStyle withBold(boolean value) | A copy with bold switched. |
public TextStyle withItalic(boolean value) | A copy with italic switched. |
public TextStyle withUnderline(boolean value) | A copy with underline switched. |
public TextStyle withStrike(boolean value) | A copy with strike-through switched. |
public TextStyle withLink(String value) | A copy with a different hyperlink. |
public TextStyle withScript(String value) | A copy with a different baseline position. |
public TextStyle withRevision(Revision value) | A copy marked as a tracked change, or with the mark removed. |
public boolean equals(Object o) | Two styles are equal when every attribute is. |
public int hashCode() | A hash consistent with equals. |
Inherited methods
Field details
NO_BACKGROUND
public static final int NO_BACKGROUND = -1Marks the absence of a highlight color.
BASELINE
public static final String BASELINE = "baseline"Normal baseline position.
SUPERSCRIPT
public static final String SUPERSCRIPT = "superscript"Raised and reduced, as in an exponent.
SUBSCRIPT
public static final String SUBSCRIPT = "subscript"Lowered and reduced, as in a chemical formula.
DEFAULT
public static final TextStyle DEFAULTThe style of text that names no formatting of its own.
font
public final String fontThe font family name.
link
public final String linkThe hyperlink target, or the empty string.
color
public final int colorThe text color.
background
public final int backgroundThe highlight color, or
NO_BACKGROUND.size
public final float sizeThe font size in points.
bold
public final boolean boldWhether the text is bold.
italic
public final boolean italicWhether the text is italic.
underline
public final boolean underlineWhether the text is underlined.
strike
public final boolean strikeWhether the text is struck through.
script
public final String scriptOne of
BASELINE, SUPERSCRIPT or SUBSCRIPT.revision
public final Revision revisionThe tracked change this run belongs to, or null.
Constructor details
TextStyle
public TextStyle(String font, float size, int color, boolean bold, boolean italic, boolean underline, boolean strike, int background, String link, String script)Creates a style.
Parameters
fontString- the font family
sizefloat- the size in points, greater than zero
colorint- the RGB text color
boldboolean- bold text
italicboolean- italic text
underlineboolean- underlined text
strikeboolean- struck-through text
backgroundint- the RGB highlight, or
NO_BACKGROUND linkString- the hyperlink target, or null or empty for none
scriptStringBASELINE,SUPERSCRIPTorSUBSCRIPT; null meansBASELINE
TextStyle
public TextStyle(String font, float size, int color, boolean bold, boolean italic, boolean underline, boolean strike, int background, String link, String script, Revision revision)Creates a style with a tracked change.
Parameters
fontString- the font family, or null for
Serif sizefloat- the size in points
colorint- the text color
boldboolean- bold
italicboolean- italic
underlineboolean- underline
strikeboolean- strikethrough
backgroundint- the highlight color, or
NO_BACKGROUND linkString- the hyperlink target, or null or empty for none
scriptStringBASELINE,SUPERSCRIPTorSUBSCRIPT; null meansBASELINErevisionRevision- the tracked change the run belongs to, or null
Method details
withFont
public TextStyle withFont(String value)A copy with a different font family.
Parameters
valueString- the family
Returns
the derived style
withSize
public TextStyle withSize(float value)A copy with a different size.
Parameters
valuefloat- the size in points
Returns
the derived style
withColor
public TextStyle withColor(int value)A copy with a different text color.
Parameters
valueint- the RGB color
Returns
the derived style
withBackground
public TextStyle withBackground(int value)A copy with a different highlight.
Parameters
valueint- the RGB color, or
NO_BACKGROUND
Returns
the derived style
withBold
public TextStyle withBold(boolean value)A copy with bold switched.
Parameters
valueboolean- bold or not
Returns
the derived style
withItalic
public TextStyle withItalic(boolean value)A copy with italic switched.
Parameters
valueboolean- italic or not
Returns
the derived style
withUnderline
public TextStyle withUnderline(boolean value)A copy with underline switched.
Parameters
valueboolean- underlined or not
Returns
the derived style
withStrike
public TextStyle withStrike(boolean value)A copy with strike-through switched.
Parameters
valueboolean- struck through or not
Returns
the derived style
withLink
public TextStyle withLink(String value)A copy with a different hyperlink.
Parameters
valueString- the target, or null or empty for none
Returns
the derived style
withScript
public TextStyle withScript(String value)A copy with a different baseline position.
Parameters
valueStringBASELINE,SUPERSCRIPTorSUBSCRIPT
Returns
the derived style
withRevision
public TextStyle withRevision(Revision value)A copy marked as a tracked change, or with the mark removed.
Parameters
valueRevision- the revision, or null
Returns
the derived style
equals
public boolean equals(Object o)Two styles are equal when every attribute is.
Parameters
oObject- the other object
Returns
true when equal
hashCode
public int hashCode()A hash consistent with
equals.Returns
the hash