Package | Class | Tree | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## controlP5
Class ControlGroup

    java.lang.Object
      controlP5.ControllerGroup
          controlP5.ControlGroup

All Implemented Interfaces:
  ControllerInterface, ControlListener, ControlP5Constants

Direct Known Subclasses:
  Accordion, CheckBox, ColorPicker, DropdownList, Group, ListBox, RadioButton

    public class ControlGroup

extends ControllerGroup
implements ControlListener

In previous versions you would use the ControlGroup class to bundle controllers in a group. Now please use the Group class to do so.

ControlGroup extends ControllerGroup, for a list and documentation of available methods see the `ControllerGroup` documentation.

See Also:
  `Group`
  +Example
    `

        /**
        * ControlP5 Group
        *
        *
        * find a list of public methods available for the Group Controller
        * at the bottom of this sketch.
        *
        * by Andreas Schlegel, 2012
        * www.sojamo.de/libraries/controlp5
        *
        */

        import controlP5.*;

        ControlP5 cp5;

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

          cp5 = new ControlP5(this);

          Group g1 = cp5.addGroup("g1")
                        .setPosition(100,100)
                        .setBackgroundHeight(100)
                        .setBackgroundColor(color(255,50))
                        ;

          cp5.addBang("A-1")
             .setPosition(10,20)
             .setSize(80,20)
             .setGroup(g1)
             ;

          cp5.addBang("A-2")
             .setPosition(10,60)
             .setSize(80,20)
             .setGroup(g1)
             ;

          Group g2 = cp5.addGroup("g2")
                        .setPosition(300,100)
                        .setWidth(300)
                        .activateEvent(true)
                        .setBackgroundColor(color(255,80))
                        .setBackgroundHeight(100)
                        .setLabel("Hello World.")
                        ;

          cp5.addSlider("S-1")
             .setPosition(80,10)
             .setSize(180,9)
             .setGroup(g2)
             ;

          cp5.addSlider("S-2")
             .setPosition(80,20)
             .setSize(180,9)
             .setGroup(g2)
             ;

          cp5.addRadioButton("radio")
             .setPosition(10,10)
             .setSize(20,9)
             .addItem("black",0)
             .addItem("red",1)
             .addItem("green",2)
             .addItem("blue",3)
             .addItem("grey",4)
             .setGroup(g2)
             ;
        }

        void draw() {
          background(0);
        }

        void controlEvent(ControlEvent theEvent) {
          if(theEvent.isGroup()) {
            println("got an event from group "
                    +theEvent.getGroup().getName()
                    +", isOpen? "+theEvent.getGroup().isOpen()
                    );

          } else if (theEvent.isController()){
            println("got something from a controller "
                    +theEvent.getController().getName()
                    );
          }
        }

        void keyPressed() {
          if(key==' ') {
            if(cp5.getGroup("g1")!=null) {
              cp5.getGroup("g1").remove();
            }
          }
        }

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

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

        Format:
        ClassName : returnType methodName(parameter type)

        controlP5.ControlGroup : Group activateEvent(boolean)
        controlP5.ControlGroup : Group addListener(ControlListener)
        controlP5.ControlGroup : Group hideBar()
        controlP5.ControlGroup : Group removeListener(ControlListener)
        controlP5.ControlGroup : Group setBackgroundColor(int)
        controlP5.ControlGroup : Group setBackgroundHeight(int)
        controlP5.ControlGroup : Group setBarHeight(int)
        controlP5.ControlGroup : Group showBar()
        controlP5.ControlGroup : Group updateInternalEvents(PApplet)
        controlP5.ControlGroup : String getInfo()
        controlP5.ControlGroup : String toString()
        controlP5.ControlGroup : boolean isBarVisible()
        controlP5.ControlGroup : int getBackgroundHeight()
        controlP5.ControlGroup : int getBarHeight()
        controlP5.ControlGroup : int listenerSize()
        controlP5.ControllerGroup : CColor getColor()
        controlP5.ControllerGroup : ControlWindow getWindow()
        controlP5.ControllerGroup : ControlWindowCanvas addCanvas(ControlWindowCanvas)
        controlP5.ControllerGroup : Controller getController(String)
        controlP5.ControllerGroup : ControllerProperty getProperty(String)
        controlP5.ControllerGroup : ControllerProperty getProperty(String, String)
        controlP5.ControllerGroup : Group add(ControllerInterface)
        controlP5.ControllerGroup : Group bringToFront()
        controlP5.ControllerGroup : Group bringToFront(ControllerInterface)
        controlP5.ControllerGroup : Group close()
        controlP5.ControllerGroup : Group disableCollapse()
        controlP5.ControllerGroup : Group enableCollapse()
        controlP5.ControllerGroup : Group hide()
        controlP5.ControllerGroup : Group moveTo(ControlWindow)
        controlP5.ControllerGroup : Group moveTo(PApplet)
        controlP5.ControllerGroup : Group open()
        controlP5.ControllerGroup : Group registerProperty(String)
        controlP5.ControllerGroup : Group registerProperty(String, String)
        controlP5.ControllerGroup : Group remove(CDrawable)
        controlP5.ControllerGroup : Group remove(ControllerInterface)
        controlP5.ControllerGroup : Group removeCanvas(ControlWindowCanvas)
        controlP5.ControllerGroup : Group removeProperty(String)
        controlP5.ControllerGroup : Group removeProperty(String, String)
        controlP5.ControllerGroup : Group setAddress(String)
        controlP5.ControllerGroup : Group setArrayValue(float[])
        controlP5.ControllerGroup : Group setColor(CColor)
        controlP5.ControllerGroup : Group setColorActive(int)
        controlP5.ControllerGroup : Group setColorBackground(int)
        controlP5.ControllerGroup : Group setColorForeground(int)
        controlP5.ControllerGroup : Group setColorLabel(int)
        controlP5.ControllerGroup : Group setColorValue(int)
        controlP5.ControllerGroup : Group setHeight(int)
        controlP5.ControllerGroup : Group setId(int)
        controlP5.ControllerGroup : Group setLabel(String)
        controlP5.ControllerGroup : Group setMouseOver(boolean)
        controlP5.ControllerGroup : Group setMoveable(boolean)
        controlP5.ControllerGroup : Group setOpen(boolean)
        controlP5.ControllerGroup : Group setPosition(PVector)
        controlP5.ControllerGroup : Group setPosition(float, float)
        controlP5.ControllerGroup : Group setStringValue(String)
        controlP5.ControllerGroup : Group setUpdate(boolean)
        controlP5.ControllerGroup : Group setValue(float)
        controlP5.ControllerGroup : Group setVisible(boolean)
        controlP5.ControllerGroup : Group setWidth(int)
        controlP5.ControllerGroup : Group show()
        controlP5.ControllerGroup : Group update()
        controlP5.ControllerGroup : Group updateAbsolutePosition()
        controlP5.ControllerGroup : Label getCaptionLabel()
        controlP5.ControllerGroup : Label getValueLabel()
        controlP5.ControllerGroup : PVector getPosition()
        controlP5.ControllerGroup : String getAddress()
        controlP5.ControllerGroup : String getInfo()
        controlP5.ControllerGroup : String getName()
        controlP5.ControllerGroup : String getStringValue()
        controlP5.ControllerGroup : String toString()
        controlP5.ControllerGroup : Tab getTab()
        controlP5.ControllerGroup : boolean isCollapse()
        controlP5.ControllerGroup : boolean isMouseOver()
        controlP5.ControllerGroup : boolean isMoveable()
        controlP5.ControllerGroup : boolean isOpen()
        controlP5.ControllerGroup : boolean isUpdate()
        controlP5.ControllerGroup : boolean isVisible()
        controlP5.ControllerGroup : boolean setMousePressed(boolean)
        controlP5.ControllerGroup : float getValue()
        controlP5.ControllerGroup : float[] getArrayValue()
        controlP5.ControllerGroup : int getHeight()
        controlP5.ControllerGroup : int getId()
        controlP5.ControllerGroup : int getWidth()
        controlP5.ControllerGroup : void remove()
        java.lang.Object : String toString()
        java.lang.Object : boolean equals(Object)

        */

    `

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
`ControlGroup(ControlP5 theControlP5, ControllerGroup theParent, java.lang.String theName, int theX, int theY, int theW, int theH)`
`ControlGroup(ControlP5 theControlP5, java.lang.String theName)` Convenience constructor to extend ControlGroup.

