Quantcast
Channel: Library Questions - Processing 2.x and 3.x Forum
Viewing all articles
Browse latest Browse all 2896

Accessing selected list elements from ControlP5 dropdown list

$
0
0

Hi guys,

What should I do to be able to print the relevant item? eg: I want the console to print out just the word 'ADD' or 'SUBTRACT' and so on. I want to later use this as part of a String Variable to pass into the default blendMode() function. That way I will be able to allow for user input/choice of blendMode. That way it would read as blendMode(ADD) or blendMode(SUBTRACT).

I tried getName(), etc but was not able to access it. Right now it prints:

1 {text=SUBTRACT, color=bg (0,45,90), fg (0,116,217), active (0,170,255), captionlabel (255,255,255), valuelabel (255,255,255), name=SUBTRACT, state=false, value=1, view=controlP5.ScrollableList$1@66a35419}

import controlP5.*;
import java.util.*;


ControlP5 cp5;

void setup() {
  size(400, 400);
  cp5 = new ControlP5(this);
  List l = Arrays.asList("ADD", "SUBTRACT", "DARKEST ", "LIGHTEST ", "DIFFERENCE", "EXCLUSION",
  "MULTIPLY", "SCREEN", "OVERLAY", "HARD_LIGHT", "SOFT_LIGHT", "DODGE", "BURN");
  /* add a ScrollableList, by default it behaves like a DropdownList */
  cp5.addScrollableList("dropdown")
    .setPosition(100, 100)
      .setSize(200, 100)
        .setBarHeight(20)
          .setItemHeight(20)
            .addItems(l)
              .setType(ScrollableList.DROPDOWN) // currently supported DROPDOWN and LIST
                ;
}

void draw() {
  background(240);
}

