Class GroupControl
java.lang.Object
org.opensourcephysics.ejs.control.GroupControl
- Direct Known Subclasses:
EjsControl
A base class to group several ControlElements, connect them
to one or more target objects in a unified form, and build a
graphic interface with all of them.
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionThe default constructor.GroupControl
(Object _target) The constructor.GroupControl
(Object _simulation, String _replaceName, Frame _replaceOwnerFrame) A specialized constructor for Ejs use. -
Method Summary
Modifier and TypeMethodDescriptionfinal ControlElement
Creates a new ControlElementfinal ControlElement
Creates a new ControlElement and gives it a namevoid
addListener
(String _name, String _method) void
addListener
(String _name, String _method, Object _anObject) Instructs the group to invoke a method (with an optional parameter) when a variable changes.final ControlElement
Creates a new ControlElement with a given name This is a special feature that is used by LauncherApplet, so that if the name coincides with a given one, a Frame becomes a Panel, so that it can be captured!final ControlElement
Creates a new ControlElement that wrapps an existing object If the object is not of the right class it will print a warning and ignore the object provided.Creates a new ControlElement that wrapps an existing object If the object is not of the right class it will print a warning and ignore the object provided.void
Adds an object to be controlled.void
appendPrefixPath
(String _prefix) Adds a prefix 'path' for unqualified elements.void
clear()
Destroy all elementsvoid
Clears the list of default package name for unqualified elementsvoid
Clears all variablesvoid
Completely destroy a ControlElement by namevoid
destroy
(ControlElement _element) Completely destroy a ControlElementboolean
getBoolean
(String _name) A convenience method to get a value as a booleangetComponent
(String _name) Returns the component of a control element by namegetContainer
(String _name) Returns the container of a control element by namegetControl
(String _name) int
Returns the current debug levelReturns the list (actually, a vector) of prefixdouble
A convenience method to get a value as a doublegetElement
(String _name) Returns a control element by nameint
A convenience method to get a value as an intstatic XML.ObjectLoader
Returns an XML.ObjectLoader to save and load data for this object.A convenience method to get a value as an ObjectReturns the owner frame for all subsequent DialogsReturns the replacement for the owner frame for all subsequent DialogsReturns the name of the replacement for the owner frame for all subsequent DialogsReturns the simulation under which the control is running This is used to up date the simulation whenever an Element changes a variable (See variableChanged in ControlElementA convenience method to get a value as a StringReturns one of the registered target objectsgetTopLevelAncestor
(String _name) Returns the top-level ancestor of an element (either the containing Window or Applet), or null if the element has not been added to any container.Returns the group value of a variable.Returns the visual of a control element by namevoid
Initialize all elementsboolean
isVariableRegistered
(String _name) Tells whether a variable is associated to any element.registerVariable
(String _name, ControlElement _element, int _index, Value _value) Associates an element internal value with a variable name.void
removeTarget
(String _name) Removes a target objectvoid
rename
(ControlElement _element, String _name) Renaming a ControlElementvoid
replaceOwnerFrame
(String _replaceName, Frame _replaceOwnerFrame) void
reset()
Reset all elementsvoid
setActive
(boolean _active) Set the active state of all elementsvoid
setDebugLevel
(int _level) Sets the debug levelvoid
setOwnerFrame
(Frame _frame) Sets the owner frame for all subsequent Dialogsvoid
setSimulation
(Simulation _sim) Sets the simulation under which the control is running This is used to up date the simulation whenever an Element changes a variable (See variableChanged in ControlElement)void
A convenience method to set a value to a booleanvoid
A convenience method to set a value to a doublevoid
A convenience method to set a value to an intvoid
A convenience method to set a value to any Objectvoid
A convenience method to set a value to a Stringvoid
Sets the group value for a variable.void
update()
Refresh all elementsvoid
variableChanged
(GroupVariable _variable, ControlElement _element, Value _value) Invoked by ControlElements when their internal variables change.
-
Field Details
-
DEBUG_NONE
public static final int DEBUG_NONE- See Also:
-
DEBUG_SET_AND_GET
public static final int DEBUG_SET_AND_GET- See Also:
-
DEBUG_ELEMENTS
public static final int DEBUG_ELEMENTS- See Also:
-
DEBUG_CONTROL
public static final int DEBUG_CONTROL- See Also:
-
DEBUG_CONTROL_VERBOSE
public static final int DEBUG_CONTROL_VERBOSE- See Also:
-
DEBUG_DRAWING
public static final int DEBUG_DRAWING- See Also:
-
DEBUG_DRAWING_VERBOSE
public static final int DEBUG_DRAWING_VERBOSE- See Also:
-
DEBUG_SYSTEM
public static final int DEBUG_SYSTEM- See Also:
-
DEBUG_SYSTEM_VERBOSE
public static final int DEBUG_SYSTEM_VERBOSE- See Also:
-
DEBUG_ALL
public static final int DEBUG_ALL- See Also:
-
replaceOwnerName
-
replaceOwnerFrame
-
-
Constructor Details
-
GroupControl
public GroupControl()The default constructor. -
GroupControl
The constructor.- Parameters:
_target
-
-
GroupControl
A specialized constructor for Ejs use. This adds elements to it in the ususal way, but replaces a Frame element of a given name by the prescribed frame.- Parameters:
_simulation
-_replaceName
-_replaceOwnerFrame
-
-
-
Method Details
-
setOwnerFrame
Sets the owner frame for all subsequent Dialogs- Parameters:
Frame
- _frame The frame that should own next Dialogs (if there are Dialogs in this group)
-
getOwnerFrame
Returns the owner frame for all subsequent Dialogs -
replaceOwnerFrame
-
getReplaceOwnerName
Returns the name of the replacement for the owner frame for all subsequent Dialogs -
getReplaceOwnerFrame
Returns the replacement for the owner frame for all subsequent Dialogs -
clearPrefixPath
public void clearPrefixPath()Clears the list of default package name for unqualified elements -
appendPrefixPath
Adds a prefix 'path' for unqualified elements. Hence "Frame" becomes _prefix + "Frame". The default list includes "org.opensourcephysics.ejs.control.swing.Control" and "org.opensourcephysics.ejs.control.drawables.Control"- Parameters:
String
- _prefix The prefix to be added to list
-
getDefaultPrefixList
Returns the list (actually, a vector) of prefix -
setSimulation
Sets the simulation under which the control is running This is used to up date the simulation whenever an Element changes a variable (See variableChanged in ControlElement)- Parameters:
Simulation
- _sim The simulation
-
getSimulation
Returns the simulation under which the control is running This is used to up date the simulation whenever an Element changes a variable (See variableChanged in ControlElement -
setDebugLevel
public void setDebugLevel(int _level) Sets the debug level- Parameters:
int
- _level The minimim level that should produce debug mesagges. Must be one of DEBUG_NONE, DEBUG_SET_AND_GET, DEBUG_ELEMENTS, DEBUG_ALL=255
-
getDebugLevel
public int getDebugLevel()Returns the current debug level- Returns:
- The actual minimim level that produces debug messages
-
getTarget
Returns one of the registered target objects- Parameters:
String
- _name The name given to the target when it was added
-
addTarget
Adds an object to be controlled. Actions can then refer to methods of the form 'name.method:parameter'- Parameters:
String
- _name A name to refer to the targetObject
- _target A target object
-
removeTarget
Removes a target object -
setValue
Sets the group value for a variable. This includes the value in all the elements of this group that are registered to this variable name.- Parameters:
String
- _name The variable nameValue
- _value The value as aValue
object
-
getValue
Returns the group value of a variable.- Parameters:
String
- _name The variable name- Returns:
- the
Value
object of the variable. If the variable has never been set, it returns null.
-
registerVariable
public GroupVariable registerVariable(String _name, ControlElement _element, int _index, Value _value) Associates an element internal value with a variable name. Later on, when the user sets the value for this variable, either programmatically or by interaction with a given element, all registered elements will be informed of the change. Invoked by ControlElements when processing the 'variable' property. Not to be used directly by users.- Parameters:
String
- _name The name of the variableControlElement
- _element The element to be registeredint
- _index An indentifier for the element internal valueValue
- _value The initial value if the variable doesn't already exist
-
isVariableRegistered
Tells whether a variable is associated to any element. Invoked by EjsControl's method 'setValue/getValue'. Not to be used directly by users.- Parameters:
ControlElement
- _element The element to be includedString
- _variable The variable name
-
variableChanged
Invoked by ControlElements when their internal variables change. Not be used directly by users. -
addListener
-
addListener
Instructs the group to invoke a method (with an optional parameter) when a variable changes.- Parameters:
String
- _name The name of the variable that may changeString
- _method The method that should be called in the controlledObject
- _anObject the object to pass in the special case the method is method(#CONTROL#) object.
-
rename
Renaming a ControlElement- Parameters:
String
- _name The new name for the element.
-
addNamed
Creates a new ControlElement with a given name This is a special feature that is used by LauncherApplet, so that if the name coincides with a given one, a Frame becomes a Panel, so that it can be captured!- Parameters:
String
- _type The class name of the new element.String
- _name The name of the new element.
-
add
Creates a new ControlElement- Parameters:
String
- _type The class name of the new element. If it is not qualified, then it is given the prefix (see above)
-
add
Creates a new ControlElement and gives it a name- Parameters:
String
- _type The class name of the new element. If it is not qualified, then it is given the default prefix (see above)String
- _propertyList A list of properties and Values to be set (see ControlElement.setProperties())
-
addObject
Creates a new ControlElement that wrapps an existing object If the object is not of the right class it will print a warning and ignore the object provided.- Parameters:
Object
- _object The element to be wrappedString
- _type The class name of the new element. If it is not qualified, then it is given the prefix (see above)
-
addObject
Creates a new ControlElement that wrapps an existing object If the object is not of the right class it will print a warning and ignore the object provided.- Parameters:
Object
- _object The element to be wrappedString
- _type The class name of the new element. If it is not qualified, then it is given the prefix (see above)String
- _propertyList A list of properties and Values to be set (see ControlElement.setProperties())
-
getElement
Returns a control element by name- Parameters:
String
- _name The name of the control element- Returns:
- the ControlElement if found, null otherwise.
-
getControl
-
getVisual
Returns the visual of a control element by name- Parameters:
String
- _name The name of the control element- Returns:
- the java.awt.Component visual of the element if found, null otherwise.
-
getComponent
Returns the component of a control element by name- Parameters:
String
- _name The name of the control element- Returns:
- the java.awt.Component component of the element if found, null otherwise.
-
getContainer
Returns the container of a control element by name- Parameters:
String
- _name The name of the control element- Returns:
- the java.awt.Container visual of the element if found, and the element is a container, null otherwise.
-
destroy
Completely destroy a ControlElement by name- Parameters:
String
- _name The name of the ControlElement to be destroyed
-
destroy
Completely destroy a ControlElement- Parameters:
ControlElement
- _element The ControlElement to be destroyed
-
reset
public void reset()Reset all elements -
initialize
public void initialize()Initialize all elements -
update
public void update()Refresh all elements -
setActive
public void setActive(boolean _active) Set the active state of all elements -
clearVariables
public void clearVariables()Clears all variables -
clear
public void clear()Destroy all elements -
getTopLevelAncestor
Returns the top-level ancestor of an element (either the containing Window or Applet), or null if the element has not been added to any container. If no element name is provided, the first control element whose component is a Window is returned.- Parameters:
String
- _name The name of the control element- Returns:
- the Container if found, null otherwise.
-
setValue
A convenience method to set a value to a boolean- Parameters:
_name
-_value
-
-
setValue
A convenience method to set a value to an int- Parameters:
_name
-_value
-
-
setValue
A convenience method to set a value to a double- Parameters:
_name
-_value
-
-
setValue
A convenience method to set a value to a String- Parameters:
_name
-_value
-
-
setValue
A convenience method to set a value to any Object- Parameters:
_name
-_value
-
-
getBoolean
A convenience method to get a value as a boolean- Parameters:
_name
-
-
getInt
A convenience method to get a value as an int- Parameters:
_name
-
-
getDouble
A convenience method to get a value as a double- Parameters:
_name
-
-
getString
A convenience method to get a value as a String- Parameters:
_name
-
-
getObject
A convenience method to get a value as an Object- Parameters:
_name
-
-
getLoader
Returns an XML.ObjectLoader to save and load data for this object.- Returns:
- the object loader
-