diff --git a/pom.xml b/pom.xml
index 6748faf..2f09960 100644
--- a/pom.xml
+++ b/pom.xml
@@ -4,7 +4,7 @@
com.marginallyclever
nodegraphcore
- 1.6.1
+ 1.6.2
NodeGraphCore
Flow based programming in Java.
@@ -57,7 +57,7 @@
org.json
json
- 20231013
+ 20250517
@@ -74,24 +74,20 @@
test
-
org.slf4j
slf4j-api
- 2.0.16
+ 2.0.17
+
+
+ ch.qos.logback
+ logback-core
+ 1.5.18
-
ch.qos.logback
logback-classic
- 1.5.16
- test
-
-
- org.slf4j
- slf4j-api
-
-
+ 1.5.18
diff --git a/src/main/java/com/marginallyclever/nodegraphcore/Node.java b/src/main/java/com/marginallyclever/nodegraphcore/Node.java
index 44b0506..a691e35 100644
--- a/src/main/java/com/marginallyclever/nodegraphcore/Node.java
+++ b/src/main/java/com/marginallyclever/nodegraphcore/Node.java
@@ -9,9 +9,11 @@
import org.json.JSONObject;
import javax.annotation.Nonnull;
+import javax.swing.*;
import java.awt.*;
import java.util.ArrayList;
import java.util.List;
+import java.util.Objects;
import java.util.UUID;
import java.util.concurrent.atomic.AtomicInteger;
@@ -167,13 +169,25 @@ public Port> getPort(int index) throws IndexOutOfBoundsException {
* @param name the name to match.
* @return the {@link Port} found or null
*/
- public Port> getPort(String name) {
+ public Port> getPort(@Nonnull String name) {
for(Port> v : ports) {
if(v.getName().equals(name)) return v;
}
return null;
}
+ /**
+ * Get the {@link Port} with the given name and set its value.
+ * @param name the {@link Port} name to match.
+ * @param value the new value to set.
+ * @throws IllegalArgumentException when the {@link Port} is not found.
+ */
+ public void setPort(@Nonnull String name, Object value) {
+ var port = getPort(name);
+ if(port == null) throw new IllegalArgumentException("Port "+name+" not found");
+ port.setValue(value);
+ }
+
/**
* @param name the {@link Port} name to match.
* @return the index of the {@link Port} with the given name or -1 if not found.
@@ -401,4 +415,12 @@ public int getComplete() {
public void setComplete(int percent) {
this.complete.set(percent);
}
+
+ /**
+ * Returns an icon for this node.
+ * @return an icon for this node or null if no icon is defined.
+ */
+ public Icon getIcon() {
+ return new ImageIcon(Objects.requireNonNull(getClass().getResource("icons8-question-mark-16.png")));
+ }
}
diff --git a/src/main/java/com/marginallyclever/nodegraphcore/NodeCategory.java b/src/main/java/com/marginallyclever/nodegraphcore/NodeCategory.java
index 746f1f1..ec6bb73 100644
--- a/src/main/java/com/marginallyclever/nodegraphcore/NodeCategory.java
+++ b/src/main/java/com/marginallyclever/nodegraphcore/NodeCategory.java
@@ -4,6 +4,11 @@
import java.util.List;
import java.util.function.Supplier;
+/**
+ * A category of {@link Node} that can be used to organize nodes into a tree structure.
+ * Each category can have a parent and children, allowing for hierarchical organization.
+ * Categories can also provide a supplier to create instances of the node type they represent.
+ */
public class NodeCategory {
private final String name;
private final Supplier supplier;
diff --git a/src/main/java/com/marginallyclever/nodegraphcore/nodes/math/ATan2.java b/src/main/java/com/marginallyclever/nodegraphcore/nodes/math/ATan2.java
index 6decc3f..2aa06d2 100644
--- a/src/main/java/com/marginallyclever/nodegraphcore/nodes/math/ATan2.java
+++ b/src/main/java/com/marginallyclever/nodegraphcore/nodes/math/ATan2.java
@@ -4,6 +4,9 @@
import com.marginallyclever.nodegraphcore.port.Input;
import com.marginallyclever.nodegraphcore.port.Output;
+import javax.swing.*;
+import java.util.Objects;
+
/**
* C=atan2(y,x)
* @author Dan Royer
@@ -30,4 +33,9 @@ public void update() {
double x = b.getValue().doubleValue();
c.setValue(Math.atan2(y,x));
}
+
+ @Override
+ public Icon getIcon() {
+ return new ImageIcon(Objects.requireNonNull(getClass().getResource("tan-curve-16.png")));
+ }
}
diff --git a/src/main/java/com/marginallyclever/nodegraphcore/nodes/math/Add.java b/src/main/java/com/marginallyclever/nodegraphcore/nodes/math/Add.java
index 9bb48ba..28cebd7 100644
--- a/src/main/java/com/marginallyclever/nodegraphcore/nodes/math/Add.java
+++ b/src/main/java/com/marginallyclever/nodegraphcore/nodes/math/Add.java
@@ -4,6 +4,9 @@
import com.marginallyclever.nodegraphcore.port.Input;
import com.marginallyclever.nodegraphcore.port.Output;
+import javax.swing.*;
+import java.util.Objects;
+
/**
* C=A+B
* @author Dan Royer
@@ -30,4 +33,9 @@ public void update() {
double bv = b.getValue().doubleValue();
c.setValue(av + bv);
}
+
+ @Override
+ public Icon getIcon() {
+ return new ImageIcon(Objects.requireNonNull(getClass().getResource("icons8-add-16.png")));
+ }
}
diff --git a/src/main/java/com/marginallyclever/nodegraphcore/nodes/math/Divide.java b/src/main/java/com/marginallyclever/nodegraphcore/nodes/math/Divide.java
index e5359da..566c8a8 100644
--- a/src/main/java/com/marginallyclever/nodegraphcore/nodes/math/Divide.java
+++ b/src/main/java/com/marginallyclever/nodegraphcore/nodes/math/Divide.java
@@ -4,6 +4,9 @@
import com.marginallyclever.nodegraphcore.port.Input;
import com.marginallyclever.nodegraphcore.port.Output;
+import javax.swing.*;
+import java.util.Objects;
+
/**
* C=A/B
*/
@@ -29,4 +32,9 @@ public void update() {
if(bv==0) c.setValue(Float.NaN);
else c.setValue(av / bv);
}
+
+ @Override
+ public Icon getIcon() {
+ return new ImageIcon(Objects.requireNonNull(getClass().getResource("icons8-divide-16.png")));
+ }
}
diff --git a/src/main/java/com/marginallyclever/nodegraphcore/nodes/math/Equals.java b/src/main/java/com/marginallyclever/nodegraphcore/nodes/math/Equals.java
index dcf20bd..8a3eabe 100644
--- a/src/main/java/com/marginallyclever/nodegraphcore/nodes/math/Equals.java
+++ b/src/main/java/com/marginallyclever/nodegraphcore/nodes/math/Equals.java
@@ -4,6 +4,9 @@
import com.marginallyclever.nodegraphcore.port.Input;
import com.marginallyclever.nodegraphcore.port.Output;
+import javax.swing.*;
+import java.util.Objects;
+
/**
* C = (A==B) ? 1 : 0
* @author Dan Royer
@@ -30,4 +33,9 @@ public void update() {
double bv = b.getValue().doubleValue();
c.setValue((av == bv) ? 1 : 0);
}
+
+ @Override
+ public Icon getIcon() {
+ return new ImageIcon(Objects.requireNonNull(getClass().getResource("icons8-equal-sign-16.png")));
+ }
}
diff --git a/src/main/java/com/marginallyclever/nodegraphcore/nodes/math/GreaterThan.java b/src/main/java/com/marginallyclever/nodegraphcore/nodes/math/GreaterThan.java
index 9100d1e..cd9b985 100644
--- a/src/main/java/com/marginallyclever/nodegraphcore/nodes/math/GreaterThan.java
+++ b/src/main/java/com/marginallyclever/nodegraphcore/nodes/math/GreaterThan.java
@@ -4,6 +4,9 @@
import com.marginallyclever.nodegraphcore.port.Input;
import com.marginallyclever.nodegraphcore.port.Output;
+import javax.swing.*;
+import java.util.Objects;
+
/**
* C = (A>B) ? 1 : 0
* @author Dan Royer
@@ -30,4 +33,9 @@ public void update() {
double bv = b.getValue().doubleValue();
c.setValue((av > bv) ? 1 : 0);
}
+
+ @Override
+ public Icon getIcon() {
+ return new ImageIcon(Objects.requireNonNull(getClass().getResource("icons8-more-than-16.png")));
+ }
}
diff --git a/src/main/java/com/marginallyclever/nodegraphcore/nodes/math/LessThan.java b/src/main/java/com/marginallyclever/nodegraphcore/nodes/math/LessThan.java
index fbc0056..e4c4bef 100644
--- a/src/main/java/com/marginallyclever/nodegraphcore/nodes/math/LessThan.java
+++ b/src/main/java/com/marginallyclever/nodegraphcore/nodes/math/LessThan.java
@@ -4,6 +4,9 @@
import com.marginallyclever.nodegraphcore.port.Input;
import com.marginallyclever.nodegraphcore.port.Output;
+import javax.swing.*;
+import java.util.Objects;
+
/**
* C = (A<B) ? 1 : 0
* @author Dan Royer
@@ -30,4 +33,9 @@ public void update() {
double bv = b.getValue().doubleValue();
c.setValue((av < bv) ? 1 : 0);
}
+
+ @Override
+ public Icon getIcon() {
+ return new ImageIcon(Objects.requireNonNull(getClass().getResource("icons8-less-than-16.png")));
+ }
}
diff --git a/src/main/java/com/marginallyclever/nodegraphcore/nodes/math/Multiply.java b/src/main/java/com/marginallyclever/nodegraphcore/nodes/math/Multiply.java
index 8004114..f7ce525 100644
--- a/src/main/java/com/marginallyclever/nodegraphcore/nodes/math/Multiply.java
+++ b/src/main/java/com/marginallyclever/nodegraphcore/nodes/math/Multiply.java
@@ -4,6 +4,9 @@
import com.marginallyclever.nodegraphcore.port.Input;
import com.marginallyclever.nodegraphcore.port.Output;
+import javax.swing.*;
+import java.util.Objects;
+
/**
* A*B {@link Node}
*/
@@ -28,4 +31,9 @@ public void update() {
double bv = b.getValue().doubleValue();
c.setValue(av * bv);
}
+
+ @Override
+ public Icon getIcon() {
+ return new ImageIcon(Objects.requireNonNull(getClass().getResource("icons8-multiply-16.png")));
+ }
}
diff --git a/src/main/java/com/marginallyclever/nodegraphcore/nodes/math/Subtract.java b/src/main/java/com/marginallyclever/nodegraphcore/nodes/math/Subtract.java
index a9e9741..019bd26 100644
--- a/src/main/java/com/marginallyclever/nodegraphcore/nodes/math/Subtract.java
+++ b/src/main/java/com/marginallyclever/nodegraphcore/nodes/math/Subtract.java
@@ -4,6 +4,9 @@
import com.marginallyclever.nodegraphcore.port.Input;
import com.marginallyclever.nodegraphcore.port.Output;
+import javax.swing.*;
+import java.util.Objects;
+
/**
* A-B {@link Node}
*/
@@ -28,4 +31,9 @@ public void update() {
double bv = b.getValue().doubleValue();
c.setValue(av - bv);
}
+
+ @Override
+ public Icon getIcon() {
+ return new ImageIcon(Objects.requireNonNull(getClass().getResource("icons8-subtract-16.png")));
+ }
}
diff --git a/src/main/resources/com/marginallyclever/nodegraphcore/.placeholder b/src/main/resources/com/marginallyclever/nodegraphcore/.placeholder
new file mode 100644
index 0000000..e69de29
diff --git a/src/main/resources/com/marginallyclever/nodegraphcore/icons8-question-mark-16.png b/src/main/resources/com/marginallyclever/nodegraphcore/icons8-question-mark-16.png
new file mode 100644
index 0000000..832d94a
Binary files /dev/null and b/src/main/resources/com/marginallyclever/nodegraphcore/icons8-question-mark-16.png differ
diff --git a/src/main/resources/com/marginallyclever/nodegraphcore/nodes/math/icons8-add-16.png b/src/main/resources/com/marginallyclever/nodegraphcore/nodes/math/icons8-add-16.png
new file mode 100644
index 0000000..7559623
Binary files /dev/null and b/src/main/resources/com/marginallyclever/nodegraphcore/nodes/math/icons8-add-16.png differ
diff --git a/src/main/resources/com/marginallyclever/nodegraphcore/nodes/math/icons8-divide-16.png b/src/main/resources/com/marginallyclever/nodegraphcore/nodes/math/icons8-divide-16.png
new file mode 100644
index 0000000..79f7057
Binary files /dev/null and b/src/main/resources/com/marginallyclever/nodegraphcore/nodes/math/icons8-divide-16.png differ
diff --git a/src/main/resources/com/marginallyclever/nodegraphcore/nodes/math/icons8-equal-sign-16.png b/src/main/resources/com/marginallyclever/nodegraphcore/nodes/math/icons8-equal-sign-16.png
new file mode 100644
index 0000000..163fcd9
Binary files /dev/null and b/src/main/resources/com/marginallyclever/nodegraphcore/nodes/math/icons8-equal-sign-16.png differ
diff --git a/src/main/resources/com/marginallyclever/nodegraphcore/nodes/math/icons8-less-or-equal-16.png b/src/main/resources/com/marginallyclever/nodegraphcore/nodes/math/icons8-less-or-equal-16.png
new file mode 100644
index 0000000..f8dea5e
Binary files /dev/null and b/src/main/resources/com/marginallyclever/nodegraphcore/nodes/math/icons8-less-or-equal-16.png differ
diff --git a/src/main/resources/com/marginallyclever/nodegraphcore/nodes/math/icons8-less-than-16.png b/src/main/resources/com/marginallyclever/nodegraphcore/nodes/math/icons8-less-than-16.png
new file mode 100644
index 0000000..ff2247c
Binary files /dev/null and b/src/main/resources/com/marginallyclever/nodegraphcore/nodes/math/icons8-less-than-16.png differ
diff --git a/src/main/resources/com/marginallyclever/nodegraphcore/nodes/math/icons8-more-or-equal-16.png b/src/main/resources/com/marginallyclever/nodegraphcore/nodes/math/icons8-more-or-equal-16.png
new file mode 100644
index 0000000..0fe6f63
Binary files /dev/null and b/src/main/resources/com/marginallyclever/nodegraphcore/nodes/math/icons8-more-or-equal-16.png differ
diff --git a/src/main/resources/com/marginallyclever/nodegraphcore/nodes/math/icons8-more-than-16.png b/src/main/resources/com/marginallyclever/nodegraphcore/nodes/math/icons8-more-than-16.png
new file mode 100644
index 0000000..c98902e
Binary files /dev/null and b/src/main/resources/com/marginallyclever/nodegraphcore/nodes/math/icons8-more-than-16.png differ
diff --git a/src/main/resources/com/marginallyclever/nodegraphcore/nodes/math/icons8-multiply-16.png b/src/main/resources/com/marginallyclever/nodegraphcore/nodes/math/icons8-multiply-16.png
new file mode 100644
index 0000000..a45b772
Binary files /dev/null and b/src/main/resources/com/marginallyclever/nodegraphcore/nodes/math/icons8-multiply-16.png differ
diff --git a/src/main/resources/com/marginallyclever/nodegraphcore/nodes/math/icons8-subtract-16.png b/src/main/resources/com/marginallyclever/nodegraphcore/nodes/math/icons8-subtract-16.png
new file mode 100644
index 0000000..c8918b0
Binary files /dev/null and b/src/main/resources/com/marginallyclever/nodegraphcore/nodes/math/icons8-subtract-16.png differ
diff --git a/src/main/resources/com/marginallyclever/nodegraphcore/nodes/math/tan_curve-16.ico b/src/main/resources/com/marginallyclever/nodegraphcore/nodes/math/tan_curve-16.ico
new file mode 100644
index 0000000..fda169d
Binary files /dev/null and b/src/main/resources/com/marginallyclever/nodegraphcore/nodes/math/tan_curve-16.ico differ