public class ScrollableList extends Controller<ScrollableList> implements ControlListener
/**
* ControlP5 ScrollableList
*
* replaces DropdownList and and ListBox.
* List can be scrolled by dragging the list or using the scroll-wheel.
*
* by Andreas Schlegel, 2014
* www.sojamo.de/libraries/controlp5
*
*/
import controlP5.*;
import java.util.*;
ControlP5 cp5;
void setup() {
size(400, 400);
cp5 = new ControlP5(this);
List l = Arrays.asList("a", "b", "c", "d", "e", "f", "g", "h");
/* add a ScrollableList, by default it behaves like a DropdownList */
cp5.addScrollableList("dropdown").setPosition(100, 100).setSize(200, 100).setItemHeight(20).addItems(l);
}
void draw() {
background(240);
}
void dropdown(int n) {
println(n, cp5.get(ScrollableList.class, "dropdown").getItem(n).get("text"));
List l = Arrays.asList("a-1", "b-1", "c-1", "d-1", "e-1", "f-1", "g-1", "h-1", "i-1", "j-1", "k-1");
cp5.get(ScrollableList.class, "dropdown").setItems(l);
}
void keyPressed() {
switch(key) {
case('1'):
/* make the ScrollableList behave like a ListBox */
cp5.get(ScrollableList.class, "dropdown").setType(ControlP5.LIST);
break;
case('2'):
/* make the ScrollableList behave like a DropdownList */
cp5.get(ScrollableList.class, "dropdown").setType(ControlP5.DROPDOWN);
break;
}
}
Modifier and Type | Class and Description |
---|---|
static class |
ScrollableList.ScrollableListView |
Modifier and Type | Field and Description |
---|---|
static int |
CHECKBOX |
static int |
DROPDOWN |
static int |
LIST |
static int |
TREE |
autoHeight, autoSpacing, autoWidth
acceptClassList, ACTION_BROADCAST, ACTION_CLICK, ACTION_DRAG, ACTION_ENTER, ACTION_EXIT, ACTION_LEAVE, ACTION_MOVE, ACTION_PRESS, ACTION_PRESSED, ACTION_RELEASE, ACTION_RELEASED, ACTION_RELEASEDOUTSIDE, ACTION_WHEEL, ACTIVE, ALL, ALT, AQUA, ARC, ARRAY, BACKSPACE, BASELINE, BITFONT, BLACK, BLUE, BOOLEAN, BOTTOM, BOTTOM_OUTSIDE, CAPTIONLABEL, CENTER, COMMANDKEY, CONTROL, controlEventClass, CUSTOM, DECREASE, DEFAULT, DELETE, DONE, DOWN, ELLIPSE, ENTER, ESCAPE, EVENT, eventMethod, FADEIN, FADEOUT, FIELD, FLOAT, FUCHSIA, GRAY, GREEN, grixel, HALF_PI, HIDE, HIGHLIGHT, HORIZONTAL, IDLE, IMAGE, INACTIVE, INCREASE, INTEGER, INVALID, J2D, KEYCONTROL, LEFT, LEFT_OUTSIDE, LIME, LINE, LOAD, MAROON, MENU, METHOD, MOVE, MULTI, MULTIPLES, NAVY, OLIVE, ORANGE, OVER, P2D, P3D, PI, PRESSED, PRINT, PURPLE, RED, RELEASE, RESET, RIGHT, RIGHT_OUTSIDE, SAVE, SHIFT, SILVER, SINGLE, SINGLE_COLUMN, SINGLE_ROW, SPRITE, standard56, standard58, STRING, SWITCH, SWITCH_BACK, SWITCH_FORE, synt24, TAB, TEAL, THEME_A, THEME_CP52014, THEME_CP5BLUE, THEME_RED, THEME_RETRO, THEME_WHITE, TOP, TOP_OUTSIDE, TRANSITION_WAIT_FADEIN, TWO_PI, UP, VALUELABEL, VERBOSE, VERTICAL, WAIT, WHITE, YELLOW
Constructor and Description |
---|
ScrollableList(ControlP5 theControlP5,
java.lang.String theName) |
Modifier and Type | Method and Description |
---|---|
java.util.Map<java.lang.String,java.lang.Object> |
addItem(java.lang.String theName,
java.lang.Object theValue)
Adds an item to the ScrollableList.
|
ScrollableList |
addItems(java.util.List<?> theItems) |
ScrollableList |
addItems(java.util.List<?> theItems,
int theOffset) |
ScrollableList |
addItems(java.lang.String[] theItems)
adds a list of items from a string array.
|
ScrollableList |
clear() |
void |
controlEvent(ControlEvent theEvent)
controlEvent is called by controlP5's ControlBroadcaster to inform available listeners about
value changes.
|
int |
getBackgroundColor() |
int |
getHeight() |
java.util.Map<java.lang.String,java.lang.Object> |
getItem(int theIndex)
returns a listBoxItem by index form the list of
items.
|
java.util.Map<java.lang.String,java.lang.Object> |
getItem(java.lang.String theItemName)
TODO faulty returns a listBoxItem by name.
|
java.util.List |
getItems() |
boolean |
isBarVisible() |
boolean |
isOpen() |
void |
keyEvent(processing.event.KeyEvent theKeyEvent) |
ScrollableList |
removeItem(java.lang.String theItemName)
Removes an item from the ScrollableList using the
unique name of the item given when added to the list.
|
ScrollableList |
setBackgroundColor(int theColor) |
ScrollableList |
setBarHeight(int theHeight) |
ScrollableList |
setBarVisible(boolean b) |
void |
setDirection(int theDirection) |
ScrollableList |
setItemHeight(int theHeight) |
ScrollableList |
setItems(java.util.List<?> theItems) |
ScrollableList |
setItems(java.util.List<?> theItems,
int theOffset) |
ScrollableList |
setItems(java.lang.String[] theItems) |
ScrollableList |
setOpen(boolean b) |
ScrollableList |
setScrollSensitivity(float theSensitivity) |
ScrollableList |
setType(int theType) |
ScrollableList |
updateDisplayMode(int theMode) |
add, addCallback, addListener, align, bringToFront, bringToFront, changeValue, continuousUpdateEvents, draw, getAbsolutePosition, getAddress, getArrayValue, getArrayValue, getBehavior, getCaptionLabel, getColor, getControllerPlugList, getControlWindow, getDecimalPrecision, getDefaultValue, getId, getInfo, getLabel, getMax, getMin, getName, getParent, getPickingColor, getPointer, getPosition, getProperty, getProperty, getStringValue, getTab, getValue, getValueLabel, getView, getWidth, getWindow, hide, init, isActive, isBroadcast, isInside, isLabelVisible, isListening, isLock, isMouseOver, isMousePressed, isMoveable, isUpdate, isUserInteraction, isVisible, linebreak, listen, listenerSize, lock, moveTo, moveTo, moveTo, moveTo, moveTo, moveTo, moveTo, moveTo, moveTo, plugTo, plugTo, plugTo, plugTo, registerProperty, registerProperty, registerTooltip, remove, remove, removeBehavior, removeCallback, removeCallback, removeListener, removeProperty, removeProperty, setAbsolutePosition, setAddress, setArrayValue, setArrayValue, setBehavior, setBroadcast, setCaptionLabel, setColor, setColorActive, setColorBackground, setColorCaptionLabel, setColorForeground, setColorValueLabel, setDecimalPrecision, setDefaultValue, setGroup, setGroup, setHeight, setId, setImage, setImage, setImages, setImages, setImages, setLabelVisible, setLock, setMax, setMin, setMouseOver, setMousePressed, setMoveable, setParent, setPosition, setPosition, setSize, setSize, setStringValue, setTab, setTab, setUpdate, setUserInteraction, setValue, setValueLabel, setValueSelf, setView, setView, setVisible, setWidth, show, toString, unlock, unplugFrom, unplugFrom, unregisterTooltip, update, updateAbsolutePosition, updateEvents, updateInternalEvents, updateSize
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
parent, setColorLabel, setColorValue, setLabel
public static final int CHECKBOX
public static final int DROPDOWN
public static final int LIST
public static final int TREE
public ScrollableList(ControlP5 theControlP5, java.lang.String theName)
public java.util.Map<java.lang.String,java.lang.Object> addItem(java.lang.String theName, java.lang.Object theValue)
theName
- StringtheValue
- intcontrolP5.ListBox#removeItem(String,int)
public ScrollableList addItems(java.util.List<?> theItems)
public ScrollableList addItems(java.util.List<?> theItems, int theOffset)
public ScrollableList addItems(java.lang.String[] theItems)
theItems
- public ScrollableList clear()
public void controlEvent(ControlEvent theEvent)
ControlListener
controlEvent
in interface ControlListener
theEvent
- ControlEventCallbackListener
,
CallbackEvent
public int getBackgroundColor()
public int getHeight()
getHeight
in interface ControllerInterface<ScrollableList>
getHeight
in class Controller<ScrollableList>
public java.util.Map<java.lang.String,java.lang.Object> getItem(int theIndex)
theIndex
- public java.util.Map<java.lang.String,java.lang.Object> getItem(java.lang.String theItemName)
theItemName
- public java.util.List getItems()
public boolean isBarVisible()
public boolean isOpen()
public void keyEvent(processing.event.KeyEvent theKeyEvent)
keyEvent
in interface ControllerInterface<ScrollableList>
keyEvent
in class Controller<ScrollableList>
public ScrollableList removeItem(java.lang.String theItemName)
theItemName
- StringListBox.addItem(String,int)
public ScrollableList setBackgroundColor(int theColor)
public ScrollableList setBarHeight(int theHeight)
public ScrollableList setBarVisible(boolean b)
public void setDirection(int theDirection)
public ScrollableList setItemHeight(int theHeight)
public ScrollableList setItems(java.util.List<?> theItems)
public ScrollableList setItems(java.util.List<?> theItems, int theOffset)
public ScrollableList setItems(java.lang.String[] theItems)
public ScrollableList setOpen(boolean b)
public ScrollableList setScrollSensitivity(float theSensitivity)
public ScrollableList setType(int theType)
public ScrollableList updateDisplayMode(int theMode)
processing library controlP5 by Andreas Schlegel. (c) 2006-2014