Class LXSwatch

java.lang.Object
heronarts.lx.LXComponent
heronarts.lx.color.LXSwatch
All Implemented Interfaces:
LXComponent.Renamable, LXLoopTask, LXPath, LXSerializable, LXOscComponent, LXParameterListener

public class LXSwatch extends LXComponent implements LXLoopTask, LXOscComponent, LXComponent.Renamable
A swatch is a set of up to 5 dynamic colors that can be referenced by patterns and effects.
  • Field Details

  • Constructor Details

    • LXSwatch

      public LXSwatch(LX lx)
  • Method Details

    • getIndex

      public int getIndex()
    • getPath

      public String getPath()
      Description copied from class: LXComponent
      Accessor for the path of this object. Returns the path this component was registered with. Some subclasses may override this if path structure is dynamic.
      Specified by:
      getPath in interface LXPath
      Overrides:
      getPath in class LXComponent
      Returns:
      path of this component relative to its parent
    • loop

      public void loop(double deltaMs)
      Specified by:
      loop in interface LXLoopTask
    • getColor

      public LXDynamicColor getColor(int index)
      Retrieves the color at a given index in the swatch. If this swatch does not specify a color at that index, then the last valid color is returned instead.
      Parameters:
      index - Index
      Returns:
      Dynamic color at that index
    • addColor

      public LXDynamicColor addColor()
      Adds a new dynamic color to the swatch
      Returns:
      The newly added color
    • addColor

      public LXDynamicColor addColor(int index, JsonObject colorObj)
    • removeColor

      public LXDynamicColor removeColor()
      Removes the last color from the swatch
      Returns:
      The removed color
    • removeColor

      public LXDynamicColor removeColor(LXDynamicColor color)
      Removes a specific color from the swatch
      Parameters:
      color - The color to remove
      Returns:
      The removed color
    • removeColor

      public LXDynamicColor removeColor(int index)
      Removes the color at a specific index from the swatch
      Parameters:
      index - Index to remove
      Returns:
      Color removed
    • addListener

      public LXSwatch addListener(LXSwatch.Listener listener)
      Registers a listener to the swatch
      Parameters:
      listener - Swatch listener
      Returns:
      this
    • removeListener

      public LXSwatch removeListener(LXSwatch.Listener listener)
      Unregisters a listener to the swatch
      Parameters:
      listener - Swatch listener
      Returns:
      this
    • save

      public void save(LX lx, JsonObject obj)
      Description copied from class: LXComponent
      Serializes the LX component. By default, all internal and user-facing parameters are serialized, as well as any explicitly registered child components. Note that child arrays are not serialized, or any other dynamic components. Subclasses may override to perform more saving, and are expected to call super.save(lx, obj) at the appropriate time.
      Specified by:
      save in interface LXSerializable
      Overrides:
      save in class LXComponent
      Parameters:
      lx - LX instance
      obj - Object to serialize into
    • load

      public void load(LX lx, JsonObject obj)
      Description copied from class: LXComponent
      Loads the LX component. Restores the ID of the component, as well as its internal and user-facing parameters. Any explicitly registered children will be automatically loaded, so long as they are direct descendants. Dynamic arrays will not be automatically loaded, this is left to subclasses to implement.
      Specified by:
      load in interface LXSerializable
      Overrides:
      load in class LXComponent
      Parameters:
      lx - LX instance
      obj - Object to deserialize
    • dispose

      public void dispose()
      Description copied from class: LXComponent
      Invoked when a component is being removed from the system and will no longer be used at all. This unregisters the component and should free up any resources and parameter listeners. Ideally after this method is called the object should be eligible for garbage collection. Subclasses are generally expected to override this method to handle their particular cleanup work. They should also generally call super.dispose() at the appropriate time to perform the basic cleanup, which may need to happen either before or after cleaning up other objects.
      Overrides:
      dispose in class LXComponent