Package g3.project.elements
Class VisualElement
- java.lang.Object
-
- nu.xom.Node
-
- nu.xom.ParentNode
-
- nu.xom.Element
-
- g3.project.elements.VisualElement
-
- All Implemented Interfaces:
Scriptable
- Direct Known Subclasses:
ImageElement
,PageElement
,PlayableElement
,ShapeElement
,TableElement
public abstract class VisualElement extends nu.xom.Element implements Scriptable
- Author:
- Group 3
-
-
Constructor Summary
Constructors Constructor Description VisualElement(java.lang.String name)
Constructor.VisualElement(java.lang.String name, java.lang.String uri)
Constructor.VisualElement(nu.xom.Element element)
Constructor.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description void
addScriptFile(java.nio.file.Path path, java.lang.String language)
Add a new script to the element.abstract void
delete(DocIO resIO)
Delete the element and sub-elements.static java.util.Optional<nu.xom.Attribute>
derefAttribute(nu.xom.Element el, java.lang.String qualifiedName)
Find qualified attribute from element.java.util.HashMap<java.lang.String,java.util.HashMap<java.lang.String,java.lang.Object>>
getAllProps()
Get all properties of an Element.java.lang.Double
getAlpha()
Get element alpha.java.util.Optional<VisualElement>
getByID(java.lang.String id)
Returns the referred element, if this is it or it is a child of this.java.util.Optional<java.lang.Double>
getDelaySecs()
Get delay in seconds.java.util.Optional<java.lang.Double>
getDurationSecs()
Get display duration in seconds.java.lang.Boolean
getEvalRequired()
Should I be re-evaluated?java.util.Optional<javafx.scene.paint.Color>
getFillColour()
Get the element's fill colour.java.lang.String
getID()
Returns the element's ID, or assigns it a new one if not present.java.util.Optional<LocObj>
getOrigin()
Get the object's X/Y location.java.util.Optional<PageElement>
getPage()
Get the page this element is of.java.util.Optional<RecursiveBindings>
getParentElementScriptingBindings()
Get Local Script Bindings of parent node, if parent node is another Scriptable element.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.Optional<SizeObj>
getSize()
Get the object's size.Returns an Optional, which may contain either the size or nothing.java.lang.Object
getStateVariable(java.lang.String name)
Get something from this element's state/scope.java.util.Optional<StrokeProps>
getStroke()
Get the stroke element for this element.java.lang.Boolean
getVisibility()
Get if the node is supposed to be visible.VisualProps
getVisualProps()
Get this element's visual properties map.java.lang.Double
getZInd()
Get the object's Z location.void
hasUpdated()
Element has changed/updated.static nu.xom.Attribute
makeAttrWithNS(java.lang.String qualifiedName, java.lang.String attrVal)
Make an attribute with a name-space.void
putStateVariable(java.lang.String name, java.lang.Object state)
Put something into this element's state/scope.void
setAlpha(java.lang.Double alpha)
Set the element Alpha.void
setDelaySecs(java.lang.Double del)
Set delay in seconds.void
setDurationSecs(java.lang.Double dur)
Set delay in seconds.void
setEvalRequired(java.lang.Boolean req)
Set if I should be re-evaluated.void
setFillColour(java.lang.String colourString)
Set the fill colour.java.lang.String
setID(java.lang.String id)
Set element ID.void
setOriginXY(LocObj loc)
Set the object's X/Y location.void
setOriginXY(java.lang.Double x, java.lang.Double y)
Set the object's X/Y location.void
setProps(java.util.HashMap<java.lang.String,java.lang.Object> props)
Set this object's properties.void
setSize(SizeObj size)
Set the element size.void
setSize(java.lang.Double x, java.lang.Double y, java.lang.Double rot)
Set element size.void
setVisibility(java.lang.Boolean vis)
Set my visibility.java.lang.Double
setZInd(java.lang.Double z)
Set the object's Z location.-
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
-
-
-
-
Constructor Detail
-
VisualElement
public VisualElement(java.lang.String name)
Constructor.- Parameters:
name
- Element name
-
VisualElement
public VisualElement(java.lang.String name, java.lang.String uri)
Constructor.- Parameters:
name
- Element nameuri
- Element URI
-
VisualElement
public VisualElement(nu.xom.Element element)
Constructor.- Parameters:
element
- Element
-
-
Method Detail
-
putStateVariable
public void putStateVariable(java.lang.String name, java.lang.Object state)
Put something into this element's state/scope.- Parameters:
name
- Name of thing.state
- Thing.
-
getStateVariable
public java.lang.Object getStateVariable(java.lang.String name)
Get something from this element's state/scope.- Parameters:
name
- Name of thing.- Returns:
- Thing or Null.
-
delete
public abstract void delete(DocIO resIO)
Delete the element and sub-elements.- Parameters:
resIO
- Resource handler to remove resources on delete.
-
derefAttribute
public static java.util.Optional<nu.xom.Attribute> derefAttribute(nu.xom.Element el, java.lang.String qualifiedName)
Find qualified attribute from element.- Parameters:
el
- Element to use.qualifiedName
- Full attribute name.- Returns:
- Maybe attribute.
-
makeAttrWithNS
public static nu.xom.Attribute makeAttrWithNS(java.lang.String qualifiedName, java.lang.String attrVal)
Make an attribute with a name-space.- Parameters:
qualifiedName
- Full name.attrVal
- Value.- Returns:
- Attribute.
-
getOrigin
public final java.util.Optional<LocObj> getOrigin()
Get the object's X/Y location. Returns an Optional, which may contain either the location or nothing. The caller can then determine the action to take.- Returns:
- Optional Location
-
setOriginXY
public final void setOriginXY(LocObj loc)
Set the object's X/Y location.- Parameters:
loc
- Location to set
-
setOriginXY
public final void setOriginXY(java.lang.Double x, java.lang.Double y)
Set the object's X/Y location.- Parameters:
x
- X location.y
- Y location.
-
getID
public final java.lang.String getID()
Returns the element's ID, or assigns it a new one if not present.- Returns:
- Unique ID
-
setID
public final java.lang.String setID(java.lang.String id)
Set element ID.- Parameters:
id
- ID to set- Returns:
- Set ID
-
getZInd
public final java.lang.Double getZInd()
Get the object's Z location. Default to 0 if not present.- Returns:
- Z-index
-
setZInd
public final java.lang.Double setZInd(java.lang.Double z)
Set the object's Z location. Returns set Z-index.- Parameters:
z
- Index to set.- Returns:
- Set index.
-
getSize
public final java.util.Optional<SizeObj> getSize()
Get the object's size.Returns an Optional, which may contain either the size or nothing. Rotation defaults to 0 if not present.- Returns:
- Optional size
-
setSize
public final void setSize(SizeObj size)
Set the element size.- Parameters:
size
- Size to set.
-
setSize
public final void setSize(java.lang.Double x, java.lang.Double y, java.lang.Double rot)
Set element size.- Parameters:
x
- X size.y
- Y size.rot
- Rotation.
-
getPage
public final java.util.Optional<PageElement> getPage()
Get the page this element is of.- Returns:
- Maybe Page.
-
setDelaySecs
public final void setDelaySecs(java.lang.Double del)
Set delay in seconds.- Parameters:
del
- Delay in seconds.
-
getDelaySecs
public final java.util.Optional<java.lang.Double> getDelaySecs()
Get delay in seconds.- Returns:
- Delay in seconds.
-
getDurationSecs
public final java.util.Optional<java.lang.Double> getDurationSecs()
Get display duration in seconds.- Returns:
- Duration in seconds.
-
setDurationSecs
public final void setDurationSecs(java.lang.Double dur)
Set delay in seconds.- Parameters:
dur
- Delay in seconds.
-
getFillColour
public final java.util.Optional<javafx.scene.paint.Color> getFillColour()
Get the element's fill colour.- Returns:
- Optional colour.
-
setFillColour
public final void setFillColour(java.lang.String colourString) throws java.lang.Exception
Set the fill colour.- Parameters:
colourString
- RGB or RGBA string.- Throws:
java.lang.Exception
- Bad colour string.
-
setAlpha
public final void setAlpha(java.lang.Double alpha)
Set the element Alpha.- Parameters:
alpha
- Alpha to set.
-
getAlpha
public final java.lang.Double getAlpha()
Get element alpha.- Returns:
- Opacity value.
-
setVisibility
public void setVisibility(java.lang.Boolean vis)
Set my visibility.- Parameters:
vis
- Visible or not.
-
getVisibility
public java.lang.Boolean getVisibility()
Get if the node is supposed to be visible.- Returns:
- Is Visible?
-
getByID
public final java.util.Optional<VisualElement> getByID(java.lang.String id)
Returns the referred element, if this is it or it is a child of this.- Parameters:
id
- Element to find.- Returns:
- Optional referred element.
-
getStroke
public final java.util.Optional<StrokeProps> getStroke()
Get the stroke element for this element.- Returns:
- Optional Stroke Element.
-
getVisualProps
public final VisualProps getVisualProps()
Get this element's visual properties map.- Returns:
- visual props. map.
-
getAllProps
public java.util.HashMap<java.lang.String,java.util.HashMap<java.lang.String,java.lang.Object>> getAllProps()
Get all properties of an Element.- Returns:
- Element's properties.
-
setProps
public void setProps(java.util.HashMap<java.lang.String,java.lang.Object> props)
Set this object's properties.- Parameters:
props
- Properties.
-
hasUpdated
public final void hasUpdated()
Element has changed/updated. Notify the engine.
-
getScriptingBindings
public final RecursiveBindings getScriptingBindings()
Get the local scope for this object.- Specified by:
getScriptingBindings
in interfaceScriptable
- Returns:
- my Bindings.
-
getParentElementScriptingBindings
public final java.util.Optional<RecursiveBindings> getParentElementScriptingBindings()
Get Local Script Bindings of parent node, if parent node is another Scriptable element.- Specified by:
getParentElementScriptingBindings
in interfaceScriptable
- Returns:
- Optional Bindings
-
getScriptEl
public final 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 final 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
Add a new script to the element. Any old file MUST have been deleted before use!- Specified by:
addScriptFile
in interfaceScriptable
- Parameters:
path
- Path to new file.language
- Script language.- Throws:
java.io.IOException
- Couldn't access Path.
-
getEvalRequired
public java.lang.Boolean getEvalRequired()
Should I be re-evaluated?- Specified by:
getEvalRequired
in interfaceScriptable
- Returns:
- To eval.
-
setEvalRequired
public void setEvalRequired(java.lang.Boolean req)
Set if I should be re-evaluated.- Specified by:
setEvalRequired
in interfaceScriptable
- Parameters:
req
- Re-eval?
-
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.
-
-