Skip to content

Commit 590d033

Browse files
Merge pull request #23 from MarginallyClever/node-icons
1.6.2
2 parents 6abb9f3 + 2c151fa commit 590d033

23 files changed

+101
-14
lines changed

pom.xml

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
<groupId>com.marginallyclever</groupId>
66
<artifactId>nodegraphcore</artifactId>
7-
<version>1.6.1</version>
7+
<version>1.6.2</version>
88

99
<name>NodeGraphCore</name>
1010
<description>Flow based programming in Java.</description>
@@ -57,7 +57,7 @@
5757
<dependency>
5858
<groupId>org.json</groupId>
5959
<artifactId>json</artifactId>
60-
<version>20231013</version>
60+
<version>20250517</version>
6161
</dependency>
6262
<!-- unit testing -->
6363
<dependency>
@@ -74,24 +74,20 @@
7474
<scope>test</scope>
7575
</dependency>
7676
<!-- for logging -->
77-
<!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-api -->
7877
<dependency>
7978
<groupId>org.slf4j</groupId>
8079
<artifactId>slf4j-api</artifactId>
81-
<version>2.0.16</version>
80+
<version>2.0.17</version>
81+
</dependency>
82+
<dependency>
83+
<groupId>ch.qos.logback</groupId>
84+
<artifactId>logback-core</artifactId>
85+
<version>1.5.18</version>
8286
</dependency>
83-
<!-- logging -->
8487
<dependency>
8588
<groupId>ch.qos.logback</groupId>
8689
<artifactId>logback-classic</artifactId>
87-
<version>1.5.16</version>
88-
<scope>test</scope>
89-
<exclusions>
90-
<exclusion>
91-
<groupId>org.slf4j</groupId>
92-
<artifactId>slf4j-api</artifactId>
93-
</exclusion>
94-
</exclusions>
90+
<version>1.5.18</version>
9591
</dependency>
9692
<!-- for finding nodes in a package -->
9793
<dependency>

src/main/java/com/marginallyclever/nodegraphcore/Node.java

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,11 @@
99
import org.json.JSONObject;
1010

1111
import javax.annotation.Nonnull;
12+
import javax.swing.*;
1213
import java.awt.*;
1314
import java.util.ArrayList;
1415
import java.util.List;
16+
import java.util.Objects;
1517
import java.util.UUID;
1618
import java.util.concurrent.atomic.AtomicInteger;
1719

