controlP5
Class Textfield

java.lang.Object
  extended by controlP5.Controller
      extended by controlP5.Textfield
All Implemented Interfaces:
CDrawable, ControllerInterface, ControlP5Constants

public class Textfield
extends Controller

description for singleline textfield. create a texfield with

controlP5.addTextfield(theName,theX,theY,theWidth,theHeight); the Textfield implementation for ControlP5 tries its best to imitate the usage and behavior of a terminal, the command line.

+Example
/**
 * ControlP5 Textflied.
 * 
 * for a more advanced example see textfieldAdvanced which 
 * demonstrates how to use keepFocus, setText, getText, getTextList,
 * clear, setAutoClear, isAutoClear or submit.
 * by andreas schlegel, 2009
 */

import controlP5.*;
ControlP5 controlP5;



String textValue = "";
Textfield myTextfield;

void setup() {
  size(400,400);
  frameRate(25);
  controlP5 = new ControlP5(this);

  myTextfield = controlP5.addTextfield("texting",100,160,200,20);
  myTextfield.setFocus(true);
  controlP5.addTextfield("textValue",100,200,200,20);
}

void draw() {
  background(0);
}


void controlEvent(ControlEvent theEvent) {
  println("controlEvent: accessing a string from controller '"+theEvent.controller().name()+"': "+theEvent.controller().stringValue());
}


public void texting(String theText) {
  // receiving text from controller texting
  println("a textfield event for controller 'texting': "+theText);
}



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
Textfield(ControlP5 theControlP5, ControllerGroup theParent, java.lang.String theName, java.lang.String theDefaultValue, int theX, int theY, int theWidth, int theHeight)
           
 
Method Summary
 void addToXMLElement(ControlP5XMLElement theElement)
           
 void clear()
          clear the current content of the textfield.
 void draw(processing.core.PApplet theApplet)
          the default draw function for each controller extending superclass Controller.
 java.lang.String getText()
          get the current text of the textfield.
 java.lang.String[] getTextList()
          returns a string array that lists all text lines that have been confirmed with a return.
 boolean isAutoClear()
          returns the current state of the autoClear flag.
 boolean isFocus()
          check if the textfield is active and in focus.
 void keepFocus(boolean theFlag)
          use true as parameter to force the textfield to stay in focus.
 void keyEvent(java.awt.event.KeyEvent theKeyEvent)
          flip throught the texfield history with cursor keys UP and DOWN.
 void setAutoClear(boolean theFlag)
          use setAutoClear(false) to not clear the content of the textfield after confirming with return.
 void setFocus(boolean theFlag)
          set the textfield's focus to true or false.
 void setPasswordMode(boolean theFlag)
          set the mode of the textfield to password mode, each character is shown as a "*" like e.g.
 void setText(java.lang.String theValue)
          setText does set the text of a textfield, but will not broadcast its value.
 void setValue(float theValue)
          set the value of the controller.
 void setValue(java.lang.String theValue)
          set the value of the textfield and will broadcast the new string value immediately.
 void submit()
          make the controller execute a return event.
 void update()
          updates the value of the controller without having to set the value explicitly.
 
Methods inherited from class controlP5.Controller
absolutePosition, add, addListener, arrayValue, behavior, captionLabel, changeValue, color, continuousUpdateEvents, controlWindow, defaultValue, disableSprite, enableSprite, getAsXML, getColor, getHeight, getPickingColor, getSprite, getTab, getWidth, getWindow, hide, id, init, isBroadcast, isInside, isLock, isMousePressed, isMoveable, isUpdate, isUserInteraction, isVisible, isXMLsavable, label, linebreak, listenerSize, lock, max, min, moveTo, moveTo, moveTo, moveTo, moveTo, moveTo, moveTo, moveTo, moveTo, name, parent, plugTo, plugTo, position, remove, remove, removeBehavior, removeListener, setArrayValue, setBehavior, setBroadcast, setCaptionLabel, setColor, setColorActive, setColorBackground, setColorCaptionLabel, setColorForeground, setColorLabel, setColorValue, setColorValueLabel, setDecimalPrecision, setDefaultValue, setDisplay, setDisplay, setGroup, setGroup, setHeight, setId, setImage, setImage, setImages, setImages, setLabel, setLabelVisible, setLock, setMax, setMin, setMousePressed, setMoveable, setParent, setPosition, setSize, setSize, setSprite, setTab, setTab, setUpdate, setUserInteraction, setValueLabel, setVisible, setWidth, setWindow, setWindow, show, stringValue, toString, trigger, unlock, unplugFrom, unplugFrom, updateAbsolutePosition, updateEvents, updateInternalEvents, updateSize, value, valueLabel
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Textfield

