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

public final class EmbeddedComponents

  1. Object
  2. EmbeddedComponents

The registry that turns an EmbeddedComponent – a type name and a state string in a document – into a live Codename One component, and back.

EmbeddedComponents.register("rating", new EmbeddedComponents.Factory() {
    public Component create(EmbeddedComponent e) {
        Slider s = new Slider();
        s.setEditable(true);
        s.setProgress(e.state.length() == 0 ? 0 : Integer.parseInt(e.state));
        return s;
    }
    public String state(Component c) {
        return String.valueOf(((Slider) c).getProgress());
    }
});

A DocumentEditor hosts live components over the pages they are on, and a RichTextArea shows them in its text through the cn1-component: image source this class registers. Formats that cannot carry a component – DOCX, ODT, RTF, PDF – get its snapshot, which snapshot renders.

Nested types

interface EmbeddedComponents.FactoryCreates the components of one type and reads their state back.

Fields

public static final String SCHEME = "cn1-component"The image source scheme that names a component in a RichTextArea.

Methods

public static void register(String type, EmbeddedComponents.Factory factory)Registers the factory for a type, replacing any earlier one.
public static EmbeddedComponents.Factory get(String type)The factory registered for a type.
public static Component create(EmbeddedComponent e)A live component for an embedded component.
public static Image render(EmbeddedComponent e, int w, int h)A picture of an embedded component: its live rendering when a factory is registered, otherwise its stored snapshot, otherwise an empty frame.
public static Image paint(Component c, int w, int h)Paints a component into a new image of its size.
public static EmbeddedComponent snapshot(EmbeddedComponent e, Component live)The embedded component with a new snapshot of a live component, for formats that can only carry a picture.
public static Document snapshots(Document d)Gives every embedded component in a document a current snapshot, before writing it in a format that can only carry pictures.
public static String toSource(EmbeddedComponent e)The cn1-component: image source naming an embedded component, for a RichTextArea.
public static EmbeddedComponent fromSource(String source)The embedded component a cn1-component: source names.

Inherited methods

Field details

SCHEME

public static final String SCHEME = "cn1-component"
The image source scheme that names a component in a RichTextArea.

Method details

register

public static void register(String type, EmbeddedComponents.Factory factory)
Registers the factory for a type, replacing any earlier one.

Parameters

type String
the type name, without ;
factory EmbeddedComponents.Factory
the factory, or null to remove the type

get

public static EmbeddedComponents.Factory get(String type)
The factory registered for a type.

Parameters

type String
the type name

Returns

the factory, or null

create

public static Component create(EmbeddedComponent e)
A live component for an embedded component.

Parameters

e EmbeddedComponent
the embedded component

Returns

the component, or null when no factory makes one

render

public static Image render(EmbeddedComponent e, int w, int h)
A picture of an embedded component: its live rendering when a factory is registered, otherwise its stored snapshot, otherwise an empty frame.

Parameters

e EmbeddedComponent
the embedded component
w int
the width in pixels
h int
the height in pixels

Returns

the image

paint

public static Image paint(Component c, int w, int h)
Paints a component into a new image of its size.

Parameters

c Component
the component, not on a form
w int
the width in pixels
h int
the height in pixels

Returns

the image

snapshot

public static EmbeddedComponent snapshot(EmbeddedComponent e, Component live)
The embedded component with a new snapshot of a live component, for formats that can only carry a picture.

Parameters

e EmbeddedComponent
the embedded component
live Component
a component showing it, or null to create one from its factory

Returns

the embedded component with a PNG snapshot, or e when none can be made

snapshots

public static Document snapshots(Document d)
Gives every embedded component in a document a current snapshot, before writing it in a format that can only carry pictures.

Parameters

d Document
the document

Returns

the document with snapshots

toSource

public static String toSource(EmbeddedComponent e)
The cn1-component: image source naming an embedded component, for a RichTextArea.

Parameters

e EmbeddedComponent
the embedded component

Returns

the source: type, size in points and state

fromSource

public static EmbeddedComponent fromSource(String source)
The embedded component a cn1-component: source names.

Parameters

source String
the source

Returns

the component, or null when the source is not one