Client API. The Codename One framework your app is built on: this runs on the device, not in a backend.
public final class RichTextDocuments
- Object
- 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
Inherited methods
Method details
show
public static void show(Document d, RichTextArea editor)Shows a document in a rich text editor.
Parameters
dDocument- the document
editorRichTextArea- the editor
toHtml
public static String toHtml(Document d)The HTML a rich text editor is given for a document.
Parameters
dDocument- the document
Returns
the HTML, embedded components named by
cn1-component: sourcesfromHtml
public static Document fromHtml(String html)A document made from HTML a rich text editor gave back.
Parameters
htmlString- the HTML
Returns
the document
readMarkdown
public static Document readMarkdown(String markdown)
throws IOExceptionReads 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
markdownString- 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
dDocument- the document
Returns
the Markdown
readRtf
public static Document readRtf(String rtf)
throws IOExceptionReads 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
rtfString- 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
dDocument- 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
editorRichTextArea- the editor
callbackSuccessCallback<Document>- given the document