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:
CheckBox

public class RadioButton
extends ControlGroup

a radio button implementation. 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.value() returns the value of the active radioButton item. radioButton.arrayValue() returns a float array that represents the active (1) and inactive (0) items of a radioButton. ControlP5 CheckBox Toggle

+Example
/**
 * ControlP5 RadioButton
 * by andreas schlegel, 2009
 */

import controlP5.*;

ControlP5 controlP5;

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

RadioButton r;
void setup() {
  size(400,400);
  smooth();
  controlP5 = new ControlP5(this);
  r = controlP5.addRadioButton("radioButton",20,160);
  r.setColorForeground(color(120));
  r.setColorActive(color(255));
  r.setColorLabel(color(255));
  r.setItemsPerRow(5);
  r.setSpacingColumn(50);

  addToRadioButton(r,"50",1);
  addToRadioButton(r,"100",2);
  addToRadioButton(r,"150",3);
  addToRadioButton(r,"200",4);
  addToRadioButton(r,"250",5);
}


void addToRadioButton(RadioButton theRadioButton, String theName, int theValue ) {
  Toggle t = theRadioButton.addItem(theName,theValue);
  t.captionLabel().setColorBackground(color(80));
  t.captionLabel().style().movePadding(2,0,-1,2);
  t.captionLabel().style().moveMargin(-2,0,0,-3);
  t.captionLabel().style().backgroundWidth = 46;
}


void draw() {
  background(myColorBackground);
}


void keyPressed() {
  if(key==' ') {
    r.deactivateAll();
  } else if (key=='a') {
    r.activate("50");
  } else if(key>='0' && key<'5') {
    // convert a key-number (48-52) to an int between 0 and 4
    int n = int(key)-48;
    r.activate(n);
  }
}

