java.lang.Object
com.marginallyclever.nodegraphcore.Node
- Direct Known Subclasses:
Add
,ATan2
,Cos
,Divide
,LoadBoolean
,LoadImage
,LoadNumber
,LoadString
,LogicalAnd
,LogicalNot
,LogicalOr
,Max
,Min
,Multiply
,PrintImage
,PrintToStdOut
,Random
,Sin
,Subgraph
,Subtract
,Tan
public abstract class Node
extends java.lang.Object
Node
is a collection of zero or more inputs and zero or more outputs connected by some operator.
The operator is defined by extending the Node
class and defining the update()
method.- Since:
- 2022-02-01
-
Field Summary
Fields Modifier and Type Field Description static int
TITLE_HEIGHT
The default height of the title bar. -
Constructor Summary
Constructors Modifier Constructor Description protected
Node(java.lang.String name)
Default constructor -
Method Summary
Modifier and Type Method Description protected void
addVariable(NodeVariable v)
Add aNodeVariable
to this node.protected void
cleanAllInputs()
Makes all input variables not dirty.void
cleanAllOutputs()
Set all outputs to not dirty.abstract Node
create()
Return one new instance of this type ofNode
.java.awt.Point
getInPosition(int index)
Returns the center of the input connection point of the requestedNodeVariable
.java.lang.String
getLabel()
Returns the label (nickname) of this node.java.lang.String
getName()
Returns the name of this node.int
getNumVariables()
Returns the number of variables in this node.java.awt.Point
getOutPosition(int index)
Returns the center of the output connection point of the requestedNodeVariable
.java.awt.Rectangle
getRectangle()
Returns the bounding rectangle for this node.int
getUniqueID()
Returns the unique ID of this Node.static int
getUniqueIDSource()
Returns the current uniqueIDSource.java.lang.String
getUniqueName()
Returns the unique name of this node, a combination of unique ID and name.NodeVariable<?>
getVariable(int index)
Get the i-thNodeVariable
in this node.java.util.List<NodeVariable<?>>
getVariables()
Returns the list of variables in this node.boolean
isDirty()
Check if any variables are dirty.void
moveRelative(int dx, int dy)
Move this node some relative cartesian value.protected void
removeVariable(NodeVariable v)
Remove aNodeVariable
from this node.void
setLabel(java.lang.String str)
Sets the label for this node.void
setPosition(java.awt.Point point)
Sets the top left corner of theNode
's rectangle.void
setRectangle(java.awt.Rectangle rectangle)
Sets the bounding rectangle for this node.void
setUniqueID(int id)
Sets the unique ID of this Node.static void
setUniqueIDSource(int index)
Adjust the UniqueIDSource, the global number used to guarantee unique names for all classes.java.lang.String
toString()
abstract void
update()
Override this method to provide the custom behavior of this node.void
updateBounds()
Recalculate the bounds of this node.void
updateIfNotDirty()
Runsupdate()
only if the node is considered dirty.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Field Details
-
TITLE_HEIGHT
public static final int TITLE_HEIGHTThe default height of the title bar.- See Also:
- Constant Field Values
-
-
Constructor Details
-
Node
protected Node(java.lang.String name)Default constructor- Parameters:
name
- the name of the class of this type of Node, for serialization and user selection. Developers of derived classes should not change this name after it is in production - it will break serialization.
-
-
Method Details
-
create
Return one new instance of this type ofNode
. Override this method in derived classes.- Returns:
- One new instance of this type of
Node
.
-
setUniqueIDSource
public static void setUniqueIDSource(int index)Adjust the UniqueIDSource, the global number used to guarantee unique names for all classes. Be very careful messing with this number! It is exposed here for folding, unfolding, and serialization.- Parameters:
index
- the new value.
-
getUniqueIDSource
public static int getUniqueIDSource()Returns the current uniqueIDSource.- Returns:
- the current uniqueIDSource.
-
setUniqueID
public void setUniqueID(int id)Sets the unique ID of this Node.- Parameters:
id
- the new ID value.
-
getUniqueID
public int getUniqueID()Returns the unique ID of this Node.- Returns:
- the unique ID of this Node.
-
getVariables
Returns the list of variables in this node.- Returns:
- the list of variables in this node.
-
setRectangle
public void setRectangle(java.awt.Rectangle rectangle)Sets the bounding rectangle for this node.- Parameters:
rectangle
- the new bounds.
-
getRectangle
public java.awt.Rectangle getRectangle()Returns the bounding rectangle for this node.- Returns:
- the bounding rectangle for this node.
-
getName
public java.lang.String getName()Returns the name of this node.- Returns:
- the name of this node.
-
getUniqueName
public java.lang.String getUniqueName()Returns the unique name of this node, a combination of unique ID and name.- Returns:
- the unique name of this node, a combination of unique ID and name.
-
update
public abstract void update()Override this method to provide the custom behavior of this node. Runs regardless of dirty inputs or outputs. -
updateIfNotDirty
public void updateIfNotDirty()Runsupdate()
only if the node is considered dirty. It is up to individual nodes to decide if they are done (no longer dirty) -
updateBounds
public void updateBounds()Recalculate the bounds of this node. -
isDirty
public boolean isDirty()Check if any variables are dirty.- Returns:
- true if any variables are dirty.
-
cleanAllInputs
protected void cleanAllInputs()Makes all input variables not dirty. -
cleanAllOutputs
public void cleanAllOutputs()Set all outputs to not dirty. -
addVariable
Add aNodeVariable
to this node.- Parameters:
v
- the newNodeVariable
-
removeVariable
Remove aNodeVariable
from this node.- Parameters:
v
- the oldNodeVariable
-
getNumVariables
public int getNumVariables()Returns the number of variables in this node.- Returns:
- the number of variables in this node.
-
getVariable
Get the i-thNodeVariable
in this node.- Parameters:
index
- the index.- Returns:
- the i-th
NodeVariable
in this node. - Throws:
java.lang.IndexOutOfBoundsException
- when an invalid index is requested.
-
toString
public java.lang.String toString()- Overrides:
toString
in classjava.lang.Object
-
getInPosition
public java.awt.Point getInPosition(int index)Returns the center of the input connection point of the requestedNodeVariable
.- Parameters:
index
- the requested index- Returns:
- the center of the input connection point of the requested
NodeVariable
.
-
getOutPosition
public java.awt.Point getOutPosition(int index)Returns the center of the output connection point of the requestedNodeVariable
.- Parameters:
index
- the requested index- Returns:
- the center of the output connection point of the requested
NodeVariable
.
-
getLabel
public java.lang.String getLabel()Returns the label (nickname) of this node.- Returns:
- the label (nickname) of this node.
-
setLabel
public void setLabel(java.lang.String str)Sets the label for this node.- Parameters:
str
- the new label.
-
setPosition
public void setPosition(java.awt.Point point)Sets the top left corner of theNode
's rectangle.- Parameters:
point
- the new position of the top left corner.
-
moveRelative
public void moveRelative(int dx, int dy)Move this node some relative cartesian value.- Parameters:
dx
- the x axis amount.dy
- the y axis amount.
-