Package org.opensourcephysics.controls
Class XMLControlElement
java.lang.Object
org.opensourcephysics.controls.XMLNode
org.opensourcephysics.controls.XMLControlElement
- All Implemented Interfaces:
Control
,XMLControl
,XMLProperty
This is a basic xml control for storing data.
- Version:
- 1.0
- Author:
- Douglas Brown
-
Nested Class Summary
Nested ClassesNested classes/interfaces inherited from interface org.opensourcephysics.controls.XMLProperty
XMLProperty.WrappedArray
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final int
boolean
static int
protected String
protected static String
protected BufferedReader
protected int
static final int
protected Object
protected BufferedWriter
static final int
protected boolean
protected Class<?>
protected boolean
protected String
Fields inherited from interface org.opensourcephysics.controls.Control
NOT_EDITABLE_BACKGROUND
Fields inherited from interface org.opensourcephysics.controls.XMLProperty
TYPE_ARRAY, TYPE_BOOLEAN, TYPE_COLLECTION, TYPE_DOUBLE, TYPE_INT, TYPE_OBJECT, TYPE_STRING, TYPE_UNKNOWN, TYPE_WRAPPED_ARRAY, types
-
Constructor Summary
ConstructorsConstructorDescriptionConstructs an empty control for the Object class.XMLControlElement
(File xmlFile) BH we need to read the File object directly, as it will have the data in it already.XMLControlElement
(Class<?> type) Constructs an empty control for the specified class.XMLControlElement
(Object obj) Constructs and loads a control with the specified object.XMLControlElement
(String input) Constructs a control and reads the specified input.XMLControlElement
(XMLControl control) Constructs a copy of the specified XMLControl.XMLControlElement
(XMLProperty parent) Constructs a control with the specified parent. -
Method Summary
Modifier and TypeMethodDescriptionaddNumbering
(String name) Appends numbering to a specified name.void
Method required by the Control interface.void
Method required by the Control interface.void
Clears all properties.clone()
Returns a copy of this control.void
dispose()
boolean
Returns true if the most recent read operation failed.void
finalize()
static Object
getAdjustedFrameData
(Object o, Object data) For Tracker, tap into TrackerIO.asyncLoader to check to see if this FrameData needs so be adjusted based on the VideoControl property "frameshift".boolean
getBoolean
(String name) Gets the boolean value of the specified named property.getChildControl
(String name) Gets the named XMLControl child of this property.Gets the XMLControl children of this property.static String
getClassName
(String xml) getData()
see TrackerPanel.LoaderGets the doctype.double
Gets the double value of the specified named property.int
Gets the int value of the specified named property.int
getLevel()
Gets the level of this property relative to the root.Gets the object value of the specified named property.Class<?>
Gets the class of the object for which this element stores data.Gets the name of the object class for which this element stores data.<T> List<T>
getObjects
(Class<T> type) Returns a list of objects of a specified class within this control.<T> List<T>
getObjects
(Class<T> type, boolean useChooser) Returns a list of objects of a specified class within this control.Gets the password.Class<?>
Gets the property class.Gets the property content of this control.Gets the property name.Gets the set of property names.Gets the names of all properties stored in this control.int
getPropertyType
(String name) Gets the type of the specified property.Gets the property content of this control.Gets the root control.Gets the string value of the specified named property.Gets the version.boolean
isValid()
Gets the valid property.loadObject
(Object obj) BH! THIS METHOD COULD FAIL IN JAVASCRIPT because importAll is false 111 references !!! Loads an object with data from this element.loadObject
(Object obj, boolean autoImport) BH! THIS METHOD WILL FAIL IN JAVASCRIPT when autoImport is false (not called in OSP or Tracker?) Loads an object with data from this element.loadObject
(Object obj, boolean autoImport, boolean importAll) Loads an object with data from this element.loadObject
(Object obj, Object data) void
Method required by the Control interface.void
println()
Method required by the Control interface.void
Method required by the Control interface.protected void
processReader
(String name, Resource res, BufferedReader in, Function<String, Void> whenDone) Read this file resourcevoid
Reads the control from a Reader, setting readFailed if there are any problems.Reads data into this control from a named source.void
readForClass
(String name, Class<?> type) Reads data into this control from a named source if the source specifies the same class as the current className.void
Reads the control from an xml string.boolean
readXMLForClass
(String xml, Class<?> type) Reads this control from an xml string if the xml specifies the same class as the current className.void
saveObject
(Object obj) Saves an object's data in this element.void
setBasepath
(String basepath) void
setDecryptPolicy
(int policy) Sets the decryption policy.void
setDoctype
(String name) Sets the doctype.void
setLockValues
(boolean lock) Locks the control's interface.void
setObjectClass
(Class<?> type) Sets the class of the object for which this element stores data.void
setPassword
(String pass) Sets the password.void
setValid
(boolean valid) Sets the valid property.void
Sets a property with the specified name and boolean value.void
Sets a property with the specified name and double value.void
void
Sets a property with the specified name and int value.void
Sets a property with the specified name and object value.void
Sets a property with the specified name and object value.void
setVersion
(String vers) Sets the version.toString()
Returns the string xml representation.toXML()
Returns this control as an xml string.void
Writes this control to a Writer.Writes this control as an xml file with the specified name.void
writeDocType
(Writer out) Writes the DTD to a Writer.Methods inherited from class org.opensourcephysics.controls.XMLNode
getParentProperty, getPropertyType, setValue
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface org.opensourcephysics.controls.XMLProperty
getParentProperty, getPropertyType, setValue
-
Field Details
-
ALWAYS_DECRYPT
public static final int ALWAYS_DECRYPT- See Also:
-
PASSWORD_DECRYPT
public static final int PASSWORD_DECRYPT- See Also:
-
NEVER_DECRYPT
public static final int NEVER_DECRYPT- See Also:
-
compactArraySize
public static int compactArraySize -
encoding
-
theClass
-
counts
-
object
-
level
protected int level -
input
-
output
-
canWrite
public boolean canWrite -
valid
protected boolean valid -
readFailed
protected boolean readFailed -
version
-
doctype
-
loader
-
-
Constructor Details
-
XMLControlElement
public XMLControlElement()Constructs an empty control for the Object class. -
XMLControlElement
Constructs an empty control for the specified class.- Parameters:
type
- the class.
-
XMLControlElement
Constructs and loads a control with the specified object.- Parameters:
obj
- the object.
-
XMLControlElement
Constructs a control with the specified parent.- Parameters:
parent
- the parent.
-
XMLControlElement
BH we need to read the File object directly, as it will have the data in it already.- Parameters:
xmlFile
-
-
XMLControlElement
Constructs a control and reads the specified input. Input may be a file name or an xml string- Parameters:
input
- the input string
-
XMLControlElement
Constructs a copy of the specified XMLControl.- Parameters:
control
- the XMLControl to copy.
-
-
Method Details
-
getBasepath
- Specified by:
getBasepath
in interfaceXMLControl
-
setBasepath
- Specified by:
setBasepath
in interfaceXMLControl
-
getData
see TrackerPanel.Loader- Returns:
- the TrackerIO.AsyncLoader if a Tracker object
-
setLockValues
public void setLockValues(boolean lock) Locks the control's interface. Values sent to the control will not update the display until the control is unlocked. Not implemented.- Specified by:
setLockValues
in interfaceControl
- Parameters:
lock
- boolean
-
setValue
Sets a property with the specified name and boolean value. -
setValue
Sets a property with the specified name and double value. -
setValue
Sets a property with the specified name and int value. -
setValue
Sets a property with the specified name and object value. -
setValue
-
setValue
Sets a property with the specified name and object value.- Parameters:
name
- the nameobj
- the objectwriteNullFinalElement
- true to write a final null array element (if needed)
-
getBoolean
Gets the boolean value of the specified named property.- Specified by:
getBoolean
in interfaceControl
- Parameters:
name
- the name- Returns:
- the boolean value, or false if none found
-
getDouble
Gets the double value of the specified named property. -
getInt
Gets the int value of the specified named property. -
getString
Gets the string value of the specified named property. -
getObject
Gets the object value of the specified named property. "framedata" arrays will be adjusted only during loading, not export, and only if needed. In that case, this.data will be TrackerIO.AsyncLoader -
getPropertyNames
Gets the set of property names.- Specified by:
getPropertyNames
in interfaceControl
- Returns:
- a set of names
-
getPropertyNamesRaw
Description copied from interface:Control
Gets the names of all properties stored in this control.- Specified by:
getPropertyNamesRaw
in interfaceControl
- Returns:
- the actual property list
-
getPropertyType
Gets the type of the specified property. Returns null if the property is not found.- Specified by:
getPropertyType
in interfaceXMLControl
- Parameters:
name
- the property name- Returns:
- the type
-
setPassword
Sets the password. Files are encrypted when the password is non-null.- Parameters:
pass
- the password or phrase
-
getPassword
Gets the password.- Returns:
- the password
-
setDecryptPolicy
public void setDecryptPolicy(int policy) Sets the decryption policy.- Parameters:
policy
- the decryption policy: NEVER_DECRYPT, PASSWORD_DECRYPT or ALWAYS_DECRYPT
-
readAsync
-
processReader
protected void processReader(String name, Resource res, BufferedReader in, Function<String, Void> whenDone) Read this file resource- Parameters:
name
-res
-in
-whenDone
- will be passed a File[] array or null
-
read
Reads data into this control from a named source.- Specified by:
read
in interfaceXMLControl
- Parameters:
fileName
- the name- Returns:
- the path of the opened document or null if failed
-
readXML
Reads the control from an xml string.- Specified by:
readXML
in interfaceXMLControl
- Parameters:
xml
- the xml string
-
read
Reads the control from a Reader, setting readFailed if there are any problems.- Specified by:
read
in interfaceXMLControl
- Parameters:
in
- the Reader
-
readForClass
Reads data into this control from a named source if the source specifies the same class as the current className. BH: never called- Parameters:
name
- the nametype
- the class- Returns:
- the path of the opened document or null if failed
-
readXMLForClass
Reads this control from an xml string if the xml specifies the same class as the current className. Utilized in org.colos.ejs.library.Simulation- Parameters:
xml
- the xml stringtype
- the class- Returns:
- true if successfully read
-
failedToRead
public boolean failedToRead()Returns true if the most recent read operation failed.- Specified by:
failedToRead
in interfaceXMLControl
- Returns:
true
if the most recent read operation failed
-
write
Writes this control as an xml file with the specified name.- Specified by:
write
in interfaceXMLControl
- Parameters:
fileName
- the file name- Returns:
- the path of the saved document or null if failed
-
write
Writes this control to a Writer.- Specified by:
write
in interfaceXMLControl
- Parameters:
out
- the Writer
-
writeDocType
Writes the DTD to a Writer.- Parameters:
out
- the Writer
-
toXML
Returns this control as an xml string.- Specified by:
toXML
in interfaceXMLControl
- Returns:
- the xml string
-
setValid
public void setValid(boolean valid) Sets the valid property.- Parameters:
valid
-true
to write the DTD and DocType
-
isValid
public boolean isValid()Gets the valid property. When true, this writes the DTD and defines the DocType when writing an xml document. Note: the presence or absense of the DocType header and DTD has no effect on the read() methods--this will always read a well-formed osp document and ignore a non-osp document.- Returns:
true
if this is valid
-
setVersion
Sets the version.- Parameters:
vers
- the version data
-
getVersion
Gets the version. May return null.- Returns:
- the version
-
setDoctype
Sets the doctype. Not yet implemented since only one doctype is defined.- Parameters:
name
- the doctype resource name
-
getDoctype
Gets the doctype. May return null.- Returns:
- the doctype
-
setObjectClass
Sets the class of the object for which this element stores data.- Parameters:
type
- theClass
of the object
-
getObjectClass
Gets the class of the object for which this element stores data.- Specified by:
getObjectClass
in interfaceXMLControl
- Returns:
- the
Class
of the object
-
getObjectClassName
Gets the name of the object class for which this element stores data.- Specified by:
getObjectClassName
in interfaceXMLControl
- Returns:
- the object class name
-
saveObject
Saves an object's data in this element.- Specified by:
saveObject
in interfaceXMLControl
- Parameters:
obj
- the object to save.
-
loadObject
BH! THIS METHOD COULD FAIL IN JAVASCRIPT because importAll is false 111 references !!! Loads an object with data from this element. This asks the user for approval and review before importing data from mismatched classes.- Specified by:
loadObject
in interfaceXMLControl
- Parameters:
obj
- the object to load- Returns:
- the loaded object
-
loadObject
- Specified by:
loadObject
in interfaceXMLControl
-
loadObject
BH! THIS METHOD WILL FAIL IN JAVASCRIPT when autoImport is false (not called in OSP or Tracker?) Loads an object with data from this element. This asks the user to review data from mismatched classes before importing it.- Parameters:
obj
- the object to loadautoImport
- true to automatically import data from mismatched classes- Returns:
- the loaded object
-
loadObject
Loads an object with data from this element. false for BOTH parameters autoImport and importAll will FAIL IN JAVASCRIPT- Parameters:
obj
- the object to loadautoImport
- true to automatically import data from mismatched classesimportAll
- true to import all importable data- Returns:
- the loaded object
-
clearValues
public void clearValues()Clears all properties.- Specified by:
clearValues
in interfaceControl
-
println
Method required by the Control interface. -
println
public void println()Method required by the Control interface. -
print
Method required by the Control interface. -
clearMessages
public void clearMessages()Method required by the Control interface.- Specified by:
clearMessages
in interfaceControl
-
calculationDone
Method required by the Control interface.- Specified by:
calculationDone
in interfaceControl
- Parameters:
s
- the string
-
getPropertyName
Gets the property name.- Specified by:
getPropertyName
in interfaceXMLProperty
- Returns:
- a name
-
getPropertyClass
Gets the property class.- Specified by:
getPropertyClass
in interfaceXMLProperty
- Returns:
- the class
-
getLevel
public int getLevel()Gets the level of this property relative to the root.- Specified by:
getLevel
in interfaceXMLProperty
- Returns:
- a non-negative integer
-
getPropertyContent
Gets the property content of this control.- Specified by:
getPropertyContent
in interfaceXMLProperty
- Returns:
- a list of XMLProperties
-
getPropsRaw
Gets the property content of this control.- Specified by:
getPropsRaw
in interfaceXMLControl
- Returns:
- a list of XMLProperties
-
getChildControl
Gets the named XMLControl child of this property. May return null.- Specified by:
getChildControl
in interfaceXMLProperty
- Parameters:
name
- the property name- Returns:
- the XMLControl
-
getChildControls
Gets the XMLControl children of this property. The returned array has length for type "object" = 1, "collection" and "array" = 0+, other types = 0.- Specified by:
getChildControls
in interfaceXMLProperty
- Returns:
- an XMLControl array
-
getRootControl
Gets the root control.- Returns:
- the root control
-
addNumbering
Appends numbering to a specified name. Increments the number each time this is called for the same name.- Parameters:
name
- the name- Returns:
- the name with appended numbering
-
toString
Returns the string xml representation. -
getObjects
Returns a list of objects of a specified class within this control.- Parameters:
type
- the Class- Returns:
- the list of objects
-
getObjects
Returns a list of objects of a specified class within this control.- Parameters:
type
- the ClassuseChooser
- true to allow user to choose- Returns:
- the list of objects
-
clone
Returns a copy of this control. -
getAdjustedFrameData
For Tracker, tap into TrackerIO.asyncLoader to check to see if this FrameData needs so be adjusted based on the VideoControl property "frameshift".- Parameters:
o
-data
-- Returns:
-
getClassName
-
finalize
public void finalize() -
dispose
public void dispose()
-