Configures a style object.
Responsibilities:
- Creating a ui to allow user configuration of a style object.
- Placing style object information onto the style blackboard of a layer.
- Determining if a style configurator can be used to configure the style
of a particular layer.
Style objects are stored a StyleBlackboard. Configurators use the blackboard
to collaborate. Objects are stored on the blackboard by id. When a configurator
queries the blackboard for an object and it does not exist, a default object
should be created and placed on the blackboard. The following is an example:
...
StyleBlackboard styleBlackboard = getStyleBlackboard();
Point style = styleBlackboard.lookup("point.style");
if (style == null) {
style = new Point();
style.setX(0);
style.setY(0);
styleBlackboard.put("point.style", style);
}
...
Each Layer has a StyleBlackboard. Configurators should not write to this
blackboard directly. Each configurator is supplied with a copy of the actual
layer blackboard.
Note:Each time a style object is changed, it must be replaced onto
the blackboard for persistance reasons.
StyleBlackboard styleBlackboard = getStyleBlackboard();
Point style = styleBlackboard.lookup("point.style");
...
style.setX(10);
style.setY(10);
styleBlackboard.put("point.style", style);
The StyleConfigurator should store no state. All state should be stored in
the style objects on the style blackboard. When a ui widget changes state, the
style object should be written to immediately to reflect the change.
When the configurator becomes active, the ui widgets should be initialized
from the values of style objects on the blackboard. This should be performed
every time refresh() is called.
Whenever style objects are read from the blackboard,
void apply() {
StyleBlackboard styleBlackboard = getStyleBlackboard();
Point style = styleBlackboard.lookup("point.style");
if (style == null) {
style = new Point();
styleBlackboard.put("point.style", style);
}
style.setX(...) //set to some value from ui
style.setY(...) //set to some value from ui
}
void init() {
StyleBlackboard styleBlackboard = getStyleBlackboard();
Point style = styleBlackboard.lookup("point.style");
if (style != null) {
//set some ui widget to value of style.getX();
//set some ui widget to value of style.getY();
}
}
A StyleConfigurator is not considered active until its ui has been created.
author: Justin Deoliveira since: 0.6.0 |