Client API. The Codename One framework your app is built on: this runs on the device, not in a backend.

public final class TextStyle

  1. Object
  2. 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

public static final int NO_BACKGROUND = -1Marks the absence of a highlight color.
public static final String BASELINE = "baseline"Normal baseline position.
public static final String SUPERSCRIPT = "superscript"Raised and reduced, as in an exponent.
public static final String SUBSCRIPT = "subscript"Lowered and reduced, as in a chemical formula.
public static final TextStyle DEFAULTThe style of text that names no formatting of its own.
public final String fontThe font family name.
public final String linkThe hyperlink target, or the empty string.
public final int colorThe text color.
public final int backgroundThe highlight color, or NO_BACKGROUND.
public final float sizeThe font size in points.
public final boolean boldWhether the text is bold.
public final boolean italicWhether the text is italic.
public final boolean underlineWhether the text is underlined.
public final boolean strikeWhether the text is struck through.
public final String scriptOne of BASELINE, SUPERSCRIPT or SUBSCRIPT.
public final Revision revisionThe tracked change this run belongs to, or null.

Constructors

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.
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.

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 = -1
Marks 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 DEFAULT
The style of text that names no formatting of its own.

font

public final String font
The font family name.

color

public final int color
The text color.

background

public final int background
The highlight color, or NO_BACKGROUND.

size

public final float size
The font size in points.

bold

public final boolean bold
Whether the text is bold.

italic

public final boolean italic
Whether the text is italic.

underline

public final boolean underline
Whether the text is underlined.

strike

public final boolean strike
Whether the text is struck through.

script

public final String script
One of BASELINE, SUPERSCRIPT or SUBSCRIPT.

revision

public final Revision revision
The 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

font String
the font family
size float
the size in points, greater than zero
color int
the RGB text color
bold boolean
bold text
italic boolean
italic text
underline boolean
underlined text
strike boolean
struck-through text
background int
the RGB highlight, or NO_BACKGROUND
link String
the hyperlink target, or null or empty for none
script String
BASELINE, SUPERSCRIPT or SUBSCRIPT; null means BASELINE

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

font String
the font family, or null for Serif
size float
the size in points
color int
the text color
bold boolean
bold
italic boolean
italic
underline boolean
underline
strike boolean
strikethrough
background int
the highlight color, or NO_BACKGROUND
link String
the hyperlink target, or null or empty for none
script String
BASELINE, SUPERSCRIPT or SUBSCRIPT; null means BASELINE
revision Revision
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

value String
the family

Returns

the derived style

withSize

public TextStyle withSize(float value)
A copy with a different size.

Parameters

value float
the size in points

Returns

the derived style

withColor

public TextStyle withColor(int value)
A copy with a different text color.

Parameters

value int
the RGB color

Returns

the derived style

withBackground

public TextStyle withBackground(int value)
A copy with a different highlight.

Parameters

value int
the RGB color, or NO_BACKGROUND

Returns

the derived style

withBold

public TextStyle withBold(boolean value)
A copy with bold switched.

Parameters

value boolean
bold or not

Returns

the derived style

withItalic

public TextStyle withItalic(boolean value)
A copy with italic switched.

Parameters

value boolean
italic or not

Returns

the derived style

withUnderline

public TextStyle withUnderline(boolean value)
A copy with underline switched.

Parameters

value boolean
underlined or not

Returns

the derived style

withStrike

public TextStyle withStrike(boolean value)
A copy with strike-through switched.

Parameters

value boolean
struck through or not

Returns

the derived style

withLink

public TextStyle withLink(String value)
A copy with a different hyperlink.

Parameters

value String
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

value String
BASELINE, SUPERSCRIPT or SUBSCRIPT

Returns

the derived style

withRevision

public TextStyle withRevision(Revision value)
A copy marked as a tracked change, or with the mark removed.

Parameters

value Revision
the revision, or null

Returns

the derived style

equals

public boolean equals(Object o)
Two styles are equal when every attribute is.

Parameters

o Object
the other object

Returns

true when equal

hashCode

public int hashCode()
A hash consistent with equals.

Returns

the hash