controlP5
Class ControlP5

java.lang.Object
  extended by controlP5.ControlP5Base
      extended by controlP5.ControlP5
All Implemented Interfaces:
ControlP5Constants

public class ControlP5
extends ControlP5Base

controlP5 is a processing and java library for creating simple control GUIs. The ControlP5 class, the core of controlP5.

All addController-Methods are located inside the ControlP5Base class.

See Also:
ControlP5Base
+Example
/**
 * ControlP5 Basics
 *
 * The following example demonstrates the basic use of controlP5.
* After initializing controlP5 you can add controllers to controlP5. * Here we use three numberboxes, one slider and one textfield. * The numberbox with name numberboxC will trigger function numberboxC() * in the example below. Whenever controlP5 detects a function in your * sketch that corresponds to the name of a controller, it will forward * an event to that function. Any event triggered by a controller * will be forwarded to function controlEvent in your sketch. * related examples ControlP5numberbox, ControlP5slider, ControlP5textfield * * by Andreas Schlegel, 2011 * 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); // create a slider // parameters: // name, minValue, maxValue, defaultValue, x, y, width, height cp5.addSlider("sliderA", 100, 200, 100, 100, 260, 100, 14); // create 3 numberboxes and assign an id for each cp5.addNumberbox("numberboxA", myColorRect, 100, 140, 100, 14).setId(1); cp5.addNumberbox("numberboxB", myColorBackground, 100, 180, 100, 14).setId(2); cp5.addNumberbox("numberboxC", 0, 100, 220, 100, 14).setId(3); // create a texfield cp5.addTextfield("textA", 100, 290, 100, 20); // change individual settings for a controller cp5.getController("numberboxA").setMax(255); cp5.getController("numberboxA").setMin(0); } void draw() { background(myColorBackground); fill(myColorRect); rect(0, 0, width, 100); } // events from controller numberboxC are received here public void numberboxC(int theValue) { println("### got an event from numberboxC : "+theValue); } // an event from slider sliderA will change the value of textfield textA here public void sliderA(int theValue) { Textfield txt = ((Textfield)cp5.getController("textA")); txt.setValue(""+theValue); } // for every change (a textfield event confirmed with a return) in textfield textA, // function textA will be invoked public void textA(String theValue) { println("### got an event from textA : "+theValue); } // function controlEvent will be invoked with every value change // in any registered controller public void controlEvent(ControlEvent theEvent) { println("got a control event from controller with id "+theEvent.getId()); switch(theEvent.getId()) { case(1): // numberboxA is registered with id 1 myColorRect = (int)(theEvent.getController().getValue()); break; case(2): // numberboxB is registered with id 2 myColorBackground = (int)(theEvent.getController().getValue()); break; } }

Field Summary
static CColor CP5BLUE
           
static boolean DEBUG
          use this static variable to turn DEBUG on or off.
static int grixel
           
static CColor RED
           
static CColor RETRO
           
static int standard56
           
static int standard58
           
static int synt24
           
static CColor WHITE
           
 
Fields inherited from interface controlP5.ControlP5Constants
acceptClassList, ACTION_BROADCAST, ACTION_ENTER, ACTION_LEAVE, ACTION_PRESSED, ACTION_RELEASED, ACTION_RELEASEDOUTSIDE, ACTIVE, ALL, ALT, ARC, ARRAY, BACKSPACE, BASELINE, BITFONT, BOOLEAN, BOTTOM, BOTTOM_OUTSIDE, CAPTIONLABEL, CENTER, COMMANDKEY, CONTROL, controlEventClass, CUSTOM, DECREASE, DEFAULT, DELETE, DONE, DOWN, ELLIPSE, ENTER, ESCAPE, EVENT, eventMethod, FADEIN, FADEOUT, FIELD, FLOAT, HALF_PI, HIDE, HIGHLIGHT, HORIZONTAL, IDLE, IMAGE, INACTIVE, INCREASE, INTEGER, INVALID, KEYCONTROL, LEFT, LEFT_OUTSIDE, LINE, LOAD, MENU, METHOD, MOVE, MULTIPLES, OVER, PI, PRESSED, PRINT, RELEASE, RESET, RIGHT, RIGHT_OUTSIDE, SAVE, SHIFT, SINGLE, SINGLE_COLUMN, SINGLE_ROW, SPRITE, STRING, SWITCH, SWITCH_BACK, SWITCH_FORE, TAB, TOP, TOP_OUTSIDE, TRANSITION_WAIT_FADEIN, TWO_PI, UP, VALUELABEL, VERBOSE, VERTICAL, WAIT
 
Constructor Summary
ControlP5(processing.core.PApplet theParent)
          Create a new instance of controlP5.
ControlP5(processing.core.PApplet theParent, ControlFont theControlFont)
           
 
Method Summary
 ControlP5 addCallback(CallbackListener theListener)
           
 ControlP5 addCallback(CallbackListener[] theListeners)
           
 ControlP5 addCallback(CallbackListener theListener, Controller[] theControllers)
           
 ControlP5 addCanvas(ControlWindowCanvas theCanvas)
          adds a ControlWindowCanvas to the default sketch window.
 ControlP5 addListener(ControlListener[] theListeners)
           
 void addPositionTo(int theX, int theY, ControllerInterface[] theControllers)
           
 void addPositionTo(int theX, int theY, java.util.List theControllers)
           
 ControllerGroup begin()
          cp5.begin() and cp5.end() are mechanisms to auto-layout controllers, see the ControlP5beginEnd example.
 ControllerGroup begin(ControllerGroup theGroup)
           
 ControllerGroup begin(ControllerGroup theGroup, int theX, int theY)
           
 ControllerGroup begin(ControlWindow theWindow)
           
 ControllerGroup begin(ControlWindow theWindow, int theX, int theY)
           
 ControllerGroup begin(int theX, int theY)
           
 ControlP5 disableMouseWheel()
          disables the mouse wheel as input for the main window, by default the mouse wheel is enabled.
 void disableShortcuts()
          disables shortcuts such as alt-h for hiding/showing controllers
 ControlP5 enableMouseWheel()
          enables the mouse wheel as input for the main window, by default the mouse wheel is enabled.
 void enableShortcuts()
          enables shortcuts.
 ControllerGroup end()
          cp5.begin() and cp5.end() are mechanisms to auto-layout controllers, see the ControlP5beginEnd example.
 ControllerGroup end(ControllerGroup theGroup)
           
 java.lang.Object get(java.lang.Class theClass, java.lang.String theName)
           
 ControllerInterface get(java.lang.String theName)
           
 java.util.List getAll()
          Returns a List of all controllers currently registered.
 java.util.List getAll(java.lang.Class theClass)
          Returns a list of controllers or groups of a particular type.
static CColor getColor()
           
 ControlBroadcaster getControlBroadcaster()
           
 Controller getController(java.lang.String theName)
           
 ControllerInterface[] getControllerList()
          Deprecated. 
 ControlFont getFont()
           
 ControllerGroup getGroup(java.lang.String theGroupName)
           
 ControlListener getListener(int theIndex)
           
 java.util.List getMouseOverList()
          convenience method to check if the mouse (or pointer) is hovering over a specific controller.
 ControlWindow.Pointer getPointer()
          convenience method to access the pointer of the main control window.
 Tab getTab(ControlWindow theWindow, java.lang.String theName)
           
 Tab getTab(java.lang.String theName)
           
 Tooltip getTooltip()
           
 ControlWindow getWindow()
          convenience method to access the main window (ControlWindow class).
 ControlWindow getWindow(processing.core.PApplet theApplet)
           
 ControlWindow getWindow(java.lang.String theWindowName)
           
 void hide()
          hide all controllers and tabs inside your sketch window.
 boolean isAutoDraw()
          check if the autoDraw function for the main window is enabled(true) or disabled(false).
 boolean isMouseOver()
          convenience method to check if the mouse (or pointer) is hovering over any controller.
 boolean isMouseOver(ControllerInterface theController)
          convenience method to check if the mouse (or pointer) is hovering over a specific controller.
 boolean isMouseWheel()
          checks the status of the mouse wheel.
 boolean isMoveable()
          Checks if controllers are generally moveable
 boolean isShortcuts()
           
 boolean isUpdate()
          checks if automatic updates are enabled.
 boolean isVisible()
          returns true or false according to the current visibility flag.
 boolean loadProperties()
          Loads properties from a default properties file and changes values of controllers accordingly.
 boolean loadProperties(java.lang.String theFilePath)
          Loads properties from a properties file and changes the values of controllers accordingly, the filepath is given by parameter theFilePath.
static java.util.logging.Logger logger()
           
 void move(java.lang.Object theObject, ControllerGroup theGroup)
           
 void moveControllersForObject(java.lang.Object theObject, ControllerGroup theGroup)
           
 void printControllerMap()
           
 ControlP5 register(java.lang.Object theObject, java.lang.String theIndex, ControllerInterface theController)
          registers a Controller with ControlP5, a Controller should/must be registered with a unique name.
 void remove(java.lang.String theName)
          removes a controlP5 element such as a controller, group, or tab by name.
 ControlP5 removeCallback(CallbackListener[] theListeners)
           
 ControlP5 removeCallback(Controller theController)
           
 ControlP5 removeCallback(Controller[] theControllers)
           
 ControlP5 removeListener(ControlListener theListener)
           
 ControlP5 removeListener(ControlListener[] theListeners)
           
 boolean saveProperties()
          Saves the current values of controllers into a default properties file
 boolean saveProperties(java.lang.String theFilePath)
          Saves the current values of controllers into a file, the filepath is given by parameter theFilePath.
 boolean saveProperties(java.lang.String theFilePath, java.lang.String[] theSets)
           
 void setAutoDraw(boolean theFlag)
          by default controlP5 draws any controller on top of any drawing done in the draw() function (this doesnt apply to P3D where controlP5.draw() has to be called manually in the sketch's draw() function ).
 void setAutoInitialization(boolean theFlag)
          autoInitialization can be very handy when it comes to initializing values, e.g.
 ControlP5 setColor(CColor theColor)
           
 ControlP5 setColorActive(int theColor)
          sets the active state color of tabs and controllers, this cascades down to all known controllers.
 ControlP5 setColorBackground(int theColor)
          sets the background color of tabs and controllers, this cascades down to all known controllers.
 ControlP5 setColorCaptionLabel(int theColor)
          sets the label color of tabs and controllers, this cascades down to all known controllers.
 ControlP5 setColorForeground(int theColor)
          sets the foreground color of tabs and controllers, this cascades down to all known controllers.
 ControlP5 setColorValueLabel(int theColor)
          sets the value color of controllers, this cascades down to all known controllers.
 boolean setFont(ControlFont theControlFont)
           
 boolean setFont(int theBitFontIndex)
           
 boolean setFont(processing.core.PFont thePFont)
           
 boolean setFont(processing.core.PFont thePFont, int theFontSize)
           
 ControlP5 setMoveable(boolean theFlag)
          Enables/disables Controllers to be moved around when ALT-key is down and mouse is dragged.
 void setTabEventsActive(boolean theFlag)
          By default event originating from tabs are disabled, use setTabEventsActive(true) to receive controlEvents when tabs are clicked.
 void setTooltip(Tooltip theTooltip)
           
 void setUpdate(boolean theFlag)
          changes the update behavior according to parameter theFlag
 void show()
          shows all controllers and tabs in your sketch.
 void update()
          forces all controllers to update.
 java.lang.String version()
          Returns the current version of controlP5
 
Methods inherited from class controlP5.ControlP5Base
addAccordion, addAccordion, addBang, addBang, addBang, addBang, addBang, addButton, addButton, addButton, addButton, addButton, addButton, addChart, addChart, addCheckBox, addCheckBox, addColorPicker, addColorPicker, addController, addController, addControllersFor, addControlWindow, addControlWindow, addControlWindow, addControlWindow, addControlWindow, addDropdownList, addDropdownList, addGroup, addGroup, addGroup, addGroup, addKnob, addKnob, addKnob, addKnob, addKnob, addKnob, addKnob, addKnob, addListBox, addListBox, addMatrix, addMatrix, addMatrix, addMultiList, addMultiList, addNumberbox, addNumberbox, addNumberbox, addNumberbox, addNumberbox, addNumberbox, addRadio, addRadio, addRadioButton, addRadioButton, addRange, addRange, addRange, addRange, addRange, addSlider, addSlider, addSlider, addSlider, addSlider, addSlider, addSlider, addSlider, addSlider2D, addSlider2D, addSlider2D, addSlider2D, addSlider2D, addTab, addTab, addTab, addTextarea, addTextarea, addTextfield, addTextfield, addTextfield, addTextfield, addTextlabel, addTextlabel, addTextlabel, addTextlabel, addTextlabel, addToggle, addToggle, addToggle, addToggle, addToggle, addToggle, addToggle, addToggle, addTooltip, getController, getLayout, getObjectForController, getProperties, getPublicMethodsFor, getPublicMethodsFor, getPublicMethodsFor, getPublicMethodsFor, getTextlabel, getTextlabel, hide, listenTo, mapKeyFor, moveTo, printPublicMethodsFor, printPublicMethodsFor, remove, removeKeyFor, removeKeysFor, removeProperty, setAutoAddDirection, setAutoSpacing, setAutoSpacing, setAutoSpacing, setAutoSpacing, setColor, setPosition, show, stopListeningTo
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CP5BLUE

public static final CColor CP5BLUE

DEBUG

public static boolean DEBUG
use this static variable to turn DEBUG on or off.


grixel

public static final int grixel
See Also:
Constant Field Values

RED

public static final CColor RED

RETRO

public static final CColor RETRO

standard56

public static final int standard56
See Also:
Constant Field Values

standard58

public static final int standard58
See Also:
Constant Field Values

synt24

public static final int synt24
See Also:
Constant Field Values

WHITE

public static final CColor WHITE
Constructor Detail

ControlP5

public ControlP5(processing.core.PApplet theParent)
Create a new instance of controlP5.

Parameters:
theParent - PApplet

ControlP5

public ControlP5(processing.core.PApplet theParent,
                 ControlFont theControlFont)
Method Detail

addCallback

public ControlP5 addCallback(CallbackListener theListener)
See Also:
CallbackEvent, CallbackListener

addCallback

public ControlP5 addCallback(CallbackListener[] theListeners)
See Also:
CallbackEvent, CallbackListener

addCallback

public ControlP5 addCallback(CallbackListener theListener,
                             Controller[] theControllers)
See Also:
CallbackEvent, CallbackListener

addCanvas

public ControlP5 addCanvas(ControlWindowCanvas theCanvas)
adds a ControlWindowCanvas to the default sketch window.

See Also:
ControlWindowCanvas

addListener

public ControlP5 addListener(ControlListener[] theListeners)
See Also:
ControlListener

addPositionTo

public void addPositionTo(int theX,
                          int theY,
                          ControllerInterface[] theControllers)

addPositionTo

public void addPositionTo(int theX,
                          int theY,
                          java.util.List theControllers)

begin

public ControllerGroup begin()
cp5.begin() and cp5.end() are mechanisms to auto-layout controllers, see the ControlP5beginEnd example.


begin

public ControllerGroup begin(ControllerGroup theGroup)

begin

public ControllerGroup begin(ControllerGroup theGroup,
                             int theX,
                             int theY)

begin

public ControllerGroup begin(ControlWindow theWindow)

begin

public ControllerGroup begin(ControlWindow theWindow,
                             int theX,
                             int theY)

begin

public ControllerGroup begin(int theX,
                             int theY)

disableMouseWheel

public ControlP5 disableMouseWheel()
disables the mouse wheel as input for the main window, by default the mouse wheel is enabled.


disableShortcuts

public void disableShortcuts()
disables shortcuts such as alt-h for hiding/showing controllers


enableMouseWheel

public ControlP5 enableMouseWheel()
enables the mouse wheel as input for the main window, by default the mouse wheel is enabled.


enableShortcuts

public void enableShortcuts()
enables shortcuts.


end

public ControllerGroup end()
cp5.begin() and cp5.end() are mechanisms to auto-layout controllers, see the ControlP5beginEnd example.


end

public ControllerGroup end(ControllerGroup theGroup)

get

public java.lang.Object get(java.lang.Class theClass,
                            java.lang.String theName)

get

public ControllerInterface get(java.lang.String theName)

getAll

public java.util.List getAll()
Returns a List of all controllers currently registered.

Returns:
List>

getAll

public java.util.List getAll(java.lang.Class theClass)
Returns a list of controllers or groups of a particular type. The following example will return a list of registered Bangs only:
 List list = controlP5.getAll(Bang.class);
 println(list);
 for(Bang b:list) {
   b.setColorForeground(color(255,255,0));
 }
 
Here the foreground color of all Bangs is changed to yellow.

Parameters:
theClass - A class that extends ControllerInterface, which applies to all Controllers and ControllerGroups
Returns:
List

getColor

public static CColor getColor()

getControlBroadcaster

public ControlBroadcaster getControlBroadcaster()
See Also:
ControlBroadcaster

getController

public Controller getController(java.lang.String theName)

getControllerList

@Deprecated
public ControllerInterface[] getControllerList()
Deprecated. 

returns a list of registered Controllers. Controllers with duplicated reference names will be ignored, only the latest of such Controllers will be included in the list. use getAll() instead

Returns:
ControllerInterface[]
See Also:
ControlP5.getAll(), ControlP5.getAll(Class)

getFont

public ControlFont getFont()

getGroup

public ControllerGroup getGroup(java.lang.String theGroupName)

getListener

public ControlListener getListener(int theIndex)
See Also:
ControlListener

getMouseOverList

public java.util.List getMouseOverList()
convenience method to check if the mouse (or pointer) is hovering over a specific controller. only applies to the main window. To receive the mouseover information for a ControlWindow use getWindow(nameOfWindow).getMouseOverList();


getPointer

public ControlWindow.Pointer getPointer()
convenience method to access the pointer of the main control window.


getTab

public Tab getTab(ControlWindow theWindow,
                  java.lang.String theName)

getTab

public Tab getTab(java.lang.String theName)

getTooltip

public Tooltip getTooltip()

getWindow

public ControlWindow getWindow()
convenience method to access the main window (ControlWindow class).


getWindow

public ControlWindow getWindow(processing.core.PApplet theApplet)

getWindow

public ControlWindow getWindow(java.lang.String theWindowName)

hide

public void hide()
hide all controllers and tabs inside your sketch window.

See Also:
ControlP5.show(), ControlP5.isVisible()

isAutoDraw

public boolean isAutoDraw()
check if the autoDraw function for the main window is enabled(true) or disabled(false).

Returns:
boolean

isMouseOver

public boolean isMouseOver()
convenience method to check if the mouse (or pointer) is hovering over any controller. only applies to the main window. To receive the mouseover information for a ControlWindow use getWindow(nameOfWindow).isMouseOver();


isMouseOver

public boolean isMouseOver(ControllerInterface theController)
convenience method to check if the mouse (or pointer) is hovering over a specific controller. only applies to the main window. To receive the mouseover information for a ControlWindow use getWindow(nameOfWindow).isMouseOver(ControllerInterface);


isMouseWheel

public boolean isMouseWheel()
checks the status of the mouse wheel.


isMoveable

public boolean isMoveable()
Checks if controllers are generally moveable


isShortcuts

public boolean isShortcuts()

isUpdate

public boolean isUpdate()
checks if automatic updates are enabled. By default this is true.

Returns:
See Also:
ControlP5.update(), ControlP5.setUpdate(boolean)

isVisible

public boolean isVisible()
returns true or false according to the current visibility flag.

See Also:
ControlP5.show(), ControlP5.hide()

loadProperties

public boolean loadProperties()
Loads properties from a default properties file and changes values of controllers accordingly.

Returns:
See Also:
ControllerProperties

loadProperties

public boolean loadProperties(java.lang.String theFilePath)
Loads properties from a properties file and changes the values of controllers accordingly, the filepath is given by parameter theFilePath.

Parameters:
theFilePath -
Returns:

logger

public static java.util.logging.Logger logger()

move

public void move(java.lang.Object theObject,
                 ControllerGroup theGroup)

moveControllersForObject

public void moveControllersForObject(java.lang.Object theObject,
                                     ControllerGroup theGroup)

printControllerMap

public void printControllerMap()

register

public ControlP5 register(java.lang.Object theObject,
                          java.lang.String theIndex,
                          ControllerInterface theController)
registers a Controller with ControlP5, a Controller should/must be registered with a unique name. If not, accessing Controllers by name is not guaranteed. the rule here is last come last serve, existing Controllers with the same name will be overridden.

Parameters:
theController - ControllerInterface
Returns:
ControlP5

remove

public void remove(java.lang.String theName)
removes a controlP5 element such as a controller, group, or tab by name.

Parameters:
theString - String

removeCallback

public ControlP5 removeCallback(CallbackListener[] theListeners)
See Also:
CallbackEvent, CallbackListener

removeCallback

public ControlP5 removeCallback(Controller theController)
See Also:
CallbackEvent, CallbackListener

removeCallback

public ControlP5 removeCallback(Controller[] theControllers)
See Also:
CallbackEvent, CallbackListener

removeListener

public ControlP5 removeListener(ControlListener theListener)
See Also:
ControlListener

removeListener

public ControlP5 removeListener(ControlListener[] theListeners)
See Also:
ControlListener

saveProperties

public boolean saveProperties()
Saves the current values of controllers into a default properties file

See Also:
ControllerProperties

saveProperties

public boolean saveProperties(java.lang.String theFilePath)
Saves the current values of controllers into a file, the filepath is given by parameter theFilePath.

See Also:
ControllerProperties

saveProperties

public boolean saveProperties(java.lang.String theFilePath,
                              java.lang.String[] theSets)

setAutoDraw

public void setAutoDraw(boolean theFlag)
by default controlP5 draws any controller on top of any drawing done in the draw() function (this doesnt apply to P3D where controlP5.draw() has to be called manually in the sketch's draw() function ). to turn off the auto drawing of controlP5, use controlP5.setAutoDraw(false). now you can call controlP5.draw() any time whenever controllers should be drawn into the sketch.

Parameters:
theFlag - boolean

setAutoInitialization

public void setAutoInitialization(boolean theFlag)
autoInitialization can be very handy when it comes to initializing values, e.g. you load a set of controllers, then the values that are attached to the controllers will be reset to its saved state. to turn of auto intialization, call setAutoInitialization(false) right after initializing controlP5 and before creating any controller.

Parameters:
theFlag - boolean

setColor

public ControlP5 setColor(CColor theColor)

setColorActive

public ControlP5 setColorActive(int theColor)
sets the active state color of tabs and controllers, this cascades down to all known controllers.


setColorBackground

public ControlP5 setColorBackground(int theColor)
sets the background color of tabs and controllers, this cascades down to all known controllers.


setColorCaptionLabel

public ControlP5 setColorCaptionLabel(int theColor)
sets the label color of tabs and controllers, this cascades down to all known controllers.


setColorForeground

public ControlP5 setColorForeground(int theColor)
sets the foreground color of tabs and controllers, this cascades down to all known controllers.


setColorValueLabel

public ControlP5 setColorValueLabel(int theColor)
sets the value color of controllers, this cascades down to all known controllers.


setFont

public boolean setFont(ControlFont theControlFont)

setFont

public boolean setFont(int theBitFontIndex)

setFont

public boolean setFont(processing.core.PFont thePFont)

setFont

public boolean setFont(processing.core.PFont thePFont,
                       int theFontSize)

setMoveable

public ControlP5 setMoveable(boolean theFlag)
Enables/disables Controllers to be moved around when ALT-key is down and mouse is dragged. Other key events are still available like ALT-h to hide and show the controllers To disable all key events, use disableKeys()


setTabEventsActive

public void setTabEventsActive(boolean theFlag)
By default event originating from tabs are disabled, use setTabEventsActive(true) to receive controlEvents when tabs are clicked.

Parameters:
theFlag -

setTooltip

public void setTooltip(Tooltip theTooltip)

setUpdate

public void setUpdate(boolean theFlag)
changes the update behavior according to parameter theFlag

Parameters:
theFlag -
See Also:
ControlP5.update(), ControlP5.isUpdate()

show

public void show()
shows all controllers and tabs in your sketch.

See Also:
ControlP5.isVisible(), ControlP5.hide()

update

public void update()
forces all controllers to update.

See Also:
ControlP5.isUpdate(), controlP5.ControlP5#setUpdate()

version

public java.lang.String version()
Returns the current version of controlP5

Returns:
String


processing library controlP5 by Andreas Schlegel. (c) 2012