Class DocumentEditor

java.lang.Object
com.codename1.ui.Component
com.codename1.ui.Container
com.codename1.wordprocessing.DocumentEditor
All Implemented Interfaces:
Animation, Editable, StyleListener, Iterable<Component>

public class DocumentEditor extends Container

A DocumentView with its embedded components alive: each component box on screen holds a real Codename One component, made by the factory EmbeddedComponents has for its type, that the user can tap, drag and type into.

DocumentModel model = new DocumentModel(new Document());
model.insertBlock(0, new Paragraph(model.newId('p'), RichText.of("Quarterly review")));
DocumentEditor editor = new DocumentEditor(model);
Form form = new Form("Editor", new BorderLayout());
form.add(BorderLayout.CENTER, editor);
form.show();

Only the components in view exist. One that scrolls out of view, or is replaced by an edit, first gives its state back to the model through its factory, as an undoable edit; call commitComponents before saving to collect the state of those still showing.

  • Constructor Details

    • DocumentEditor

      public DocumentEditor()
      An editor of an empty document.
    • DocumentEditor

      public DocumentEditor(DocumentModel model)

      An editor of a model.

      Parameters
      • model: the model
    • DocumentEditor

      public DocumentEditor(DocumentView view)

      An editor around a view, for a DocumentView subclass.

      Parameters
      • view: the view
  • Method Details

    • getView

      public DocumentView getView()

      The view.

      Returns

      the document view

    • getModel

      public DocumentModel getModel()

      The model.

      Returns

      the view's model

    • getLiveComponent

      public Component getLiveComponent(String paragraphId, int offset)

      The live component showing an embedded component, while it is in view.

      Parameters
      • paragraphId: the paragraph holding it

      • offset: its offset in the paragraph

      Returns

      the component, or null

    • getLiveComponentCount

      public int getLiveComponentCount()

      The number of live components.

      Returns

      how many embedded components are alive now

    • initComponent

      protected void initComponent()
      Description copied from class: Component
      Allows subclasses to bind functionality that relies on fully initialized and "ready for action" component state
      Overrides:
      initComponent in class Component
    • deinitialize

      protected void deinitialize()
      Description copied from class: Component
      Invoked to indicate that the component initialization is being reversed since the component was detached from the container hierarchy. This allows the component to deregister animators and cleanup after itself. This method is the opposite of the initComponent() method.
      Overrides:
      deinitialize in class Component
    • commitComponents

      public void commitComponents()
      Writes the state of every live component into the model.