controlP5
Class ControllerGroup

java.lang.Object
  extended by controlP5.ControllerGroup
All Implemented Interfaces:
ControllerInterface, ControlListener, ControlP5Constants
Direct Known Subclasses:
ControlGroup, Tab, Textarea

public abstract class ControllerGroup
extends java.lang.Object
implements ControllerInterface, ControlP5Constants, ControlListener

ControllerGroup is an abstract class and is extended by class ControlGroup, Tab, or the ListBox.


Field Summary
 
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, MULTI, 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
ControllerGroup(ControlP5 theControlP5, java.lang.String theName)
          Convenience constructor to extend ControllerGroup.
 
Method Summary
 java.lang.Object add(ControllerInterface theElement)
          Adds a controller to the group, but use Controller.setGroup() instead.
 ControlWindowCanvas addCanvas(ControlWindowCanvas theCanvas)
          Adds a canvas to a controllerGroup such as a tab or group.
 java.lang.Object addCloseButton()
          TODO redesign or deprecate add a close button to the controlbar of this controlGroup.
 java.lang.Object addDrawable(CDrawable theElement)
           
 java.lang.Object addListener(ControlListener theListener)
           
 java.lang.Object bringToFront()
           
 java.lang.Object bringToFront(ControllerInterface theController)
           
 java.lang.Object close()
           
 void controlEvent(ControlEvent theEvent)
          controlEvent is called by controlP5's ControlBroadcaster to inform available listeners about value changes.
 java.lang.Object disableCollapse()
           
 java.lang.Object enableCollapse()
           
 processing.core.PVector getAbsolutePosition()
           
 java.lang.String getAddress()
          
 float[] getArrayValue()
          
 float getArrayValue(int theIndex)
           
 Label getCaptionLabel()
           
 CColor getColor()
          
 Controller getController(java.lang.String theController)
           
 int getHeight()
          
 int getId()
          
 java.lang.String getInfo()
           
 java.lang.String getName()
           
 processing.core.PVector getPosition()
          
 ControllerProperty getProperty(java.lang.String thePropertyName)
          
 ControllerProperty getProperty(java.lang.String theSetter, java.lang.String theGetter)
          
 java.lang.String getStringValue()
          
 Tab getTab()
           
 float getValue()
          
 Label getValueLabel()
           
 int getWidth()
          
 ControlWindow getWindow()
           
 java.lang.Object hide()
           
 java.lang.Object hideArrow()
           
 java.lang.Object hideBar()
           
 boolean isBarVisible()
           
 boolean isCollapse()
           
 boolean isMouseOver()
          
 boolean isMoveable()
           
 boolean isOpen()
           
 boolean isUpdate()
          checks the update status of a controller.
 boolean isVisible()
           
 int listenerSize()
           
 java.lang.Object moveTo(ControllerGroup theGroup)
           
 java.lang.Object moveTo(ControllerGroup theGroup, Tab theTab, ControlWindow theControlWindow)
           
 java.lang.Object moveTo(ControlWindow theControlWindow)
           
 java.lang.Object moveTo(ControlWindow theControlWindow, java.lang.String theTabName)
           
 java.lang.Object moveTo(processing.core.PApplet thePApplet)
           
 java.lang.Object moveTo(java.lang.String theTabName)
           
 java.lang.Object moveTo(java.lang.String theTabName, ControlWindow theControlWindow)
           
 java.lang.Object moveTo(Tab theTab)
           
 java.lang.Object moveTo(Tab theTab, ControlWindow theControlWindow)
           
 java.lang.Object open()
           
 java.lang.Object registerProperty(java.lang.String thePropertyName)
          
 java.lang.Object registerProperty(java.lang.String theSetter, java.lang.String theGetter)
          
 void remove()
          removes the group from controlP5.
 java.lang.Object remove(CDrawable theElement)
           
 java.lang.Object remove(ControllerInterface theElement)
          Removes a controller from the group, but use Controller.setGroup() instead.
 java.lang.Object removeCanvas(ControlWindowCanvas theCanvas)
          Removes a canvas from a controller group.
 java.lang.Object removeCloseButton()
          TODO redesign or deprecate remove the close button.
 java.lang.Object removeListener(ControlListener theListener)
           
 java.lang.Object removeProperty(java.lang.String thePropertyName)
          
 java.lang.Object removeProperty(java.lang.String theSetter, java.lang.String theGetter)
          
 java.lang.Object setAddress(java.lang.String theAddress)
          
 java.lang.Object setArrayValue(float[] theArray)
           
 java.lang.Object setArrayValue(int theIndex, float theValue)
           
 java.lang.Object setCaptionLabel(java.lang.String theValue)
           
 java.lang.Object setColor(CColor theColor)
          
 java.lang.Object setColorActive(int theColor)
          
 java.lang.Object setColorBackground(int theColor)
          
 java.lang.Object setColorForeground(int theColor)
          
 java.lang.Object setColorLabel(int theColor)
          
 java.lang.Object setColorValue(int theColor)
          
 java.lang.Object setGroup(ControllerGroup theGroup)
           
 java.lang.Object setGroup(java.lang.String theName)
           
 java.lang.Object setHeight(int theHeight)
           
 java.lang.Object setId(int theId)
          
 java.lang.Object setLabel(java.lang.String theLabel)
           
 java.lang.Object setMouseOver(boolean theFlag)
           
 java.lang.Object setMoveable(boolean theFlag)
          set the moveable status of the group, when false, the group can't be moved.
 java.lang.Object setOpen(boolean theFlag)
           
 java.lang.Object setPosition(float theX, float theY)
          set the position of this controller.
 java.lang.Object setPosition(processing.core.PVector thePVector)
          
 java.lang.Object setSize(int theWidth, int theHeight)
           
 java.lang.Object setStringValue(java.lang.String theValue)
          
 java.lang.Object setTab(ControlWindow theWindow, java.lang.String theName)
           
 java.lang.Object setTab(java.lang.String theName)
           
 java.lang.Object setTab(Tab theTab)
           
 java.lang.Object setTitle(java.lang.String theTitle)
           
 java.lang.Object setUpdate(boolean theFlag)
          enables or disables the update function of a controller.
 java.lang.Object setValue(float theValue)
          
 java.lang.Object setVisible(boolean theFlag)
           
 java.lang.Object setWidth(int theWidth)
           
 java.lang.Object show()
           
 java.lang.Object showArrow()
           
 java.lang.Object showBar()
           
 java.lang.String toString()
           
 java.lang.Object updateAbsolutePosition()
          
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface controlP5.ControllerInterface
continuousUpdateEvents, draw, getParent, getPickingColor, init, keyEvent, parent, setAbsolutePosition, setMousePressed, update, updateEvents, updateInternalEvents
 

