controlP5

## Class ControlEvent

- java.lang.Object
- - controlP5.ControlEvent

-     public class ControlEvent
      extends java.lang.Object

  A controlEvent is sent to a PApplet or a ControlListener whenever a controller value has changed. Events can also be sent when a tab is activated, but by default tab events are disabled and have to be enabled with `Tab` Tab.activateEvent(). for detailed information see the tab documentation.
  +Example
    `

        /**
         * ControlP5 ControlEvent.
         * every control event is automatically forwarded to the function controlEvent(ControlEvent)
         * inside a sketch if such function is available. For further details about the API of
         * the ControlEvent class, please refer to the documentation.
         *
         *
         * find a list of public methods available for ControlEvent
         * at the bottom of this sketch's source code
         *
         * by Andreas Schlegel, 2012
         * www.sojamo.de/libraries/controlP5
         *
         */

        import controlP5.*;

        ControlP5 cp5;

        public int myColorRect1 = 200;

        public int myColorRect2 = 100;

        void setup() {
          size(400, 400);
          noStroke();

          cp5 = new ControlP5(this);
          cp5.addNumberbox("n1")
             .setValue(myColorRect1)
             .setPosition(20, 20)
             .setSize(100, 20)
             .setMin(0)
             .setMax(255)
             .setId(1);

          cp5.addNumberbox("n2")
             .setValue(myColorRect2)
             .setPosition(20, 60)
             .setSize(100, 20)
             .setMin(0)
             .setMax(255)
             .setId(2);

          cp5.addTextfield("n3")
             .setPosition(20, 100)
             .setSize(100, 20)
             .setId(3);

        }

        void draw() {
          background(ControlP5.MAROON);
          fill(ControlP5.RED, myColorRect1);
          rect(140, 20, 240, 170);
          fill(ControlP5.FUCHSIA, myColorRect2);
          rect(140, 210, 240, 170);
        }

        void controlEvent(ControlEvent theEvent) {
          println("got a control event from controller with id "+theEvent.getController().getId());

          if (theEvent.isFrom(cp5.getController("n1"))) {
            println("this event was triggered by Controller n1");
          }

          switch(theEvent.getController().getId()) {
            case(1):
            myColorRect1 = (int)(theEvent.getController().getValue());
            break;
            case(2):
            myColorRect2 = (int)(theEvent.getController().getValue());
            break;
            case(3):
            println(theEvent.getController().getStringValue());
            break;
          }
        }

        /*
        a list of all methods available for the ControlEvent Controller
        use ControlP5.printPublicMethodsFor(ControlEvent.class);
        to print the following list into the console.

        You can find further details about class ControlEvent in the javadoc.

        Format:
        ClassName : returnType methodName(parameter type)

        controlP5.ControlEvent : ControlGroup getGroup()
        controlP5.ControlEvent : Controller getController()
        controlP5.ControlEvent : String getLabel()
        controlP5.ControlEvent : String getName()
        controlP5.ControlEvent : String getStringValue()
        controlP5.ControlEvent : String toString()
        controlP5.ControlEvent : Tab getTab()
        controlP5.ControlEvent : boolean isAssignableFrom(Class)
        controlP5.ControlEvent : boolean isController()
        controlP5.ControlEvent : boolean isFrom(ControllerInterface)
        controlP5.ControlEvent : boolean isFrom(String)
        controlP5.ControlEvent : boolean isGroup()
        controlP5.ControlEvent : boolean isTab()
        controlP5.ControlEvent : float getArrayValue(int)
        controlP5.ControlEvent : float getValue()
        controlP5.ControlEvent : float[] getArrayValue()
        controlP5.ControlEvent : int getId()
        controlP5.ControlEvent : int getType()
        java.lang.Object : String toString()
        java.lang.Object : boolean equals(Object)

        created: 2015/03/24 12:22:35

        */

    `

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static int` | `CONTROLLER`
    `static int` | `GROUP`
    `static int` | `TAB`
    `static int` | `UNDEFINDED`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `ControlEvent(ControllerGroup<?> theController)`
    `ControlEvent(Tab theController)`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `float[]` | `getArrayValue()` Returns a float array, applies to e.g.
    `float` | `getArrayValue(int theIndex)` Returns a float value at a particular index from a controller's array value.
    `Controller<?>` | `getController()` Returns the instance of the controller sending the ControlEvent.
    `ControlGroup<?>` | `getGroup()` Returns the group that evoked the ControlEvent
    `int` | `getId()` Returns the controller's id, if an id has not been set before the default value -1 will be returned.
    `java.lang.String` | `getLabel()` Gets the text of the controller's label that has evoked the event.
    `java.lang.String` | `getName()` returns the controller's name
    `java.lang.String` | `getStringValue()`
    `Tab` | `getTab()` Returns the tab that triggered the ControlEvent
    `int` | `getType()`
    `float` | `getValue()`
    `boolean` | `isAssignableFrom(java.lang.Class<?> c)`
    `boolean` | `isController()` Checks if the ControlEvent was triggered by a controller
    `boolean` | `isFrom(ControllerInterface<?> theController)` Checks if the ControlEvent originates from a specific Controller or ControllerGroup.
    `boolean` | `isFrom(java.lang.String theControllerName)` checks if the ControlEvent originates from a specific Controller or ControllerGroup identifiable by name.
    `boolean` | `isGroup()` Checks if the ControlEvent was triggered by a ControlGroup
    `boolean` | `isTab()` Checks if the ControlEvent was triggered by a tab
    `java.lang.String` | `toString()`

    - ### Methods inherited from class java.lang.Object

      `equals, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- - ### Field Detail

    - #### CONTROLLER

          public static int CONTROLLER

    - #### GROUP

          public static int GROUP

    - #### TAB

          public static int TAB

    - #### UNDEFINDED

          public static int UNDEFINDED

  - ### Constructor Detail

    - #### ControlEvent

          public ControlEvent(ControllerGroup<?> theController)

      Parameters:
        `theController` - Controller

    - #### ControlEvent

          public ControlEvent(Tab theController)

      Parameters:
        `theController` - Controller

  - ### Method Detail

    - #### getArrayValue

          public float[] getArrayValue()

      Returns a float array, applies to e.g. Range.
      Returns:
        float[]

    - #### getArrayValue

          public float getArrayValue(int theIndex)

      Returns a float value at a particular index from a controller's array value. No error checking available here, will throw ArrayIndexOutOfBOundsException in case of unavailable index.
      Parameters:
        `theIndex` -
      Returns:

    - #### getController

          public Controller<?> getController()

      Returns the instance of the controller sending the ControlEvent.
      Returns:
        Controller

    - #### getGroup

          public ControlGroup<?> getGroup()

      Returns the group that evoked the ControlEvent
      Returns:
        ControlGroup

    - #### getId

          public int getId()

      Returns the controller's id, if an id has not been set before the default value -1 will be returned.
      Returns:

    - #### getLabel

          public java.lang.String getLabel()

      Gets the text of the controller's label that has evoked the event.
      Returns:
        String

    - #### getName

          public java.lang.String getName()

      returns the controller's name
      Returns:
        String

    - #### getStringValue

          public java.lang.String getStringValue()

    - #### getTab

          public Tab getTab()

      Returns the tab that triggered the ControlEvent
      Returns:
        Tab Tab

    - #### getType

          public int getType()

      Returns:
        int returned is ControlP5.CONTROLLER, or ControlP5.TAB, or ControlP5.GROUP

    - #### getValue

          public float getValue()

    - #### isAssignableFrom

          public boolean isAssignableFrom(java.lang.Class<?> c)

    - #### isController

          public boolean isController()

      Checks if the ControlEvent was triggered by a controller
      Returns:
        boolean
      See Also:
        `Controller`

    - #### isFrom

          public boolean isFrom(ControllerInterface<?> theController)

      Checks if the ControlEvent originates from a specific Controller or ControllerGroup.
      Parameters:
        `theController` -
      Returns:
        boolean

    - #### isFrom

          public boolean isFrom(java.lang.String theControllerName)

      checks if the ControlEvent originates from a specific Controller or ControllerGroup identifiable by name.
      Parameters:
        `theController` -
      Returns:
        boolean

    - #### isGroup

          public boolean isGroup()

      Checks if the ControlEvent was triggered by a ControlGroup
      Returns:
        boolean
      See Also:
        `ControllerGroup`

    - #### isTab

          public boolean isTab()

      Checks if the ControlEvent was triggered by a tab
      Returns:
        boolean
      See Also:
        `Tab`

    - #### toString

          public java.lang.String toString()

      Overrides:
        `toString` in class `java.lang.Object`

processing library controlP5 by Andreas Schlegel. (c) 2006-2015