controlP5
Class ControlEvent

java.lang.Object
  extended by 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 myColorRect = 200;

public int myColorBackground = 100;


void setup() {
  size(400, 400);
  noStroke();
  
  cp5 = new ControlP5(this);
  cp5.addNumberbox("n1")
     .setValue(myColorRect)
     .setPosition(100, 160)
     .setSize(100, 14)
     .setId(1);
     
  cp5.addNumberbox("n2")
     .setValue(myColorBackground)
     .setPosition(100, 200)
     .setSize(100, 14)
     .setId(2);
     
  cp5.addTextfield("n3")
     .setPosition(100, 240)
     .setSize(100, 20)
     .setId(3);
     
}

void draw() {
  background(myColorBackground);
  fill(myColorRect);
  rect(0, 0, width, 100);
}


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):
    myColorRect = (int)(theEvent.getController().getValue());
    break;
    case(2):
    myColorBackground = (int)(theEvent.getController().getValue());
    break;
    case(3):
    println(theEvent.getController().getStringValue());
    break;
  }
}


/*
 a list of all methods available for ControlEvent
 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 : Tab getTab() 
 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 getValue() 
 controlP5.ControlEvent : float[] getArrayValue() 
 controlP5.ControlEvent : int getId() 
 controlP5.ControlEvent : int getType() 
 java.lang.Object : String toString() 
 java.lang.Object : boolean equals(Object) 
 */
 
 

Field Summary
static int CONTROLLER
           
static int GROUP
           
static int TAB
           
static int UNDEFINDED
           
 
Method Summary
 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
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-2012