Constructor Detail

ControllerGroup

public ControllerGroup(ControlP5 theControlP5,
                       java.lang.String theName)
Convenience constructor to extend ControllerGroup.

Parameters:
theControlP5 -
theName -
+Example
/**
 * ControlP5 extending Controllers
 *
 * the following example shows how to extend the Controller class to 
 * create customizable Controllers. You can either extend the Controller class itself,
 * or any class that extends Controller itself like the Slider, Button, DropdownList, etc. 
 * 
 * How to:
 *
 * 1) do a super call to the convenience constructor requiring 
 * 2 parameter (ControlP5 instance, name)  
 *
 * 2) the Controller class has a set of empty methods that allow you to capture
 * inputs from the mouse including 
 * onEnter(), onLeave(), onPress(), onRelease(), onClick(), onScroll(int), onDrag()
 * These you can override and include functionality as needed.
 *
 * 3) use method getPointer() to return the local (relative) 
 * xy-coordinates of the controller
 *  
 * 4) after instantiation custom controllers are treated the same 
 * as default controlP5 controllers.
 *  
 * by Andreas Schlegel, 2012
 * www.sojamo.de/libraries/controlp5
 *
 */

import controlP5.*;

ControlP5 cp5;
PApplet p;

void setup() {
  size(400, 400);
  cp5 = new ControlP5(this);
  
  // create 2 groups to show nesting of custom controllers and
  //   
  Group g1 = cp5.addGroup("a").setPosition(0,100).setWidth(180);
  Group g2 = cp5.addGroup("b").setPosition(0,10).setWidth(180);
  g2.moveTo(g1);
  
  // create 2 custom Controllers from class MyButton
  // MyButton extends Controller and inherits all methods accordingly.
  new MyButton(cp5, "b1").setPosition(0, 0).setSize(180, 200).moveTo(g2);
  new MyButton(cp5, "b2").setPosition(205, 15).setSize(180, 200);
  
}


void draw() {
  background(0);
}

// b1 will be called from Controller b1
public void b1(float theValue) {
  println("yay button "+theValue);
}

public void controlEvent(ControlEvent theEvent) {
  println("controlEvent : "+theEvent);
}


// Create a custom Controller, please not that 
// MyButton extends Controller, 
// is an indicator for the super class about the type of 
// custom controller to be created.

class MyButton extends Controller {

  int current = 0xffff0000;

  float a = 128;
  
  float na;
  
  int y;
  
