Class Paragraph

java.lang.Object
com.codename1.wordprocessing.Paragraph
All Implemented Interfaces:
Block

public final class Paragraph extends Object implements Block

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);
  • Field Details

    • LEFT

      public static final String LEFT
      Start-aligned text.
      See Also:
    • CENTER

      public static final String CENTER
      Centered text.
      See Also:
    • JUSTIFY

      public static final String JUSTIFY
      Text stretched to both margins.
      See Also:
    • NO_LIST

      public static final String NO_LIST
      Not a list item.
      See Also:
    • BULLET

      public static final String BULLET
      A bulleted list item.
      See Also:
    • NUMBERED

      public static final String NUMBERED
      A numbered list item.
      See Also:
    • 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: the block id

      • text: 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: the block id

      • style: the named style

      • align: the alignment

      • list: the list kind

      • listLevel: the list level, 0 to 8

      • listStart: the restart number, or zero

      • before: space above

      • after: space below

      • indent: left indent

      • lineSpacing: the line spacing multiple

      • pageBreak: page break before

      • keepNext: keep with next

      • text: the text

  • Method Details

    • withIndents

      public Paragraph withIndents(float left, float first, float right)

      A copy with different indents.

      Parameters
      • left: the left indent

      • first: the first line's indent relative to left; negative hangs

      • right: the right indent

      Returns

      the copy

    • withTabs

      public Paragraph withTabs(List<TabStop> value)

      A copy with different tab stops.

      Parameters
      • value: 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

      Specified by:
      id in interface Block
    • 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: the text
      Returns

      the copy

    • withStyle

      public Paragraph withStyle(String value)

      A copy with a different named style.

      Parameters
      • value: the style
      Returns

      the copy

    • withAlign

      public Paragraph withAlign(String value)

      A copy with a different alignment.

      Parameters
      • value: LEFT, CENTER, RIGHT or JUSTIFY
      Returns

      the copy

    • withList

      public Paragraph withList(String kind, int level)

      A copy with different list membership.

      Parameters
      • kind: NO_LIST, BULLET or NUMBERED

      • level: the nesting level

      Returns

      the copy

    • withListStart

      public Paragraph withListStart(int value)

      A copy whose numbered list restarts.

      Parameters
      • value: 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: space above

      • spaceAfter: space below

      • lines: the line spacing multiple

      Returns

      the copy

    • withIndent

      public Paragraph withIndent(float value)

      A copy with a different left indent.

      Parameters
      • value: the indent
      Returns

      the copy

    • withPageBreak

      public Paragraph withPageBreak(boolean value)

      A copy with the page break switched.

      Parameters
      • value: break before or not
      Returns

      the copy

    • withKeepNext

      public Paragraph withKeepNext(boolean value)

      A copy with keep-with-next switched.

      Parameters
      • value: 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: 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: the other object
      Returns

      true when equal

      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()

      A hash consistent with equals.

      Returns

      the hash

      Overrides:
      hashCode in class Object