What is PathGraph
Path Graph is a library with all the tools necessary to create and work both path and walk graphs in a stable and simple way.
Why PathGraph
If you need a ready-to-use library for user-side representing path graphs in which there are nodes, edges, and associated costs, which offers a user-friendly to represent, manage, and interact graphs, then this it's the right solution.
Fork-Based Project
This library is a fork based on the source code of the SmartGraph v2.0.0. It is modified to suite in specific path graphs features in a stable interface.
Note
Read the Javadoc for more details: PathGraph-JavaFX-1.0.9-javadoc
Note
Library available on Maven Central: PathGraph-JavaFX-1.0.9
<dependency>
<groupId>io.github.vittoriopiotti</groupId>
<artifactId>PathGraph-JavaFX</artifactId>
<version>1.0.9</version>
</dependency>
- Features
- Graph Logic
- Get Started
- Ready to Code
- Examples
- Callbacks
- DTO · Data Transfer Object
- JSON · Data Management
- Configuration and Styling
- Licenses
-
Nodes:
New Node
,Rename Node
,Delete Node
-
Edges:
New Edge
,Delete Edge
,Rotate Edge
,Split Edge
,Set Cost
-
Graph:
Upload JSON
,Download JSON
,Clear Graph
,Show Path
,Take Screenshot
,Drag
,Zoom
,Adjust Position
- Limit of 26 Nodes nameable only with uppercase characters
- Limit of two edges with opposite directions beetween two nodes
- Loop creation is not allowed
- Edge cost is an integer number
- Edge directions can be:
Bidirectional
,Natural Direction
,Opposite Direction
Forward-compatible
Import External Dependencies
JavaFX-Swing-22
, JavaFX-Controls-22
, JavaFX-FXML-22
Import Library
Able to:
-
POM configuration:
<dependency> <groupId>io.github.vittoriopiotti</groupId> <artifactId>PathGraph-JavaFX</artifactId> <version>1.0.9</version> </dependency>
-
Manual configuration:
Download and import jar in your module dependencies:
PathGraph-JavaFX-1.0.9.jar
Show POM.xml dependencies
<dependency>
<groupId>io.github.vittoriopiotti</groupId>
<artifactId>PathGraph-JavaFX</artifactId>
<version>1.0.9</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-swing</artifactId>
<version>22</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
<version>22</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-fxml</artifactId>
<version>22</version>
</dependency>
import com.vittoriopiotti.pathgraph.app.*;
Note
PathGraph
to create your custom interfacePathGraphUI
for ready-to-use interface
PathGraph
Vanilla configurations to use in your project in which create your custom UI.
Handles the graph's display and logic independently of the user interface, acting as a standalone component without any user interface restrictions, provifind all necessary features.
PathGraph pg = new PathGraph();
Empty callbacks
or
PathGraph pg = new PathGraph(
(ContextMenuCallback) ()->{},
(EdgeCallback) (MouseEvent e, Character c1, Character c2)->{},
(NodeCallback) (MouseEvent e, Character c1, Character c2)->{},
(BackgroundCallback) (MouseEvent e)->{},
(ZoomCallback) (Double n)->{},
(AdjustPositionCallback) ()->{}
);
With callbacks
PathGraphUI
Ready-to-use configuration with default UI.
Extends PathGraph to provide a layer on top of the graph management functionalities. It allows for the interaction with the graph through a visual interface over the underlying graph logic.
PathGraphUI pg = new PathGraphUI(
(Stage) stage,
(Scene) scene
);
With default UI
or
PathGraphUI pg = new PathGraphUI(
(Stage) stage,
(Scene) scene,
/* is enabled top-left menu */
true,
/* is enabled bot-left menu */
true,
/* is enabled bot-mid menu */
true,
/* is enabled right-mid menu */
true,
/* is enabled top-right menu */
true,
/* is hide UI */
false
);
With custom UI
In both cases are customizable the visibility of the UI and its components only with an instance of PathGraphUI
:
Hide UI
, Show UI
, Toggle UI
, Set UI
Note
To enable the use of library setup
must be called only one time after making stage visible with (Stage) stage.show()
Before calling setup, no operations of any kind can be performed on the graph
pg.setup();
or
pg.setup().thenRun(() -> {
/* actions to perform on first load */
/* e.g. put here components, callbacks setting, graph configurations */
});
Graph operations are limited to these contexts:
- Setup: ensures execution post-initialization in
pg.setup().thenRun(()->{})
. - Event Handlers: Safe within JavaFX event actions.
- JavaFX Timers: Use for delayed, thread-safe execution.
Vanilla configurations to use in your project in which create your custom UI.
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.stage.Stage;
import javafx.scene.layout.BorderPane;
import com.vittoriopiotti.pathgraph.app.PathGraph;
public class ExampleOfPathGraph extends Application {
@Override
public void start(Stage primaryStage) {
/* 1. Create javafx window */
BorderPane root = new BorderPane();
Scene scene = new Scene(root,500,300);
primaryStage.setScene(scene);
/* 2. Show primary stage */
primaryStage.show();
/* 3. Instance object */
PathGraph pg = new PathGraph();
/* 4. Add PathGraph in a container */
root.setCenter(pg);
/* 6. Setup */
pg.setup().thenRun(() -> {
/* 5. Custom configurations */
pg.enableListenersGraph(true);
pg.enableListenersPane(true);
pg.setAutomaticLayout(true);
/* Set callbacks */
pg.setBackgroundCallback(event -> {
pg.newNode();
event.consume();
});
pg.setNodeCallback((event,label) -> {
pg.newEdge(label);
event.consume();
});
pg.setEdgeCallback((event,start,end) -> {
pg.deleteEdge(start,end);
event.consume();
});
/* 7. Make Graphs */
pg.newNode('A');
pg.newNode('B');
pg.newNode('C');
pg.newEdge('A', 'B', 1);
pg.newEdge('C', 'A', 2, false);
});
}
public static void main(String[] args) {
launch();
}
}
Ready-to-use configuration with default UI.
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.stage.Stage;
import javafx.scene.layout.BorderPane;
import com.vittoriopiotti.pathgraph.app.PathGraphUI;
public class ExampleOfPathGraphUI extends Application {
@Override
public void start(Stage primaryStage) {
/* 1. Create javafx window */
BorderPane root = new BorderPane();
Scene scene = new Scene(root,500,300);
primaryStage.setScene(scene);
/* 2. Show primary stage */
primaryStage.show();
/* 3. Instance object */
PathGraphUI pg = new PathGraphUI(primaryStage,scene);
/* 4. Add PathGraph in a container */
root.setCenter(pg);
/* 5. Setup */
pg.setup().thenRun(() -> {
/* 6. Make Graphs */
pg.newNode('A');
pg.newNode('B');
pg.newNode('C');
pg.newEdge('A', 'B', 1);
pg.newEdge('C', 'A', 2, false);
});
}
public static void main(String[] args) {
launch();
}
}
Note
Customizable callbacks only with an instance of PathGraph
(PathGraphUI
is a ready-to-use configuration).
Usage:
-
Import package to use callback objects:
import com.vittoriopiotti.pathgraph.callbacks.*;
-
Call setter methods to apply new callbacks passing callback objects:
Set All Callbacks
,Set Context Menu Callback
,Set Edge Callback
,Set Node Callback
,Set Background Callback
,Set Zoom Callback
,Set Adjust Position Callback
Snippet:
EdgeCallback ec = (event,start,end) ->{
if (event.getButton() == MouseButton.SECONDARY) {
System.out.println(
pg.rotateEdge(start,end) ?
"rotate edge successfully" :
"rotate edge error"
);
}else if (event.getButton() == MouseButton.PRIMARY) {
System.out.println(
pg.deleteEdge(start,end) ?
"delete edge successfully" :
"delete edge error"
);
}
event.consume();
};
(PathGraph) pg.setEdgeCallback(ec);
Tip
-
Use of a
ContextMenu
with customMenuItem
orButton
to perform the actions -
Use
event.consume()
to prevent the propagation of the event -
Use the
return status
to feedback errors with aModal Dialog
Note
Read the Javadoc for more details: (see)
Providing to rappresent graph components in a simple and serializable structure.
Import package:
import com.vittoriopiotti.pathgraph.dto.*;
Usage:
- Converting graph data into JSON format
- Reconstructing graph data from JSON
- Support structure for graph operations
Get Nodes Json
, Get Edges Json
, Get Connections Json
, Get Graph Json
, Upload Json
, Download Json
Graph
{
"nodes": ["A", "B","C"],
"edges": [
{
"from": "A",
"to": "B",
"cost": 1,
"isArrowed": true
},
{
"from": "B",
"to": "A",
"cost": 10,
"isArrowed": true
},
{
"from": "B",
"to": "C",
"cost": 2,
"isArrowed": false
}
]
}
Nodes
{
"nodes": [
"A",
"C",
"B"
]
}
Edges
{
"edges": [
{
"from": "A",
"to": "B",
"cost": 1,
"isArrowed": true
},
{
"from": "C",
"to": "A",
"cost": 2,
"isArrowed": false
}
]
}
Connections
{
"connections": [
{
"node": "B",
"edges": [
]
},
{
"node": "A",
"edges": [
{
"to": "B",
"cost": 1
},
{
"to": "C",
"cost": 2
}
]
},
{
"node": "C",
"edges": [
{
"to": "A",
"cost": 2
}
]
}
]
}
In future versions will be optimized the management of configurations and styles similar to the original project of the fork (see).
Currently, the styles and configurations are preset and cannot be modified.
Note
SVG icons from Bootstrap
Copyright 2024 Vittorio Piotti (GitHub page) (Personal page)
Version v1.0.4
License GPL-3.0
Copyright 2019 - 2024 Bruno Silva (GitHub page) (Personal page)
Version v2.0.0
License MIT
Copyright 2011-2018 The Bootstrap Authors
Version v1.11.0
License MIT
This library is a fork based on the source code of the SmartGraph v2.0.0 library on which existing classes have been modified and new ones have been added. PathGraph is therefore the adaptation of SmartGraph to specific path graphs features in a stable user interface.