public class IntegerControl extends DynamicControlParent
DynamicControl classes of type ControlType.INT in a simple API
IntegerControl controls with the same name and ControlScope will respond to a message send. For example:
For example, consider two IntegerControls with the same ControlScope and name
Setting the value of control1 will cause any objects listening to control1 or control2 to receive the action. EG
valueChanged(int) )} listener that is implemented when the class is created.
IntegerControl control1 = new IntegerControl(this, "Read", 0);
IntegerControl control2 = new IntegerControl(this, "Read", 0) {
@Override
public void valueChanged(int control_val) {
System.out.println("Read " + control_val);
}
};
control1.setValue(2); // this will also set the value of control2
valueChanged(int) function to be called with the new value, causing Read 2 to be printed to standard output. This is
because both controls are ControlScope.SKETCH by default and are both have their name as "Read.
setValue(int, double) function. Eg
ControlScope and name, to true 1 second in the future
getValue() function.
If you require a handler on the class, override the valueChanged(int) function| Constructor and Description |
|---|
IntegerControl(java.lang.Object parent_sketch,
java.lang.String name,
int initial_value)
Constructor for abstract IntegerControl.
|
IntegerControl(java.lang.Object parent_sketch,
java.lang.String name,
int initial_value,
int min_val,
int max_val,
DynamicControl.DISPLAY_TYPE display_type)
Constructor for IntegerControl if you want it displayed other than text control.
|
| Modifier and Type | Method and Description |
|---|---|
int |
getValue()
Get the value for the control.
|
IntegerControl |
setControlScope(ControlScope new_scope)
Changed the
ControlScope the object has has. |
IntegerControl |
setDisplayRange(int minimum,
int maximum,
DynamicControl.DISPLAY_TYPE display_type)
Set how we want this control displayed
|
IntegerControl |
setDisplayType(DynamicControl.DISPLAY_TYPE display_type)
Change how to display object
We must do this in subclass
|
void |
setValue(int val)
set the value for the control.
|
void |
setValue(int val,
double scheduler_time)
set the value for the control at a specific time.
|
void |
valueChanged(int control_val)
When the control receives the value, it will be passed through to the valueChanged(int) listener that is implemented when the class is created. |
addControlListener, addControlScopeListener, addControlTarget, addControlTarget, clearControlTargets, getDynamicControl, getSendingDevice, removeControlListener, removeControlScopeChangedListener, removeControlTarget, removeControlTarget, removeListeners, setControlTarget, setControlTargetpublic IntegerControl(java.lang.Object parent_sketch,
java.lang.String name,
int initial_value,
int min_val,
int max_val,
DynamicControl.DISPLAY_TYPE display_type)
parent_sketch - The parent object for controlname - The name to Displayinitial_value - Initial value of the objectmin_val - Minimum value to display on Slidermax_val - Maximum value to display on Sliderdisplay_type - The way we want object displayedpublic IntegerControl(java.lang.Object parent_sketch,
java.lang.String name,
int initial_value)
parent_sketch - The parent object for controlname - The name to Displayinitial_value - Initial value of the objectpublic int getValue()
IntegerControl control1 = new IntegerControl(this, "Read", 0);
IntegerControl control2 = new IntegerControl(this, "Read", 0) {
@Override
public void valueChanged(int control_val) {
System.out.println("Read " + control_val);
}
};
int val = control1.getValue(); // val = 0
control1.setValue(2);
val = control1.getValue();// val = 1
public void valueChanged(int control_val)
valueChanged(int) listener that is implemented when the class is created.
IntegerControl control1 = new IntegerControl(this, "Read", 0);
IntegerControl control2 = new IntegerControl(this, "Read", 0) {
@Override
public void valueChanged(int control_val) {
System.out.println("Read " + control_val);
}
};
control1.setValue(2); // this will also set the value of control2
valueChanged(int) function to be called with the new value, causing Read 2 to be printed to standard outputcontrol_val - the value receivedpublic void setValue(int val)
DynamicControl with matching name, type and ControlScope and call valueChanged(int).
IntegerControl control1 = new IntegerControl(this, "Read", 0);
IntegerControl control2 = new IntegerControl(this, "Read", 0) {
@Override
public void valueChanged(int control_val) {
System.out.println("Read " + control_val);
}
};
control1.setValue(2); // this will also set the value of control2
valueChanged(int) function to be called with the new value, causing Read 2 to be printed to standard outputval - the value to set topublic void setValue(int val,
double scheduler_time)
setValue(int) with the exception that the valueChanged(int) event will be caused at the HBScheduler scheduled time passed in.
DynamicControl objects to respond 1 second in the future
IntegerControl control1 = new IntegerControl(this, "Read", 0);
IntegerControl control2 = new IntegerControl(this, "Read", 0) {
@Override
public void valueChanged(int control_val) {
System.out.println("Read " + control_val);
}
};
control1.setValue(2, HB.getSchedulerTime() + 1000); // this will also set the value of control2
val - the value to set toscheduler_time - the scheduler time this is supposed to occur atpublic IntegerControl setDisplayType(DynamicControl.DISPLAY_TYPE display_type)
display_type - The new Control Scopepublic IntegerControl setControlScope(ControlScope new_scope)
ControlScope the object has has. It will update control map so the correct events will be generated based on its scopesetControlScope in class DynamicControlParentnew_scope - The new Control Scopepublic IntegerControl setDisplayRange(int minimum, int maximum, DynamicControl.DISPLAY_TYPE display_type)
minimum - minimum display value on slidermaximum - maximum display value on sliderdisplay_type - the type of display