diff --git a/pom.xml b/pom.xml
index 11abd12..3b3698a 100644
--- a/pom.xml
+++ b/pom.xml
@@ -4,7 +4,7 @@
com.marginallyclever
donatello
- 1.9.0
+ 1.9.2
Donatello
GUI for nodegraphcore flow-based programming
@@ -278,25 +278,17 @@
org.slf4j
slf4j-api
- 2.0.16
+ 2.0.17
ch.qos.logback
logback-core
- 1.5.16
- compile
+ 1.5.18
ch.qos.logback
logback-classic
- 1.5.16
- runtime
-
-
- org.slf4j
- slf4j-api
-
-
+ 1.5.18
@@ -335,7 +327,7 @@
-->
com.github.marginallyclever
nodegraphcore
- 1.6.1
+ 1.6.2
diff --git a/src/main/java/com/marginallyclever/donatello/FactoryCategoryCellRenderer.java b/src/main/java/com/marginallyclever/donatello/FactoryCategoryCellRenderer.java
index 30f4e64..1e9b494 100644
--- a/src/main/java/com/marginallyclever/donatello/FactoryCategoryCellRenderer.java
+++ b/src/main/java/com/marginallyclever/donatello/FactoryCategoryCellRenderer.java
@@ -1,5 +1,6 @@
package com.marginallyclever.donatello;
+import com.marginallyclever.nodegraphcore.Node;
import com.marginallyclever.nodegraphcore.NodeCategory;
import javax.swing.*;
@@ -7,25 +8,39 @@
import javax.swing.tree.DefaultTreeCellRenderer;
import java.awt.*;
+/**
+ * Custom cell renderer for displaying node categories in a tree.
+ * It sets the text and color based on the category's supplier.
+ */
class FactoryCategoryCellRenderer extends DefaultTreeCellRenderer {
@Override
public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus) {
- super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus);
- var branch = (DefaultMutableTreeNode) value;
- if (branch.getUserObject() instanceof NodeCategory category) {
- if (category.getSupplier() == null) {
- setForeground(Color.LIGHT_GRAY);
+ JLabel label = (JLabel) super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus);
+
+ DefaultMutableTreeNode node = (DefaultMutableTreeNode) value;
+ Object userObject = node.getUserObject();
+ if (userObject instanceof NodeCategory category) {
+ label.setText(category.getName());
+ if (category.getSupplier() != null) {
+ try {
+ Node n = category.getSupplier().get();
+ if (n != null) {
+ var icon = n.getIcon();
+ if(icon != null) {
+ label.setIcon(icon);
+ } else {
+ label.setIcon(getDefaultLeafIcon());
+ }
+ } else {
+ label.setIcon(getDefaultLeafIcon());
+ }
+ } catch (Exception e) {
+ label.setIcon(getDefaultLeafIcon());
+ }
} else {
- setForeground(Color.BLACK);
+ label.setIcon(getDefaultOpenIcon());
}
- setText(category.getName());
- /*
- Supplier supplier = category.getSupplier();
- if (supplier != null) {
- Node node = category.getSupplier().get();
- setIcon(node.getIcon());
- }*/
}
- return this;
+ return label;
}
}
diff --git a/src/main/java/com/marginallyclever/donatello/NodeFactoryPanel.java b/src/main/java/com/marginallyclever/donatello/NodeFactoryPanel.java
index f7f33ba..1c989e1 100644
--- a/src/main/java/com/marginallyclever/donatello/NodeFactoryPanel.java
+++ b/src/main/java/com/marginallyclever/donatello/NodeFactoryPanel.java
@@ -20,8 +20,6 @@
/**
* Swing UI allowing a user to create a new {@link Node} as registered with a {@link NodeFactory}.
- * @author Dan Royer
- * @since 2022-02-11
*/
public class NodeFactoryPanel extends JPanel {
private static final Logger logger = LoggerFactory.getLogger(NodeFactoryPanel.class);
diff --git a/src/main/java/com/marginallyclever/donatello/NodeHelper.java b/src/main/java/com/marginallyclever/donatello/NodeHelper.java
index 687d217..f3dbe6d 100644
--- a/src/main/java/com/marginallyclever/donatello/NodeHelper.java
+++ b/src/main/java/com/marginallyclever/donatello/NodeHelper.java
@@ -7,6 +7,10 @@
import java.util.ArrayList;
import java.util.List;
+/**
+ * Helper class for working with {@link Node} objects in a {@link Graph}.
+ * Provides methods to retrieve outgoing connections and neighbors of nodes.
+ */
public class NodeHelper {
public static List getAllOutgoingConnections(Graph graph, Node source) {
List adjacent = new ArrayList<>();
diff --git a/src/main/java/com/marginallyclever/donatello/graphview/GraphViewPanel.java b/src/main/java/com/marginallyclever/donatello/graphview/GraphViewPanel.java
index b2bbbe2..2623c81 100644
--- a/src/main/java/com/marginallyclever/donatello/graphview/GraphViewPanel.java
+++ b/src/main/java/com/marginallyclever/donatello/graphview/GraphViewPanel.java
@@ -351,7 +351,8 @@ public void paintNodeTitleBar(Graphics g, Node n) {
g.setColor(settings.getNodeColorTitleFont());
box.height = Node.TITLE_HEIGHT;
paintText(g,n.getLabel(),box,ALIGN_LEFT,ALIGN_CENTER);
- paintText(g,n.getName(),box,ALIGN_RIGHT,ALIGN_CENTER);
+ //paintText(g,n.getName(),box,ALIGN_RIGHT,ALIGN_CENTER);
+ paintIcon(g,n,box,ALIGN_RIGHT,ALIGN_CENTER);
}
private void paintProgressBar(Graphics g, Node n,Rectangle r) {
@@ -457,7 +458,6 @@ public void paintPortConnectionPoints(Graphics g, Port> v) {
g.drawOval(p.x-radius,p.y-radius,radius*2,radius*2);
}
}
-
/**
* Use the graphics context to paint text within a box with the provided alignment.
* @param g the graphics context
@@ -490,6 +490,29 @@ public static void paintText(Graphics g,String str,Rectangle box,int alignH,int
layout.draw((Graphics2D)g,x,y);
}
+ public void paintIcon(Graphics g, Node n, Rectangle box, int alignH, int alignV) {
+ Icon icon = n.getIcon();
+ if(icon == null) return;
+
+ int x,y;
+ if(alignH == ALIGN_LEFT) {
+ x = box.x;
+ } else if(alignH == ALIGN_RIGHT) {
+ x = box.x + box.width - icon.getIconWidth();
+ } else {
+ x = box.x + (box.width - icon.getIconWidth()) / 2;
+ }
+
+ if(alignV == ALIGN_TOP) {
+ y = box.y;
+ } else if(alignV == ALIGN_BOTTOM) {
+ y = box.y + box.height - icon.getIconHeight();
+ } else {
+ y = box.y + (box.height - icon.getIconHeight()) / 2;
+ }
+
+ icon.paintIcon(this, g, x, y);
+ }
/**
* Paint the male end of connection points at this {@link Port}.
* @param g the {@link Graphics} context