Client API. The Codename One framework your app is built on: this runs on the device, not in a backend.
public final class Paragraph
- Object
- 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
Constructors
Methods
Inherited methods
Field details
LEFT
public static final String LEFT = "left"Start-aligned text.
CENTER
public static final String CENTER = "center"Centered text.
RIGHT
public static final String RIGHT = "right"End-aligned 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 idThe block id.
style
public final String styleThe named paragraph style (
Normal, Heading1 … Heading6, Title, Quote, Code
or an application’s own).align
public final String alignOne of
LEFT, CENTER, RIGHT or JUSTIFY.list
public final String listOne of
NO_LIST, BULLET or NUMBERED.listLevel
public final int listLevelThe list nesting level, from zero.
listStart
public final int listStartThe number a numbered list restarts at, or zero to continue the previous list.
before
public final float beforeSpace above the paragraph.
after
public final float afterSpace below the paragraph.
indent
public final float indentLeft indent.
lineSpacing
public final float lineSpacingLine spacing as a multiple of the single line height.
pageBreak
public final boolean pageBreakWhether a page break precedes the paragraph.
keepNext
public final boolean keepNextWhether the paragraph stays on the page of the one that follows it.
text
public final RichText textThe paragraph’s text.
firstLine
public final float firstLineThe first line’s indent relative to
indent; negative for a hanging indent.rightIndent
public final float rightIndentThe right indent, in points.
tabs
public final List<TabStop> tabsThe 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
idString- the block id
textRichText- 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
idString- the block id
styleString- the named style
alignString- the alignment
listString- the list kind
listLevelint- the list level, 0 to 8
listStartint- the restart number, or zero
beforefloat- space above
afterfloat- space below
indentfloat- left indent
lineSpacingfloat- the line spacing multiple
pageBreakboolean- page break before
keepNextboolean- keep with next
textRichText- the text
Method details
withIndents
public Paragraph withIndents(float left, float first, float right)A copy with different indents.
Parameters
leftfloat- the left indent
firstfloat- the first line’s indent relative to
left; negative hangs rightfloat- the right indent
Returns
the copy
withTabs
public Paragraph withTabs(List<TabStop> value)A copy with different tab stops.
Parameters
valueList<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
valueRichText- the text
Returns
the copy
withStyle
public Paragraph withStyle(String value)A copy with a different named style.
Parameters
valueString- the style
Returns
the copy
withAlign
public Paragraph withAlign(String value)A copy with a different alignment.
Parameters
valueStringLEFT,CENTER,RIGHTorJUSTIFY
Returns
the copy
withList
public Paragraph withList(String kind, int level)A copy with different list membership.
Parameters
kindStringNO_LIST,BULLETorNUMBEREDlevelint- the nesting level
Returns
the copy
withListStart
public Paragraph withListStart(int value)A copy whose numbered list restarts.
Parameters
valueint- 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
spaceBeforefloat- space above
spaceAfterfloat- space below
linesfloat- the line spacing multiple
Returns
the copy
withIndent
public Paragraph withIndent(float value)A copy with a different left indent.
Parameters
valuefloat- the indent
Returns
the copy
withPageBreak
public Paragraph withPageBreak(boolean value)A copy with the page break switched.
Parameters
valueboolean- break before or not
Returns
the copy
withKeepNext
public Paragraph withKeepNext(boolean value)A copy with keep-with-next switched.
Parameters
valueboolean- keep or not
Returns
the copy
withId
public Paragraph withId(String value)A copy with another id, used when a paragraph is duplicated.
Parameters
valueString- the new id
Returns
the copy
equals
public boolean equals(Object o)Two paragraphs are equal when every attribute, the id included, is.
Parameters
oObject- the other object
Returns
true when equal
hashCode
public int hashCode()A hash consistent with
equals.Returns
the hash