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
18 changes: 5 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>donatello</artifactId>
<version>1.9.0</version>
<version>1.9.2</version>

<name>Donatello</name>
<description>GUI for nodegraphcore flow-based programming</description>
Expand Down Expand Up @@ -278,25 +278,17 @@
<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.16</version>
<scope>compile</scope>
<version>1.5.18</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.5.16</version>
<scope>runtime</scope>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</exclusion>
</exclusions>
<version>1.5.18</version>
</dependency>

<dependency>
Expand Down Expand Up @@ -335,7 +327,7 @@
-->
<groupId>com.github.marginallyclever</groupId>
<artifactId>nodegraphcore</artifactId>
<version>1.6.1</version>
<version>1.6.2</version>
</dependency>
</dependencies>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,31 +1,46 @@
package com.marginallyclever.donatello;

import com.marginallyclever.nodegraphcore.Node;
import com.marginallyclever.nodegraphcore.NodeCategory;

import javax.swing.*;
import javax.swing.tree.DefaultMutableTreeNode;
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<Node> supplier = category.getSupplier();
if (supplier != null) {
Node node = category.getSupplier().get();
setIcon(node.getIcon());
}*/
}
return this;
return label;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/com/marginallyclever/donatello/NodeHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<Node> getAllOutgoingConnections(Graph graph, Node source) {
List<Node> adjacent = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Loading