Skip to content

Commit

Permalink
Fix paths to resource files when using the jar
Browse files Browse the repository at this point in the history
  • Loading branch information
dimanyfantakis committed Sep 21, 2024
1 parent d9c2ee3 commit 1fd7a8a
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 21 deletions.
11 changes: 3 additions & 8 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,6 @@
<name>JavaFXSmartGraph</name>
<url>file://${pom.basedir}/libs/JavaFXSmartGraph</url>
</repository>
<repository>
<id>PlantUML</id>
<name>PlantUML</name>
<url>file://${pom.basedir}/libs/PlantUML</url>
</repository>
<repository>
<id>ithaka</id>
<url>http://beckchr.github.io/ithaka-maven/mvnrepo/</url>
Expand Down Expand Up @@ -104,9 +99,9 @@
<version>0.1</version>
</dependency>
<dependency>
<groupId>PlantUML</groupId>
<artifactId>PlantUML</artifactId>
<version>1.2023.7</version>
<groupId>net.sourceforge.plantuml</groupId>
<artifactId>plantuml</artifactId>
<version>1.2023.9</version>
</dependency>
<dependency>
<groupId>com.github.javaparser</groupId>
Expand Down
52 changes: 39 additions & 13 deletions src/main/java/model/diagram/javafx/JavaFXClassVisualization.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,28 @@
import com.brunomnsilva.smartgraph.graph.Vertex;
import com.brunomnsilva.smartgraph.graphview.SmartCircularSortedPlacementStrategy;
import com.brunomnsilva.smartgraph.graphview.SmartGraphPanel;
import com.brunomnsilva.smartgraph.graphview.SmartGraphProperties;
import model.diagram.ClassDiagram;
import model.graph.Arc;
import model.graph.ArcType;
import model.graph.ClassifierVertex;
import model.graph.VertexType;

import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.Collection;
import java.util.Objects;
import java.util.Set;

public class JavaFXClassVisualization implements JavaFXVisualization
{

public static final String DEFAULT_PROPERTIES_PATH = "styles/smartgraph.properties";
public static final String DEFAULT_STYLE_PATH = "styles/smartgraph.css";

private final ClassDiagram classDiagram;
private SmartGraphPanel<String, String> graphView;
private Collection<Vertex<String>> vertexCollection;
Expand All @@ -34,16 +44,28 @@ public SmartGraphPanel<String, String> createGraphView()
{
Graph<String, String> graph = createGraph();
vertexCollection = graph.vertices();
graphView = new SmartGraphPanel<>(graph, new SmartCircularSortedPlacementStrategy());
graphView = createGraphView(graph);
setSinkVertexCustomStyle();
return graphView;
}


@Override
public Collection<Vertex<String>> getVertexCollection()
private static SmartGraphPanel<String, String> createGraphView(Graph<String, String> graph)
{
return vertexCollection;
try (InputStream resource = JavaFXClassVisualization.class.getClassLoader().getResourceAsStream(DEFAULT_PROPERTIES_PATH))
{
SmartGraphProperties properties = new SmartGraphProperties(resource);

URL url = JavaFXClassVisualization.class.getClassLoader().getResource(DEFAULT_STYLE_PATH);
URI cssFile = Objects.requireNonNull(url).toURI();

return new SmartGraphPanel<>(graph, properties, new SmartCircularSortedPlacementStrategy(), cssFile);
}
catch (IOException | URISyntaxException ignored)
{
// Fallback to default paths.
return new SmartGraphPanel<>(graph, new SmartCircularSortedPlacementStrategy());
}
}


Expand All @@ -55,10 +77,10 @@ private Graph<String, String> createGraph()
directedGraph.insertVertex(classifierVertex.getName());
}
insertSinkVertexArcs(directedGraph);

return directedGraph;
}


private void insertSinkVertexArcs(Digraph<String, String> directedGraph)
{
for (Set<Arc<ClassifierVertex>> arcs : classDiagram.getDiagram().values())
Expand Down Expand Up @@ -86,18 +108,22 @@ private void setSinkVertexCustomStyle()
{
for (ClassifierVertex classifierVertex : classDiagram.getDiagram().keySet())
{
if (classifierVertex.getVertexType().equals(VertexType.INTERFACE))
{
graphView.getStylableVertex(classifierVertex.getName()).setStyleClass("vertexInterface");
}
else
{
graphView.getStylableVertex(classifierVertex.getName()).setStyleClass("vertexPackage");
}
String styleClass = classifierVertex.getVertexType().equals(VertexType.INTERFACE) ?
"vertexInterface" :
"vertexPackage";

graphView.getStylableVertex(classifierVertex.getName()).setStyleClass(styleClass);
}
}


@Override
public Collection<Vertex<String>> getVertexCollection()
{
return vertexCollection;
}


@Override
public SmartGraphPanel<String, String> getLoadedGraph()
{
Expand Down

0 comments on commit 1fd7a8a

Please sign in to comment.