public enum ControlScope extends java.lang.Enum<ControlScope>
ControlScope
dictates how far (in
a topological sense) the object can reach in order to communicate with other
DynamicControl
objects. The different scopes available are:
UNIQUE
- a new independent control is created and only sends messages to registered listeners
SKETCH
- messages are also sent to other controls with the same name and scope belonging to other instances in the same sketch.
CLASS
- messages are also sent to other controls with the same name and scope belonging to other instances of the same class.
DEVICE
- messages are also sent to other controls with the same name and scope on the same device
GLOBAL
- messages are also sent to other controls with the same name and scope on the entire network.
TARGET
- messages are also sent to other controls with the same name and scope on specific or targeted devices on the network.
SKETCH
, so if DynamicControlParent.setControlScope(ControlScope)
or DynamicControl.setControlScope(ControlScope)
is not called, controls have SKETCH
For two Controls to match, they must have the same ControlScope, ControlType
, and Name. For example:
IntegerControl control1 = new IntegerControlSender(this, "ControlName", 0); control1.setControlScope(ControlScope.CLASS); IntegerTextControl control2 = new IntegerTextControl(this, "ControlName", 0) { @Override public void valueChanged(int control_val) {// Write your DynamicControl code below this line System.out.println("Read " + control_val); // Write your DynamicControl code above this line } };// End DynamicControl control2 code control2.setControlScope(ControlScope.CLASS); control1.setValue(2);The control1 and control2 will match because they both have a matching
CLASS
condition, the same name ("ControlName")
and are of type ControlType.INT
. The result will be that control2 will receive the value from
control1, which will result in Read 2 being printed to standard output.Enum Constant and Description |
---|
CLASS
Messages are sent to all devices of the same
ControlType , ControlScope and name to all instances of the same Class as the first parameter of the control constructor. |
DEVICE
Messages are sent to all devices of the same
ControlType , ControlScope and name on the same device. |
GLOBAL
Messages are sent to all devices of the same
ControlType , ControlScope and name on the entire network. |
SKETCH
Messages are sent to all devices of the same
ControlType , ControlScope and name to all instances of the same Object as the first parameter of the control constructor. |
TARGET
Messages are sent to registered listeners with the same scope and specific or targeted devices on the network.
|
UNIQUE
An independent control that only sends messages to the GUI and not to other Controls.
|
Modifier and Type | Method and Description |
---|---|
static ControlScope |
valueOf(java.lang.String name)
Returns the enum constant of this type with the specified name.
|
static ControlScope[] |
values()
Returns an array containing the constants of this enum type, in
the order they are declared.
|
public static final ControlScope UNIQUE
public static final ControlScope SKETCH
ControlType
, ControlScope
and name to all instances of the same Object
as the first parameter of the control constructor.
IntegerControl control1 = new IntegerControlSender(this, "ControlName", 0); control1.setControlScope(ControlScope.SKETCH); IntegerTextControl control2 = new IntegerTextControl(this, "ControlName", 0) { @Override public void valueChanged(int control_val) {// Write your DynamicControl code below this line System.out.println("Read " + control_val); // Write your DynamicControl code above this line } };// End DynamicControl control2 code control2.setControlScope(ControlScope.SKETCH); control1.setValue(2);The control1 and control2 will match because they both have a matching
CLASS
condition and have the same Object
as the first parameter of the control constructor , the same name ("ControlName")
and are of type ControlType.INT
. The result will be that control2 will receive the value from
control1, which will result in Read 2 being printed to standard output.
SKETCH
is different to CLASS
in that if this code was sent multiple times on identical sketches,
control1 and control2 would only match on the same sketch.
SKETCH
controls can be defined as another object. For example:
Object controlObject = hb.get("ControlObject"); IntegerControl control1 = new IntegerControlSender(controlObject, "ControlName", 0); IntegerTextControl control2 = new IntegerTextControl(controlObject, "ControlName", 0) {control1 and control2 match because they are both using controlObject as the control reference.
public static final ControlScope CLASS
ControlType
, ControlScope
and name to all instances of the same Class
as the first parameter of the control constructor.
This is the default scope and if DynamicControlParent.setControlScope(ControlScope)
or DynamicControl.setControlScope(ControlScope)
is not called, controls have SKETCH
IntegerControl control1 = new IntegerControlSender(this, "ControlName", 0); control1.setControlScope(ControlScope.CLASS); IntegerTextControl control2 = new IntegerTextControl(this, "ControlName", 0) { @Override public void valueChanged(int control_val) {// Write your DynamicControl code below this line System.out.println("Read " + control_val); // Write your DynamicControl code above this line } };// End DynamicControl control2 code control2.setControlScope(ControlScope.CLASS); control1.setValue(2);The control1 and control2 will match because they both have a matching
CLASS
condition and have the same Class
as the first parameter of the control constructor , the same name ("ControlName")
and are of type ControlType.INT
. The result will be that control2 will receive the value from
control1, which will result in Read 2 being printed to standard output.
CLASS
is different to SKETCH
in that if this code was sent multiple times on identical sketches,
control1 and control2 on all the sketches would match on all sketches.public static final ControlScope DEVICE
ControlType
, ControlScope
and name on the same device. For example:
IntegerControl control1 = new IntegerControlSender(this, "ControlName", 0); control1.setControlScope(ControlScope.DEVICE); IntegerTextControl control2 = new IntegerTextControl(this, "ControlName", 0) { @Override public void valueChanged(int control_val) {// Write your DynamicControl code below this line System.out.println("Read " + control_val); // Write your DynamicControl code above this line } };// End DynamicControl control2 code control2.setControlScope(ControlScope.DEVICE); control1.setValue(2);The value 2 will be sent to every
IntegerControl
or DynamicControl
of ControlType.INT
on this device that has the
name "ControlName" and has DEVICE
.public static final ControlScope GLOBAL
ControlType
, ControlScope
and name on the entire network.
// this is on device 1 IntegerControl control1 = new IntegerControlSender(this, "ControlName", 0); control1.setControlScope(ControlScope.GLOBAL); control1.setValue(2); // this is on device 2 IntegerTextControl control2 = new IntegerTextControl(this, "ControlName", 0) { @Override public void valueChanged(int control_val) {// Write your DynamicControl code below this line System.out.println("Read " + control_val); // Write your DynamicControl code above this line } };// End DynamicControl control2 code control2.setControlScope(ControlScope.GLOBAL);The value 2 will be sent to every
IntegerControl
or DynamicControl
of ControlType.INT
on the entire network that has the
name "ControlName" and has GLOBAL
.public static final ControlScope TARGET
DynamicControlParent.setControlTarget(String...)
and DynamicControlParent.setControlTarget(InetAddress...)
for specific details on
sending messages to a specific target address. Consider the following
IntegerControl control1 = new IntegerControlSender(this, "ControlName", 0); control1.setControlScope(ControlScope.TARGET); control1.addControlTarget("HB-123456", "HB-654321"); control1.addControlTarget( "192.168.0.2"); IntegerTextControl control2 = new IntegerTextControl(this, "ControlName", 0) { @Override public void valueChanged(int control_val) {// Write your DynamicControl code below this line System.out.println("Read " + control_val); // Write your DynamicControl code above this line } };// End DynamicControl control2 code control2.setControlScope(ControlScope.TARGET); control1.setValue(2); // This will not be seen by control2 unless control1 has this device as one of it's targets // This is on device "HB-654321" IntegerTextControl control3 = new IntegerTextControl(this, "ControlName", 0) { @Override public void valueChanged(int control_val) {// Write your DynamicControl code below this line System.out.println("Read " + control_val); // Write your DynamicControl code above this line } };// End DynamicControl receiver code control3.setControlScope(ControlScope.TARGET);In this example, control1 will send the value of 2 to devices whose names are HB-123456 or HB-654321, or at address "192.168.0.2". Controls on those devices of
ControlType.INT
, name "ControlName"
with TARGET
will accept the message. In this case, we see that control3
matches this (as it is on device "HB-654321") so it will print "Read 2" to the standard output;
however, control2 will not receive the message even though it is on the same device as control1 because
control1 did not have it's own device as a target through @link DynamicControlParent#setControlTarget(String...)}public static ControlScope[] values()
for (ControlScope c : ControlScope.values()) System.out.println(c);
public static ControlScope valueOf(java.lang.String name)
name
- the name of the enum constant to be returned.java.lang.IllegalArgumentException
- if this enum type has no constant with the specified namejava.lang.NullPointerException
- if the argument is null