public class Textarea extends ControllerGroup<Textarea> implements ControlListener
/**
* ControlP5 Textarea
*
*
* find a list of public methods available for the Textarea Controller
* at the bottom of this sketch.
*
* by Andreas Schlegel, 2012
* www.sojamo.de/libraries/controlp5
*
*/
import controlP5.*;
ControlP5 cp5;
Textarea myTextarea;
void setup() {
size(700,400);
cp5 = new ControlP5(this);
myTextarea = cp5.addTextarea("txt")
.setPosition(100,100)
.setSize(200,200)
.setFont(createFont("arial",12))
.setLineHeight(14)
.setColor(color(128))
.setColorBackground(color(255,100))
.setColorForeground(color(255,100));
;
myTextarea.setText("Lorem Ipsum is simply dummy text of the printing and typesetting"
+" industry. Lorem Ipsum has been the industry's standard dummy text"
+" ever since the 1500s, when an unknown printer took a galley of type"
+" and scrambled it to make a type specimen book. It has survived not"
+" only five centuries, but also the leap into electronic typesetting,"
+" remaining essentially unchanged. It was popularised in the 1960s"
+" with the release of Letraset sheets containing Lorem Ipsum passages,"
+" and more recently with desktop publishing software like Aldus"
+" PageMaker including versions of Lorem Ipsum."
);
cp5.addSlider("changeWidth")
.setRange(100,400)
.setValue(200)
.setPosition(100,20)
.setSize(100,19)
;
cp5.addSlider("changeHeight")
.setRange(100,400)
.setValue(200)
.setPosition(100,40)
.setSize(100,19)
;
}
void keyPressed() {
if(key=='r') {
myTextarea.setText("Lorem ipsum dolor sit amet, consectetur adipiscing elit."
+" Quisque sed velit nec eros scelerisque adipiscing vitae eu sem."
+" Quisque malesuada interdum lectus. Pellentesque pellentesque molestie"
+" vestibulum. Maecenas ultricies, neque at porttitor lacinia, tellus enim"
+" suscipit tortor, ut dapibus orci lorem non ipsum. Mauris ut velit velit."
+" Fusce at purus in augue semper tincidunt imperdiet sit amet eros."
+" Vestibulum nunc diam, fringilla vitae tristique ut, viverra ut felis."
+" Proin aliquet turpis ornare leo aliquam dapibus. Integer dui nisi, condimentum"
+" ut sagittis non, fringilla vestibulum sapien. Sed ullamcorper libero et massa"
+" congue in facilisis mauris lobortis. Fusce cursus risus sit amet leo imperdiet"
+" lacinia faucibus turpis tempus. Pellentesque pellentesque augue sed purus varius"
+" sed volutpat dui rhoncus. Lorem ipsum dolor sit amet, consectetur adipiscing elit"
);
} else if(key=='c') {
myTextarea.setColor(0xffffffff);
}
}
void draw() {
background(0);
if(keyPressed && key==' ') {
myTextarea.scroll((float)mouseX/(float)width);
}
if(keyPressed && key=='l') {
myTextarea.setLineHeight(mouseY);
}
}
void changeWidth(int theValue) {
myTextarea.setWidth(theValue);
}
void changeHeight(int theValue) {
myTextarea.setHeight(theValue);
}
/*
a list of all methods available for the Textarea Controller
use ControlP5.printPublicMethodsFor(Textarea.class);
to print the following list into the console.
You can find further details about class Textarea in the javadoc.
Format:
ClassName : returnType methodName(parameter type)
controlP5.ControllerGroup : CColor getColor()
controlP5.ControllerGroup : Canvas addCanvas(Canvas)
controlP5.ControllerGroup : ControlWindow getWindow()
controlP5.ControllerGroup : Controller getController(String)
controlP5.ControllerGroup : ControllerProperty getProperty(String)
controlP5.ControllerGroup : ControllerProperty getProperty(String, String)
controlP5.ControllerGroup : Label getCaptionLabel()
controlP5.ControllerGroup : Label getValueLabel()
controlP5.ControllerGroup : String getAddress()
controlP5.ControllerGroup : String getInfo()
controlP5.ControllerGroup : String getName()
controlP5.ControllerGroup : String getStringValue()
controlP5.ControllerGroup : String toString()
controlP5.ControllerGroup : Tab getTab()
controlP5.ControllerGroup : Textarea add(ControllerInterface)
controlP5.ControllerGroup : Textarea addListener(ControlListener)
controlP5.ControllerGroup : Textarea bringToFront()
controlP5.ControllerGroup : Textarea bringToFront(ControllerInterface)
controlP5.ControllerGroup : Textarea close()
controlP5.ControllerGroup : Textarea disableCollapse()
controlP5.ControllerGroup : Textarea enableCollapse()
controlP5.ControllerGroup : Textarea hide()
controlP5.ControllerGroup : Textarea hideArrow()
controlP5.ControllerGroup : Textarea hideBar()
controlP5.ControllerGroup : Textarea moveTo(ControlWindow)
controlP5.ControllerGroup : Textarea moveTo(PApplet)
controlP5.ControllerGroup : Textarea open()
controlP5.ControllerGroup : Textarea registerProperty(String)
controlP5.ControllerGroup : Textarea registerProperty(String, String)
controlP5.ControllerGroup : Textarea remove(CDrawable)
controlP5.ControllerGroup : Textarea remove(ControllerInterface)
controlP5.ControllerGroup : Textarea removeCanvas(Canvas)
controlP5.ControllerGroup : Textarea removeListener(ControlListener)
controlP5.ControllerGroup : Textarea removeProperty(String)
controlP5.ControllerGroup : Textarea removeProperty(String, String)
controlP5.ControllerGroup : Textarea setAddress(String)
controlP5.ControllerGroup : Textarea setArrayValue(float[])
controlP5.ControllerGroup : Textarea setArrayValue(int, float)
controlP5.ControllerGroup : Textarea setCaptionLabel(String)
controlP5.ControllerGroup : Textarea setColor(CColor)
controlP5.ControllerGroup : Textarea setColorActive(int)
controlP5.ControllerGroup : Textarea setColorBackground(int)
controlP5.ControllerGroup : Textarea setColorForeground(int)
controlP5.ControllerGroup : Textarea setColorLabel(int)
controlP5.ControllerGroup : Textarea setColorValue(int)
controlP5.ControllerGroup : Textarea setHeight(int)
controlP5.ControllerGroup : Textarea setId(int)
controlP5.ControllerGroup : Textarea setLabel(String)
controlP5.ControllerGroup : Textarea setMouseOver(boolean)
controlP5.ControllerGroup : Textarea setMoveable(boolean)
controlP5.ControllerGroup : Textarea setOpen(boolean)
controlP5.ControllerGroup : Textarea setPosition(float, float)
controlP5.ControllerGroup : Textarea setPosition(float[])
controlP5.ControllerGroup : Textarea setSize(int, int)
controlP5.ControllerGroup : Textarea setStringValue(String)
controlP5.ControllerGroup : Textarea setTitle(String)
controlP5.ControllerGroup : Textarea setUpdate(boolean)
controlP5.ControllerGroup : Textarea setValue(float)
controlP5.ControllerGroup : Textarea setVisible(boolean)
controlP5.ControllerGroup : Textarea setWidth(int)
controlP5.ControllerGroup : Textarea show()
controlP5.ControllerGroup : Textarea showArrow()
controlP5.ControllerGroup : Textarea showBar()
controlP5.ControllerGroup : Textarea update()
controlP5.ControllerGroup : Textarea updateAbsolutePosition()
controlP5.ControllerGroup : boolean isBarVisible()
controlP5.ControllerGroup : boolean isCollapse()
controlP5.ControllerGroup : boolean isMouseOver()
controlP5.ControllerGroup : boolean isMoveable()
controlP5.ControllerGroup : boolean isOpen()
controlP5.ControllerGroup : boolean isUpdate()
controlP5.ControllerGroup : boolean isVisible()
controlP5.ControllerGroup : boolean setMousePressed(boolean)
controlP5.ControllerGroup : float getArrayValue(int)
controlP5.ControllerGroup : float getValue()
controlP5.ControllerGroup : float[] getArrayValue()
controlP5.ControllerGroup : float[] getPosition()
controlP5.ControllerGroup : int getHeight()
controlP5.ControllerGroup : int getId()
controlP5.ControllerGroup : int getWidth()
controlP5.ControllerGroup : int listenerSize()
controlP5.ControllerGroup : void controlEvent(ControlEvent)
controlP5.ControllerGroup : void remove()
controlP5.Textarea : Label getValueLabel()
controlP5.Textarea : String getStringValue()
controlP5.Textarea : String getText()
controlP5.Textarea : Textarea append(String)
controlP5.Textarea : Textarea append(String, int)
controlP5.Textarea : Textarea clear()
controlP5.Textarea : Textarea disableColorBackground()
controlP5.Textarea : Textarea enableColorBackground()
controlP5.Textarea : Textarea hideScrollbar()
controlP5.Textarea : Textarea scroll(float)
controlP5.Textarea : Textarea setBorderColor(int)
controlP5.Textarea : Textarea setColor(int)
controlP5.Textarea : Textarea setColorBackground(int)
controlP5.Textarea : Textarea setFont(ControlFont)
controlP5.Textarea : Textarea setFont(PFont)
controlP5.Textarea : Textarea setFont(int)
controlP5.Textarea : Textarea setHeight(int)
controlP5.Textarea : Textarea setLineHeight(int)
controlP5.Textarea : Textarea setScrollActive(int)
controlP5.Textarea : Textarea setScrollBackground(int)
controlP5.Textarea : Textarea setScrollForeground(int)
controlP5.Textarea : Textarea setSize(int, int)
controlP5.Textarea : Textarea setText(String)
controlP5.Textarea : Textarea setWidth(int)
controlP5.Textarea : Textarea showScrollbar()
controlP5.Textarea : boolean isScrollable()
controlP5.Textarea : float getValue()
controlP5.Textarea : void controlEvent(ControlEvent)
java.lang.Object : String toString()
java.lang.Object : boolean equals(Object)
created: 2015/03/24 12:21:29
*/
acceptClassList, ACTION_BROADCAST, ACTION_CLICK, ACTION_DOUBLE_PRESS, ACTION_DRAG, ACTION_END_DRAG, ACTION_ENTER, ACTION_EXIT, ACTION_LEAVE, ACTION_MOVE, ACTION_PRESS, ACTION_PRESSED, ACTION_RELEASE, ACTION_RELEASE_OUTSIDE, ACTION_RELEASED, ACTION_RELEASEDOUTSIDE, ACTION_START_DRAG, ACTION_WHEEL, ACTIVE, ALL, ALT, AQUA, ARC, ARRAY, BACKSPACE, BASELINE, BITFONT, BLACK, BLUE, BOOLEAN, BOTTOM, BOTTOM_OUTSIDE, CAPTIONLABEL, CENTER, CHECKBOX, COMMANDKEY, CONTROL, controlEventClass, CUSTOM, DECREASE, DEFAULT, DELETE, delimiter, DONE, DOWN, DROPDOWN, 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, JSON, KEYCONTROL, LEFT, LEFT_OUTSIDE, LIME, LINE, LIST, LOAD, MAROON, MENU, METHOD, MOVE, MULTI, MULTIPLES, NAVY, OLIVE, ORANGE, OVER, P2D, P3D, pathdelimiter, PI, PRESS, PRESSED, PRINT, PURPLE, RED, RELEASE, RELEASED, RESET, RIGHT, RIGHT_OUTSIDE, SAVE, SERIALIZED, 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_GREY, THEME_RED, THEME_RETRO, TOP, TOP_OUTSIDE, TRANSITION_WAIT_FADEIN, TREE, TWO_PI, UP, VALUELABEL, VERBOSE, VERTICAL, WAIT, WHITE, YELLOW
Constructor and Description |
---|
Textarea(ControlP5 theControlP5,
java.lang.String theName)
Convenience constructor to extend Textarea.
|
Textarea(java.lang.String theText,
int theX,
int theY) |
Modifier and Type | Method and Description |
---|---|
Textarea |
append(java.lang.String theText) |
Textarea |
append(java.lang.String theText,
int max) |
Textarea |
clear() |
void |
controlEvent(ControlEvent theEvent)
controlEvent is called by controlP5's ControlBroadcaster to inform available listeners about
value changes.
|
Textarea |
disableColorBackground() |
Textarea |
enableColorBackground() |
float |
getScrollPosition() |
java.lang.String |
getStringValue() |
java.lang.String |
getText()
returns the text content of the textarea.
|
float |
getValue() |
Label |
getValueLabel()
returns the instance of the textarea's label.
|
Textarea |
hideScrollbar() |
boolean |
isScrollable() |
Textarea |
scroll(float theValue)
scroll the Textarea remotely.
|
void |
scrolled(int theStep) |
Textarea |
setBorderColor(int theColor) |
Textarea |
setColor(int theColor)
set the text color of the textarea.
|
Textarea |
setColorBackground(int theColor) |
Textarea |
setFont(ControlFont theFont) |
Textarea |
setFont(int theFontIndex) |
Textarea |
setFont(processing.core.PFont thePFont) |
Textarea |
setHeight(int theValue)
set the height of the textarea.
|
Textarea |
setLineHeight(int theLineHeight)
set the lineheight of the textarea.
|
Textarea |
setScrollActive(int theColor) |
Textarea |
setScrollBackground(int theColor) |
Textarea |
setScrollForeground(int theColor) |
Textarea |
setSize(int theWidth,
int theHeight) |
Textarea |
setText(java.lang.String theText)
set the text of the textarea.
|
Textarea |
setWidth(int theValue)
set the width of the textarea.
|
Textarea |
showScrollbar() |
java.lang.String |
stringValue()
Deprecated.
|
float |
value()
Deprecated.
|
Label |
valueLabel()
Deprecated.
|
add, addCanvas, addCloseButton, addDrawable, addListener, bringToFront, bringToFront, close, continuousUpdateEvents, disableCollapse, draw, enableCollapse, getAbsolutePosition, getAddress, getArrayValue, getArrayValue, getCaptionLabel, getColor, getController, getHeight, getId, getInfo, getName, getParent, getPickingColor, getPosition, getProperty, getProperty, getTab, getWidth, getWindow, hide, hideArrow, hideBar, init, isBarVisible, isCollapse, isMouseOver, isMoveable, isOpen, isUpdate, isVisible, keyEvent, listenerSize, moveTo, moveTo, moveTo, moveTo, moveTo, moveTo, moveTo, moveTo, moveTo, open, registerProperty, registerProperty, remove, remove, remove, removeCanvas, removeCloseButton, removeListener, removeProperty, removeProperty, set, setAbsolutePosition, setAddress, setArrayValue, setArrayValue, setCaptionLabel, setColor, setColorActive, setColorForeground, setColorLabel, setColorValue, setGroup, setGroup, setId, setLabel, setMouseOver, setMousePressed, setMoveable, setOpen, setPosition, setPosition, setStringValue, setTab, setTab, setTab, setTitle, setUpdate, setValue, setVisible, show, showArrow, showBar, toString, update, updateAbsolutePosition, updateEvents, updateInternalEvents, x, y
public Textarea(ControlP5 theControlP5, java.lang.String theName)
theControlP5
- theName
- /**
* ControlP5 extending Controllers
*
* the following example shows how to extend the Controller class to
* create customizable Controllers. You can either extend the Controller class itself,
* or any class that extends Controller itself like the Slider, Button, DropdownList, etc.
*
* How to:
*
* 1) do a super call to the convenience constructor requiring
* 2 parameter (ControlP5 instance, name)
*
* 2) the Controller class has a set of empty methods that allow you to capture
* inputs from the mouse including
* onEnter(), onLeave(), onPress(), onRelease(), onClick(), onScroll(int), onDrag()
* These you can override and include functionality as needed.
*
* 3) use method getPointer() to return the local (relative)
* xy-coordinates of the controller
*
* 4) after instantiation custom controllers are treated the same
* as default controlP5 controllers.
*
* by Andreas Schlegel, 2012
* www.sojamo.de/libraries/controlp5
*
*/
import controlP5.*;
ControlP5 cp5;
PApplet p;
void setup() {
size(400, 400);
cp5 = new ControlP5(this);
// create 2 groups to show nesting of custom controllers and
//
Group g1 = cp5.addGroup("a").setPosition(0,100).setWidth(180);
Group g2 = cp5.addGroup("b").setPosition(0,10).setWidth(180);
g2.moveTo(g1);
// create 2 custom Controllers from class MyButton
// MyButton extends Controller and inherits all methods accordingly.
new MyButton(cp5, "b1").setPosition(0, 0).setSize(180, 200).moveTo(g2);
new MyButton(cp5, "b2").setPosition(205, 15).setSize(180, 200);
}
void draw() {
background(0);
}
// b1 will be called from Controller b1
public void b1(float theValue) {
println("yay button "+theValue);
}
public void controlEvent(ControlEvent theEvent) {
println("controlEvent : "+theEvent);
}
// Create a custom Controller, please not that
// MyButton extends Controller,
// is an indicator for the super class about the type of
// custom controller to be created.
class MyButton extends Controller {
int current = 0xffff0000;
float a = 128;
float na;
int y;
// use the convenience constructor of super class Controller
// MyButton will automatically registered and move to the
// default controlP5 tab.
MyButton(ControlP5 cp5, String theName) {
super(cp5, theName);
// replace the default view with a custom view.
setView(new ControllerView() {
public void display(PGraphics p, Object b) {
// draw button background
na += (a-na) * 0.1;
p.fill(current,na);
p.rect(0, 0, getWidth(), getHeight());
// draw horizontal line which can be moved on the x-axis
// using the scroll wheel.
p.fill(0,255,0);
p.rect(0,y,width,10);
// draw the custom label
p.fill(128);
translate(0,getHeight()+14);
p.text(getName(),0,0);
p.text(getName(),0,0);
}
}
);
}
// override various input methods for mouse input control
void onEnter() {
cursor(HAND);
println("enter");
a = 255;
}
void onScroll(int n) {
println("scrolling");
y -= n;
y = constrain(y,0,getHeight()-10);
}
void onPress() {
println("press");
current = 0xffffff00;
}
void onClick() {
Pointer p1 = getPointer();
println("clicked at "+p1.x()+", "+p1.y());
current = 0xffffff00;
setValue(y);
}
void onRelease() {
println("release");
current = 0xffffffff;
}
void onMove() {
println("moving "+this+" "+_myControlWindow.getMouseOverList());
}
void onDrag() {
current = 0xff0000ff;
Pointer p1 = getPointer();
float dif = dist(p1.px(),p1.py(),p1.x(),p1.y());
println("dragging at "+p1.x()+", "+p1.y()+" "+dif);
}
void onReleaseOutside() {
onLeave();
}
void onLeave() {
println("leave");
cursor(ARROW);
a = 128;
}
}
public Textarea(java.lang.String theText, int theX, int theY)
theText
- StringtheX
- inttheY
- intpublic Textarea append(java.lang.String theText)
public Textarea append(java.lang.String theText, int max)
public Textarea clear()
public void controlEvent(ControlEvent theEvent)
ControlListener
controlEvent
in interface ControlListener
controlEvent
in class ControllerGroup<Textarea>
theEvent
- ControlEventCallbackListener
,
CallbackEvent
public Textarea disableColorBackground()
public Textarea enableColorBackground()
public float getScrollPosition()
public java.lang.String getStringValue()
getStringValue
in interface ControllerInterface<Textarea>
getStringValue
in class ControllerGroup<Textarea>
public java.lang.String getText()
public float getValue()
getValue
in interface ControllerInterface<Textarea>
getValue
in class ControllerGroup<Textarea>
public Label getValueLabel()
getValueLabel
in class ControllerGroup<Textarea>
public Textarea hideScrollbar()
public boolean isScrollable()
public Textarea scroll(float theValue)
theValue
- public void scrolled(int theStep)
public Textarea setBorderColor(int theColor)
theColor
- public Textarea setColor(int theColor)
theColor
- intpublic Textarea setColorBackground(int theColor)
setColorBackground
in interface ControllerInterface<Textarea>
setColorBackground
in class ControllerGroup<Textarea>
public Textarea setFont(ControlFont theFont)
public Textarea setFont(int theFontIndex)
public Textarea setFont(processing.core.PFont thePFont)
public Textarea setHeight(int theValue)
setHeight
in class ControllerGroup<Textarea>
theValue
- intpublic Textarea setLineHeight(int theLineHeight)
theLineHeight
- intpublic Textarea setScrollActive(int theColor)
theColor
- public Textarea setScrollBackground(int theColor)
theColor
- public Textarea setScrollForeground(int theColor)
theColor
- public Textarea setSize(int theWidth, int theHeight)
setSize
in class ControllerGroup<Textarea>
public Textarea setText(java.lang.String theText)
theText
- Stringpublic Textarea setWidth(int theValue)
setWidth
in class ControllerGroup<Textarea>
theValue
- intpublic Textarea showScrollbar()
@Deprecated public java.lang.String stringValue()
@Deprecated public float value()
@Deprecated public Label valueLabel()
processing library controlP5 by Andreas Schlegel. (c) 2006-2015