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 intTITLE_HEIGHTThe default height of the title bar. -
Constructor Summary
Constructors Modifier Constructor Description protectedNode(java.lang.String name)Default constructor -
Method Summary
Modifier and Type Method Description protected voidaddVariable(NodeVariable v)Add aNodeVariableto this node.protected voidcleanAllInputs()Makes all input variables not dirty.voidcleanAllOutputs()Set all outputs to not dirty.abstract Nodecreate()Return one new instance of this type ofNode.java.awt.PointgetInPosition(int index)Returns the center of the input connection point of the requestedNodeVariable.java.lang.StringgetLabel()Returns the label (nickname) of this node.java.lang.StringgetName()Returns the name of this node.intgetNumVariables()Returns the number of variables in this node.java.awt.PointgetOutPosition(int index)Returns the center of the output connection point of the requestedNodeVariable.java.awt.RectanglegetRectangle()Returns the bounding rectangle for this node.intgetUniqueID()Returns the unique ID of this Node.static intgetUniqueIDSource()Returns the current uniqueIDSource.java.lang.StringgetUniqueName()Returns the unique name of this node, a combination of unique ID and name.NodeVariable<?>getVariable(int index)Get the i-thNodeVariablein this node.java.util.List<NodeVariable<?>>getVariables()Returns the list of variables in this node.booleanisDirty()Check if any variables are dirty.voidmoveRelative(int dx, int dy)Move this node some relative cartesian value.protected voidremoveVariable(NodeVariable v)Remove aNodeVariablefrom this node.voidsetLabel(java.lang.String str)Sets the label for this node.voidsetPosition(java.awt.Point point)Sets the top left corner of theNode's rectangle.voidsetRectangle(java.awt.Rectangle rectangle)Sets the bounding rectangle for this node.voidsetUniqueID(int id)Sets the unique ID of this Node.static voidsetUniqueIDSource(int index)Adjust the UniqueIDSource, the global number used to guarantee unique names for all classes.java.lang.StringtoString()abstract voidupdate()Override this method to provide the custom behavior of this node.voidupdateBounds()Recalculate the bounds of this node.voidupdateIfNotDirty()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 aNodeVariableto this node.- Parameters:
v- the newNodeVariable
-
removeVariable
Remove aNodeVariablefrom 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-thNodeVariablein this node.- Parameters:
index- the index.- Returns:
- the i-th
NodeVariablein this node. - Throws:
java.lang.IndexOutOfBoundsException- when an invalid index is requested.
-
toString
public java.lang.String toString()- Overrides:
toStringin 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.
-