controlP5
Class CheckBox

java.lang.Object
  extended by controlP5.ControllerGroup
      extended by controlP5.ControlGroup
          extended by controlP5.CheckBox
All Implemented Interfaces:
ControllerInterface, ControlListener, ControlP5Constants

public class CheckBox
extends ControlGroup

A multiple-choice radioButton. items are added to a checkBox and can be organized in rows and columns. items of a checkBox are of type Toggle.

See Also:
Toggle
+Example
/**
 * ControlP5 Checkbox
 * an example demonstrating the use of a checkbox in controlP5. 
 * CheckBox extends the RadioButton class.
 * to control a checkbox use: 
 * activate(), deactivate(), activateAll(), deactivateAll(), toggle(), getState()
 *
 * find a list of public methods available for the Checkbox Controller 
 * at the bottom of this sketch's source code
 *
 * by Andreas Schlegel, 2012
 * www.sojamo.de/libraries/controlP5
 *
 */


import controlP5.*;

ControlP5 cp5;

CheckBox checkbox;

int myColorBackground;

void setup() {
  size(700, 400);
  smooth();
  cp5 = new ControlP5(this);
  checkbox = cp5.addCheckBox("checkBox")
                .setPosition(100, 200)
                .setColorForeground(color(120))
                .setColorActive(color(255))
                .setColorLabel(color(255))
                .setSize(40, 40)
                .setItemsPerRow(3)
                .setSpacingColumn(30)
                .setSpacingRow(20)
                .addItem("0", 0)
                .addItem("10", 10)
                .addItem("50", 50)
                .addItem("100", 100)
                .addItem("200", 200)
                .addItem("5", 5)
                ;
}

void keyPressed() {
  if (key==' ') {
    checkbox.deactivateAll();
  } 
  else {
    for (int i=0;i<6;i++) {
      // check if key 0-5 have been pressed and toggle
      // the checkbox item accordingly.
      if (keyCode==(48 + i)) { 
        // the index of checkbox items start at 0
        checkbox.toggle(i);
        println("toggle "+checkbox.getItem(i).name());
        // also see 
        // checkbox.activate(index);
        // checkbox.deactivate(index);
      }
    }
  }
}

void draw() {
  background(0);
  pushMatrix();
  translate(width/2 + 200, height/2);
  fill(myColorBackground);
  ellipse(0,0,200,200);
  popMatrix();
}

