|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.opensourcephysics.ejs.control.ControlElement
public abstract class ControlElement
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 retrived 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' responsability to trigger an action in response to a user's gesture (with the mouse or keyboard)
GroupControl
Field Summary | |
---|---|
static int |
ACTION
|
protected boolean |
isUnderEjs
|
static int |
METHOD_FOR_VARIABLE
|
static java.lang.String |
METHOD_TRIGGER
|
protected GroupControl |
myGroup
|
protected java.lang.Object |
myObject
|
protected java.util.Hashtable<java.lang.String,java.lang.String> |
myPropertiesTable
|
static int |
NAME
|
static int |
VARIABLE_CHANGED
|
Constructor Summary | |
---|---|
ControlElement(java.lang.Object _object)
Constructor ControlElement |
Method Summary | |
---|---|
ControlElement |
addAction(int _type,
java.lang.Object _target,
java.lang.String _method)
Defines a generic action that can be invoked from this ControlElement . |
ControlElement |
addAction(int _type,
java.lang.Object _target,
java.lang.String _method,
MethodWithOneParameter _secondAction)
This is an advanced form of addAction that allows for nested actions |
ControlElement |
addAction(int _type,
java.lang.String _method)
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) |
java.awt.Component |
getComponent()
Provided for backwards compatibiliy only |
GroupControl |
getGroup()
Gets the GroupControl in which it operates |
java.lang.Object |
getObject()
|
java.lang.String |
getProperty(java.lang.String _property)
Returns the value of a property. |
abstract java.lang.String |
getPropertyInfo(java.lang.String _property)
Returns information about a given property. |
abstract java.util.ArrayList<java.lang.String> |
getPropertyList()
Returns the list of all properties that can be set for this ControlElement. |
Simulation |
getSimulation()
Gets the Simulation in which it runs |
Value |
getValue(int _index)
Gets the value of any internal variable. |
java.awt.Component |
getVisual()
Provided for backwards compatibiliy only |
boolean |
implementsProperty(java.lang.String _property)
Whether the element implements a given property |
void |
initialize()
initializes the element. |
void |
invokeActions()
Invokes all actions of type ACTION |
void |
invokeActions(int _type)
Invokes all actions of this BasicControl of a given type |
boolean |
isActive()
Returns the active status of the ControlElement . |
Value |
parseConstant(java.lang.String _propertyType,
java.lang.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 GroupVariable |
boolean |
propertyIsTypeOf(java.lang.String _property,
java.lang.String _keyword)
Returns wether a property information contains a given keyword in its preamble |
java.lang.String |
propertyType(java.lang.String _property)
Returns the type of the property |
void |
removeAction(int _type,
java.lang.Object _target,
java.lang.String _method)
Removes an action. |
void |
removeAction(int _type,
java.lang.String _method)
Similar to removeAction but extracts the target from the method |
void |
reset()
resets the element |
void |
setActive(boolean _act)
Sets whether a ControlElement actually invokes actions. |
void |
setDefaultValue(int _index)
|
void |
setGroup(GroupControl _group)
Sets the GroupControl in which to operate |
ControlElement |
setProperties(java.lang.String _propertyList)
Sets more than one property at once. |
ControlElement |
setProperty(java.lang.String _property,
java.lang.String _value)
Sets a property for this ControlElement . |
void |
setValue(int _index,
Value _value)
Sets the value of the registered variables. |
java.lang.String |
toString()
Reports its name, if it has been set. |
void |
variableChanged(int _variableIndex,
Value _value)
Reports changes of internal variables |
void |
variableChangedDoNotUpdate(int _variableIndex,
Value _value)
Reports changes of internal variables but simulation doesn't update Needed by RadioButtons |
void |
variablePropertiesClear()
Clear all registered internal variable properties |
void |
variablesChanged(int[] _variableIndex,
Value[] _value)
Reports changes of more than one internal variables |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
protected GroupControl myGroup
protected java.util.Hashtable<java.lang.String,java.lang.String> myPropertiesTable
protected java.lang.Object myObject
protected boolean isUnderEjs
public static final int NAME
public static final int ACTION
public static final int VARIABLE_CHANGED
public static final int METHOD_FOR_VARIABLE
public static final java.lang.String METHOD_TRIGGER
Constructor Detail |
---|
public ControlElement(java.lang.Object _object)
_object
- Method Detail |
---|
public java.lang.Object getObject()
public abstract java.util.ArrayList<java.lang.String> getPropertyList()
public abstract java.lang.String getPropertyInfo(java.lang.String _property)
public Value parseConstant(java.lang.String _propertyType, java.lang.String _value)
String
- _property The property nameString
- _value The proposed value for the propertypublic void setValue(int _index, Value _value)
int
- _index A keyword index that distinguishes among variablesValue
- _value The object holding the value for the variable.public void setDefaultValue(int _index)
public Value getValue(int _index)
int
- _index A keyword index that distinguishes among variables
public ControlElement setProperty(java.lang.String _property, java.lang.String _value)
ControlElement
. 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:
String
- _property The property nameString
- _value The value desired for the property
setProperty
GroupControl
public final ControlElement setProperties(java.lang.String _propertyList)
property=value
must be separated by ';'.
If any value has a ';' in it, then it must be set
in a separate setProperty
call.
String
- _propertyList The list of properties and Values
to be set
setProperties
public final java.lang.String getProperty(java.lang.String _property)
String
- _property The property namepublic final boolean propertyIsTypeOf(java.lang.String _property, java.lang.String _keyword)
String
- _property The property nameString
- _keyword The keyword to look forpublic final java.lang.String propertyType(java.lang.String _property)
String
- _property The property name
public java.awt.Component getComponent()
public java.awt.Component getVisual()
public void reset()
public void initialize()
public boolean implementsProperty(java.lang.String _property)
_property
- the propertypublic final void variablePropertiesClear()
public java.lang.String toString()
toString
in class java.lang.Object
public void destroy()
public final ControlElement addAction(int _type, java.lang.Object _target, java.lang.String _method)
ControlElement
. It is the responsability 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).
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.
setProperty
or adAction
.public final ControlElement addAction(int _type, java.lang.Object _target, java.lang.String _method, MethodWithOneParameter _secondAction)
public final ControlElement addAction(int _type, java.lang.String _method)
public final void removeAction(int _type, java.lang.Object _target, java.lang.String _method)
int
- _type The action typeObject
- _target The object whose method will be invokedString
- _method The method to call in the target object.addAction(int,Object,String)
public final void removeAction(int _type, java.lang.String _method)
public final void invokeActions()
public final void invokeActions(int _type)
int
- _type The action typepublic final void variableChangedDoNotUpdate(int _variableIndex, Value _value)
int
- _variableIndex the index of the internal variable that changedValue
- _value the new value for the variablepublic final void variableChanged(int _variableIndex, Value _value)
int
- _variableIndex the index of the internal variable that changedValue
- _value the new value for the variablepublic final void variablesChanged(int[] _variableIndex, Value[] _value)
int[]
- _variableIndexes the indexes of the internal variables that changedValue[]
- _value the new values for the variablespublic final void setActive(boolean _act)
ControlElement
actually invokes actions.
The default is true.
boolean
- _active Whether it is activepublic final boolean isActive()
ControlElement
.
public final void setGroup(GroupControl _group)
GroupControl
- _group The GroupControlpublic final GroupControl getGroup()
public final Simulation getSimulation()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |