Class ComponentStack

All Implemented Interfaces:
Iterable<GuiComponent>, Collection<GuiComponent>, List<GuiComponent>, SequencedCollection<GuiComponent>

public class ComponentStack extends AbstractList<GuiComponent>
A stack of components that comprise the layers of a GUI element.

Each component layer has an opportunity to grab some of the GUI element's space for itself before passing a smaller space down to its children.

When computing preferred size, the order is reversed (top down) gathering up the preferred size of each layer based on how it wants to wrap the layer above it. In this way, each layer kind of acts like a decorator for the layer above it.

Preferred size calculation and reshaping are all done in 3D and each layer can choose to reposition or reshape the next layer in any of these dimensions.

[a picture would be worth a thousand words]

It is often desirable to be able to insert specific types of components into specific layers in the stack. For example, "insets" on the bottom. Thus the component stack keeps a list of layer names that enforce this default ordering of named layers. Layers don't have to be named, but when they are they are kept in the order defined in this layer ordering list.

  • Constructor Details

    • ComponentStack

      public ComponentStack(String... layerOrder)
      Creates a component stack with the specified layer ordering.
  • Method Details

    • getArray

      protected GuiComponent[] getArray()
    • get

      public GuiComponent get(int index)
      Specified by:
      get in interface List<GuiComponent>
      Specified by:
      get in class AbstractList<GuiComponent>
    • size

      public int size()
      Specified by:
      size in interface Collection<GuiComponent>
      Specified by:
      size in interface List<GuiComponent>
      Specified by:
      size in class AbstractCollection<GuiComponent>
    • setLayerOrder

      public void setLayerOrder(String... layerOrder)
      Sets a new layer ordering. This will invalidate and rebuild the component stack.
    • hasLayer

      public boolean hasLayer(String layerName)
      Returns true if the specified layer name exists in the layer order list.
    • getLayerOrder

      public String[] getLayerOrder()
      Returns the current layer order.
    • attach

      public void attach(GuiControl parent)
    • detach

      public void detach(GuiControl parent)
    • rebuildStack

      protected void rebuildStack()
      Completely rebuilds the component stack from the index, layer ordering, and top list. This should be called whenever changes are made to these data structures that cannot be reconciled with surgical changes to the components list.
    • addComponent

      public <T extends GuiComponent> T addComponent(T c)
      Adds a new component to the top of the stack.
    • setComponent

      public <T extends GuiComponent> T setComponent(String layer, T c)
      Sets the specified component to the specified layer and returns the specified component. Note: this is different than java.util.List.set() behavior where it would return the previous value.
    • getComponent

      public <T extends GuiComponent> T getComponent(String layer)
      Returns the component that was previously associated with the specified layer.
    • removeComponent

      public <T extends GuiComponent> T removeComponent(String layer)
      Removes the component that was previously associated with the specified layer.
    • removeComponent

      public boolean removeComponent(GuiComponent c)
      Removes the specified component from the stack.
    • toString

      public String toString()
      Overrides:
      toString in class AbstractCollection<GuiComponent>