public Textfield(ControlP5 theControlP5,
                 ControllerGroup theParent,
                 java.lang.String theName,
                 java.lang.String theDefaultValue,
                 int theX,
                 int theY,
                 int theWidth,
                 int theHeight)
Parameters:
theControllerProperties - ControllerProperties
Method Detail

setValue

public void setValue(float theValue)
Description copied from class: Controller
set the value of the controller.

Specified by:
setValue in class Controller
Parameters:
theValue - float

setPasswordMode

public void setPasswordMode(boolean theFlag)
set the mode of the textfield to password mode, each character is shown as a "*" like e.g. in online password forms.

Parameters:
theFlag - boolean

setFocus

public void setFocus(boolean theFlag)
set the textfield's focus to true or false.

Parameters:
theFlag - boolean

keepFocus

public void keepFocus(boolean theFlag)
use true as parameter to force the textfield to stay in focus. to go back to normal focus behavior, use false.

Parameters:
theFlag -

isFocus

public boolean isFocus()
check if the textfield is active and in focus.

Returns:
boolean

setValue

public void setValue(java.lang.String theValue)
set the value of the textfield and will broadcast the new string value immediately. what is the difference between setValue and setText? setValue does broadcast the value that has been set, setText does not broadcast the value, but only updates the content of a textfield. for further information about how setText works, see the setText documentation.

Parameters:
theValue - String

setText

public void setText(java.lang.String theValue)
setText does set the text of a textfield, but will not broadcast its value. use setText to force the textfield to change its text. you can call setText any time, nevertheless when autoClear is set to true (which is the default), it will NOT work when called from within controlEvent or within a method that has been identified by ControlP5 to forward messages to, when return has been pressed to confirm a textfield.
use setAutoClear(false) to enable setText to be executed for the above case. use yourTextfield.isAutoClear() to check if autoClear is true or false.
setText replaces the current/latest content of a textfield but does NOT overwrite the content. when scrolling through the list of textlines (use key up and down), the previous content that has been replaced will be put back into place again - since it has not been confirmed with return.

Parameters:
theValue -

update

public void update()
Description copied from class: Controller
updates the value of the controller without having to set the value explicitly. update does not visually update the controller. the updating status can be set with setUpdate(true/false) and checked with isUpdate(). setUpdate ( )

Specified by:
update in interface ControllerInterface
Overrides:
update in class Controller

draw

public void draw(processing.core.PApplet theApplet)
Description copied from class: Controller
the default draw function for each controller extending superclass Controller. This draw function will take care of default matrix operations and will call the display function of the current ControllerDisplay object active for this particular controller.

Specified by:
draw in interface CDrawable
Specified by:
draw in interface ControllerInterface
Overrides:
draw in class Controller
Parameters:
theApplet - PApplet
See Also:
ControllerDisplay

keyEvent

public void keyEvent(java.awt.event.KeyEvent theKeyEvent)
flip throught the texfield history with cursor keys UP and DOWN. go back and forth with cursor keys LEFT and RIGHT.

Specified by:
keyEvent in interface ControllerInterface
Overrides:
keyEvent in class Controller
Parameters:
theKeyEvent - KeyEvent

getText

public java.lang.String getText()
get the current text of the textfield.

Returns:
String

getTextList

public java.lang.String[] getTextList()
returns a string array that lists all text lines that have been confirmed with a return.

Returns:

clear

public void clear()
clear the current content of the textfield.


setAutoClear

public void setAutoClear(boolean theFlag)
use setAutoClear(false) to not clear the content of the textfield after confirming with return.

Parameters:
theFlag -

isAutoClear

public boolean isAutoClear()
returns the current state of the autoClear flag.

Returns:

submit

public void submit()
make the controller execute a return event. submit the current content of the texfield.


addToXMLElement

public void addToXMLElement(ControlP5XMLElement theElement)
Parameters:
theElement - ControlP5XMLElement


processing library controlP5 by Andreas Schlegel. (c) 2010