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

public final class Paragraph

  1. Object
  2. Paragraph

ImplementsBlock

An immutable paragraph: styled text plus the paragraph’s own layout. Distances are in points.

Every with... method returns a copy that keeps the id, so the copy replaces the original in a document:

Paragraph p = new Paragraph("p1", RichText.of("Hello")).withAlign(Paragraph.CENTER);

Fields

public static final String LEFT = "left"Start-aligned text.
public static final String CENTER = "center"Centered text.
public static final String RIGHT = "right"End-aligned text.
public static final String JUSTIFY = "justify"Text stretched to both margins.
public static final String NO_LIST = ""Not a list item.
public static final String BULLET = "bullet"A bulleted list item.
public static final String NUMBERED = "number"A numbered list item.
public final String idThe block id.
public final String styleThe named paragraph style (Normal, Heading1 … Heading6, Title, Quote, Code or an application’s own).
public final String alignOne of LEFT, CENTER, RIGHT or JUSTIFY.
public final String listOne of NO_LIST, BULLET or NUMBERED.
public final int listLevelThe list nesting level, from zero.
public final int listStartThe number a numbered list restarts at, or zero to continue the previous list.
public final float beforeSpace above the paragraph.
public final float afterSpace below the paragraph.
public final float indentLeft indent.
public final float lineSpacingLine spacing as a multiple of the single line height.
public final boolean pageBreakWhether a page break precedes the paragraph.
public final boolean keepNextWhether the paragraph stays on the page of the one that follows it.
public final RichText textThe paragraph’s text.
public final float firstLineThe first line’s indent relative to indent; negative for a hanging indent.
public final float rightIndentThe right indent, in points.
public final List<TabStop> tabsThe tab stops, ordered by position; empty for the default stops every half inch.

Constructors

public Paragraph(String id, RichText text)A Normal paragraph with default layout.
public Paragraph(String id, String style, String align, String list, int listLevel, int listStart, float before, float after, float indent, float lineSpacing, boolean pageBreak, boolean keepNext, RichText text)A paragraph with every attribute given.

Methods

public Paragraph withIndents(float left, float first, float right)A copy with different indents.
public Paragraph withTabs(List<TabStop> value)A copy with different tab stops.
public String id()The block id.
public String plainText()The text without formatting.
public boolean isHeading()Whether the paragraph is a heading, that is its style is Heading1 to Heading6 or Title.
public int headingLevel()The heading level: 1 to 6 for Heading1 to Heading6, 1 for Title, 0 otherwise.
public Paragraph withText(RichText value)A copy with different text.
public Paragraph withStyle(String value)A copy with a different named style.
public Paragraph withAlign(String value)A copy with a different alignment.
public Paragraph withList(String kind, int level)A copy with different list membership.
public Paragraph withListStart(int value)A copy whose numbered list restarts.
public Paragraph withSpacing(float spaceBefore, float spaceAfter, float lines)A copy with different spacing.
public Paragraph withIndent(float value)A copy with a different left indent.
public Paragraph withPageBreak(boolean value)A copy with the page break switched.
public Paragraph withKeepNext(boolean value)A copy with keep-with-next switched.
public Paragraph withId(String value)A copy with another id, used when a paragraph is duplicated.
public boolean equals(Object o)Two paragraphs are equal when every attribute, the id included, is.
public int hashCode()A hash consistent with equals.

Inherited methods

Field details

LEFT

public static final String LEFT = "left"
Start-aligned text.

CENTER

public static final String CENTER = "center"
Centered text.

JUSTIFY

public static final String JUSTIFY = "justify"
Text stretched to both margins.

NO_LIST

public static final String NO_LIST = ""
Not a list item.

BULLET

public static final String BULLET = "bullet"
A bulleted list item.

NUMBERED

public static final String NUMBERED = "number"
A numbered list item.

id

public final String id
The block id.

style

public final String style
The named paragraph style (Normal, Heading1 … Heading6, Title, Quote, Code or an application’s own).

align

public final String align
One of LEFT, CENTER, RIGHT or JUSTIFY.

list

public final String list
One of NO_LIST, BULLET or NUMBERED.

listLevel

public final int listLevel
The list nesting level, from zero.

listStart