void controlEvent(ControlEvent theEvent) {
  print("got an event from "+theEvent.group().name()+"\t");
  for(int i=0;i

Field Summary
 
Fields inherited from interface controlP5.ControlP5Constants
acceptClassList, ACTIVE, ALT, ARC, ARRAY, BACKSPACE, BOOLEAN, BOTTOM, CENTER, CONTROL, controlEventClass, CUSTOM, DECREASE, DEFAULT, DELETE, DOWN, ELLIPSE, ENTER, ESCAPE, EVENT, eventMethod, FIELD, FLOAT, HALF_PI, HIDE, HIGHLIGHT, HORIZONTAL, IMAGE, INCREASE, INTEGER, INVALID, KEYCONTROL, LEFT, LINE, LOAD, MENU, METHOD, MOVE, OVER, PI, PRESSED, PRINT, RELEASE, RESET, RIGHT, SAVE, SHIFT, SPRITE, STRING, SWITCH, SWITCH_BACK, SWITCH_FORE, TAB, TOP, TWO_PI, UP, VERBOSE, VERTICAL
 
Constructor Summary
RadioButton(ControlP5 theControlP5, ControllerGroup theParent, java.lang.String theName, int theX, int theY)
           
 
Method Summary
 void activate(int theIndex)
          deactivate the currently active radio button and make a new radio button active.
 void activate(java.lang.String theRadioButtonName)
          active an item of the Radio button by name.
 Toggle addItem(java.lang.String theName, float theValue)
          add items to a radioButton/checkBox.
 Toggle addItem(Toggle theToggle, float theValue)
          add items to a radioButton/checkBox.
 void controlEvent(ControlEvent theEvent)
          controlEvent is called whenever a radioButton item is (de-)activated.
 void deactivate(int theIndex)
          deactivate a radio button.
 void deactivate(java.lang.String theRadioButtonName)
          deactivate a RadioButton and set the value of the radio controller to the default value (-1).
 void deactivateAll()
          deactivate all radioButton items.
 Toggle getItem(int theIndex)
          get an item from the list of toggles by index.
 boolean getState(int theIndex)
          get the state of a checkBox item - which can be true (for on) and false (for off).
 boolean getState(java.lang.String theRadioButtonName)
          get the state of a checkBox item - which can be true (for on) and false (for off).
 void removeItem(java.lang.String theName)
          remove an item from the radioButton/checkBox list.
 processing.core.PImage setImage(processing.core.PImage theImage)
          Controller.DEFAULT (background) Controller.OVER (foreground) Controller.ACTIVE (active)
 processing.core.PImage setImage(processing.core.PImage theImage, int theState)
           
 RadioButton setImages(processing.core.PImage theImage1, processing.core.PImage theImage2, processing.core.PImage theImage3)
           
 void setItemHeight(int theItemHeight)
          set the height of a radioButton/checkBox item.
 void setItemsPerRow(int theValue)
          items for a radioButton or a checkBox are organized in columns and rows.
 void setItemWidth(int theItemWidth)
          set the width of a radioButton/checkBox item.
 void setNoneSelectedAllowed(boolean theValue)
          in order to always have 1 item selected, use setNoneSelectedAllowed(false).
 void setSize(int theWidth, int theHeight)
           
 void setSize(processing.core.PImage theImage)
           
 void setSpacingColumn(int theSpacing)
          set the (pixel) spacing between columns.
 void setSpacingRow(int theSpacing)
          set the (pixel) spacing between rows.
 void toggle(int theIndex)
           
 java.lang.String toString()
           
 void updateLayout()
           
 
Methods inherited from class controlP5.ControlGroup
activateEvent, addCloseButton, addToXMLElement, arrayValue, getBackgroundHeight, hideBar, isBarVisible, mousePressed, removeCloseButton, setArrayValue, setBackgroundColor, setBackgroundHeight, setBarHeight, showBar, stringValue, value
 
Methods inherited from class controlP5.ControllerGroup
absolutePosition, add, addCanvas, addDrawable, captionLabel, close, color, continuousUpdateEvents, controller, disableCollapse, draw, enableCollapse, getAsXML, getColor, getHeight, getPickingColor, getTab, getWidth, getWindow, hide, id, init, isCollapse, isMoveable, isOpen, isUpdate, isVisible, isXMLsavable, keyEvent, moveTo, moveTo, moveTo, moveTo, moveTo, moveTo, moveTo, moveTo, name, open, parent, position, remove, remove, remove, removeCanvas, setColorActive, setColorBackground, setColorForeground, setColorLabel, setColorValue, setGroup, setGroup, setHeight, setId, setLabel, setMousePressed, setMoveable, setOpen, setPosition, setTab, setTab, setTab, setUpdate, setVisible, setWidth, show, update, updateAbsolutePosition, updateEvents, updateInternalEvents, valueLabel
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

RadioButton

public RadioButton(ControlP5 theControlP5,
                   ControllerGroup theParent,
                   java.lang.String theName,
                   int theX,
                   int theY)
Method Detail

addItem

public Toggle addItem(java.lang.String theName,
                      float theValue)
add items to a radioButton/checkBox. items are of type Toggle.

Parameters:
theName -
theValue -
Returns:

addItem

public Toggle addItem(Toggle theToggle,
                      float theValue)
add items to a radioButton/checkBox. items are of type Toggle.

Parameters:
theToggle -
theValue -
Returns:

removeItem

public void removeItem(java.lang.String theName)
remove an item from the radioButton/checkBox list. The item is identified by name.

Parameters:
theName -

setImages

public RadioButton setImages(processing.core.PImage theImage1,
                             processing.core.PImage theImage2,
                             processing.core.PImage theImage3)

setImage

public processing.core.PImage setImage(processing.core.PImage theImage)
Controller.DEFAULT (background) Controller.OVER (foreground) Controller.ACTIVE (active)

Parameters:
theImage -

setImage

public processing.core.PImage setImage(processing.core.PImage theImage,
                                       int theState)

setSize

public void setSize(processing.core.PImage theImage)

setSize

public void setSize(int theWidth,
                    int theHeight)

setItemHeight

public void 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 -

setItemWidth

public void 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 -

getItem

public Toggle getItem(int theIndex)
get an item from the list of toggles by index.

Parameters:
theIndex -
Returns:

getState

public boolean getState(int theIndex)
get the state of a checkBox item - which can be true (for on) and false (for off). Identifier is the name of the checkBox item.

Parameters:
theIndex -
Returns:

getState

public boolean getState(java.lang.String theRadioButtonName)
get the state of a checkBox item - which can be true (for on) and false (for off). Identifier is the name of the checkBox item.

Parameters:
theRadioButtonName -
Returns:

updateLayout

public void updateLayout()

setItemsPerRow

public void setItemsPerRow(int theValue)
items for 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 nxt row.

Parameters:
theValue -

setSpacingColumn

public void setSpacingColumn(int theSpacing)
set the (pixel) spacing between columns.

Parameters:
theSpacing -

setSpacingRow

public void setSpacingRow(int theSpacing)
set the (pixel) spacing between rows.

Parameters:
theSpacing -

deactivateAll

public void deactivateAll()
deactivate all radioButton items.


activate

public void activate(int theIndex)
deactivate the currently active radio button and make a new radio button active.

Parameters:
theIndex -

deactivate

public void deactivate(int theIndex)
deactivate a radio button. the radio button must be active before deactivating to trigger an event.

Parameters:
theIndex -

activate

public void activate(java.lang.String theRadioButtonName)
active an item of the Radio button by name.

Parameters:
theRadioButtonName -

deactivate

public void deactivate(java.lang.String theRadioButtonName)
deactivate a RadioButton and set the value of the radio controller to the default value (-1).

Parameters:
theRadioButtonName -

toggle

public void toggle(int theIndex)

controlEvent

public void controlEvent(ControlEvent theEvent)
controlEvent is called whenever a radioButton item is (de-)activated. this happens internally.

Specified by:
controlEvent in interface ControlListener
Overrides:
controlEvent in class ControlGroup
Parameters:
theEvent - ControlEvent Controller

setNoneSelectedAllowed

public void setNoneSelectedAllowed(boolean theValue)
in order to always have 1 item selected, use setNoneSelectedAllowed(false). the default value is true. this does not apply to the multipleChoice mode.

Parameters:
theValue -

toString

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


processing library controlP5 by Andreas Schlegel. (c) 2010