From ce0c90d59d7ef3afdaf6f10654c8c13d573a5671 Mon Sep 17 00:00:00 2001 From: Dan Royer Date: Wed, 18 Jun 2025 12:57:21 -0700 Subject: [PATCH 1/3] display node icons --- .../FactoryCategoryCellRenderer.java | 43 +++++++++++++------ .../donatello/NodeFactoryPanel.java | 2 - .../donatello/NodeHelper.java | 4 ++ .../donatello/graphview/GraphViewPanel.java | 27 +++++++++++- 4 files changed, 58 insertions(+), 18 deletions(-) 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 From 52e74dc5d15315ed028b6fb0205816c3a01b9cc1 Mon Sep 17 00:00:00 2001 From: Dan Royer Date: Wed, 16 Jul 2025 10:35:03 -0700 Subject: [PATCH 2/3] 1.9.1 bump dependencies --- pom.xml | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/pom.xml b/pom.xml index 11abd12..8c3032a 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ com.marginallyclever donatello - 1.9.0 + 1.9.1 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 @@ -333,9 +325,9 @@ Github/Jitpack/etc can find the copy published by Jitpack. I have to do this dance every time. --> - com.github.marginallyclever + com.marginallyclever nodegraphcore - 1.6.1 + 1.6.2 From 22fda3553afc2b96572826b520ca0e6e7d611cfd Mon Sep 17 00:00:00 2001 From: Dan Royer Date: Wed, 16 Jul 2025 10:40:30 -0700 Subject: [PATCH 3/3] 1.9.2 --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 8c3032a..3b3698a 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ com.marginallyclever donatello - 1.9.1 + 1.9.2 Donatello GUI for nodegraphcore flow-based programming @@ -325,7 +325,7 @@ Github/Jitpack/etc can find the copy published by Jitpack. I have to do this dance every time. --> - com.marginallyclever + com.github.marginallyclever nodegraphcore 1.6.2