Class GroupControl

java.lang.Object
org.opensourcephysics.ejs.control.GroupControl
Direct Known Subclasses:
EjsControl

public class GroupControl extends Object
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 Details

  • Constructor Details

    • GroupControl

      public GroupControl()
      The default constructor.
    • GroupControl

      public GroupControl(Object _target)
      The constructor.
      Parameters:
      _target -
    • GroupControl

      public GroupControl(Object _simulation, String _replaceName, Frame _replaceOwnerFrame)
      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

      public void setOwnerFrame(Frame _frame)
      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

      public Frame getOwnerFrame()
      Returns the owner frame for all subsequent Dialogs
    • replaceOwnerFrame

      public void replaceOwnerFrame(String _replaceName, Frame _replaceOwnerFrame)
    • getReplaceOwnerName

      public String getReplaceOwnerName()
      Returns the name of the replacement for the owner frame for all subsequent Dialogs
    • getReplaceOwnerFrame

      public Frame 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

      public void appendPrefixPath(String _prefix)
      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

      public Vector<String> getDefaultPrefixList()
      Returns the list (actually, a vector) of prefix
    • setSimulation

      public void 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)
      Parameters:
      Simulation - _sim The simulation
    • getSimulation

      public 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

      public Object getTarget(String _name)
      Returns one of the registered target objects
      Parameters:
      String - _name The name given to the target when it was added
    • addTarget

      public void addTarget(String _name, Object _target)
      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 target
      Object - _target A target object
    • removeTarget

      public void removeTarget(String _name)
      Removes a target object
    • setValue

      public void setValue(String _name, Value _value)
      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 name
      Value - _value The value as a Value object
    • getValue

      public Value getValue(String _name)
      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 variable
      ControlElement - _element The element to be registered
      int - _index An indentifier for the element internal value
      Value - _value The initial value if the variable doesn't already exist
    • isVariableRegistered

      public boolean isVariableRegistered(String _name)
      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 included
      String - _variable The variable name
    • variableChanged

      public void variableChanged(GroupVariable _variable, ControlElement _element, Value _value)
      Invoked by ControlElements when their internal variables change. Not be used directly by users.
    • addListener

      public void addListener(String _name, String _method)
    • addListener

      public void addListener(String _name, String _method, Object _anObject)
      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 change
      String - _method The method that should be called in the controlled
      Object - _anObject the object to pass in the special case the method is method(#CONTROL#) object.
    • rename

      public void rename(ControlElement _element, String _name)
      Renaming a ControlElement
      Parameters:
      String - _name The new name for the element.
    • addNamed

      public final ControlElement addNamed(String _type, String _name)
      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

      public final ControlElement add(String _type)
      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

      public final ControlElement add(String _type, String _propertyList)
      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

      public final ControlElement addObject(Object _object, String _type)
      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 wrapped
      String - _type The class name of the new element. If it is not qualified, then it is given the prefix (see above)
    • addObject

      public ControlElement addObject(Object _object, String _type, String _propertyList)
      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 wrapped
      String - _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

      public ControlElement getElement(String _name)
      Returns a control element by name
      Parameters:
      String - _name The name of the control element
      Returns:
      the ControlElement if found, null otherwise.
    • getControl

      public ControlElement getControl(String _name)
    • getVisual

      public Component getVisual(String _name)
      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

      public Component getComponent(String _name)
      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

      public Container getContainer(String _name)
      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

      public void destroy(String _name)
      Completely destroy a ControlElement by name
      Parameters:
      String - _name The name of the ControlElement to be destroyed
    • destroy

      public void destroy(ControlElement _element)
      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

      public Container getTopLevelAncestor(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. 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

      public void setValue(String _name, boolean _value)
      A convenience method to set a value to a boolean
      Parameters:
      _name -
      _value -
    • setValue

      public void setValue(String _name, int _value)
      A convenience method to set a value to an int
      Parameters:
      _name -
      _value -
    • setValue

      public void setValue(String _name, double _value)
      A convenience method to set a value to a double
      Parameters:
      _name -
      _value -
    • setValue

      public void setValue(String _name, String _value)
      A convenience method to set a value to a String
      Parameters:
      _name -
      _value -
    • setValue

      public void setValue(String _name, Object _value)
      A convenience method to set a value to any Object
      Parameters:
      _name -
      _value -
    • getBoolean

      public boolean getBoolean(String _name)
      A convenience method to get a value as a boolean
      Parameters:
      _name -
    • getInt

      public int getInt(String _name)
      A convenience method to get a value as an int
      Parameters:
      _name -
    • getDouble

      public double getDouble(String _name)
      A convenience method to get a value as a double
      Parameters:
      _name -
    • getString

      public String getString(String _name)
      A convenience method to get a value as a String
      Parameters:
      _name -
    • getObject

      public Object getObject(String _name)
      A convenience method to get a value as an Object
      Parameters:
      _name -
    • getLoader

      public static XML.ObjectLoader getLoader()
      Returns an XML.ObjectLoader to save and load data for this object.
      Returns:
      the object loader