void controlEvent(ControlEvent theEvent) {
  if (theEvent.isFrom(checkbox)) {
    myColorBackground = 0;
    print("got an event from "+checkbox.getName()+"\t");
    // checkbox uses arrayValue to store the state of 
    // individual checkbox-items. usage:
    println(checkbox.getArrayValue());
    int col = 0;
    for (int i=0;i

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, 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
 
Method Summary
 CheckBox activate(int theIndex)
          Activates a single checkbox item by index
 CheckBox activate(java.lang.String theName)
          Activates a single checkbox item by name
 CheckBox activateAll()
           
 CheckBox addItem(java.lang.String theName, float theValue)
           
 CheckBox addItem(Toggle theToggle, float theValue)
           
 CheckBox deactivate(int theIndex)
          deactivate a single checkbox item by index
 CheckBox deactivate(java.lang.String theName)
          Deactivates a single checkbox item by name
 CheckBox deactivateAll()
           
 Toggle getItem(int theIndex)
          Gets a radio button item by index.
 java.util.List getItems()
           
 boolean getState(int theIndex)
          Gets the state of an item - this can be true (for on) or false (for off) - by index.
 boolean getState(java.lang.String theName)
          Gets the state of an item - this can be true (for on) or false (for off) - by name.
 CheckBox hideLabels()
           
 CheckBox plugTo(java.lang.Object theObject)
           
 CheckBox removeItem(java.lang.String theName)
           
 CheckBox setArrayValue(float[] theArray)
          Sets the value for all CheckBox items according to the values of the array passed on.
 CheckBox setColorLabels(int theColor)
           
 CheckBox setImage(processing.core.PImage theImage)
           
 CheckBox setImage(processing.core.PImage theImage, int theState)
           
 CheckBox setImages(processing.core.PImage theDefaultImage, processing.core.PImage theOverImage, processing.core.PImage theActiveImage)
           
 CheckBox setItemHeight(int theItemHeight)
          set the height of a radioButton/checkBox item.
 CheckBox setItemsPerRow(int theValue)
          Items of a radioButton or a checkBox are organized in columns and rows.
 CheckBox setItemWidth(int theItemWidth)
          set the width of a radioButton/checkBox item.
 CheckBox setNoneSelectedAllowed(boolean theValue)
          In order to always have 1 item selected, use setNoneSelectedAllowed(false), by default this is true.
 CheckBox setSize(int theWidth, int theHeight)
           
 CheckBox setSize(processing.core.PImage theImage)
           
 CheckBox setSpacingColumn(int theSpacing)
          Sets the spacing in pixels between columns.
 CheckBox setSpacingRow(int theSpacing)
          Sets the spacing in pixels between rows.
 CheckBox showLabels()
           
 CheckBox toggle(int theIndex)
          toggle a single checkbox item by index
 void toggle(java.lang.String theName)
          deactivate a single checkbox item by name
 CheckBox toUpperCase(boolean theValue)
           
 
Methods inherited from class controlP5.ControlGroup
activateEvent, addCloseButton, addListener, controlEvent, getBackgroundHeight, getBarHeight, getInfo, hideBar, isBarVisible, listenerSize, mousePressed, removeCloseButton, removeListener, setBackgroundColor, setBackgroundHeight, setBarHeight, showBar, stringValue, toString, updateInternalEvents
 
Methods inherited from class controlP5.ControllerGroup
add, addCanvas, addDrawable, bringToFront, bringToFront, close, disableCollapse, enableCollapse, getAbsolutePosition, getAddress, getArrayValue, getCaptionLabel, getColor, getController, getHeight, getId, getName, getPosition, getProperty, getProperty, getStringValue, getTab, getValue, getValueLabel, getWidth, getWindow, hide, isCollapse, isMouseOver, isMoveable, isOpen, isUpdate, isVisible, moveTo, moveTo, moveTo, moveTo, moveTo, moveTo, moveTo, moveTo, moveTo, open, registerProperty, registerProperty, remove, remove, remove, removeCanvas, removeProperty, removeProperty, setAddress, setColor, setColorActive, setColorBackground, setColorForeground, setColorLabel, setColorValue, setGroup, setGroup, setHeight, setId, setLabel, setMouseOver, setMoveable, setOpen, setPosition, setPosition, setStringValue, setTab, setTab, setTab, setUpdate, setValue, setVisible, setWidth, show, 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
 

Method Detail

activate

public final CheckBox activate(int theIndex)
Activates a single checkbox item by index


activate

public final CheckBox activate(java.lang.String theName)
Activates a single checkbox item by name


activateAll

public final CheckBox activateAll()

addItem

public CheckBox addItem(java.lang.String theName,
                        float theValue)
Parameters:
theName -
theValue -
Returns:

addItem

public CheckBox addItem(Toggle theToggle,
                        float theValue)
Parameters:
theToggle -
theValue -
Returns:

deactivate

public final CheckBox deactivate(int theIndex)
deactivate a single checkbox item by index


deactivate

public final CheckBox deactivate(java.lang.String theName)
Deactivates a single checkbox item by name


deactivateAll

public CheckBox deactivateAll()

getItem

public Toggle getItem(int theIndex)
Gets a radio button item by index.

Parameters:
theIndex -
Returns:
Toggle

getItems

public java.util.List getItems()

getState

public boolean getState(int theIndex)
Gets the state of an item - this can be true (for on) or false (for off) - by index.

Parameters:
theIndex -
Returns:
boolean

getState

public boolean getState(java.lang.String theName)
Gets the state of an item - this can be true (for on) or false (for off) - by name.

Parameters:
theName -
Returns:

hideLabels

public CheckBox hideLabels()

plugTo

public CheckBox plugTo(java.lang.Object theObject)

removeItem

public CheckBox removeItem(java.lang.String theName)
Parameters:
theName -

setArrayValue

public CheckBox setArrayValue(float[] theArray)
Sets the value for all CheckBox items according to the values of the array passed on. 0 will turn off an item, any other value will turn it on.

Overrides:
setArrayValue in class ControllerGroup
Returns:
ControllerGroup

setColorLabels

public CheckBox setColorLabels(int theColor)

setImage

public CheckBox setImage(processing.core.PImage theImage)
Parameters:
theImage -

setImage

public CheckBox setImage(processing.core.PImage theImage,
                         int theState)
Parameters:
theImage -
theState - use Controller.DEFAULT (background), or Controller.OVER (foreground), or Controller.ACTIVE (active)
Returns:

setImages

public CheckBox setImages(processing.core.PImage theDefaultImage,
                          processing.core.PImage theOverImage,
                          processing.core.PImage theActiveImage)
Parameters:
theDefaultImage -
theOverImage -
theActiveImage -
Returns:
CheckBox

setItemHeight

public CheckBox setItemHeight(int theItemHeight)
set the height of a radioButton/checkBox item. by default the height is 11px. in order to recognize a custom height, the itemHeight has to be set before adding items to a radioButton/checkBox.

Parameters:
theItemHeight -

setItemsPerRow

public CheckBox setItemsPerRow(int theValue)
Items of a radioButton or a checkBox are organized in columns and rows. SetItemsPerRow sets the limit of items per row. items exceeding the limit will be pushed to the next row.

Parameters:
theValue -

setItemWidth

public CheckBox setItemWidth(int theItemWidth)
set the width of a radioButton/checkBox item. by default the width is 11px. in order to recognize a custom width, the itemWidth has to be set before adding items to a radioButton/checkBox.

Parameters:
theItemWidth -

setNoneSelectedAllowed

public CheckBox setNoneSelectedAllowed(boolean theValue)
In order to always have 1 item selected, use setNoneSelectedAllowed(false), by default this is true. setNoneSelectedAllowed does not apply when in multipleChoice mode.

Parameters:
theValue -

setSize

public CheckBox setSize(int theWidth,
                        int theHeight)

setSize

public CheckBox setSize(processing.core.PImage theImage)

setSpacingColumn

public CheckBox setSpacingColumn(int theSpacing)
Sets the spacing in pixels between columns.

Parameters:
theSpacing -

setSpacingRow

public CheckBox setSpacingRow(int theSpacing)
Sets the spacing in pixels between rows.

Parameters:
theSpacing -

showLabels

public CheckBox showLabels()

toggle

public final CheckBox toggle(int theIndex)
toggle a single checkbox item by index


toggle

public final void toggle(java.lang.String theName)
deactivate a single checkbox item by name


toUpperCase

public CheckBox toUpperCase(boolean theValue)


processing library controlP5 by Andreas Schlegel. (c) 2012