Method Summary
`java.lang.Object` | `activateEvent(boolean theFlag)` activates or deactivates the Event status of a ControlGroup.
`java.lang.Object` | `addListener(ControlListener theListener)` adds a listener to the controller.
`void` | `controlEvent(ControlEvent theEvent)` controlEvent is called by controlP5's ControlBroadcaster to inform available listeners about value changes.
`int` | `getBackgroundHeight()` get the height of the controlGroup's background.
`int` | `getBarHeight()`
`java.lang.String` | `getInfo()`
`int` | `listenerSize()`
`void` | `mousePressed()`
`java.lang.Object` | `removeListener(ControlListener theListener)` remove a listener from the controller.
`java.lang.Object` | `setBackgroundColor(int theColor)` set the background color of a controlGroup.
`java.lang.Object` | `setBackgroundHeight(int theHeight)` set the height of the controlGroup's background.
`java.lang.Object` | `setBarHeight(int theHeight)` set the height of the top bar (used to open/close and move a controlGroup).
`java.lang.Object` | `setSize(int theWidth, int theHeight)`
`java.lang.String` | `stringValue()` !!! experimental, see ControllerGroup.value()
`java.lang.String` | `toString()`
`java.lang.Object` | `updateInternalEvents(processing.core.PApplet theApplet)` a method for putting input events like e.g.

