Interface Container

All Superinterfaces:
Component, TextGUIElement
All Known Subinterfaces:
Border
All Known Implementing Classes:
AbstractBasePane.ContentHolder, AbstractBasePane.EmptyMenuBar, AbstractBorder, AbstractComposite, Borders.DoubleLine, Borders.SingleLine, Borders.StandardBorder, MenuBar, Panel, SplitPanel

public interface Container extends Component
Container is a component that contains a collection of child components. The basic example of an implementation of this is the Panel class which uses a layout manager to size and position the children over its area. Note that there is no method for adding components to the container, since this depends on the implementation. In general, composites that contains one one (or zero) children, the method for specifying the child is in Composite. Multi-child containers are generally using the Panel implementation which has an addComponent(..) method.
  • Method Details

    • getChildCount

      int getChildCount()
      Returns the number of children this container currently has
      Returns:
      Number of children currently in this container
    • getChildren

      Collection<Component> getChildren()
      Returns collection that is to be considered a copy of the list of children contained inside of this object. Modifying this collection will not affect any internal state.

      This method isn't deprecated but it should have originally been defined as returning a List instead of a Collection. See getChildrenList for a method with this signature.

      Returns:
      Child-components inside of this Container
      See Also:
    • getChildrenList

      List<Component> getChildrenList()
      Returns list that is to be considered a copy of the list of children inside of this container. Modifying this list will not affect any internal state. This method is essentially the same as getChildren but the returned collection is a list.
      Returns:
      Child-components inside of this Container
      See Also:
    • containsComponent

      boolean containsComponent(Component component)
      Returns true if this container contains the supplied component either directly or indirectly through intermediate containers.
      Parameters:
      component - Component to check if it's part of this container
      Returns:
      true if the component is inside this Container, otherwise false
    • removeComponent

      boolean removeComponent(Component component)
      Removes the component from the container. This should remove the component from the Container's internal data structure as well as call the onRemoved(..) method on the component itself if it was found inside the container.
      Parameters:
      component - Component to remove from the Container
      Returns:
      true if the component existed inside the container and was removed, false otherwise
    • nextFocus

      Interactable nextFocus(Interactable fromThis)
      Given an interactable, find the next one in line to receive focus. If the interactable isn't inside this container, this method should return null.
      Parameters:
      fromThis - Component from which to get the next interactable, or if null, pick the first available interactable
      Returns:
      The next interactable component, or null if there are no more interactables in the list
    • previousFocus

      Interactable previousFocus(Interactable fromThis)
      Given an interactable, find the previous one in line to receive focus. If the interactable isn't inside this container, this method should return null.
      Parameters:
      fromThis - Component from which to get the previous interactable, or if null, pick the last interactable in the list
      Returns:
      The previous interactable component, or null if there are no more interactables in the list
    • handleInput

      boolean handleInput(KeyStroke key)
      If an interactable component inside this container received a keyboard event that wasn't handled, the GUI system will recursively send the event to each parent container to give each of them a chance to consume the event. Return false if the implementer doesn't care about this particular keystroke and it will be automatically sent up the hierarchy the to next container. If you return true, the event will stop here and won't be reported as unhandled.
      Parameters:
      key - Keystroke that was ignored by the interactable inside this container
      Returns:
      true if this event was handled by this container and shouldn't be processed anymore, false if the container didn't take any action on the event and want to pass it on
    • updateLookupMap

      void updateLookupMap(InteractableLookupMap interactableLookupMap)
      Takes a lookup map and updates it with information about where all the interactables inside of this container are located.
      Parameters:
      interactableLookupMap - Interactable map to update