controlP5
Class RadioButton

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

public class RadioButton
extends ControlGroup

A radioButton is a list of toggles that can be turned on or off. radioButton is of type ControllerGroup, therefore a controllerPlug can't be set. this means that an event from a radioButton can't be forwarded to a method other than controlEvent in a sketch. a radioButton has 2 sets of values. radioButton.getValue() returns the value of the active radioButton item. radioButton.getArrayValue() returns a float array that represents the active (1) and inactive (0) items of a radioButton. ControlP5 CheckBox Toggle

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


import controlP5.*;

ControlP5 cp5;

int myColorBackground = color(0,0,0);

RadioButton r;

void setup() {
  size(700,400);
  
  cp5 = new ControlP5(this);
  r = cp5.addRadioButton("radioButton")
         .setPosition(20,160)
         .setSize(40,20)
         .setColorForeground(color(120))
         .setColorActive(color(255))
         .setColorLabel(color(255))
         .setItemsPerRow(5)
         .setSpacingColumn(50)
         .addItem("50",1)
         .addItem("100",2)
         .addItem("150",3)
         .addItem("200",4)
         .addItem("250",5)
         ;
     
     for(Toggle t:r.getItems()) {
       t.captionLabel().setColorBackground(color(255,80));
       t.captionLabel().style().moveMargin(-7,0,0,-3);
       t.captionLabel().style().movePadding(7,0,0,3);
       t.captionLabel().style().backgroundWidth = 45;
       t.captionLabel().style().backgroundHeight = 13;
     }
}


void draw() {
  background(myColorBackground);
}


void keyPressed() {
  switch(key) {
    case('0'): r.deactivateAll(); break;
    case('1'): r.activate(0); break;
    case('2'): r.activate(1); break;
    case('3'): r.activate(2); break;
    case('4'): r.activate(3); break;
    case('5'): r.activate(4); break;
  }
  
}

void controlEvent(ControlEvent theEvent) {
  if(theEvent.isFrom(r)) {
    print("got an event from "+theEvent.getName()+"\t");
    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
 RadioButton activate(int theIndex)
          Deactivates all active RadioButton items and only activates the item corresponding to theIndex.
 RadioButton activate(java.lang.String theName)
          Actives an item of the Radio button by name.
 RadioButton addItem(java.lang.String theName, float theValue)
           
 RadioButton addItem(Toggle theToggle, float theValue)
           
 RadioButton deactivate(int theIndex)
           
 RadioButton deactivate(java.lang.String theName)
          Deactivates a RadioButton by name and sets the value of the RadioButton to the default value -1.
 RadioButton deactivateAll()
           
 Toggle getItem(int theIndex)
          Gets a radio button item by index.
 Toggle getItem(java.lang.String theName)
           
 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.
 RadioButton hideLabels()
           
 RadioButton plugTo(java.lang.Object theObject)
           
 RadioButton plugTo(java.lang.Object theObject, java.lang.String thePlugName)
           
 RadioButton removeItem(java.lang.String theName)
           
 RadioButton setArrayValue(float[] theArray)
          Sets the value for all RadioButton items according to the values of the array passed on.
 RadioButton setColorLabels(int theColor)
           
 RadioButton setImage(processing.core.PImage theImage)
           
 RadioButton setImage(processing.core.PImage theImage, int theState)
           
 RadioButton setImages(processing.core.PImage theDefaultImage, processing.core.PImage theOverImage, processing.core.PImage theActiveImage)
           
 RadioButton setItemHeight(int theItemHeight)
          set the height of a radioButton/checkBox item.
 RadioButton setItemsPerRow(int theValue)
          Items of a radioButton or a checkBox are organized in columns and rows.
 RadioButton setItemWidth(int theItemWidth)
          set the width of a radioButton/checkBox item.
 RadioButton setNoneSelectedAllowed(boolean theValue)
          In order to always have 1 item selected, use setNoneSelectedAllowed(false), by default this is true.
 RadioButton setSize(int theWidth, int theHeight)
           
 RadioButton setSize(processing.core.PImage theImage)
           
 RadioButton setSpacingColumn(int theSpacing)
          Sets the spacing in pixels between columns.
 RadioButton setSpacingRow(int theSpacing)
          Sets the spacing in pixels between rows.
 RadioButton showLabels()
           
 RadioButton 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 RadioButton activate(int theIndex)
Deactivates all active RadioButton items and only activates the item corresponding to theIndex.

Parameters:
theIndex -

activate

public RadioButton activate(java.lang.String theName)
Actives an item of the Radio button by name.

Parameters:
theName -

addItem

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

addItem

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

deactivate

public RadioButton deactivate(int theIndex)
Parameters:
theIndex -

deactivate

public RadioButton deactivate(java.lang.String theName)
Deactivates a RadioButton by name and sets the value of the RadioButton to the default value -1.

Parameters:
theName -

deactivateAll

public RadioButton deactivateAll()

getItem

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

Parameters:
theIndex -
Returns:
Toggle

getItem

public Toggle getItem(java.lang.String theName)

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 RadioButton hideLabels()

plugTo

public RadioButton plugTo(java.lang.Object theObject)

plugTo

public RadioButton plugTo(java.lang.Object theObject,
                          java.lang.String thePlugName)

removeItem

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

setArrayValue

public RadioButton setArrayValue(float[] theArray)
Sets the value for all RadioButton 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 RadioButton setColorLabels(int theColor)

setImage

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

setImage

public RadioButton 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 RadioButton setImages(processing.core.PImage theDefaultImage,
                             processing.core.PImage theOverImage,
                             processing.core.PImage theActiveImage)
Parameters:
theDefaultImage -
theOverImage -
theActiveImage -
Returns:
RadioButton

setItemHeight

public RadioButton 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 RadioButton 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 RadioButton 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 RadioButton 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 RadioButton setSize(int theWidth,
                           int theHeight)

setSize

public RadioButton setSize(processing.core.PImage theImage)

setSpacingColumn

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

Parameters:
theSpacing -

setSpacingRow

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

Parameters:
theSpacing -

showLabels

public RadioButton showLabels()

toUpperCase

public RadioButton toUpperCase(boolean theValue)


processing library controlP5 by Andreas Schlegel. (c) 2012