Class ComponentEdit

java.lang.Object
com.codename1.util.UndoableEdit
com.codename1.ui.ComponentEdit

public class ComponentEdit extends UndoableEdit

An edit made through a component, which brings that component back into view when it is undone or redone.

The history (com.codename1.util.UndoHistory) knows nothing about components; this wrapper is what ties a step to one. When the step is replayed and the component is on the form being shown, the component takes the focus, if it can, and is scrolled into view, so the user sees what changed. An edit made on another form is still replayed, without switching forms.

Components that support undo wrap their own edits this way. An application recording its own edits wraps them the same way:

TextField field = new TextField("Draft");
field.setText("Final");
UndoHistory.getGlobal().record(new ComponentEdit(field, new UndoableEdit() {
    public void undo() {
        field.setText("Draft");
    }

    public void redo() {
        field.setText("Final");
    }
}));
  • Constructor Summary

    Constructors
    Constructor
    Description
    Wraps an edit made through a component.
  • Method Summary

    Modifier and Type
    Method
    Description
    The component the edit was made in.
    The wrapped edit.
    A short name for the change, such as "Move" or "Delete", for an "Undo Move" menu item.
    boolean
    False once what this edit changes can no longer take it, for instance after the component it was made in was given another document.
    void
    Makes the change again, after undo.
    protected void
    Brings the component into view when it is on the form being shown: gives it the focus if it can take it and scrolls it into view.
    void
    Takes the change back.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • ComponentEdit

      public ComponentEdit(Component component, UndoableEdit edit)

      Wraps an edit made through a component.

      Parameters
      • component: the component the edit was made in

      • edit: the edit itself

  • Method Details

    • getComponent

      public Component getComponent()
      The component the edit was made in.
    • getEdit

      public UndoableEdit getEdit()
      The wrapped edit.
    • undo

      public void undo()
      Description copied from class: UndoableEdit
      Takes the change back.
      Specified by:
      undo in class UndoableEdit
    • redo

      public void redo()
      Description copied from class: UndoableEdit
      Makes the change again, after undo.
      Specified by:
      redo in class UndoableEdit
    • getName

      public String getName()
      Description copied from class: UndoableEdit
      A short name for the change, such as "Move" or "Delete", for an "Undo Move" menu item. Null by default.
      Overrides:
      getName in class UndoableEdit
    • isAlive

      public boolean isAlive()
      Description copied from class: UndoableEdit
      False once what this edit changes can no longer take it, for instance after the component it was made in was given another document. A history passes over such an edit and forgets it. True by default.
      Overrides:
      isAlive in class UndoableEdit
    • reveal

      protected void reveal()
      Brings the component into view when it is on the form being shown: gives it the focus if it can take it and scrolls it into view.