public final int listStart
The number a numbered list restarts at, or zero to continue the previous list.

before

public final float before
Space above the paragraph.

after

public final float after
Space below the paragraph.

indent

public final float indent
Left indent.

lineSpacing

public final float lineSpacing
Line spacing as a multiple of the single line height.

pageBreak

public final boolean pageBreak
Whether a page break precedes the paragraph.

keepNext

public final boolean keepNext
Whether the paragraph stays on the page of the one that follows it.

text

public final RichText text
The paragraph’s text.

firstLine

public final float firstLine
The first line’s indent relative to indent; negative for a hanging indent.

rightIndent

public final float rightIndent
The right indent, in points.

tabs

public final List<TabStop> tabs
The tab stops, ordered by position; empty for the default stops every half inch.

Constructor details

Paragraph

public Paragraph(String id, RichText text)
A Normal paragraph with default layout.

Parameters

id String
the block id
text RichText
the text

Paragraph

public Paragraph(String id, String style, String align, String list, int listLevel, int listStart, float before, float after, float indent, float lineSpacing, boolean pageBreak, boolean keepNext, RichText text)
A paragraph with every attribute given.

Parameters

id String
the block id
style String
the named style
align String
the alignment
list String
the list kind
listLevel int
the list level, 0 to 8
listStart int
the restart number, or zero
before float
space above
after float
space below
indent float
left indent
lineSpacing float
the line spacing multiple
pageBreak boolean
page break before
keepNext boolean
keep with next
text RichText
the text

Method details

withIndents

public Paragraph withIndents(float left, float first, float right)
A copy with different indents.

Parameters

left float
the left indent
first float
the first line’s indent relative to left; negative hangs
right float
the right indent

Returns

the copy

withTabs

public Paragraph withTabs(List<TabStop> value)
A copy with different tab stops.

Parameters

value List<TabStop>
the stops in any order, or null for the default ones; at most 64 are kept and a later stop at the same position replaces an earlier one

Returns

the copy

id

public String id()
The block id.

Returns

the id

plainText

public String plainText()
The text without formatting.

Returns

the characters

isHeading

public boolean isHeading()
Whether the paragraph is a heading, that is its style is Heading1 to Heading6 or Title.

Returns

true for a heading

headingLevel

public int headingLevel()
The heading level: 1 to 6 for Heading1 to Heading6, 1 for Title, 0 otherwise.

Returns

the level

withText

public Paragraph withText(RichText value)
A copy with different text.

Parameters

value RichText
the text

Returns

the copy

withStyle

public Paragraph withStyle(String value)
A copy with a different named style.

Parameters

value String
the style

Returns

the copy

withAlign

public Paragraph withAlign(String value)
A copy with a different alignment.

Parameters

value String
LEFT, CENTER, RIGHT or JUSTIFY

Returns

the copy

withList

public Paragraph withList(String kind, int level)
A copy with different list membership.

Parameters

kind String
NO_LIST, BULLET or NUMBERED
level int
the nesting level

Returns

the copy

withListStart

public Paragraph withListStart(int value)
A copy whose numbered list restarts.

Parameters

value int
the first number, or zero to continue

Returns

the copy

withSpacing

public Paragraph withSpacing(float spaceBefore, float spaceAfter, float lines)
A copy with different spacing.

Parameters

spaceBefore float
space above
spaceAfter float
space below
lines float
the line spacing multiple

Returns

the copy

withIndent

public Paragraph withIndent(float value)
A copy with a different left indent.

Parameters

value float
the indent

Returns

the copy

withPageBreak

public Paragraph withPageBreak(boolean value)
A copy with the page break switched.

Parameters

value boolean
break before or not

Returns

the copy

withKeepNext

public Paragraph withKeepNext(boolean value)
A copy with keep-with-next switched.

Parameters

value boolean
keep or not

Returns

the copy

withId

public Paragraph withId(String value)
A copy with another id, used when a paragraph is duplicated.

Parameters

value String
the new id

Returns

the copy

equals

public boolean equals(Object o)
Two paragraphs are equal when every attribute, the id included, is.

Parameters

o Object
the other object

Returns

true when equal

hashCode

public int hashCode()
A hash consistent with equals.

Returns

the hash