public class ControllerProperties
extends java.lang.Object
/**
* ControlP5 Properties
*
*
* saves controller values to a properties-file
* loads controller values from a properties-file
*
* Properties will only save values not the Controller itself.
*
* Also take a look at the use/ControlP5snapshot example to
* save controller values to memory.
*
* Use ControllerProperties to load and save serialized controller properties
* to a properties file.
* The controllers implementing save/load properties so far are
* Slider, Knob, Numberbox, Toggle, Checkbox, RadioButton, Textlabel,
* Matrix, Range, Textarea, ListBox, Dropdown, ColorPicker.
* Properties are currently saved in the java serialization format.
*
* saveProperties(String theFilename) and loadProperties(String theFilename)
* by default properties will be saved to your sketch folder as controlP5.ser
* if that file already exists it will be overwritten. for custom property files
* see the comments inside keyPressed() below.
*
* find a list of public methods available for the ControllerProperties class
* at the bottom of this sketch's source code
*
* default properties load/save key combinations are
* alt+shift+l to load properties
* alt+shift+s to save properties
*
* by andreas schlegel, 2012
* www.sojamo.de/libraries/controlp5
*
*/
import controlP5.*;
ControlP5 cp5;
public int myColor = color(0, 0, 0);
public int sliderValue = 100;
public int sliderTicks1 = 100;
public int sliderTicks2 = 30;
void setup() {
size(700, 400);
noStroke();
cp5 = new ControlP5(this);
cp5.addSlider("slider")
.setBroadcast(false)
.setRange(0, 200)
.setPosition(20, 100)
.setSize(10, 100)
.setBroadcast(true)
.setValue(100)
;
cp5.addSlider("sliderTicks1")
.setRange(0, 255)
.setPosition(100, 100)
.setSize(10, 100)
.setNumberOfTickMarks(5)
;
cp5.addSlider("sliderValue")
.setRange(0, 255)
.setValue(128)
.setPosition(200, 180)
.setSize(100, 10)
;
cp5.addSlider("sliderTicks2")
.setRange(0, 255)
.setValue(128)
.setPosition(200, 220)
.setSize(100, 10)
.setNumberOfTickMarks(7)
.setSliderMode(Slider.FLEXIBLE)
;
}
void draw() {
background(sliderTicks1);
fill(sliderValue);
rect(0, 0, width, 100);
fill(myColor);
rect(0, 300, width, 70);
fill(sliderTicks2);
rect(0, 370, width, 30);
}
public void slider(float theColor) {
myColor = color(theColor);
println("a slider event. setting background to "+theColor);
}
void keyPressed() {
// default properties load/save key combinations are
// alt+shift+l to load properties
// alt+shift+s to save properties
if (key=='1') {
cp5.saveProperties(("hello.properties"));
}
else if (key=='2') {
cp5.loadProperties(("hello.properties"));
}
}
/*
a list of all methods available for the ControllerProperties Controller
use ControlP5.printPublicMethodsFor(ControllerProperties.class);
to print the following list into the console.
You can find further details about class ControllerProperties in the javadoc.
Format:
ClassName : returnType methodName(parameter type)
controlP5.ControllerProperties : ArrayList getSnapshotIndices()
controlP5.ControllerProperties : ControllerProperties addSet(String)
controlP5.ControllerProperties : ControllerProperties delete(ControllerProperty)
controlP5.ControllerProperties : ControllerProperties getSnapshot(String)
controlP5.ControllerProperties : ControllerProperties move(ControllerInterface, String, String)
controlP5.ControllerProperties : ControllerProperties move(ControllerProperty, String, String)
controlP5.ControllerProperties : ControllerProperties only(ControllerProperty, String)
controlP5.ControllerProperties : ControllerProperties print()
controlP5.ControllerProperties : ControllerProperties register(ControllerInterface, String)
controlP5.ControllerProperties : ControllerProperties remove(ControllerInterface)
controlP5.ControllerProperties : ControllerProperties remove(ControllerInterface, String)
controlP5.ControllerProperties : ControllerProperties remove(ControllerInterface, String, String)
controlP5.ControllerProperties : ControllerProperties removeSnapshot(String)
controlP5.ControllerProperties : ControllerProperties saveSnapshot(String)
controlP5.ControllerProperties : ControllerProperties saveSnapshotAs(String, String)
controlP5.ControllerProperties : ControllerProperties setSnapshot(String)
controlP5.ControllerProperties : ControllerProperties updateSnapshot(String)
controlP5.ControllerProperties : ControllerProperty getProperty(ControllerInterface, String)
controlP5.ControllerProperties : ControllerProperty getProperty(ControllerInterface, String, String)
controlP5.ControllerProperties : ControllerProperty register(ControllerInterface, String, String)
controlP5.ControllerProperties : HashSet getPropertySet(ControllerInterface)
controlP5.ControllerProperties : List get(ControllerInterface)
controlP5.ControllerProperties : Map get()
controlP5.ControllerProperties : String toString()
controlP5.ControllerProperties : boolean load()
controlP5.ControllerProperties : boolean load(String)
controlP5.ControllerProperties : boolean save()
controlP5.ControllerProperties : boolean saveAs(String)
controlP5.ControllerProperties : void setFormat(Format)
java.lang.Object : String toString()
java.lang.Object : boolean equals(Object)
*/
Modifier and Type | Field and Description |
---|---|
static int |
CLOSE |
static java.lang.String |
defaultName |
static java.util.logging.Logger |
logger |
static int |
OPEN |
Constructor and Description |
---|
ControllerProperties(ControlP5 theControlP5) |
Modifier and Type | Method and Description |
---|---|
ControllerProperties |
addSet(java.lang.String theSet) |
ControllerProperties |
copy(ControllerInterface<?> theController,
java.lang.String... theSet) |
ControllerProperties |
copy(ControllerProperty theProperty,
java.lang.String... theSet)
copies a ControllerProperty from one set to other(s);
|
ControllerProperties |
delete(ControllerProperty theProperty)
deletes a ControllerProperty from all Sets including the default set.
|
java.util.Map<ControllerProperty,java.util.HashSet<java.lang.String>> |
get() |
java.util.List<ControllerProperty> |
get(ControllerInterface<?> theController) |
ControllerProperty |
getProperty(ControllerInterface<?> theController,
java.lang.String theProperty) |
ControllerProperty |
getProperty(ControllerInterface<?> theController,
java.lang.String theSetter,
java.lang.String theGetter) |
java.util.HashSet<ControllerProperty> |
getPropertySet(ControllerInterface<?> theController) |
ControllerProperties |
getSnapshot(java.lang.String theKey)
restores properties previously stored as snapshot in memory.
|
java.util.ArrayList<java.lang.String> |
getSnapshotIndices()
properties stored in memory can be accessed by index, getSnapshotIndices() returns the index of the snapshot
list.
|
boolean |
load()
load properties from the default properties file 'controlP5.properties'
|
boolean |
load(java.lang.String thePropertiesPath) |
ControllerProperties |
move(ControllerInterface<?> theController,
java.lang.String fromSet,
java.lang.String toSet) |
ControllerProperties |
move(ControllerProperty theProperty,
java.lang.String fromSet,
java.lang.String toSet)
Moves a ControllerProperty from one set to another.
|
ControllerProperties |
only(ControllerProperty theProperty,
java.lang.String theSet)
stores a ControllerProperty in one particular set only.
|
ControllerProperties |
print() |
ControllerProperties |
register(ControllerInterface<?> theController,
java.lang.String theProperty)
registering a property with only one parameter assumes that there is a setter and getter function present for the
Controller.
|
ControllerProperty |
register(ControllerInterface<?> theController,
java.lang.String thePropertySetter,
java.lang.String thePropertyGetter)
adds a property based on names of setter and getter methods of a controller.
|
ControllerProperties |
remove(ControllerInterface<?> theController) |
ControllerProperties |
remove(ControllerInterface<?> theController,
java.lang.String... theSet) |
ControllerProperties |
remove(ControllerInterface<?> theController,
java.lang.String theProperty) |
ControllerProperties |
remove(ControllerInterface<?> theController,
java.lang.String theSetter,
java.lang.String theGetter) |
ControllerProperties |
remove(ControllerProperty theProperty,
java.lang.String... theSet)
removes a ControllerProperty from one or multiple sets.
|
ControllerProperties |
removeSnapshot(java.lang.String theKey)
removes a snapshot by key.
|
boolean |
save()
saves all registered properties into the default 'controlP5.properties' file into your sketch folder.
|
boolean |
saveAs(java.lang.String thePropertiesPath)
saves all registered properties into a file specified by parameter thePropertiesPath.
|
boolean |
saveAs(java.lang.String thePropertiesPath,
java.lang.String... theSets)
saves a list of properties sets into a file specified by parameter thePropertiesPath.
|
ControllerProperties |
saveSnapshot(java.lang.String theKey)
saves a snapshot into your sketch's sketch folder.
|
ControllerProperties |
saveSnapshotAs(java.lang.String thePropertiesPath,
java.lang.String theKey)
saves a snapshot to the file with path given by the first parameter (thePropertiesPath).
|
void |
setFormat(controlP5.ControllerProperties.PropertiesStorageFormat theFormat)
use ControllerProperties.SERIALIZED, ControllerProperties.XML or ControllerProperties.JSON as parameter.
|
ControllerProperties |
setSnapshot(java.lang.String theKey)
logs all registered properties in memory.
|
java.lang.String |
toString() |
ControllerProperties |
updateSnapshot(java.lang.String theKey)
convenience method, setSnapshot(String) also works here since it will override existing log with the same key.
|
public static final int CLOSE
public static java.lang.String defaultName
public static final java.util.logging.Logger logger
public static final int OPEN
public ControllerProperties(ControlP5 theControlP5)
public ControllerProperties addSet(java.lang.String theSet)
public ControllerProperties copy(ControllerInterface<?> theController, java.lang.String... theSet)
public ControllerProperties copy(ControllerProperty theProperty, java.lang.String... theSet)
public ControllerProperties delete(ControllerProperty theProperty)
public java.util.Map<ControllerProperty,java.util.HashSet<java.lang.String>> get()
public java.util.List<ControllerProperty> get(ControllerInterface<?> theController)
public ControllerProperty getProperty(ControllerInterface<?> theController, java.lang.String theProperty)
public ControllerProperty getProperty(ControllerInterface<?> theController, java.lang.String theSetter, java.lang.String theGetter)
public java.util.HashSet<ControllerProperty> getPropertySet(ControllerInterface<?> theController)
public ControllerProperties getSnapshot(java.lang.String theKey)
setSnapshot(String)
public java.util.ArrayList<java.lang.String> getSnapshotIndices()
public boolean load()
public boolean load(java.lang.String thePropertiesPath)
public ControllerProperties move(ControllerInterface<?> theController, java.lang.String fromSet, java.lang.String toSet)
public ControllerProperties move(ControllerProperty theProperty, java.lang.String fromSet, java.lang.String toSet)
public ControllerProperties only(ControllerProperty theProperty, java.lang.String theSet)
public ControllerProperties print()
public ControllerProperties register(ControllerInterface<?> theController, java.lang.String theProperty)
theProperty
- public ControllerProperty register(ControllerInterface<?> theController, java.lang.String thePropertySetter, java.lang.String thePropertyGetter)
thePropertySetter
- thePropertyGetter
- public ControllerProperties remove(ControllerInterface<?> theController)
public ControllerProperties remove(ControllerInterface<?> theController, java.lang.String... theSet)
public ControllerProperties remove(ControllerInterface<?> theController, java.lang.String theProperty)
public ControllerProperties remove(ControllerInterface<?> theController, java.lang.String theSetter, java.lang.String theGetter)
public ControllerProperties remove(ControllerProperty theProperty, java.lang.String... theSet)
public ControllerProperties removeSnapshot(java.lang.String theKey)
public boolean save()
public boolean saveAs(java.lang.String thePropertiesPath)
public boolean saveAs(java.lang.String thePropertiesPath, java.lang.String... theSets)
public ControllerProperties saveSnapshot(java.lang.String theKey)
public ControllerProperties saveSnapshotAs(java.lang.String thePropertiesPath, java.lang.String theKey)
public void setFormat(controlP5.ControllerProperties.PropertiesStorageFormat theFormat)
public ControllerProperties setSnapshot(java.lang.String theKey)
theKey
- getSnapshot(String)
public java.lang.String toString()
toString
in class java.lang.Object
public ControllerProperties updateSnapshot(java.lang.String theKey)
processing library controlP5 by Andreas Schlegel. (c) 2006-2014