Package g3.project.elements
Class DocElement
- java.lang.Object
-
- nu.xom.Node
-
- nu.xom.ParentNode
-
- nu.xom.Element
-
- g3.project.elements.DocElement
-
- All Implemented Interfaces:
Scriptable
public final class DocElement extends nu.xom.Element implements Scriptable
- Author:
- Group 3
-
-
Constructor Summary
Constructors Constructor Description DocElement(java.lang.String name)
DocElement(java.lang.String name, java.lang.String uri)
DocElement(nu.xom.Element element)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addScriptFile(java.nio.file.Path path, java.lang.String language)
Attach a new script to the element.void
deleteElement(VisualElement el, DocIO resIO)
Delete an element.void
deleteElement(java.lang.String id, DocIO resIO)
Delete an element.java.util.function.Consumer<VisualElement>
getChangeCallback()
Get the change callback.java.util.Optional<PageElement>
getCurrentPage()
Get the currently open page.java.util.Optional<VisualElement>
getElementByID(java.lang.String id)
Returns an element in the doc by its' ID.java.lang.Boolean
getEvalRequired()
Get if the element requires evaluating again.java.lang.String
getNewUniqueID(java.lang.String idForType)
Return a new Unique ID for an element.java.util.Optional<PageElement>
getPage(java.lang.Integer pageNum)
Maybe get a target page.java.util.Optional<PageElement>
getPage(java.lang.String pageID)
Maybe get target page.java.util.ArrayList<PageElement>
getPages()
java.util.Optional<RecursiveBindings>
getParentElementScriptingBindings()
Get the program-base definitions.java.util.Optional<Scriptable>
getParentScriptable()
Get the parent of this Scriptable element.java.lang.String
getRealType()
Return the type of the element.java.util.Optional<ScriptElement>
getScriptEl()
Get the ScriptElement attached to this object.RecursiveBindings
getScriptingBindings()
Get the local scope for this object.java.util.ArrayList<java.lang.String>
getValidationErrors()
Get any validation errors in the document.void
insertPage(java.lang.Integer pageNum, PageElement el)
Add a new page.java.lang.String
insertPage(java.lang.Integer pageNum, java.lang.String pageTitle, java.lang.Double xSize, java.lang.Double ySize)
Add a page with the specified requirements.void
movePage(PageElement page, java.lang.Integer to)
Move a page.void
setChangeCallback(java.util.function.Consumer<VisualElement> func)
Set change callback.void
setEvalRequired(java.lang.Boolean req)
Set if the element requires evaluating again.void
setValidationErrors(java.util.ArrayList<java.lang.String> errors)
Set doc validation errors.java.lang.Boolean
validateUniqueID(java.lang.String id)
Validates if the given ID is unique or not.-
Methods inherited from class nu.xom.Element
addAttribute, addNamespaceDeclaration, appendChild, copy, getAttribute, getAttribute, getAttribute, getAttributeCount, getAttributeValue, getAttributeValue, getBaseURI, getChildElements, getChildElements, getChildElements, getFirstChildElement, getFirstChildElement, getLocalName, getNamespaceDeclarationCount, getNamespacePrefix, getNamespacePrefix, getNamespaceURI, getNamespaceURI, getQualifiedName, getValue, insertChild, removeAttribute, removeChildren, removeNamespaceDeclaration, setBaseURI, setLocalName, setNamespacePrefix, setNamespaceURI, shallowCopy, toString, toXML
-
Methods inherited from class nu.xom.ParentNode
appendChild, getChild, getChildCount, indexOf, insertChild, removeChild, removeChild, replaceChild
-
-
-
-
Method Detail
-
setChangeCallback
public void setChangeCallback(java.util.function.Consumer<VisualElement> func)
Set change callback.- Parameters:
func
- Notifier Function.
-
getChangeCallback
public java.util.function.Consumer<VisualElement> getChangeCallback()
Get the change callback.- Returns:
- change callback.
-
setValidationErrors
public void setValidationErrors(java.util.ArrayList<java.lang.String> errors)
Set doc validation errors.- Parameters:
errors
- validation errors.
-
getValidationErrors
public java.util.ArrayList<java.lang.String> getValidationErrors()
Get any validation errors in the document.- Returns:
- Array of validation errors.
-
getPages
public java.util.ArrayList<PageElement> getPages()
- Returns:
- ArrayList containing the Doc's pages
-
getCurrentPage
public java.util.Optional<PageElement> getCurrentPage()
Get the currently open page.- Returns:
- Maybe Page (if open).
-
getPage
public java.util.Optional<PageElement> getPage(java.lang.String pageID)
Maybe get target page.- Parameters:
pageID
- Target page ID.- Returns:
- Maybe page.
-
getPage
public java.util.Optional<PageElement> getPage(java.lang.Integer pageNum)
Maybe get a target page.- Parameters:
pageNum
- Target page number.- Returns:
- Maybe page.
-
movePage
public void movePage(PageElement page, java.lang.Integer to)
Move a page.- Parameters:
page
- Page to move.to
- New location.
-
insertPage
public void insertPage(java.lang.Integer pageNum, PageElement el)
Add a new page.- Parameters:
pageNum
- Page number.el
- Page.
-
insertPage
public java.lang.String insertPage(java.lang.Integer pageNum, java.lang.String pageTitle, java.lang.Double xSize, java.lang.Double ySize)
Add a page with the specified requirements.- Parameters:
pageNum
- Page Number.pageTitle
- Page Title/Friendly Name.xSize
- X Size in PX.ySize
- Y Size in PX.- Returns:
- New Page's ID.
-
getNewUniqueID
public java.lang.String getNewUniqueID(java.lang.String idForType)
Return a new Unique ID for an element. The param is not really necessary, but useful- Parameters:
idForType
- Type of object (will be prefixed to returned ID).- Returns:
- New UID
-
validateUniqueID
public java.lang.Boolean validateUniqueID(java.lang.String id)
Validates if the given ID is unique or not. The element it will be attached to must NOT already be in the doc!- Parameters:
id
- ID to validate.- Returns:
- Validity
-
getElementByID
public java.util.Optional<VisualElement> getElementByID(java.lang.String id)
Returns an element in the doc by its' ID.- Parameters:
id
- ID of element.- Returns:
- Optional of Element
-
deleteElement
public void deleteElement(java.lang.String id, DocIO resIO)
Delete an element.- Parameters:
id
- Element ID.resIO
- Resource IO to cleanup resources.
-
deleteElement
public void deleteElement(VisualElement el, DocIO resIO)
Delete an element.- Parameters:
el
- Element.resIO
- Resource IO to cleanup resources.
-
getScriptingBindings
public RecursiveBindings getScriptingBindings()
Description copied from interface:Scriptable
Get the local scope for this object.- Specified by:
getScriptingBindings
in interfaceScriptable
- Returns:
- my Bindings.
-
getParentElementScriptingBindings
public java.util.Optional<RecursiveBindings> getParentElementScriptingBindings()
Get the program-base definitions.- Specified by:
getParentElementScriptingBindings
in interfaceScriptable
- Returns:
- Optional Bindings
-
getScriptEl
public java.util.Optional<ScriptElement> getScriptEl()
Get the ScriptElement attached to this object. There should only be one element.- Specified by:
getScriptEl
in interfaceScriptable
- Returns:
- my (first) script element.
-
getRealType
public java.lang.String getRealType()
Description copied from interface:Scriptable
Return the type of the element.- Specified by:
getRealType
in interfaceScriptable
- Returns:
- Type-name
-
addScriptFile
public void addScriptFile(java.nio.file.Path path, java.lang.String language) throws java.io.IOException
Attach a new script to the element.- Specified by:
addScriptFile
in interfaceScriptable
- Parameters:
path
- Internal path to file.language
- Script language.- Throws:
java.io.IOException
- Couldn't access path.
-
getEvalRequired
public java.lang.Boolean getEvalRequired()
Description copied from interface:Scriptable
Get if the element requires evaluating again.- Specified by:
getEvalRequired
in interfaceScriptable
- Returns:
- Is Eval required?
-
setEvalRequired
public void setEvalRequired(java.lang.Boolean req)
Description copied from interface:Scriptable
Set if the element requires evaluating again.- Specified by:
setEvalRequired
in interfaceScriptable
- Parameters:
req
- Re-Evaluate is required?
-
getParentScriptable
public java.util.Optional<Scriptable> getParentScriptable()
Description copied from interface:Scriptable
Get the parent of this Scriptable element.- Specified by:
getParentScriptable
in interfaceScriptable
- Returns:
- Maybe parent.
-
-