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

public final class RichTextDocuments

  1. Object
  2. RichTextDocuments

Moves content between a RichTextArea and a Document, so the light editor and the paged one can work on the same text.

final DocumentModel model = new DocumentModel(new Document());
model.insertBlock(0, new Paragraph(model.newId('p'), RichText.of("Edit me")));
RichTextArea editor = new RichTextArea();
RichTextDocuments.show(model.getDocument(), editor);
// later, once the user has edited the text
RichTextDocuments.read(editor, new SuccessCallback<Document>() {
    public void onSucess(Document d) {
        model.setDocument(d);
    }
});

Content goes through HTML, so what HTML cannot say – page size, tracked changes, comments – is not carried. Embedded components are: the editor shows each through the image source EmbeddedComponents registers, and reading back restores its type, size and state.

Methods

public static void show(Document d, RichTextArea editor)Shows a document in a rich text editor.
public static String toHtml(Document d)The HTML a rich text editor is given for a document.
public static Document fromHtml(String html)A document made from HTML a rich text editor gave back.
public static Document readMarkdown(String markdown) throws IOExceptionReads Markdown.
public static String writeMarkdown(Document d)Writes Markdown.
public static Document readRtf(String rtf) throws IOExceptionReads RTF from a string, as a clipboard gives it.
public static String writeRtf(Document d)Writes RTF.
public static void read(RichTextArea editor, SuccessCallback<Document> callback)Reads a rich text editor’s content as a document.

Inherited methods

Method details

show

public static void show(Document d, RichTextArea editor)
Shows a document in a rich text editor.

Parameters

d Document
the document
editor RichTextArea
the editor

toHtml

public static String toHtml(Document d)
The HTML a rich text editor is given for a document.

Parameters

d Document
the document

Returns

the HTML, embedded components named by cn1-component: sources

fromHtml

public static Document fromHtml(String html)
A document made from HTML a rich text editor gave back.

Parameters

html String
the HTML

Returns

the document

readMarkdown

public static Document readMarkdown(String markdown) throws IOException
Reads Markdown. Unlike Document.read, this reaches no other format’s code, so an application that only exchanges Markdown with a rich text editor carries no DOCX, ODT or PDF support.

Parameters

markdown String
the source

Returns

the document

Throws

IOException
when the source nests too deeply for the thread’s stack

writeMarkdown

public static String writeMarkdown(Document d)
Writes Markdown.

Parameters

d Document
the document

Returns

the Markdown

readRtf

public static Document readRtf(String rtf) throws IOException
Reads RTF from a string, as a clipboard gives it. Characters above U+00FF, which RTF spells with escapes, are kept: each becomes the backslash-u control word that says it.

Parameters

rtf String
the source

Returns

the document

Throws

IOException
when the source is not RTF or nests too deeply for the thread’s stack

writeRtf

public static String writeRtf(Document d)
Writes RTF.

Parameters

d Document
the document

Returns

the RTF, which is 7-bit

read

public static void read(RichTextArea editor, SuccessCallback<Document> callback)
Reads a rich text editor’s content as a document. The editor answers asynchronously.

Parameters

editor RichTextArea
the editor
callback SuccessCallback<Document>
given the document