  // use the convenience constructor of super class Controller
  // MyButton will automatically registered and move to the 
  // default controlP5 tab.
  
  MyButton(ControlP5 cp5, String theName) {
    super(cp5, theName);
    
    // replace the default view with a custom view.
    setView(new ControllerView() {
      public void display(PApplet p, Object b) {
        // draw button background
        na += (a-na) * 0.1; 
        p.fill(current,na);
        p.rect(0, 0, getWidth(), getHeight());
        
        // draw horizontal line which can be moved on the x-axis 
        // using the scroll wheel. 
        p.fill(0,255,0);
        p.rect(0,y,width,10);
        
        // draw the custom label 
        p.fill(128);
        translate(0,getHeight()+14);
        p.text(getName(),0,0);
        p.text(getName(),0,0);
        
      }
    }
    );
  }

  // override various input methods for mouse input control
  void onEnter() {
    cursor(HAND);
    println("enter");
    a = 255;
  }
  
  void onScroll(int n) {
    println("scrolling");
    y -= n;
    y = constrain(y,0,getHeight()-10);
  }
  
  void onPress() {
    println("press");
    current = 0xffffff00;
  }
  
  void onClick() {
    Pointer p1 = getPointer();
    println("clicked at "+p1.x()+", "+p1.y());
    current = 0xffffff00;
    setValue(y);
  }

  void onRelease() {
    println("release");
    current = 0xffffffff;
  }
  
  void onMove() {
    println("moving "+this+" "+_myControlWindow.getMouseOverList());
  }

  void onDrag() {
    current = 0xff0000ff;
    Pointer p1 = getPointer();
    float dif = dist(p1.px(),p1.py(),p1.x(),p1.y());
    println("dragging at "+p1.x()+", "+p1.y()+" "+dif);
  }
  
  void onReleaseOutside() {
    onLeave();
  }

  void onLeave() {
    println("leave");
    cursor(ARROW);
    a = 128;
  }
}

Method Detail

add

public java.lang.Object add(ControllerInterface theElement)
Adds a controller to the group, but use Controller.setGroup() instead.

Specified by:
add in interface ControllerInterface
Parameters:
theElement - ControllerInterface
Returns:
ControllerGroup

addCanvas

public ControlWindowCanvas addCanvas(ControlWindowCanvas theCanvas)
Adds a canvas to a controllerGroup such as a tab or group. Use processing's draw methods to add visual content.

Parameters:
theCanvas -
Returns:
ControlWindowCanvas

addCloseButton

public java.lang.Object addCloseButton()
TODO redesign or deprecate add a close button to the controlbar of this controlGroup.


addDrawable

public java.lang.Object addDrawable(CDrawable theElement)
Parameters:
theElement - CDrawable
Returns:
ControllerGroup

addListener

public java.lang.Object addListener(ControlListener theListener)
Specified by:
addListener in interface ControllerInterface
Parameters:
theListener - ControlListener
Returns:
Controller
See Also:
ControlListener

bringToFront

public java.lang.Object bringToFront()
Specified by:
bringToFront in interface ControllerInterface

bringToFront

public java.lang.Object bringToFront(ControllerInterface theController)
Specified by:
bringToFront in interface ControllerInterface

close

public java.lang.Object close()

controlEvent

public void controlEvent(ControlEvent theEvent)
Description copied from interface: ControlListener
controlEvent is called by controlP5's ControlBroadcaster to inform available listeners about value changes. Use the CallbackListener to get informed when actions such as pressed, release, drag, etc are performed.

Specified by:
controlEvent in interface ControlListener
Parameters:
theEvent - ControlEvent
See Also:
CallbackListener, CallbackEvent

disableCollapse

public java.lang.Object disableCollapse()
Returns:
ControllerGroup

enableCollapse

public java.lang.Object enableCollapse()
Returns:
ControllerGroup

getAbsolutePosition

public processing.core.PVector getAbsolutePosition()
Specified by:
getAbsolutePosition in interface ControllerInterface

getAddress

public java.lang.String getAddress()

Specified by:
getAddress in interface ControllerInterface

getArrayValue

public float[] getArrayValue()

Specified by:
getArrayValue in interface ControllerInterface

getArrayValue

public float getArrayValue(int theIndex)
Specified by:
getArrayValue in interface ControllerInterface
Parameters:
theIndex -
Returns:
float

getCaptionLabel

public Label getCaptionLabel()

getColor

public CColor getColor()

Specified by:
getColor in interface ControllerInterface

getController

public Controller getController(java.lang.String theController)

getHeight

public int getHeight()

Specified by:
getHeight in interface ControllerInterface

getId

public int getId()