Methods inherited from class controlP5.ControllerGroup
`add, addCanvas, addCloseButton, addDrawable, bringToFront, bringToFront, close, disableCollapse, enableCollapse, getAbsolutePosition, getAddress, getArrayValue, getArrayValue, getCaptionLabel, getColor, getController, getHeight, getId, getName, getPosition, getProperty, getProperty, getStringValue, getTab, getValue, getValueLabel, getWidth, getWindow, hide, hideArrow, hideBar, isBarVisible, isCollapse, isMouseOver, isMoveable, isOpen, isUpdate, isVisible, moveTo, moveTo, moveTo, moveTo, moveTo, moveTo, moveTo, moveTo, moveTo, open, registerProperty, registerProperty, remove, remove, remove, removeCanvas, removeCloseButton, removeProperty, removeProperty, setAddress, setArrayValue, setArrayValue, setCaptionLabel, setColor, setColorActive, setColorBackground, setColorForeground, setColorLabel, setColorValue, setGroup, setGroup, setHeight, setId, setLabel, setMouseOver, setMoveable, setOpen, setPosition, setPosition, setStringValue, setTab, setTab, setTab, setTitle, setUpdate, setValue, setVisible, setWidth, show, showArrow, showBar, 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`

Constructor Detail

### ControlGroup

    public ControlGroup(ControlP5 theControlP5,
                        ControllerGroup theParent,
                        java.lang.String theName,
                        int theX,
                        int theY,
                        int theW,
                        int theH)

### ControlGroup

    public ControlGroup(ControlP5 theControlP5,
                        java.lang.String theName)

  Convenience constructor to extend ControlGroup.

  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

### activateEvent

    public java.lang.Object activateEvent(boolean theFlag)

  activates or deactivates the Event status of a ControlGroup.

  Parameters:
    `theFlag` - boolean
  See Also:
    `Tab`

### addListener

    public java.lang.Object addListener(ControlListener theListener)

  adds a listener to the controller.

  Specified by:
    `addListener` in interface `ControllerInterface`
  Overrides:
    `addListener` in class `ControllerGroup`
  Parameters:
    `theListener` - ControlListener
  Returns:
    ControlGroup
  See Also:
    `ControlListener`

### 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`
  Overrides:
    `controlEvent` in class `ControllerGroup`
  Parameters:
    `theEvent` - ControlEvent
  See Also:
    `CallbackListener`, `CallbackEvent`

### getBackgroundHeight

    public int getBackgroundHeight()

  get the height of the controlGroup's background.

  Returns:

### getBarHeight

    public int getBarHeight()

  Returns:
    int

### getInfo

    public java.lang.String getInfo()

  Overrides:
    `getInfo` in class `ControllerGroup`

### listenerSize

    public int listenerSize()

  Overrides:
    `listenerSize` in class `ControllerGroup`
  Returns:
    int

### mousePressed

    public void mousePressed()

### removeListener

    public java.lang.Object removeListener(ControlListener theListener)

  remove a listener from the controller.

  Overrides:
    `removeListener` in class `ControllerGroup`
  Parameters:
    `theListener` - ControlListener
  Returns:
    ControlGroup
  See Also:
    `ControlListener`

### setBackgroundColor

    public java.lang.Object setBackgroundColor(int theColor)

  set the background color of a controlGroup.

  Parameters:
    `theColor` -
  Returns:
    ControlGroup

### setBackgroundHeight

    public java.lang.Object setBackgroundHeight(int theHeight)

  set the height of the controlGroup's background.

  Parameters:
    `theHeight` -
  Returns:
    ControlGroup

### setBarHeight

    public java.lang.Object setBarHeight(int theHeight)

  set the height of the top bar (used to open/close and move a controlGroup).

  Parameters:
    `theHeight` -
  Returns:
    ControlGroup

### setSize

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

  Overrides:
    `setSize` in class `ControllerGroup`

### stringValue

    public java.lang.String stringValue()

  !!! experimental, see ControllerGroup.value()

  Overrides:
    `stringValue` in class `ControllerGroup`
  Returns:
    String

### toString

    public java.lang.String toString()

  Overrides:
    `toString` in class `ControllerGroup`

### updateInternalEvents

    public java.lang.Object updateInternalEvents(processing.core.PApplet theApplet)

  Description copied from interface: `ControllerInterface`
  a method for putting input events like e.g. mouse or keyboard events and queries. this has been taken out of the draw method for better overwriting capability.

  Specified by:
    `updateInternalEvents` in interface `ControllerInterface`
  Overrides:
    `updateInternalEvents` in class `ControllerGroup`

Package | Class | Tree | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

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