Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 9 additions & 13 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<groupId>com.marginallyclever</groupId>
<artifactId>nodegraphcore</artifactId>
<version>1.6.1</version>
<version>1.6.2</version>

<name>NodeGraphCore</name>
<description>Flow based programming in Java.</description>
Expand Down Expand Up @@ -57,7 +57,7 @@
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20231013</version>
<version>20250517</version>
</dependency>
<!-- unit testing -->
<dependency>
Expand All @@ -74,24 +74,20 @@
<scope>test</scope>
</dependency>
<!-- for logging -->
<!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-api -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>2.0.16</version>
<version>2.0.17</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-core</artifactId>
<version>1.5.18</version>
</dependency>
<!-- logging -->
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.5.16</version>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</exclusion>
</exclusions>
<version>1.5.18</version>
</dependency>
<!-- for finding nodes in a package -->
<dependency>
Expand Down
24 changes: 23 additions & 1 deletion src/main/java/com/marginallyclever/nodegraphcore/Node.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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")));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<Node> supplier;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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")));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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")));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand All @@ -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")));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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")));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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&gt;B) ? 1 : 0
* @author Dan Royer
Expand All @@ -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")));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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&lt;B) ? 1 : 0
* @author Dan Royer
Expand All @@ -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")));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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}
*/
Expand All @@ -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")));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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}
*/
Expand All @@ -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")));
}
}
Empty file.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading