public class ClassObjectControl extends DynamicControlParent
DynamicControl
classes of type ControlType.OBJECT
in a simple API. This enables sending of entire classes as a single message.
TripleAxisMessage
using the setValue(Object)
ClassObjectControl
objects with the same name and ControlScope
will respond to a setValue(Object)
.
Additionally, the Class
of the object that we are sending must also be defined. For example:
consider two ClassObjectControl
with the same ControlScope
and name:
ClassObjectControl control1 = new ClassObjectControl(this, "Accel", TripleAxisMessage.class); ClassObjectControl control2 = new ClassObjectControl(this, "Accel", TripleAxisMessage.class) { @Override public void valueChanged(Object object_val) { TripleAxisMessage control_val = (TripleAxisMessage) object_val; System.out.println("x:" + control_val.getX() + " y:" + control_val.getY() + " z" + control_val.getZ()); } }; TripleAxisMessage msg = new TripleAxisMessage(0.1f, 0.2f, 0.3f); control1.setValue(msg);
valueChanged(Object)
function with the new value, causing x:0.1 y:0.2 z:0.3 to be printed to standard output
setValue(Object, double)
function. For example, the message can be scheduled to execute in 1 second as follows: Class
type must be defined within the control
valueChanged(Object)
classConstructor and Description |
---|
ClassObjectControl(java.lang.Object parent_sketch,
java.lang.String name,
java.lang.Class<?> class_type)
Constructor for abstract ClassObjectControl
derive from this class
|
Modifier and Type | Method and Description |
---|---|
protected static java.lang.Object |
createDefaultObject(java.lang.Class<?> class_type) |
java.lang.Object |
getValue()
Get the value for the control
|
ClassObjectControl |
setControlScope(ControlScope new_scope)
Changed the scope that the control has.
|
ClassObjectControl |
setDisplayType(DynamicControl.DISPLAY_TYPE display_type)
Change how to display object as
DynamicControl.DISPLAY_TYPE
We must do this in subclass |
void |
setValue(java.lang.Object val)
set the value for the control.
|
void |
setValue(java.lang.Object val,
double scheduler_time)
Identical to the
setValue(Object) with the exception that the valueChanged(Object) event will be caused at the HBScheduler scheduled time passed in. |
void |
valueChanged(java.lang.Object control_val)
Fired event that occurs when the value for the control has been set.
|
addControlListener, addControlScopeListener, addControlTarget, addControlTarget, clearControlTargets, getDynamicControl, getSendingDevice, removeControlListener, removeControlScopeChangedListener, removeControlTarget, removeControlTarget, removeListeners, setControlTarget, setControlTarget
public ClassObjectControl(java.lang.Object parent_sketch, java.lang.String name, java.lang.Class<?> class_type)
parent_sketch
- The parent object for controlname
- The name to Displayclass_type
- Initial value of the object. The value in the return function valueChanged(Object)
will be castprotected static java.lang.Object createDefaultObject(java.lang.Class<?> class_type)
public java.lang.Object getValue()
public void valueChanged(java.lang.Object control_val)
ClassObjectControl control1 = new ClassObjectControl(this, "Accel", TripleAxisMessage.class); ClassObjectControl control2 = new ClassObjectControl(this, "Accel", TripleAxisMessage.class) { @Override public void valueChanged(Object object_val) { TripleAxisMessage control_val = (TripleAxisMessage) object_val; System.out.println("x:" + control_val.getX() + " y:" + control_val.getY() + " z" + control_val.getZ()); } }; TripleAxisMessage msg = new TripleAxisMessage(0.1f, 0.2f, 0.3f); control1.setValue(msg);
valueChanged(Object)
function with the new value, causing x:0.1 y:0.2 z:0.3 to be printed to standard outputcontrol_val
- The class object that has been received. If the value could not be cast, the function will not be calledpublic void setValue(java.lang.Object val)
ControlScope
. For example:
ClassObjectControl control1 = new ClassObjectControl(this, "Accel", TripleAxisMessage.class); ClassObjectControl control2 = new ClassObjectControl(this, "Accel", TripleAxisMessage.class) { @Override public void valueChanged(Object object_val) { TripleAxisMessage control_val = (TripleAxisMessage) object_val; System.out.println("x:" + control_val.getX() + " y:" + control_val.getY() + " z" + control_val.getZ()); } }; TripleAxisMessage msg = new TripleAxisMessage(0.1f, 0.2f, 0.3f); control1.setValue(msg);
valueChanged(Object)
function with the new value, causing x:0.1 y:0.2 z:0.3 to be printed to standard outputval
- the value to set topublic void setValue(java.lang.Object val, double scheduler_time)
setValue(Object)
with the exception that the valueChanged(Object)
event will be caused at the HBScheduler
scheduled time passed in. For example, the
following code will cause the valueChanged(Object)
to be fired 1 second in the future:
ClassObjectControl control1 = new ClassObjectControl(this, "Accel", TripleAxisMessage.class); ClassObjectControl control1 = new ClassObjectControl(this, "Accel", TripleAxisMessage.class); ClassObjectControl control2 = new ClassObjectControl(this, "Accel", TripleAxisMessage.class) { @Override public void valueChanged(Object object_val) { TripleAxisMessage control_val = (TripleAxisMessage) object_val; System.out.println("x:" + control_val.getX() + " y:" + control_val.getY() + " z" + control_val.getZ()); } }; TripleAxisMessage msg = new TripleAxisMessage(0.1f, 0.2f, 0.3f); control1.setValue(msg, HB.getSchedulerTime() + 1000);
val
- the value to set toscheduler_time
- the scheduler time this is supposed to occur atpublic ClassObjectControl setControlScope(ControlScope new_scope)
setControlScope
in class DynamicControlParent
new_scope
- The new Control Scopepublic ClassObjectControl setDisplayType(DynamicControl.DISPLAY_TYPE display_type)
DynamicControl.DISPLAY_TYPE
We must do this in subclassdisplay_type
- The new Display Type