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 intbooleanstatic intprotected Stringprotected static Stringprotected BufferedReaderprotected intstatic final intprotected Objectprotected BufferedWriterstatic final intprotected booleanprotected Class<?>protected booleanprotected StringFields inherited from interface org.opensourcephysics.controls.Control
NOT_EDITABLE_BACKGROUNDFields 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.voidMethod required by the Control interface.voidMethod required by the Control interface.voidClears all properties.clone()Returns a copy of this control.voiddispose()booleanReturns true if the most recent read operation failed.voidfinalize()static ObjectgetAdjustedFrameData(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".booleangetBoolean(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 StringgetClassName(String xml) getData()see TrackerPanel.LoaderGets the doctype.doubleGets the double value of the specified named property.intGets the int value of the specified named property.intgetLevel()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.intgetPropertyType(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.booleanisValid()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) voidMethod required by the Control interface.voidprintln()Method required by the Control interface.voidMethod required by the Control interface.protected voidprocessReader(String name, Resource res, BufferedReader in, Function<String, Void> whenDone) Read this file resourcevoidReads the control from a Reader, setting readFailed if there are any problems.Reads data into this control from a named source.voidreadForClass(String name, Class<?> type) Reads data into this control from a named source if the source specifies the same class as the current className.voidReads the control from an xml string.booleanreadXMLForClass(String xml, Class<?> type) Reads this control from an xml string if the xml specifies the same class as the current className.voidsaveObject(Object obj) Saves an object's data in this element.voidsetBasepath(String basepath) voidsetDecryptPolicy(int policy) Sets the decryption policy.voidsetDoctype(String name) Sets the doctype.voidsetLockValues(boolean lock) Locks the control's interface.voidsetObjectClass(Class<?> type) Sets the class of the object for which this element stores data.voidsetPassword(String pass) Sets the password.voidsetValid(boolean valid) Sets the valid property.voidSets a property with the specified name and boolean value.voidSets a property with the specified name and double value.voidvoidSets a property with the specified name and int value.voidSets a property with the specified name and object value.voidSets a property with the specified name and object value.voidsetVersion(String vers) Sets the version.toString()Returns the string xml representation.toXML()Returns this control as an xml string.voidWrites this control to a Writer.Writes this control as an xml file with the specified name.voidwriteDocType(Writer out) Writes the DTD to a Writer.Methods inherited from class org.opensourcephysics.controls.XMLNode
getParentProperty, getPropertyType, setValueMethods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods 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:
getBasepathin interfaceXMLControl
-
setBasepath
- Specified by:
setBasepathin 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:
setLockValuesin 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:
getBooleanin 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:
getPropertyNamesin interfaceControl- Returns:
- a set of names
-
getPropertyNamesRaw
Description copied from interface:ControlGets the names of all properties stored in this control.- Specified by:
getPropertyNamesRawin interfaceControl- Returns:
- the actual property list
-
getPropertyType
Gets the type of the specified property. Returns null if the property is not found.- Specified by:
getPropertyTypein 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:
readin 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:
readXMLin interfaceXMLControl- Parameters:
xml- the xml string
-
read
Reads the control from a Reader, setting readFailed if there are any problems.- Specified by:
readin 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:
failedToReadin interfaceXMLControl- Returns:
trueif the most recent read operation failed
-
write
Writes this control as an xml file with the specified name.- Specified by:
writein 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:
writein 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:
toXMLin interfaceXMLControl- Returns:
- the xml string
-
setValid
public void setValid(boolean valid) Sets the valid property.- Parameters:
valid-trueto 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:
trueif 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- theClassof the object
-
getObjectClass
Gets the class of the object for which this element stores data.- Specified by:
getObjectClassin interfaceXMLControl- Returns:
- the
Classof the object
-
getObjectClassName
Gets the name of the object class for which this element stores data.- Specified by:
getObjectClassNamein interfaceXMLControl- Returns:
- the object class name
-
saveObject
Saves an object's data in this element.- Specified by:
saveObjectin 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:
loadObjectin interfaceXMLControl- Parameters:
obj- the object to load- Returns:
- the loaded object
-
loadObject
- Specified by:
loadObjectin 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:
clearValuesin 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:
clearMessagesin interfaceControl
-
calculationDone
Method required by the Control interface.- Specified by:
calculationDonein interfaceControl- Parameters:
s- the string
-
getPropertyName
Gets the property name.- Specified by:
getPropertyNamein interfaceXMLProperty- Returns:
- a name
-
getPropertyClass
Gets the property class.- Specified by:
getPropertyClassin interfaceXMLProperty- Returns:
- the class
-
getLevel
public int getLevel()Gets the level of this property relative to the root.- Specified by:
getLevelin interfaceXMLProperty- Returns:
- a non-negative integer
-
getPropertyContent
Gets the property content of this control.- Specified by:
getPropertyContentin interfaceXMLProperty- Returns:
- a list of XMLProperties
-
getPropsRaw
Gets the property content of this control.- Specified by:
getPropsRawin interfaceXMLControl- Returns:
- a list of XMLProperties
-
getChildControl
Gets the named XMLControl child of this property. May return null.- Specified by:
getChildControlin 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:
getChildControlsin 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()
-