Class 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 Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceCreates the components of one type and reads their state back. -
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic ComponentA live component for an embedded component.static EmbeddedComponentfromSource(String source) The embedded component acn1-component:source names.static EmbeddedComponents.FactoryThe factory registered for a type.static ImagePaints a component into a new image of its size.static voidregister(String type, EmbeddedComponents.Factory factory) Registers the factory for a type, replacing any earlier one.static Imagerender(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.static EmbeddedComponentsnapshot(EmbeddedComponent e, Component live) The embedded component with a new snapshot of a live component, for formats that can only carry a picture.static DocumentGives every embedded component in a document a current snapshot, before writing it in a format that can only carry pictures.static StringThecn1-component:image source naming an embedded component, for aRichTextArea.
-
Field Details
-
SCHEME
The image source scheme that names a component in aRichTextArea.- See Also:
-
-
Method Details
-
register
Registers the factory for a type, replacing any earlier one.
Parameters
-
type: the type name, without; -
factory: the factory, or null to remove the type
-
-
get
The factory registered for a type.
Parameters
type: the type name
Returns
the factory, or null
-
create
A live component for an embedded component.
Parameters
e: the embedded component
Returns
the component, or null when no factory makes one
-
render
A picture of an embedded component: its live rendering when a factory is registered, otherwise its stored snapshot, otherwise an empty frame.
Parameters
-
e: the embedded component -
w: the width in pixels -
h: the height in pixels
Returns
the image
-
-
paint
-
snapshot
The embedded component with a new snapshot of a live component, for formats that can only carry a picture.
Parameters
-
e: the embedded component -
live: a component showing it, or null to create one from its factory
Returns
the embedded component with a PNG snapshot, or
ewhen none can be made -
-
snapshots
-
toSource
The
cn1-component:image source naming an embedded component, for aRichTextArea.Parameters
e: the embedded component
Returns
the source: type, size in points and state
-
fromSource
The embedded component a
cn1-component:source names.Parameters
source: the source
Returns
the component, or null when the source is not one
-