Class AbstractEditorComponent

All Implemented Interfaces:
Animation, Editable, EditorHost, StyleListener, Iterable<Component>
Direct Known Subclasses:
CodeEditor, RichTextArea

public abstract class AbstractEditorComponent extends Container implements EditorHost

Base class for the native visual editors (rich text and code) introduced by Codename One.

The editor components are designed around a semantic command channel rather than a single hard-coded implementation. Every concrete editor (RichTextArea, CodeEditor) speaks to its backend exclusively through #command(String, String), #query(String, String, SuccessCallback) and the inbound #onEditorEvent(String, String) dispatch. Two interchangeable backends honor that channel:

  1. The pure Codename One text engine (com.codename1.ui.editor) which renders the document itself with Graphics/Font and binds to the platform text input source (soft keyboard, hardware keyboard and IME). This is the default where the port exposes low-level text input.
  2. A BrowserComponent fallback on ports that don't expose low-level text input. Its contenteditable surface remains editable through the platform web view.
  3. An optional native backend supplied by the platform port (see com.codename1.impl.CodenameOneImplementation#createNativeEditorPeer(AbstractEditorComponent, String)). When a port returns a non-null native peer the editor drives it through editorPeerCommand / editorPeerQuery instead of the pure engine, allowing a platform to provide a genuinely native experience.

All backends are addressed with the same vocabulary so concrete editors never need to know which one is active.

  • Field Details

    • BACKEND_PURE

      public static final int BACKEND_PURE
      Backend identifier: the pure Codename One text engine.
      See Also:
    • BACKEND_BROWSER

      public static final int BACKEND_BROWSER
      Backend identifier for the BrowserComponent compatibility fallback.
      See Also:
  • Constructor Details

    • AbstractEditorComponent

      protected AbstractEditorComponent(String uiid)

      Creates the editor and begins asynchronous backend initialization.

      Parameters
      • uiid: the UIID applied to the editor container
  • Method Details

    • setDefaultBackend

      @Deprecated public static void setDefaultBackend(int backend)
      Deprecated.

      Deprecated compatibility hook. Backend selection is automatic: the pure engine is used when low-level text input is available and the browser fallback is used otherwise.

      Parameters
      • backend: ignored
    • getDefaultBackend

      @Deprecated public static int getDefaultBackend()
      Deprecated.
      Returns the preferred pure backend. Actual selection may fall back to the browser at runtime.
    • fireEditorEvent

      public void fireEditorEvent(String type, String value)

      Entry point invoked by native editor peers to deliver events back to Codename One. This routes to the same dispatch path used by the browser message bridge so subclasses handle events uniformly regardless of backend.

      Parameters
      • type: the event type

      • value: optional payload, may be null

      Specified by:
      fireEditorEvent in interface EditorHost
    • command

      protected void command(String name, String arg)

      Sends a one way command to the active backend. If the backend is not ready yet the command is queued and replayed once initialization completes.

      Parameters
      • name: the semantic command name understood by both backends

      • arg: an optional string argument, may be null

    • query

      protected void query(String name, String arg, SuccessCallback<String> callback)

      Queries the active backend for a string value asynchronously. The callback is always invoked on the EDT. If the backend is not ready the query is deferred until it is.

      Parameters
      • name: the semantic query name understood by both backends

      • arg: an optional string argument, may be null

      • callback: receives the query result

    • onReady

      public void onReady(Runnable r)

      Runs the supplied task once the editor backend is ready, or immediately if it already is.

      Parameters
      • r: the task to run on the EDT when the editor is ready
    • isEditorReady

      public boolean isEditorReady()
      Returns true once the underlying editor backend has finished initializing and is ready to accept commands.
    • isNativeEditor

      public boolean isNativeEditor()
      True when a platform supplied native editor backend is in use, false for the pure and browser backends.
    • getInternalBrowser

      public BrowserComponent getInternalBrowser()
      Returns the browser fallback, or null when the pure or native backend is active.
    • addChangeListener

      public void addChangeListener(ActionListener l)

      Adds a listener notified whenever the editor content changes.

      Parameters
      • l: the change listener
    • removeChangeListener

      public void removeChangeListener(ActionListener l)

      Removes a previously registered change listener.

      Parameters
      • l: the change listener
    • addReadyListener

      public void addReadyListener(ActionListener l)

      Adds a listener notified once when the editor backend becomes ready.

      Parameters
      • l: the ready listener
    • removeReadyListener

      public void removeReadyListener(ActionListener l)

      Removes a previously registered ready listener.

      Parameters
      • l: the ready listener
    • setEditable

      public void setEditable(boolean editable)

      Enables or disables editing. A disabled editor still displays content but rejects input.

      Parameters
      • editable: true to allow editing
    • isEditable

      public boolean isEditable()
      Returns true if the editor currently allows editing.
      Specified by:
      isEditable in interface Editable
      Overrides:
      isEditable in class Component
    • focusEditor

      public void focusEditor()
      Requests keyboard focus for the editing surface, showing the virtual keyboard on touch devices.
    • blurEditor

      public void blurEditor()
      Removes keyboard focus from the editing surface, hiding the virtual keyboard on touch devices.
    • isTextInputSupported

      public boolean isTextInputSupported()
      True when the platform can bind a low level text input client (see com.codename1.impl.CodenameOneImplementation#isTextInputSupported).
      Specified by:
      isTextInputSupported in interface EditorHost
    • startTextInput

      public Object startTextInput(TextInputClient client, TextInputConfig config)
      Binds the client to the platform text input source and returns an opaque handle.
      Specified by:
      startTextInput in interface EditorHost
    • updateTextInputState

      public void updateTextInputState(Object handle, TextInputState state)
      Pushes the client's editing state down to the bound input source.
      Specified by:
      updateTextInputState in interface EditorHost
    • stopTextInput

      public void stopTextInput(Object handle)
      Unbinds a previously bound text input client.
      Specified by:
      stopTextInput in interface EditorHost
    • editorChanged

      public void editorChanged()
      Notifies the owning editor that the document content changed so it can fire its change listeners.
      Specified by:
      editorChanged in interface EditorHost