Class AbstractContainer

All Implemented Interfaces:
com.globalmentor.beans.PropertyBindable, com.globalmentor.beans.PropertyConstrainable, io.clogr.Clogged, Component, CompositeComponent, Container, LayoutComponent, Displayable, InfoModel, LabelModel, Model, PresentationModel, DepictedObject, Iterable<Component>
Direct Known Subclasses:
AbstractBox, AbstractContainerControl, AbstractPanel, GroupPanel, SpinnerControl, TextBox

public abstract class AbstractContainer extends AbstractLayoutComponent implements Container
Abstract implementation of a container component. Iterating over child components is thread safe.
Author:
Garret Wilson
  • Constructor Details

    • AbstractContainer

      public AbstractContainer(Layout<? extends Constraints> layout)
      Layout constructor with a default info model.
      Parameters:
      layout - The layout definition for the container.
      Throws:
      NullPointerException - if the given layout is null.
    • AbstractContainer

      public AbstractContainer(InfoModel infoModel, Layout<? extends Constraints> layout)
      Info model and layout constructor.
      Parameters:
      infoModel - The component info model.
      layout - The layout definition for the container.
      Throws:
      NullPointerException - if the given info model and/or layout is null.
  • Method Details

    • size

      public int size()
      Specified by:
      size in interface Container
      Overrides:
      size in class AbstractListCompositeComponent
      Returns:
      The number of child components in this component.
    • isEmpty

      public boolean isEmpty()
      Specified by:
      isEmpty in interface Container
      Overrides:
      isEmpty in class AbstractListCompositeComponent
      Returns:
      Whether this component contains no child components.
    • contains

      public boolean contains(Object component)
      Description copied from class: AbstractListCompositeComponent
      Determines whether this component contains the given component.
      Specified by:
      contains in interface Container
      Overrides:
      contains in class AbstractListCompositeComponent
      Parameters:
      component - The component to check.
      Returns:
      true if this component contains the given component.
    • indexOf

      public int indexOf(Object component)
      Description copied from class: AbstractListCompositeComponent
      Returns the index in the component of the first occurrence of the specified component.
      Specified by:
      indexOf in interface Container
      Overrides:
      indexOf in class AbstractListCompositeComponent
      Parameters:
      component - The component the index of which should be returned.
      Returns:
      The index in this component of the first occurrence of the specified component, or -1 if this component does not contain the given component.
    • lastIndexOf

      public int lastIndexOf(Object component)
      Description copied from class: AbstractListCompositeComponent
      Returns the index in this component of the last occurrence of the specified component.
      Specified by:
      lastIndexOf in interface Container
      Overrides:
      lastIndexOf in class AbstractListCompositeComponent
      Parameters:
      component - The component the last index of which should be returned.
      Returns:
      The index in this component of the last occurrence of the specified component, or -1 if this component does not contain the given component.
    • get

      public Component get(int index)
      Description copied from class: AbstractListCompositeComponent
      Returns the component at the specified index in the component.
      Specified by:
      get in interface Container
      Overrides:
      get in class AbstractListCompositeComponent
      Parameters:
      index - The index of the component to return.
      Returns:
      The component at the specified position in this component.
    • add

      public void add(int index, Component component)
      Adds a child component with default constraints to the container at the specified index.
      Parameters:
      index - The index at which the component should be added.
      component - The component to add to this container.
      Throws:
      IllegalArgumentException - if the component already has a parent.
      IllegalStateException - if the installed layout does not support default constraints.
      IndexOutOfBoundsException - if the index is less than zero or greater than the number of child components.
    • add

      public boolean add(Component component)
      Description copied from interface: Container
      Adds a component with default constraints to the container.
      Specified by:
      add in interface Container
      Parameters:
      component - The component to add to this container.
      Returns:
      true if this container changed as a result of the operation.
    • add

      public void add(int index, Component component, Constraints constraints)
      Description copied from interface: Container
      Adds a component along with constraints to the container at the specified index. This is a convenience method that first sets the constraints of the component.
      Specified by:
      add in interface Container
      Parameters:
      index - The index at which the component should be added.
      component - The component to add to this container.
      constraints - The constraints for the layout, or null if default constraints should be used.
    • add

      public boolean add(Component component, Constraints constraints)
      Description copied from interface: Container
      Adds a component along with constraints to the container. This is a convenience method that first sets the constraints of the component.
      Specified by:
      add in interface Container
      Parameters:
      component - The component to add to this container.
      constraints - The constraints for the layout, or null if default constraints should be used.
      Returns:
      true if this container changed as a result of the operation.
    • add

      public Component add(int index, Prototype prototype)
      Adds a component based upon the given prototype to the container with default constraints at the specified index.

      This implementation delegates to add(int, Component).

      Specified by:
      add in interface Container
      Parameters:
      index - The index at which the component should be added.
      prototype - The prototype of the component to add.
      Returns:
      The component created to represent the given prototype.
      See Also:
    • add

      public Component add(Prototype prototype)
      Adds a component based upon the given prototype to the container with default constraints.

      This implementation delegates to add(Component).

      Specified by:
      add in interface Container
      Parameters:
      prototype - The prototype of the component to add.
      Returns:
      The component created to represent the given prototype.
      See Also:
    • add

      public Component add(int index, Prototype prototype, Constraints constraints)
      Adds a component based upon the given prototype to the container along with constraints at the specified index.

      This implementation delegates to add(int, Component, Constraints).

      Specified by:
      add in interface Container
      Parameters:
      index - The index at which the component should be added.
      prototype - The prototype of the component to add.
      constraints - The constraints for the layout, or null if default constraints should be used.
      Returns:
      The component created to represent the given prototype.
      See Also:
    • add

      public Component add(Prototype prototype, Constraints constraints)
      Adds a component based upon the given prototype to the container along with constraints.

      This implementation delegates to add(Component, Constraints).

      Specified by:
      add in interface Container
      Parameters:
      prototype - The prototype of the component to add.
      constraints - The constraints for the layout, or null if default constraints should be used.
      Returns:
      The component created to represent the given prototype.
    • createComponent

      public Component createComponent(Prototype prototype)
      Creates a component appropriate for the context of this component from the given prototype. This version creates the following components, in order of priority:
      ActionPrototype
      Button
      LabelPrototype
      Label
      MenuPrototype
      DropMenu
      TogglePrototype
      BooleanSelectButton
      ValuePrototype<Boolean>
      CheckControl
      ValuePrototype<Number> with installed RangeValidator
      SliderControl
      ValuePrototype<?>
      TextControl
      Parameters:
      prototype - The prototype of the component to create.
      Returns:
      A new component based upon the given prototype.
      Throws:
      IllegalArgumentException - if no component can be created from the given prototype
    • remove

      public boolean remove(Object componentObject)
      Description copied from interface: Container
      Removes a component from the container.
      Specified by:
      remove in interface Container
      Parameters:
      componentObject - The component to remove.
      Returns:
      true if this collection changed as a result of the operation.
    • remove

      public Component remove(int index)
      Description copied from interface: Container
      Removes the child component at the specified position in this container.
      Specified by:
      remove in interface Container
      Parameters:
      index - The index of the component to removed.
      Returns:
      The value previously at the specified position.
    • clear

      public void clear()
      Description copied from interface: Container
      Removes all of the components from this container.
      Specified by:
      clear in interface Container
    • iterator

      public Iterator<Component> iterator()
      Specified by:
      iterator in interface Iterable<Component>
    • getChildComponents

      public List<Component> getChildComponents()
      Specified by:
      getChildComponents in interface CompositeComponent
      Overrides:
      getChildComponents in class AbstractListCompositeComponent
      Returns:
      An iterable to child components.
    • setChildren

      public void setChildren(List<Component> children)
      Sets the children in this container. This method along with getChildComponents() provides a children property for alternate children access.
      Parameters:
      children - The new children for this container in order.
      See Also:
    • setLayout

      public <T extends Constraints> void setLayout(Layout<T> newLayout)
      Description copied from class: AbstractLayoutComponent
      Sets the layout definition for the component. This is a bound property. The layout is marked as not yet having a theme applied, as the specific theme rules applied to the layout may depend on the layout's owner.
      Specified by:
      setLayout in interface Container
      Overrides:
      setLayout in class AbstractLayoutComponent
      Type Parameters:
      T - The type of the constraints.
      Parameters:
      newLayout - The new layout definition for the container.
      See Also: