Class Layer

All Implemented Interfaces:
SceneObjectList, SceneObject, HasProperties, Serializable, Cloneable, Iterable<Thing>, Collection<Thing>, List<Thing>, RandomAccess, SequencedCollection<Thing>

public class Layer extends ArrayList<Thing> implements SceneObjectList
A Layer is a fundamental concept in the rendering pipeline, representing a collection of Thing instances that are rendered together. The SceneManager processes these layers in a specific order, drawing the contents of each layer to the screen.

The Layer class extends ArrayList, providing a way to manage the objects within it. You can add, remove, and reorder objects in a layer to dynamically change the scene's composition.

  • Layers allow you to group related Things, making it easier to manage complex scenes.
See Also:
  • Field Details

  • Constructor Details

    • Layer

      public Layer(String id, boolean invokeSwingHooks)
      Default Constructor
      Parameters:
      id - The identifier of the layer.
      invokeSwingHooks - Whether to invoke swing hooks
    • Layer

      public Layer(String id)
      Default Constructor
      Parameters:
      id - The identifier of the layer.
    • Layer

      public Layer()
      Default Constructor. This constructor should not be used by a user as this instantiates the default layer.
  • Method Details

    • fromRaw

      public static Layer fromRaw(String id, boolean hidden)
      Creates a Layer from raw data. Specifically used for loading from files.
      Parameters:
      id - The identifier of the layer.
      hidden - Whether the layer is hidden.
      Returns:
      The created Layer.
    • usableLayersStream

      public Stream<Thing> usableLayersStream()
    • invokeSwingHooks

      public void invokeSwingHooks()
      Description copied from interface: SceneObjectList
      A method to initialise anything swing related within the constructor. This is typically called within the SceneObjectList's constructor who needs to create an object outside the EDT thread.

      A use case (the current use case) would be when an SceneObjectList is loaded from disk to memory and the Spinner dialog is blocking the EDT thread. After the throbber has finished, you may call invokeSwingHooks safely rather than fighting with a blocked EDT thread.

      Specified by:
      invokeSwingHooks in interface SceneObjectList
    • getName

      public String getName()
      Returns the identifier of this layer
      Specified by:
      getName in interface SceneObject
      Returns:
      The identifier of this layer
    • getId

      public UUID getId()
      The ID of a layer is irrelevant as it's label is used as it's identifier
      Specified by:
      getId in interface SceneObject
      Returns:
      The UUID of this layer
    • getProperties

      public ArrayList<Property<?,?>> getProperties()
      Description copied from interface: HasProperties
      Returns an ArrayList of Property objects associated with this instance. Each property can hold a value of a specific type and have a specific key type.
      Specified by:
      getProperties in interface HasProperties
      Returns:
      an ArrayList of properties.
    • addProps

      private void addProps()
    • squashWith

      public DirtyAction<Layer> squashWith(Layer otherlayer)
      Merges the contents of another Layer into this layer. All GObjects from the otherlayer are added to this layer. The otherlayer itself remains unchanged.
      Parameters:
      otherlayer - The Layer whose contents are to be merged into this layer.
      Returns:
      An Action representing the squash operation, which can be undone if needed.
    • draw

      public void draw(Graphics2D graphics2D)
      Draws all Thing instances in this layer using the provided Graphics2D context. The drawing order is determined by the distance of each Thing's centroid from the camera position, ensuring proper depth representation in the rendered scene.
      Parameters:
      graphics2D - The Graphics2D context used for drawing.
    • instantDelete

      public void instantDelete()
      Description copied from interface: SceneObjectList
      An internal delete method which all implementors should override for instantaneous deletion.

      This method should not be called by a user interface things. However, any object overriding the method must provide a way to delete everything relating to it.

      Specified by:
      instantDelete in interface SceneObjectList
    • getIdentity

      public TreeNodeIdentity<Layer> getIdentity()
      Description copied from interface: SceneObjectList
      Returns the TreeNodeIdentity for the given object to use within the LayerTree
      Specified by:
      getIdentity in interface SceneObjectList
      Returns:
      The identity
    • getTreeNode

      public DefaultMutableTreeNode getTreeNode()
      Description copied from interface: SceneObjectList
      The actual tree node for the representation of this object within LayerTree
      Specified by:
      getTreeNode in interface SceneObjectList
      Returns:
      The tree node
    • getOnSelect

      public BiConsumer<? extends SceneObjectList,DefaultMutableTreeNode> getOnSelect()
      Description copied from interface: SceneObjectList
      The callback for when the object is selected in the tree.
      Specified by:
      getOnSelect in interface SceneObjectList
      Returns:
      The callback
    • toString

      public String toString()
      Overrides:
      toString in class AbstractCollection<Thing>
    • isHidden

      public boolean isHidden()
      Description copied from interface: SceneObjectList
      Whether the given object is hidden or not
      Specified by:
      isHidden in interface SceneObjectList
      Returns:
      true if hidden, false otherwise
    • isForDeletion

      public boolean isForDeletion()
      Description copied from interface: SceneObjectList
      Labels the object as for deletion. Has similar implications as being hidden however it will be cleaned up later and won't be available on lists.
      Specified by:
      isForDeletion in interface SceneObjectList
      Returns:
      true if the object was marked for deletion
    • setForDeletion

      public void setForDeletion(boolean forDeletion)
      Description copied from interface: SceneObjectList
      Marks the object for deletion.
      Specified by:
      setForDeletion in interface SceneObjectList
    • toggleVisibility

      public Action<Boolean> toggleVisibility()
      Description copied from interface: SceneObjectList
      Toggles the visibility of the object.
      Specified by:
      toggleVisibility in interface SceneObjectList
      Returns:
      An action that toggles the visibility of the object and returns the new visibility state.
    • deleteLater

      public DirtyVoidAction deleteLater()
      Description copied from interface: SceneObjectList
      Deletes the object.

      The use of the word "later" is because the action of deletion is only ever done once the Action object is out of the history's bounds. At that point CleanableAction.cleanup() is called, which actually deletes.

      Specified by:
      deleteLater in interface SceneObjectList
      Returns:
      An action that deletes the object.
    • setHidden

      public void setHidden(boolean hidden)
      Description copied from interface: SceneObjectList
      Hides the object. This is for internal use. GUI and other user things should make use of SceneObjectList.toggleVisibility() instead.
      Specified by:
      setHidden in interface SceneObjectList