Specified by:
getId in interface ControllerInterface

getInfo

public java.lang.String getInfo()

getName

public java.lang.String getName()
Specified by:
getName in interface ControllerInterface
Returns:
String

getPosition

public processing.core.PVector getPosition()

Specified by:
getPosition in interface ControllerInterface

getProperty

public ControllerProperty getProperty(java.lang.String thePropertyName)

Specified by:
getProperty in interface ControllerInterface

getProperty

public ControllerProperty getProperty(java.lang.String theSetter,
                                      java.lang.String theGetter)

Specified by:
getProperty in interface ControllerInterface

getStringValue

public java.lang.String getStringValue()

Specified by:
getStringValue in interface ControllerInterface

getTab

public Tab getTab()
Specified by:
getTab in interface ControllerInterface
Returns:
Tab

getValue

public float getValue()

Specified by:
getValue in interface ControllerInterface

getValueLabel

public Label getValueLabel()

getWidth

public int getWidth()

Specified by:
getWidth in interface ControllerInterface

getWindow

public ControlWindow getWindow()
Specified by:
getWindow in interface ControllerInterface
Returns:
ControlWindow

hide

public java.lang.Object hide()
Specified by:
hide in interface ControllerInterface

hideArrow

public java.lang.Object hideArrow()
Returns:
ControlGroup

hideBar

public java.lang.Object hideBar()

isBarVisible

public boolean isBarVisible()
Returns:
boolean

isCollapse

public boolean isCollapse()

isMouseOver

public boolean isMouseOver()

Specified by:
isMouseOver in interface ControllerInterface
Returns:
boolean

isMoveable

public boolean isMoveable()

isOpen

public boolean isOpen()
Returns:
boolean

isUpdate

public boolean isUpdate()
checks the update status of a controller.

Specified by:
isUpdate in interface ControllerInterface
Returns:
boolean

isVisible

public boolean isVisible()
Specified by:
isVisible in interface ControllerInterface
Returns:
boolean

listenerSize

public int listenerSize()
Returns:
int

moveTo

public final java.lang.Object moveTo(ControllerGroup theGroup)
Specified by:
moveTo in interface ControllerInterface

moveTo

public final java.lang.Object moveTo(ControllerGroup theGroup,
                                     Tab theTab,
                                     ControlWindow theControlWindow)
Specified by:
moveTo in interface ControllerInterface
Parameters:
theGroup - ControlGroup
theTab - Tab
theControlWindow - ControlWindow
Returns:
ControllerGroup

moveTo

public java.lang.Object moveTo(ControlWindow theControlWindow)

moveTo

public final java.lang.Object moveTo(ControlWindow theControlWindow,
                                     java.lang.String theTabName)

moveTo

public java.lang.Object moveTo(processing.core.PApplet thePApplet)

moveTo

public final java.lang.Object moveTo(java.lang.String theTabName)

moveTo

public final java.lang.Object moveTo(java.lang.String theTabName,
                                     ControlWindow theControlWindow)

moveTo

public final java.lang.Object moveTo(Tab theTab)

moveTo

public final java.lang.Object moveTo(Tab theTab,
                                     ControlWindow theControlWindow)

open

public java.lang.Object open()

registerProperty

public java.lang.Object registerProperty(java.lang.String thePropertyName)

Specified by:
registerProperty in interface ControllerInterface

registerProperty

public java.lang.Object registerProperty(java.lang.String theSetter,
                                         java.lang.String theGetter)

Specified by:
registerProperty in interface ControllerInterface

remove

public void remove()
removes the group from controlP5.

Specified by:
remove in interface ControllerInterface

remove

public java.lang.Object remove(CDrawable theElement)
Parameters:
theElement - CDrawable
Returns:
ControllerGroup

remove

public java.lang.Object remove(ControllerInterface theElement)
Removes a controller from the group, but use Controller.setGroup() instead.

Specified by:
remove in interface ControllerInterface
Parameters:
theElement - ControllerInterface
Returns:
ControllerGroup

removeCanvas

public java.lang.Object removeCanvas(ControlWindowCanvas theCanvas)
Removes a canvas from a controller group.

Parameters:
theCanvas -
Returns:
ControllerGroup

removeCloseButton

public java.lang.Object removeCloseButton()
TODO redesign or deprecate remove the close button.


removeListener

public java.lang.Object removeListener(ControlListener theListener)
Parameters:
theListener - ControlListener
Returns:
Controller
See Also:
ControlListener

removeProperty

public java.lang.Object removeProperty(java.lang.String thePropertyName)

Specified by:
removeProperty in interface ControllerInterface

removeProperty