@@ -167,13 +169,25 @@ public Port<?> getPort(int index) throws IndexOutOfBoundsException {
167169
* @param name the name to match.
168170
* @return the {@link Port} found or null
169171
*/
170-
public Port<?> getPort(String name) {
172+
public Port<?> getPort(@Nonnull String name) {
171173
for(Port<?> v : ports) {
172174
if(v.getName().equals(name)) return v;
173175
}
174176
return null;
175177
}
176178

179+
/**
180+
* Get the {@link Port} with the given name and set its value.
181+
* @param name the {@link Port} name to match.
182+
* @param value the new value to set.
183+
* @throws IllegalArgumentException when the {@link Port} is not found.
184+
*/
185+
public void setPort(@Nonnull String name, Object value) {
186+
var port = getPort(name);
187+
if(port == null) throw new IllegalArgumentException("Port "+name+" not found");
188+
port.setValue(value);
189+
}
190+
177191
/**
178192
* @param name the {@link Port} name to match.
179193
* @return the index of the {@link Port} with the given name or -1 if not found.
@@ -401,4 +415,12 @@ public int getComplete() {
401415
public void setComplete(int percent) {
402416
this.complete.set(percent);
403417
}
418+
419+
/**
420+
* Returns an icon for this node.
421+
* @return an icon for this node or null if no icon is defined.
422+
*/
423+
public Icon getIcon() {
424+
return new ImageIcon(Objects.requireNonNull(getClass().getResource("icons8-question-mark-16.png")));
425+
}
404426
}

src/main/java/com/marginallyclever/nodegraphcore/NodeCategory.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44
import java.util.List;
55
import java.util.function.Supplier;
66

7+
/**
8+
* A category of {@link Node} that can be used to organize nodes into a tree structure.
9+
* Each category can have a parent and children, allowing for hierarchical organization.
10+
* Categories can also provide a supplier to create instances of the node type they represent.
11+
*/
712
public class NodeCategory {
813
private final String name;
914
private final Supplier<Node> supplier;

src/main/java/com/marginallyclever/nodegraphcore/nodes/math/ATan2.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
import com.marginallyclever.nodegraphcore.port.Input;
55
import com.marginallyclever.nodegraphcore.port.Output;
66

7+
import javax.swing.*;
8+
import java.util.Objects;
9+
710
/**
811
* C=atan2(y,x)
912
* @author Dan Royer
@@ -30,4 +33,9 @@ public void update() {
3033
double x = b.getValue().doubleValue();
3134
c.setValue(Math.atan2(y,x));
3235
}
36+
37+
@Override
38+
public Icon getIcon() {
39+
return new ImageIcon(Objects.requireNonNull(getClass().getResource("tan-curve-16.png")));
40+
}
3341
}

src/main/java/com/marginallyclever/nodegraphcore/nodes/math/Add.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
import com.marginallyclever.nodegraphcore.port.Input;
55
import com.marginallyclever.nodegraphcore.port.Output;
66

7+
import javax.swing.*;
8+
import java.util.Objects;
9+
710
/**
811
* C=A+B
912
* @author Dan Royer
@@ -30,4 +33,9 @@ public void update() {
3033
double bv = b.getValue().doubleValue();
3134
c.setValue(av + bv);
3235
}
36+
37+
@Override
38+
public Icon getIcon() {
39+
return new ImageIcon(Objects.requireNonNull(getClass().getResource("icons8-add-16.png")));
40+
}
3341
}

src/main/java/com/marginallyclever/nodegraphcore/nodes/math/Divide.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
import com.marginallyclever.nodegraphcore.port.Input;
55
import com.marginallyclever.nodegraphcore.port.Output;
66

7+
import javax.swing.*;
8+
import java.util.Objects;
9+
710
/**
811
* C=A/B
912
*/
@@ -29,4 +32,9 @@ public void update() {
2932
if(bv==0) c.setValue(Float.NaN);
3033
else c.setValue(av / bv);
3134
}
35+
36+
@Override
37+
public Icon getIcon() {
38+
return new ImageIcon(Objects.requireNonNull(getClass().getResource("icons8-divide-16.png")));
39+
}
3240
}

src/main/java/com/marginallyclever/nodegraphcore/nodes/math/Equals.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
import com.marginallyclever.nodegraphcore.port.Input;
55
import com.marginallyclever.nodegraphcore.port.Output;
66

7+
import javax.swing.*;
8+
import java.util.Objects;
9+
710
/**
811
* C = (A==B) ? 1 : 0
912
* @author Dan Royer
@@ -30,4 +33,9 @@ public void update() {
3033
double bv = b.getValue().doubleValue();
3134
c.setValue((av == bv) ? 1 : 0);
3235
}
36+
37+
@Override
38+
public Icon getIcon() {
39+
return new ImageIcon(Objects.requireNonNull(getClass().getResource("icons8-equal-sign-16.png")));
40+
}
3341
}

src/main/java/com/marginallyclever/nodegraphcore/nodes/math/GreaterThan.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
import com.marginallyclever.nodegraphcore.port.Input;
55
import com.marginallyclever.nodegraphcore.port.Output;
66

7+
import javax.swing.*;
8+
import java.util.Objects;
9+
710
/**
811
* C = (A&gt;B) ? 1 : 0
912
* @author Dan Royer
@@ -30,4 +33,9 @@ public void update() {
3033
double bv = b.getValue().doubleValue();
3134
c.setValue((av > bv) ? 1 : 0);
3235
}
36+
37+
@Override
38+
public Icon getIcon() {
39+
return new ImageIcon(Objects.requireNonNull(getClass().getResource("icons8-more-than-16.png")));
40+
}
3341
}

src/main/java/com/marginallyclever/nodegraphcore/nodes/math/LessThan.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
import com.marginallyclever.nodegraphcore.port.Input;
55
import com.marginallyclever.nodegraphcore.port.Output;
66

7+
import javax.swing.*;
8+
import java.util.Objects;
9+
710
/**
811
* C = (A&lt;B) ? 1 : 0
912
* @author Dan Royer
@@ -30,4 +33,9 @@ public void update() {
3033
double bv = b.getValue().doubleValue();
3134
c.setValue((av < bv) ? 1 : 0);
3235
}
36+
37+
@Override
38+
public Icon getIcon() {
39+
return new ImageIcon(Objects.requireNonNull(getClass().getResource("icons8-less-than-16.png")));
40+
}
3341
}

src/main/java/com/marginallyclever/nodegraphcore/nodes/math/Multiply.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
import com.marginallyclever.nodegraphcore.port.Input;
55
import com.marginallyclever.nodegraphcore.port.Output;
66

7+
import javax.swing.*;
8+
import java.util.Objects;
9+
710
/**
811
* A*B {@link Node}
912
*/
@@ -28,4 +31,9 @@ public void update() {
2831
double bv = b.getValue().doubleValue();
2932
c.setValue(av * bv);
3033
}
34+
35+
@Override
36+
public Icon getIcon() {
37+
return new ImageIcon(Objects.requireNonNull(getClass().getResource("icons8-multiply-16.png")));
38+
}
3139
}

0 commit comments

Comments
 (0)