Skip to content

Commit

Permalink
added recent files menu
Browse files Browse the repository at this point in the history
  • Loading branch information
i-make-robots committed Jan 3, 2025
1 parent 9209b67 commit 1541df8
Show file tree
Hide file tree
Showing 22 changed files with 559 additions and 22 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Donatello Flow-based Programming Editor

A pure Java implementation of [Flow-based Programming](https://en.wikipedia.org/wiki/Dataflow_programming) (FBP) and a GUI editor.
A pure Java implementation of [Flow-based Programming](https://en.wikipedia.org/wiki/Dataflow_programming) (FBP).

![img](docs/preview-for-github.png)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ <h1 title="Class ActionCopyGraph" class="title">Class ActionCopyGraph</h1>
</div>
<div class="inheritance" title="Inheritance Tree">java.lang.Object
<div class="inheritance">javax.swing.AbstractAction
<div class="inheritance">com.marginallyclever.donatello.actions.CopyGraphAction</div>
<div class="inheritance">com.marginallyclever.donatello.actions.GraphCopyAction</div>
</div>
</div>
<section class="description">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ <h1 title="Class ActionFoldGraph" class="title">Class ActionFoldGraph</h1>
</div>
<div class="inheritance" title="Inheritance Tree">java.lang.Object
<div class="inheritance">javax.swing.AbstractAction
<div class="inheritance">com.marginallyclever.donatello.actions.FoldGraphAction</div>
<div class="inheritance">com.marginallyclever.donatello.actions.GraphFoldAction</div>
</div>
</div>
<section class="description">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ <h1 title="Class ActionNewGraph" class="title">Class ActionNewGraph</h1>
</div>
<div class="inheritance" title="Inheritance Tree">java.lang.Object
<div class="inheritance">javax.swing.AbstractAction
<div class="inheritance">com.marginallyclever.donatello.actions.NewGraphAction</div>
<div class="inheritance">com.marginallyclever.donatello.actions.GraphNewAction</div>
</div>
</div>
<section class="description">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ <h1 title="Class ActionPrintGraph" class="title">Class ActionPrintGraph</h1>
</div>
<div class="inheritance" title="Inheritance Tree">java.lang.Object
<div class="inheritance">javax.swing.AbstractAction
<div class="inheritance">com.marginallyclever.donatello.actions.PrintGraphAction</div>
<div class="inheritance">com.marginallyclever.donatello.actions.GraphPrintAction</div>
</div>
</div>
<section class="description">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ <h1 title="Class ActionSaveGraph" class="title">Class ActionSaveGraph</h1>
</div>
<div class="inheritance" title="Inheritance Tree">java.lang.Object
<div class="inheritance">javax.swing.AbstractAction
<div class="inheritance">com.marginallyclever.donatello.actions.SaveGraphAction</div>
<div class="inheritance">com.marginallyclever.donatello.actions.GraphSaveAsAction</div>
</div>
</div>
<section class="description">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ <h1 title="Class ActionStraightenGraph" class="title">Class ActionStraightenGrap
</div>
<div class="inheritance" title="Inheritance Tree">java.lang.Object
<div class="inheritance">javax.swing.AbstractAction
<div class="inheritance">com.marginallyclever.donatello.actions.StraightenGraphAction</div>
<div class="inheritance">com.marginallyclever.donatello.actions.GraphStraightenAction</div>
</div>
</div>
<section class="description">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ <h1 title="Class ActionUnfoldGraph" class="title">Class ActionUnfoldGraph</h1>
</div>
<div class="inheritance" title="Inheritance Tree">java.lang.Object
<div class="inheritance">javax.swing.AbstractAction
<div class="inheritance">com.marginallyclever.donatello.actions.UnfoldGraphAction</div>
<div class="inheritance">com.marginallyclever.donatello.actions.GraphUnfoldAction</div>
</div>
</div>
<section class="description">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ <h1 title="Class ActionUpdateGraph" class="title">Class ActionUpdateGraph</h1>
</div>
<div class="inheritance" title="Inheritance Tree">java.lang.Object
<div class="inheritance">javax.swing.AbstractAction
<div class="inheritance">com.marginallyclever.donatello.actions.UpdateGraphAction</div>
<div class="inheritance">com.marginallyclever.donatello.actions.GraphUpdateAction</div>
</div>
</div>
<section class="description">
Expand Down
14 changes: 7 additions & 7 deletions docs/javadoc/serialized-form.html
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ <h5>editor</h5>
</li>
<li>
<section class="serialized-class-details" id="com.marginallyClever.nodeGraphSwing.actions.ActionCopyGraph">
<h3>Class <a href="com.marginallyClever.NodeGraphCore/com/marginallyClever/nodeGraphSwing/actions/ActionCopyGraph.html" title="class in com.marginallyclever.donatello.actions">com.marginallyclever.donatello.actions.CopyGraphAction</a> extends javax.swing.AbstractAction implements Serializable</h3>
<h3>Class <a href="com.marginallyClever.NodeGraphCore/com/marginallyClever/nodeGraphSwing/actions/ActionCopyGraph.html" title="class in com.marginallyclever.donatello.actions">com.marginallyclever.donatello.actions.GraphCopyAction</a> extends javax.swing.AbstractAction implements Serializable</h3>
<ul class="block-list">
<li>
<section class="detail">
Expand Down Expand Up @@ -331,7 +331,7 @@ <h5>editor</h5>
</li>
<li>
<section class="serialized-class-details" id="com.marginallyClever.nodeGraphSwing.actions.ActionFoldGraph">
<h3>Class <a href="com.marginallyClever.NodeGraphCore/com/marginallyClever/nodeGraphSwing/actions/ActionFoldGraph.html" title="class in com.marginallyclever.donatello.actions">com.marginallyclever.donatello.actions.FoldGraphAction</a> extends javax.swing.AbstractAction implements Serializable</h3>
<h3>Class <a href="com.marginallyClever.NodeGraphCore/com/marginallyClever/nodeGraphSwing/actions/ActionFoldGraph.html" title="class in com.marginallyclever.donatello.actions">com.marginallyclever.donatello.actions.GraphFoldAction</a> extends javax.swing.AbstractAction implements Serializable</h3>
<ul class="block-list">
<li>
<section class="detail">
Expand Down Expand Up @@ -398,7 +398,7 @@ <h5>fc</h5>
</li>
<li>
<section class="serialized-class-details" id="com.marginallyClever.nodeGraphSwing.actions.ActionNewGraph">
<h3>Class <a href="com.marginallyClever.NodeGraphCore/com/marginallyClever/nodeGraphSwing/actions/ActionNewGraph.html" title="class in com.marginallyclever.donatello.actions">com.marginallyclever.donatello.actions.NewGraphAction</a> extends javax.swing.AbstractAction implements Serializable</h3>
<h3>Class <a href="com.marginallyClever.NodeGraphCore/com/marginallyClever/nodeGraphSwing/actions/ActionNewGraph.html" title="class in com.marginallyclever.donatello.actions">com.marginallyclever.donatello.actions.GraphNewAction</a> extends javax.swing.AbstractAction implements Serializable</h3>
<ul class="block-list">
<li>
<section class="detail">
Expand Down Expand Up @@ -436,7 +436,7 @@ <h5>editor</h5>
</li>
<li>
<section class="serialized-class-details" id="com.marginallyClever.nodeGraphSwing.actions.ActionPrintGraph">
<h3>Class <a href="com.marginallyClever.NodeGraphCore/com/marginallyClever/nodeGraphSwing/actions/ActionPrintGraph.html" title="class in com.marginallyclever.donatello.actions">com.marginallyclever.donatello.actions.PrintGraphAction</a> extends javax.swing.AbstractAction implements Serializable</h3>
<h3>Class <a href="com.marginallyClever.NodeGraphCore/com/marginallyClever/nodeGraphSwing/actions/ActionPrintGraph.html" title="class in com.marginallyclever.donatello.actions">com.marginallyclever.donatello.actions.GraphPrintAction</a> extends javax.swing.AbstractAction implements Serializable</h3>
<ul class="block-list">
<li>
<section class="detail">
Expand All @@ -455,7 +455,7 @@ <h5>editor</h5>
</li>
<li>
<section class="serialized-class-details" id="com.marginallyClever.nodeGraphSwing.actions.ActionSaveGraph">
<h3>Class <a href="com.marginallyClever.NodeGraphCore/com/marginallyClever/nodeGraphSwing/actions/ActionSaveGraph.html" title="class in com.marginallyclever.donatello.actions">com.marginallyclever.donatello.actions.SaveGraphAction</a> extends javax.swing.AbstractAction implements Serializable</h3>
<h3>Class <a href="com.marginallyClever.NodeGraphCore/com/marginallyClever/nodeGraphSwing/actions/ActionSaveGraph.html" title="class in com.marginallyclever.donatello.actions">com.marginallyclever.donatello.actions.GraphSaveAsAction</a> extends javax.swing.AbstractAction implements Serializable</h3>
<ul class="block-list">
<li>
<section class="detail">
Expand All @@ -479,7 +479,7 @@ <h5>fc</h5>
</li>
<li>
<section class="serialized-class-details" id="com.marginallyClever.nodeGraphSwing.actions.ActionStraightenGraph">
<h3>Class <a href="com.marginallyClever.NodeGraphCore/com/marginallyClever/nodeGraphSwing/actions/ActionStraightenGraph.html" title="class in com.marginallyclever.donatello.actions">com.marginallyclever.donatello.actions.StraightenGraphAction</a> extends javax.swing.AbstractAction implements Serializable</h3>
<h3>Class <a href="com.marginallyClever.NodeGraphCore/com/marginallyClever/nodeGraphSwing/actions/ActionStraightenGraph.html" title="class in com.marginallyclever.donatello.actions">com.marginallyclever.donatello.actions.GraphStraightenAction</a> extends javax.swing.AbstractAction implements Serializable</h3>
<ul class="block-list">
<li>
<section class="detail">
Expand All @@ -503,7 +503,7 @@ <h5>SNAP_SIZE</h5>
</li>
<li>
<section class="serialized-class-details" id="com.marginallyClever.nodeGraphSwing.actions.ActionUnfoldGraph">
<h3>Class <a href="com.marginallyClever.NodeGraphCore/com/marginallyClever/nodeGraphSwing/actions/ActionUnfoldGraph.html" title="class in com.marginallyclever.donatello.actions">com.marginallyclever.donatello.actions.UnfoldGraphAction</a> extends javax.swing.AbstractAction implements Serializable</h3>
<h3>Class <a href="com.marginallyClever.NodeGraphCore/com/marginallyClever/nodeGraphSwing/actions/ActionUnfoldGraph.html" title="class in com.marginallyclever.donatello.actions">com.marginallyclever.donatello.actions.GraphUnfoldAction</a> extends javax.swing.AbstractAction implements Serializable</h3>
<ul class="block-list">
<li>
<section class="detail">
Expand Down
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20230227</version>
<version>20231013</version>
</dependency>
<!-- unit testing -->
<dependency>
Expand All @@ -83,7 +83,7 @@
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.2.10</version>
<version>1.4.12</version>
<scope>test</scope>
</dependency>
<!-- for finding nodes in a package -->
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/marginallyclever/nodegraphcore/Dock.java
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public void setValue(Object arg0) {
* Returns the class of this value type.
* @return the class of this value type.
*/
public Class<T> getTypeClass() {
public Class<T> getType() {
return type;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@ public static void createDirectoryIfMissing(String dir) {
public static List<String> listFilesInDirectory(String dir) {
File[] found = new File(dir).listFiles();
List<String> absoluteNames = new ArrayList<>();
for( File f : found ) {
absoluteNames.add(f.getAbsolutePath());
if(!Objects.isNull(found)) {
for( File f : found ) {
absoluteNames.add(f.getAbsolutePath());
}
}
return absoluteNames;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.marginallyclever.nodegraphcore.dynamic;

import io.github.classgraph.ClassGraph;
import io.github.classgraph.ScanResult;

import java.util.HashSet;
import java.util.Set;

/**
* Scans the classpath for all classes and packages.
*/
public class ClassPathScanner {
public static Set<String> getVisiblePackagesAndClasses() {
Set<String> classNames = new HashSet<>();

try (ScanResult scanResult = new ClassGraph()
.enableSystemJarsAndModules()
.enableAllInfo()
.acceptPackages("java", "javax", "com.marginallyclever") //, "com", "org", "jdk", "sun"
.scan()) {

classNames.addAll(scanResult.getAllClasses().getNames());
}

return classNames;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
package com.marginallyclever.nodegraphcore.dynamic;

import javax.swing.*;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import java.awt.*;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Set;

/**
* A panel that can be used to search for a class and invoke a method dynamically at runtime. The method can be static
* or non-static.
*/
public class ClassSearchPanel extends JPanel {
private final JTextField searchBar;
private final JList<String> searchResults;
private final DefaultListModel<String> searchResultsModel;
private final JScrollPane searchResultsScrollPane;

private final Set<String> classNames;

private MethodSelectionPanel methodSelectionPanel;

public ClassSearchPanel() {
setLayout(new BorderLayout());

// Get the list of visible packages and classes
classNames = ClassPathScanner.getVisiblePackagesAndClasses();
ArrayList<String> names = new ArrayList<>(classNames);
Collections.sort(names);
names.forEach(System.out::println);

searchBar = new JTextField(30);
searchBar.getDocument().addDocumentListener(new DocumentListener() {
public void changedUpdate(DocumentEvent documentEvent) {
updateSearchResults();
}

public void insertUpdate(DocumentEvent documentEvent) {
updateSearchResults();
}

public void removeUpdate(DocumentEvent documentEvent) {
updateSearchResults();
}
});
searchBar.addKeyListener(new SearchBarKeyListener());
searchBar.setFocusTraversalKeysEnabled(false);

searchResultsModel = new DefaultListModel<>();
searchResultsModel.setSize(15);
searchResults = new JList<>(searchResultsModel);
searchResults.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
searchResults.addKeyListener(new SearchResultKeyListener());
searchResults.addMouseListener(new SearchResultMouseListener());
searchResults.setVisibleRowCount(5);
searchResults.setVisible(true);

searchResultsScrollPane = new JScrollPane(searchResults);
searchResultsScrollPane.setVisible(false);

setBorder(BorderFactory.createTitledBorder("Class"));
add(searchBar, BorderLayout.NORTH);
add(searchResultsScrollPane, BorderLayout.CENTER);

searchBar.setText("java.lang.String");
}

private void updateSearchResults() {
String searchText = searchBar.getText().trim();
searchResultsModel.clear();

if (searchText.isEmpty()) {
searchResultsScrollPane.setVisible(false);
return;
}

// Perform the search and get the class names based on the search text
List<String> closeMatches = new ArrayList<>();
int matchCount = 0;
for (String className : classNames) {
if (className.startsWith(searchText)) {
int firstDotIndex = className.indexOf('.', searchText.length());
if (firstDotIndex != -1) {
className = className.substring(0, firstDotIndex);
}
if(!closeMatches.contains(className)) {
closeMatches.add(className);
}
}
}

Collections.sort(closeMatches);
for(String className : closeMatches) {
searchResultsModel.addElement(className);
matchCount++;
}

searchResultsScrollPane.setVisible(!searchResultsModel.isEmpty());
}

private class SearchBarKeyListener extends KeyAdapter {
@Override
public void keyReleased(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_ENTER) {
updateItemFound();
} else if (e.getKeyCode() == KeyEvent.VK_DOWN) {
searchResults.requestFocus();
}
}
}

private void updateItemFound() {
if (!searchBar.getText().trim().isEmpty()) {
String className = searchBar.getText().trim();
if(classExists(className)) {
System.out.println("Found class "+className);
searchResultsScrollPane.setVisible(false);

// Replace the center part of the panel with MethodSelectionPanel
if(methodSelectionPanel!=null) {
remove(methodSelectionPanel);
}
methodSelectionPanel = new MethodSelectionPanel(className);
add(methodSelectionPanel, BorderLayout.CENTER);
}
revalidate();
repaint();
} else if(methodSelectionPanel!=null) {
methodSelectionPanel.setVisible(false);
}
}

private boolean classExists(String className) {
try {
Class.forName(className);
return true;
} catch (ClassNotFoundException e) {
return false;
}
}

private class SearchResultKeyListener extends KeyAdapter {
@Override
public void keyReleased(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_ENTER) {
changeSearchBarItemSelected();
} else if (e.getKeyCode() == KeyEvent.VK_UP && searchResults.getSelectedIndex() == 0) {
searchBar.requestFocus();
}
}
}

private class SearchResultMouseListener extends MouseAdapter {
@Override
public void mouseClicked(MouseEvent e) {
if (e.getClickCount() == 2) {
changeSearchBarItemSelected();
}
}
}

private void changeSearchBarItemSelected() {
String className = searchResults.getSelectedValue();
searchBar.setText(className);
searchResultsScrollPane.setVisible(false);
updateItemFound();
}
}
Loading

0 comments on commit 1541df8

Please sign in to comment.