Class ControlElement
- Direct Known Subclasses:
ControlDrawable
,ControlSwingElement
ControlElement
is a base class for an object that
can be managed using a series of configurable properties, hold actions
that when invoked graphically call other objects' methods, and be
responsible for the display and change of one or more internal variables.
ControlElement
s can be included into a GroupControl,
thus acting in a coordinated way.
In fact, the best way to use a ControlElement
, is to include
it into a GroupControl and then configure it using the
setProperty()
method.
After this, the value common to several of these ControlElements can be set and retrieved using a single setValue() or getValue() call from the ControlGroup.
You can also add any action you want to a ControlElement, but it is the implementing class' responsibility to trigger an action in response to a user's gesture (with the mouse or keyboard)
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final int
protected boolean
static final int
static final String
protected GroupControl
protected Object
static final int
static final int
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal ControlElement
Defines a generic action that can be invoked from thisControlElement
.final ControlElement
addAction
(int _type, Object _target, String _method, MethodWithOneParameter _secondAction) This is an advanced form of addAction that allows for nested actionsfinal ControlElement
Similar to the other addAction but extracts the target from the method, which must be of the form 'target.method:optional parameter', where target has been previously added to the list of targets of the group.void
destroy()
Clears any trace of myself (specially in the group)Provided for backwards compatibiliy onlyfinal GroupControl
getGroup()
Gets the GroupControl in which it operatesfinal String
getProperty
(String _property) Returns the value of a property.abstract String
getPropertyInfo
(String _property) Returns information about a given property.Returns the list of all properties that can be set for this ControlElement.final Simulation
Gets the Simulation in which it runsgetValue
(int _index) Gets the value of any internal variable.Provided for backwards compatibiliy onlyboolean
implementsProperty
(String _property) Whether the element implements a given propertyvoid
initializes the element.final void
Invokes all actions of type ACTIONfinal void
invokeActions
(int _type) Invokes all actions of this BasicControl of a given typefinal boolean
isActive()
Returns the active status of theControlElement
.parseConstant
(String _propertyType, String _value) Checks if a value can be considered a valid constant value for a property If not, it returns null, meaning the value can be considered to be a GroupVariablefinal boolean
propertyIsTypeOf
(String _property, String _keyword) Returns whether a property information contains a given keyword in its preamblefinal String
propertyType
(String _property) Returns the type of the propertyfinal void
removeAction
(int _type, Object _target, String _method) Removes an action.final void
removeAction
(int _type, String _method) Similar to removeAction but extracts the target from the methodvoid
reset()
resets the elementfinal void
setActive
(boolean _act) Sets whether aControlElement
actually invokes actions.void
setDefaultValue
(int _index) final void
setGroup
(GroupControl _group) Sets the GroupControl in which to operatefinal ControlElement
setProperties
(String _propertyList) Sets more than one property at once.setProperty
(String _property, String _value) Sets a property for thisControlElement
.void
Sets the value of the registered variables.toString()
Reports its name, if it has been set.final void
variableChanged
(int _variableIndex, Value _value) Reports changes of internal variablesfinal void
variableChangedDoNotUpdate
(int _variableIndex, Value _value) Reports changes of internal variables but simulation doesn't update Needed by RadioButtonsfinal void
Clear all registered internal variable propertiesfinal void
variablesChanged
(int[] _variableIndex, Value[] _value) Reports changes of more than one internal variables
-
Field Details
-
myGroup
-
myPropertiesTable
-
myObject
-
isUnderEjs
protected boolean isUnderEjs -
NAME
public static final int NAME- See Also:
-
ACTION
public static final int ACTION- See Also:
-
VARIABLE_CHANGED
public static final int VARIABLE_CHANGED- See Also:
-
METHOD_FOR_VARIABLE
public static final int METHOD_FOR_VARIABLE- See Also:
-
METHOD_TRIGGER
- See Also:
-
-
Constructor Details
-
ControlElement
Constructor ControlElement- Parameters:
_object
-
-
-
Method Details
-
getObject
-
getPropertyList
Returns the list of all properties that can be set for this ControlElement. Subclasses that add properties should implement this. Order is crucial here: Both for the presentation in an editor (f.i. ViewElement) and for the setValue() method. -
getPropertyInfo
Returns information about a given property. Subclasses that add properties should implement this. Order in the implementation is irrelevant.- The first keyword is ALWAYS the type. If more than one type is accepted, they are separated by | (do NOT use spaces!)
- The keyword CONSTANT applies to properties that can not be changed using the setValue() methods
- The keyword VARIABLE_EXPECTED is used when a String could be accepted, but a variable has priority. In this case, a String requires using inverted commas or quotes
- The keyword NotTrimmed specifies that leading or trailing spaces must be respected when present. This is useful for labels or titles, for instance
- The keyword BASIC is used by Ejs to group properties to the left hand side of the property editor
- The keyword HIDDEN is used by Ejs so that it does not display an entry in the editor field
- The keywords PREVIOUS and POSTPROCESS indicate that, when setting several properties at once (using setProperties()) the property must be process before, resp. after, the others
-
parseConstant
Checks if a value can be considered a valid constant value for a property If not, it returns null, meaning the value can be considered to be a GroupVariable- Parameters:
String
- _property The property nameString
- _value The proposed value for the property
-
setValue
Sets the value of the registered variables. Subclasses with internal values should extend this Order is crucial here: it must match exactly that of the getPropertyList() method.- Parameters:
int
- _index A keyword index that distinguishes among variablesValue
- _value The object holding the value for the variable.
-
setDefaultValue
public void setDefaultValue(int _index) -
getValue
Gets the value of any internal variable. Subclasses with internal values should extend this- Parameters:
int
- _index A keyword index that distinguishes among variables- Returns:
- Value _value The object holding the value for the variable.
-
setProperty
Sets a property for thisControlElement
. Implementing classes are responsible of deciding (by declaring them in the getPropertyList() method) what properties turn into visual changes, or different behaviour, of the ControlElement.However, every propery is accepted, even if it is not meaningful for a particular implementation of this interface. This can serve as a repository of information for future use.
Implementing classes should make sure that the following requirements are met:
- Properties can be set in any order. The final result should not depend on the order. Exceptions must be explicitly documented.
- Any property can be modified. If so, the old value, and whatever meaning it had, is superseded by the new one. If the new one is null, the old one is simply removed and setDefaultValue(index) is called in case a precise default value should be used.
- When the element is part of a GroupControl, final users should not use this setProperty method directly, but go through the corresponding method of the group.
- Parameters:
String
- _property The property nameString
- _value The value desired for the property- Returns:
- This same element. This is useful to nest more than one call to
setProperty
- See Also:
-
setProperties
Sets more than one property at once. The pairsproperty=value
must be separated by ';'. If any value has a ';' in it, then it must be set in a separatesetProperty
call.- Parameters:
String
- _propertyList The list of properties and Values to be set- Returns:
- This same element. This is useful to nest more
than one call to
setProperties
-
getProperty
Returns the value of a property.- Parameters:
String
- _property The property name
-
propertyIsTypeOf
Returns whether a property information contains a given keyword in its preamble- Parameters:
String
- _property The property nameString
- _keyword The keyword to look for
-
propertyType
Returns the type of the property- Parameters:
String
- _property The property name- Returns:
- String The type of the property
-
getComponent
Provided for backwards compatibiliy only -
getVisual
Provided for backwards compatibiliy only -
reset
public void reset()resets the element -
initialize
public void initialize()initializes the element. A kind of soft reset() -
implementsProperty
Whether the element implements a given property- Parameters:
_property
- the property
-
variablePropertiesClear
public final void variablePropertiesClear()Clear all registered internal variable properties -
toString
Reports its name, if it has been set. If not, returns a standard value. -
destroy
public void destroy()Clears any trace of myself (specially in the group) -
addAction
Defines a generic action that can be invoked from thisControlElement
. It is the responsibility of implementing classes to decide what actions types can be invoked and how.If the method field is not a valid method for this target object it will ignore the command (and perhaps print an error message).
- Parameters:
int
- _type The action typeObject
- _target The object whose method will be invokedString
- _method The method to call in the target object. The method can accept a single CONSTANT parameter, either boolean, int, double or String. See MethodWithOneParameter for more details.- Returns:
- This same element. This is useful to nest it with
other calls to
setProperty
oradAction
.
-
addAction
public final ControlElement addAction(int _type, Object _target, String _method, MethodWithOneParameter _secondAction) This is an advanced form of addAction that allows for nested actions -
addAction
Similar to the other addAction but extracts the target from the method, which must be of the form 'target.method:optional parameter', where target has been previously added to the list of targets of the group. -
removeAction
Removes an action. If the action does not exists, it does nothing.- Parameters:
int
- _type The action typeObject
- _target The object whose method will be invokedString
- _method The method to call in the target object.- See Also:
-
removeAction
Similar to removeAction but extracts the target from the method -
invokeActions
public final void invokeActions()Invokes all actions of type ACTION -
invokeActions
public final void invokeActions(int _type) Invokes all actions of this BasicControl of a given type- Parameters:
int
- _type The action type
-
variableChangedDoNotUpdate
Reports changes of internal variables but simulation doesn't update Needed by RadioButtons- Parameters:
int
- _variableIndex the index of the internal variable that changedValue
- _value the new value for the variable
-
variableChanged
Reports changes of internal variables- Parameters:
int
- _variableIndex the index of the internal variable that changedValue
- _value the new value for the variable
-
variablesChanged
Reports changes of more than one internal variables- Parameters:
int
- [] _variableIndexes the indexes of the internal variables that changedValue
- [] _value the new values for the variables
-
setActive
public final void setActive(boolean _act) Sets whether aControlElement
actually invokes actions. The default is true.- Parameters:
boolean
- _active Whether it is active
-
isActive
public final boolean isActive()Returns the active status of theControlElement
. -
setGroup
Sets the GroupControl in which to operate- Parameters:
GroupControl
- _group The GroupControl
-
getGroup
Gets the GroupControl in which it operates- Returns:
- the GroupControl
-
getSimulation
Gets the Simulation in which it runs- Returns:
- the Simulation
-