Client API. The Codename One framework your app is built on: this runs on the device, not in a backend.
public final class EmbeddedComponents
- Object
- 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.Factory | Creates 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
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
typeString- the type name, without
; factoryEmbeddedComponents.Factory- the factory, or null to remove the type
get
public static EmbeddedComponents.Factory get(String type)The factory registered for a type.
Parameters
typeString- the type name
Returns
the factory, or null
create
public static Component create(EmbeddedComponent e)A live component for an embedded component.
Parameters
eEmbeddedComponent- 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
eEmbeddedComponent- the embedded component
wint- the width in pixels
hint- 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
cComponent- the component, not on a form
wint- the width in pixels
hint- 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
eEmbeddedComponent- the embedded component
liveComponent- 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 madesnapshots
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
dDocument- 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
eEmbeddedComponent- 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
sourceString- the source
Returns
the component, or null when the source is not one