public java.lang.Object removeProperty(java.lang.String theSetter,
                                       java.lang.String theGetter)

Specified by:
removeProperty in interface ControllerInterface

setAddress

public java.lang.Object setAddress(java.lang.String theAddress)

Specified by:
setAddress in interface ControllerInterface

setArrayValue

public java.lang.Object setArrayValue(float[] theArray)
Specified by:
setArrayValue in interface ControllerInterface
Parameters:
theArray -
Returns:
ControllerGroup

setArrayValue

public java.lang.Object setArrayValue(int theIndex,
                                      float theValue)
Specified by:
setArrayValue in interface ControllerInterface
Parameters:
theIndex -
theValue -
Returns:
Controller

setCaptionLabel

public java.lang.Object setCaptionLabel(java.lang.String theValue)
Specified by:
setCaptionLabel in interface ControllerInterface

setColor

public java.lang.Object setColor(CColor theColor)

Specified by:
setColor in interface ControllerInterface

setColorActive

public java.lang.Object setColorActive(int theColor)

Specified by:
setColorActive in interface ControllerInterface

setColorBackground

public java.lang.Object setColorBackground(int theColor)

Specified by:
setColorBackground in interface ControllerInterface

setColorForeground

public java.lang.Object setColorForeground(int theColor)

Specified by:
setColorForeground in interface ControllerInterface

setColorLabel

public java.lang.Object setColorLabel(int theColor)

Specified by:
setColorLabel in interface ControllerInterface

setColorValue

public java.lang.Object setColorValue(int theColor)

Specified by:
setColorValue in interface ControllerInterface

setGroup

public final java.lang.Object setGroup(ControllerGroup theGroup)
Parameters:
theGroup - ControllerGroup
Returns:
ControllerGroup

setGroup

public final java.lang.Object setGroup(java.lang.String theName)
Parameters:
theName - String
Returns:
ControllerGroup

setHeight

public java.lang.Object setHeight(int theHeight)
Parameters:
theHeight -
Returns:
ControllerGroup

setId

public java.lang.Object setId(int theId)

Specified by:
setId in interface ControllerInterface

setLabel

public java.lang.Object setLabel(java.lang.String theLabel)
Specified by:
setLabel in interface ControllerInterface
Parameters:
theLabel - String
Returns:
ControllerGroup

setMouseOver

public java.lang.Object setMouseOver(boolean theFlag)
Specified by:
setMouseOver in interface ControllerInterface

setMoveable

public java.lang.Object setMoveable(boolean theFlag)
set the moveable status of the group, when false, the group can't be moved.

Parameters:
theFlag - boolean
Returns:
ControllerGroup

setOpen

public java.lang.Object setOpen(boolean theFlag)

setPosition

public java.lang.Object setPosition(float theX,
                                    float theY)
set the position of this controller.

Specified by:
setPosition in interface ControllerInterface
Parameters:
theX - float
theY - float

setPosition

public java.lang.Object setPosition(processing.core.PVector thePVector)

Specified by:
setPosition in interface ControllerInterface

setSize

public java.lang.Object setSize(int theWidth,
                                int theHeight)

setStringValue

public java.lang.Object setStringValue(java.lang.String theValue)

Specified by:
setStringValue in interface ControllerInterface

setTab

public final java.lang.Object setTab(ControlWindow theWindow,
                                     java.lang.String theName)

setTab

public final java.lang.Object setTab(java.lang.String theName)
Parameters:
theName - String
Returns:
ControllerGroup

setTab

public final java.lang.Object setTab(Tab theTab)
Parameters:
theTab - Tab
Returns:
ControllerGroup

setTitle

public java.lang.Object setTitle(java.lang.String theTitle)

setUpdate

public java.lang.Object setUpdate(boolean theFlag)
enables or disables the update function of a controller.

Specified by:
setUpdate in interface ControllerInterface
Parameters:
theFlag - boolean
Returns:
ControllerGroup

setValue

public java.lang.Object setValue(float theValue)

Specified by:
setValue in interface ControllerInterface

setVisible

public java.lang.Object setVisible(boolean theFlag)
Parameters:
theFlag - boolean
Returns:
ControllerGroup

setWidth

public java.lang.Object setWidth(int theWidth)
Parameters:
theWidth -
Returns:
ControllerGroup

show

public java.lang.Object show()
Specified by:
show in interface ControllerInterface

showArrow

public java.lang.Object showArrow()
Returns:
ControlGroup

showBar

public java.lang.Object showBar()

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

updateAbsolutePosition

public java.lang.Object updateAbsolutePosition()

Specified by:
updateAbsolutePosition in interface ControllerInterface


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