Class EmbeddedComponents

java.lang.Object
com.codename1.wordprocessing.EmbeddedComponents

public final class EmbeddedComponents extends Object

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.

  • Field Details

    • SCHEME

      public static final String SCHEME
      The image source scheme that names a component in a RichTextArea.
      See Also:
  • Method Details

    • register

      public static void register(String type, EmbeddedComponents.Factory factory)

      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

      public static EmbeddedComponents.Factory get(String type)

      The factory registered for a type.

      Parameters
      • type: the type name
      Returns

      the factory, or null

    • create

      public static Component create(EmbeddedComponent e)

      A live component for an embedded component.

      Parameters
      • e: 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: the embedded component

      • w: the width in pixels

      • h: 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: the component, not on a form

      • w: the width in pixels

      • h: 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: 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 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: 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: 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: the source
      Returns

      the component, or null when the source is not one