-
Notifications
You must be signed in to change notification settings - Fork 61
Core Concepts
Bruno Silva edited this page Jun 2, 2025
·
2 revisions
Understanding these core classes and interfaces is key to effectively using JavaFXSmartGraph.
-
Interface:
com.brunomnsilva.smartgraph.graph.Graph -
Purpose: Represents the abstract data type for a graph (or digraph). It's generic, allowing you to define the type of elements stored in vertices (
V) and edges (E). -
Key Methods:
-
numVertices(),numEdges() -
vertices(),edges(): Return collections of vertices and edges. -
insertVertex(V vElement): Adds a new vertex. -
insertEdge(Vertex<V> u, Vertex<V> v, E edgeElement): Adds an edge between two vertices (for undirected graphs). -
insertEdge(V uElement, V vElement, E edgeElement): Convenience method to add an edge by vertex elements. removeVertex(Vertex<V> v)removeEdge(Edge<E,V> e)
-
-
Implementation:
com.brunomnsilva.smartgraph.graph.GraphEdgeListis the default adjacency list implementation.DigraphEdgeListis available for directed graphs.
-
Interface:
com.brunomnsilva.smartgraph.graph.Vertex -
Purpose: Represents a vertex in the graph. It holds the user-defined element of type
V. -
Key Methods:
-
element(): Returns the stored element.
-
-
Interface:
com.brunomnsilva.smartgraph.graph.Edge -
Purpose: Represents an edge connecting two vertices. It holds the user-defined element of type
E. -
Key Methods:
-
element(): Returns the stored element. -
vertices(): Returns an array of the two endpoint vertices. - For digraphs, you might have
outbound()andinbound()methods.
-
-
Class:
com.brunomnsilva.smartgraph.graphview.SmartGraphPanel -
Extends:
javafx.scene.layout.Pane -
Purpose: This is the main JavaFX UI component responsible for visualizing the
Graph. It manages the creation and layout of visual representations for vertices (SmartGraphVertexNode) and edges (SmartGraphEdgeNode). -
Constructor:
SmartGraphPanel(Graph<V, E> graph, SmartPlacementStrategy placementStrategy)orSmartGraphPanel(Graph<V, E> graph, SmartGraphProperties properties, SmartPlacementStrategy placementStrategy) -
Key Methods:
-
init(): Initializes the graph visualization. Must be called after the panel is created and preferably after it has been added to a scene (so its size is known for layout). -
update(): Forces a re-render of the graph. Call this if you dynamically add/remove vertices/edges from the underlying graph model afterinit()has been called. -
setVertexPosition(Vertex<V> v, double x, double y): Programmatically sets the position of a vertex. -
getStylableVertex(Vertex<V> v): Returns theSmartStylableNodefor a vertex for programmatic styling. -
getStylableEdge(Edge<E,V> e): Returns theSmartStylableNodefor an edge. -
setVertexDoubleClickAction(Consumer<SmartGraphVertex<V>> action): Set an action upon vertex double click. -
setEdgeDoubleClickAction(Consumer<SmartGraphEdge<E,V>> action): Set an action upon edge double click. -
setAutomaticLayout(boolean N_ARE_AUTO_PLACED): Enable/disable automatic layout.
-
-
Interface:
com.brunomnsilva.smartgraph.graphview.SmartPlacementStrategy - Purpose: Defines how vertices are initially placed on the panel.
-
Implementations:
-
SmartCircularSortedPlacementStrategy: Places vertices in a circle, sorted by their element's string representation. -
SmartRandomPlacementStrategy: Places vertices randomly. - You can create your own custom placement strategies.
-
-
Class:
com.brunomnsilva.smartgraph.graphview.SmartGraphProperties -
Purpose: A utility class to define properties for the graph view, often passed as a string in the
SmartGraphPanelconstructor. These can control aspects like default CSS files or behavior toggles.- Example:
SmartGraphProperties properties = new SmartGraphProperties("graph.css;"); - Supported properties often include:
edge.arrow = true/falsevertex.allow_drag = true/false-
vertex.label.placement = center/top/bottom(may vary by implementation) - A CSS file path (e.g.,
mystyles.css;)
- Example:
-
Interface:
com.brunomnsilva.smartgraph.graphview.SmartStylableNode -
Purpose: Implemented by visual nodes (
SmartGraphVertexNode,SmartGraphEdgeNode,SmartLabel,SmartArrow) to provide a consistent API for applying CSS styles programmatically. -
Key Methods:
setStyleInline(String css)setStyleClass(String cssClass)addStyleClass(String cssClass)removeStyleClass(String cssClass)
These core components work together to provide the graph visualization capabilities.