void dropdown(int n) {
  /* request the selected item based on index n */
  println(n, cp5.get(ScrollableList.class, "dropdown").getItem(n));

  //--------------------------------------------------------------------------------------------------------
  //MY NOTE: what should I do to be able to print the relevant item? eg: I want the console to print out
  // just the word Add or Subtract. I want to later use this as part of a String Variable to pass into
  // the default blendMode() function. That way I will be able to allow for user input/choice of blendMode.
  // right now it prints:

  // 1 {text=SUBTRACT, color=bg (0,45,90), fg (0,116,217), active (0,170,255), captionlabel (255,255,255),
  //valuelabel (255,255,255), name=SUBTRACT, state=false, value=1, view=controlP5.ScrollableList$1@66a35419}
  //--------------------------------------------------------------------------------------------------------


  /* here an item is stored as a Map  with the following key-value pairs:
   * name, the given name of the item
   * text, the given text of the item by default the same as name
   * value, the given value of the item, can be changed by using .getItem(n).put("value", "abc"); a value here is of type Object therefore can be anything
   * color, the given color of the item, how to change, see below
   * view, a customizable view, is of type CDrawable
   */

  //   CColor c = new CColor();
  //  c.setBackground(color(255,0,0));
  //  cp5.get(ScrollableList.class, "dropdown").getItem(n).put("color", c);
}


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

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

 Format:
 ClassName : returnType methodName(parameter type)


 controlP5.Controller : CColor getColor()
 controlP5.Controller : ControlBehavior getBehavior()
 controlP5.Controller : ControlWindow getControlWindow()
 controlP5.Controller : ControlWindow getWindow()
 controlP5.Controller : ControllerProperty getProperty(String)
 controlP5.Controller : ControllerProperty getProperty(String, String)
 controlP5.Controller : ControllerView getView()
 controlP5.Controller : Label getCaptionLabel()
 controlP5.Controller : Label getValueLabel()
 controlP5.Controller : List getControllerPlugList()
 controlP5.Controller : Pointer getPointer()
 controlP5.Controller : ScrollableList addCallback(CallbackListener)
 controlP5.Controller : ScrollableList addListener(ControlListener)
 controlP5.Controller : ScrollableList addListenerFor(int, CallbackListener)
 controlP5.Controller : ScrollableList align(int, int, int, int)
 controlP5.Controller : ScrollableList bringToFront()
 controlP5.Controller : ScrollableList bringToFront(ControllerInterface)
 controlP5.Controller : ScrollableList hide()
 controlP5.Controller : ScrollableList linebreak()
 controlP5.Controller : ScrollableList listen(boolean)
 controlP5.Controller : ScrollableList lock()
 controlP5.Controller : ScrollableList onChange(CallbackListener)
 controlP5.Controller : ScrollableList onClick(CallbackListener)
 controlP5.Controller : ScrollableList onDoublePress(CallbackListener)
 controlP5.Controller : ScrollableList onDrag(CallbackListener)
 controlP5.Controller : ScrollableList onDraw(ControllerView)
 controlP5.Controller : ScrollableList onEndDrag(CallbackListener)
 controlP5.Controller : ScrollableList onEnter(CallbackListener)
 controlP5.Controller : ScrollableList onLeave(CallbackListener)
 controlP5.Controller : ScrollableList onMove(CallbackListener)
 controlP5.Controller : ScrollableList onPress(CallbackListener)
 controlP5.Controller : ScrollableList onRelease(CallbackListener)
 controlP5.Controller : ScrollableList onReleaseOutside(CallbackListener)
 controlP5.Controller : ScrollableList onStartDrag(CallbackListener)
 controlP5.Controller : ScrollableList onWheel(CallbackListener)
 controlP5.Controller : ScrollableList plugTo(Object)
 controlP5.Controller : ScrollableList plugTo(Object, String)
 controlP5.Controller : ScrollableList plugTo(Object[])
 controlP5.Controller : ScrollableList plugTo(Object[], String)
 controlP5.Controller : ScrollableList registerProperty(String)
 controlP5.Controller : ScrollableList registerProperty(String, String)
 controlP5.Controller : ScrollableList registerTooltip(String)
 controlP5.Controller : ScrollableList removeBehavior()
 controlP5.Controller : ScrollableList removeCallback()
 controlP5.Controller : ScrollableList removeCallback(CallbackListener)
 controlP5.Controller : ScrollableList removeListener(ControlListener)
 controlP5.Controller : ScrollableList removeListenerFor(int, CallbackListener)
 controlP5.Controller : ScrollableList removeListenersFor(int)
 controlP5.Controller : ScrollableList removeProperty(String)
 controlP5.Controller : ScrollableList removeProperty(String, String)
 controlP5.Controller : ScrollableList setArrayValue(float[])
 controlP5.Controller : ScrollableList setArrayValue(int, float)
 controlP5.Controller : ScrollableList setBehavior(ControlBehavior)
 controlP5.Controller : ScrollableList setBroadcast(boolean)
 controlP5.Controller : ScrollableList setCaptionLabel(String)
 controlP5.Controller : ScrollableList setColor(CColor)
 controlP5.Controller : ScrollableList setColorActive(int)
 controlP5.Controller : ScrollableList setColorBackground(int)
 controlP5.Controller : ScrollableList setColorCaptionLabel(int)
 controlP5.Controller : ScrollableList setColorForeground(int)
 controlP5.Controller : ScrollableList setColorLabel(int)
 controlP5.Controller : ScrollableList setColorValue(int)
 controlP5.Controller : ScrollableList setColorValueLabel(int)
 controlP5.Controller : ScrollableList setDecimalPrecision(int)
 controlP5.Controller : ScrollableList setDefaultValue(float)
 controlP5.Controller : ScrollableList setHeight(int)
 controlP5.Controller : ScrollableList setId(int)
 controlP5.Controller : ScrollableList setImage(PImage)
 controlP5.Controller : ScrollableList setImage(PImage, int)
 controlP5.Controller : ScrollableList setImages(PImage, PImage, PImage)
 controlP5.Controller : ScrollableList setImages(PImage, PImage, PImage, PImage)
 controlP5.Controller : ScrollableList setLabel(String)
 controlP5.Controller : ScrollableList setLabelVisible(boolean)
 controlP5.Controller : ScrollableList setLock(boolean)
 controlP5.Controller : ScrollableList setMax(float)
 controlP5.Controller : ScrollableList setMin(float)
 controlP5.Controller : ScrollableList setMouseOver(boolean)
 controlP5.Controller : ScrollableList setMoveable(boolean)
 controlP5.Controller : ScrollableList setPosition(float, float)
 controlP5.Controller : ScrollableList setPosition(float[])
 controlP5.Controller : ScrollableList setSize(PImage)
 controlP5.Controller : ScrollableList setSize(int, int)
 controlP5.Controller : ScrollableList setStringValue(String)
 controlP5.Controller : ScrollableList setUpdate(boolean)
 controlP5.Controller : ScrollableList setValue(float)
 controlP5.Controller : ScrollableList setValueLabel(String)
 controlP5.Controller : ScrollableList setValueSelf(float)
 controlP5.Controller : ScrollableList setView(ControllerView)
 controlP5.Controller : ScrollableList setVisible(boolean)
 controlP5.Controller : ScrollableList setWidth(int)
 controlP5.Controller : ScrollableList show()
 controlP5.Controller : ScrollableList unlock()
 controlP5.Controller : ScrollableList unplugFrom(Object)
 controlP5.Controller : ScrollableList unplugFrom(Object[])
 controlP5.Controller : ScrollableList unregisterTooltip()
 controlP5.Controller : ScrollableList update()
 controlP5.Controller : ScrollableList updateSize()
 controlP5.Controller : String getAddress()
 controlP5.Controller : String getInfo()
 controlP5.Controller : String getName()
 controlP5.Controller : String getStringValue()
 controlP5.Controller : String toString()
 controlP5.Controller : Tab getTab()
 controlP5.Controller : boolean isActive()
 controlP5.Controller : boolean isBroadcast()
 controlP5.Controller : boolean isInside()
 controlP5.Controller : boolean isLabelVisible()
 controlP5.Controller : boolean isListening()
 controlP5.Controller : boolean isLock()
 controlP5.Controller : boolean isMouseOver()
 controlP5.Controller : boolean isMousePressed()
 controlP5.Controller : boolean isMoveable()
 controlP5.Controller : boolean isUpdate()
 controlP5.Controller : boolean isVisible()
 controlP5.Controller : float getArrayValue(int)
 controlP5.Controller : float getDefaultValue()
 controlP5.Controller : float getMax()
 controlP5.Controller : float getMin()
 controlP5.Controller : float getValue()
 controlP5.Controller : float[] getAbsolutePosition()
 controlP5.Controller : float[] getArrayValue()
 controlP5.Controller : float[] getPosition()
 controlP5.Controller : int getDecimalPrecision()
 controlP5.Controller : int getHeight()
 controlP5.Controller : int getId()
 controlP5.Controller : int getWidth()
 controlP5.Controller : int listenerSize()
 controlP5.Controller : void remove()
 controlP5.Controller : void setView(ControllerView, int)
 controlP5.ScrollableList : List getItems()
 controlP5.ScrollableList : Map getItem(String)
 controlP5.ScrollableList : Map getItem(int)
 controlP5.ScrollableList : ScrollableList addItem(String, Object)
 controlP5.ScrollableList : ScrollableList addItems(List)
 controlP5.ScrollableList : ScrollableList addItems(Map)
 controlP5.ScrollableList : ScrollableList addItems(String[])
 controlP5.ScrollableList : ScrollableList clear()
 controlP5.ScrollableList : ScrollableList close()
 controlP5.ScrollableList : ScrollableList open()
 controlP5.ScrollableList : ScrollableList removeItem(String)
 controlP5.ScrollableList : ScrollableList removeItems(List)
 controlP5.ScrollableList : ScrollableList setBackgroundColor(int)
 controlP5.ScrollableList : ScrollableList setBarHeight(int)
 controlP5.ScrollableList : ScrollableList setBarVisible(boolean)
 controlP5.ScrollableList : ScrollableList setItemHeight(int)
 controlP5.ScrollableList : ScrollableList setItems(List)
 controlP5.ScrollableList : ScrollableList setItems(Map)
 controlP5.ScrollableList : ScrollableList setItems(String[])
 controlP5.ScrollableList : ScrollableList setOpen(boolean)
 controlP5.ScrollableList : ScrollableList setScrollSensitivity(float)
 controlP5.ScrollableList : ScrollableList setType(int)
 controlP5.ScrollableList : boolean isBarVisible()
 controlP5.ScrollableList : boolean isOpen()
 controlP5.ScrollableList : int getBackgroundColor()
 controlP5.ScrollableList : int getBarHeight()
 controlP5.ScrollableList : int getHeight()
 controlP5.ScrollableList : void controlEvent(ControlEvent)
 controlP5.ScrollableList : void keyEvent(KeyEvent)
 controlP5.ScrollableList : void setDirection(int)
 controlP5.ScrollableList : void updateItemIndexOffset()
 java.lang.Object : String toString()
 java.lang.Object : boolean equals(Object)

 created: 2015/03/24 12:21:22

 */

Viewing all articles
Browse latest Browse all 2896

Trending Articles