Class AbstractEditComponentTextControl<EC extends Component>

Type Parameters:
EC - The type of component being edited.
All Implemented Interfaces:
com.globalmentor.beans.PropertyBindable, com.globalmentor.beans.PropertyConstrainable, io.clogr.Clogged, Component, CompositeComponent, Container, ContainerControl, Control, EditComponent, InputFocusableComponent, LayoutComponent, ModalComponent<AbstractEditComponentTextControl.Mode>, EditListenable, Displayable, Enableable, InfoModel, LabelModel, Model, PresentationModel, DepictedObject, Iterable<Component>
Direct Known Subclasses:
EditComponentLabelControl, EditComponentTextControl

public abstract class AbstractEditComponentTextControl<EC extends Component> extends AbstractContainerControl implements ModalComponent<AbstractEditComponentTextControl.Mode>, EditComponent
Control that allows some component text property to be edited in-place. Editing can be started by calling setMode(AbstractEditComponentTextControl.Mode) with AbstractEditComponentTextControl.Mode.EDIT.

This class binds a single left mouse click input to getEditActionPrototype(), the command ProcessCommand.CONTINUE to getAcceptActionPrototype(), and the command ProcessCommand.ABORT to getRejectActionPrototype().

Author:
Garret Wilson
  • Constructor Details

    • AbstractEditComponentTextControl

      public AbstractEditComponentTextControl(EC editedComponent, String editedProperty, ValueControl<String> editControl, Flow flow)
      Edited component, value control, and flow constructor.
      Parameters:
      editedComponent - The component the text of which is to be edited.
      editedProperty - The component property that will be affected when the text changes.
      editControl - The control used to edit the text.
      flow - The logical axis (line or page) along which information is flowed.
      Throws:
      NullPointerException - if the edited component, value control, text property, and/or flow axis is null.
  • Method Details

    • isEditable

      public boolean isEditable()
      Specified by:
      isEditable in interface EditComponent
      Returns:
      Whether the value is editable and the component will allow the the user to change the value.
    • setEditable

      public void setEditable(boolean newEditable)
      Description copied from interface: EditComponent
      Sets whether the value is editable and the component will allow the the user to change the value. This is a bound property of type Boolean.
      Specified by:
      setEditable in interface EditComponent
      Parameters:
      newEditable - true if the component should allow the user to change the value.
      See Also:
    • getMode

      Specified by:
      getMode in interface ModalComponent<EC extends Component>
      Returns:
      The current mode of interaction, or null if the component is in a modeless state.
    • setMode

      public void setMode(AbstractEditComponentTextControl.Mode newMode)
      Description copied from interface: ModalComponent
      Sets the mode of interaction. This is a bound property.
      Specified by:
      setMode in interface ModalComponent<EC extends Component>
      Parameters:
      newMode - The new mode of component interaction.
      See Also:
    • getEditedComponent

      public EC getEditedComponent()
      Returns:
      The component the text of which is to be edited.
    • getEditControl

      public ValueControl<String> getEditControl()
      Returns:
      The control used to edit the text.
    • getEditActionPrototype

      public ActionPrototype getEditActionPrototype()
      Returns:
      The action prototype for editing the text.
    • getAcceptActionPrototype

      public ActionPrototype getAcceptActionPrototype()
      Returns:
      The action prototype for accepting edits.
    • getRejectActionPrototype

      public ActionPrototype getRejectActionPrototype()
      Returns:
      The action prototype for rejecting edits.
    • getDeleteActionPrototype

      public ActionPrototype getDeleteActionPrototype()
      Returns:
      The action prototype for deleting the text.
    • editLabel

      public void editLabel()
      Initiates editing.
    • acceptEdit

      public void acceptEdit()
      Accepts edits. If the component is not in edit mode, no action occurs. This implementation defers to acceptEdit(String).
      See Also:
    • acceptEdit

      protected void acceptEdit(String text)
      Accepts edits with the given text. If the component is not in edit mode, no action occurs. This implementation sets the edit component text to the given text and fires and edited event.
      Parameters:
      text - The edited text to accept.
      See Also:
    • rejectEdit

      public void rejectEdit()
      Cancels edits.
    • deleteLabel

      public void deleteLabel()
      Removes the current label by setting it to null.
    • update

      protected void update()
      Description copied from class: AbstractComponent
      Updates the condition of the component based upon the state. This method is a convenience method for complex components that would like to perform wholesale updates any prototypes, enabled/disabled status, proxied actions, etc. This version does nothing.
      Overrides:
      update in class AbstractComponent
    • getText

      protected abstract String getText(EC editedComponent)
      Retrieves the text from the edited component.
      Parameters:
      editedComponent - The component the text of which is to be edited.
      Returns:
      The current text of the edited component
    • setText

      protected abstract void setText(EC editedComponent, String newText)
      Updates the text of the edited component.
      Parameters:
      editedComponent - The component the text of which is to be edited.
      newText - The new text to set in the edited component.
    • addEditListener

      public void addEditListener(EditListener editListener)
      Description copied from interface: EditListenable
      Adds an edit listener.
      Specified by:
      addEditListener in interface EditListenable
      Parameters:
      editListener - The edit listener to add.
    • removeEditListener

      public void removeEditListener(EditListener editListener)
      Description copied from interface: EditListenable
      Removes an edit listener.
      Specified by:
      removeEditListener in interface EditListenable
      Parameters:
      editListener - The edit listener to remove.
    • fireEdited

      protected void fireEdited()
      Fires an edit event to all registered edit listeners. This method delegates to fireEdited(EditEvent).
      See Also:
    • fireEdited

      protected void fireEdited(EditEvent editEvent)
      Fires a given edit event to all registered edit listeners.
      Parameters:
      editEvent - The edit event to fire.