Skip to content

Commit

Permalink
Add functionality to view the SVG diagram of PlantUML
Browse files Browse the repository at this point in the history
  • Loading branch information
dimanyfantakis committed Apr 1, 2024
1 parent 5d61f33 commit 6cd7a48
Show file tree
Hide file tree
Showing 68 changed files with 889 additions and 615 deletions.
5 changes: 5 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,11 @@
<artifactId>maven-assembly-plugin</artifactId>
<version>3.6.0</version>
</dependency>
<dependency>
<groupId>org.apache.xmlgraphics</groupId>
<artifactId>batik-all</artifactId>
<version>1.17</version>
</dependency>
</dependencies>
<build>
<plugins>
Expand Down
64 changes: 37 additions & 27 deletions src/main/java/controller/Controller.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package controller;

import com.brunomnsilva.smartgraph.graphview.SmartGraphPanel;
import manager.DiagramManager;
import manager.SourceProject;

import java.io.File;
Expand All @@ -11,24 +12,23 @@ public interface Controller
{

/**
* This method creates the tree of the project by calling the DiagramManager's createTree method.
* This method creates the tree of the project by calling {@link DiagramManager#createSourceProject(Path)}.
*
* @param sourcePackagePath the project's source package path
* @return the SourceProject created
* @return the {@link SourceProject} created.
*/
SourceProject createTree(Path sourcePackagePath);

/**
* This method converts the created tree to a diagram, by creating the corresponding DiagramManager
* based on the type of the graph, i.e. package or class and then calling the createDiagram
* method of the DiagramManager.
* This method converts the created tree to a diagram,
* by calling {@link DiagramManager#convertTreeToDiagram(List)} with the given arguments.
*
* @param chosenFileNames the names of the files selected by the designer to be included in the diagram
* @param chosenFileNames the names of the files selected by the designer to be included in the diagram.
*/
void convertTreeToDiagram(List<String> chosenFileNames);

/**
* This method arranges the diagram by calling the DiagramManager's arrangeDiagram method.
* This method arranges the diagram by calling the {@link DiagramManager#arrangeDiagram()}.
*/
void arrangeDiagram();

Expand All @@ -39,59 +39,69 @@ public interface Controller
SmartGraphPanel<String, String> applySpecificLayout(String choice);

/**
* This method exports the diagram to a GraphML file by calling
* the DiagramManager's exportDiagramToGraphML method.
* This method exports the diagram to a GraphML file
* by calling {@link DiagramManager#exportDiagramToGraphML(Path)}.
*
* @param graphMLSavePath the selected path by the designer where the diagram will be saved
* @return the created File in which the diagram was saved
* @param graphMLSavePath the selected path by the designer where the diagram will be saved.
* @return the created File in which the diagram was saved.
*/
File exportDiagramToGraphML(Path graphMLSavePath);

/**
* This method saves the diagram to a text file by calling the DiagramManager's saveDiagram method.
* This method saves the diagram to a text file
* by calling {@link DiagramManager#saveDiagram(Path)}.
*
* @param graphSavePath the selected path by the designer where the diagram will be saved
* @return the created File in which the diagram was saved
* @param graphSavePath the selected path by the designer where the diagram will be saved.
* @return the created File in which the diagram was saved.
*/
File saveDiagram(Path graphSavePath);

/**
* This method loads a diagram from a text file by calling the DiagramManager's loadDiagram method.
* This method loads a diagram from a text file
* by calling {@link DiagramManager#loadDiagram(Path)}.
*
* @param graphSavePath the file's path where the diagram is saved
* @param graphSavePath the file's path where the diagram is saved.
*/
void loadDiagram(Path graphSavePath);

/**
* This method creates the JavaFX graphView by calling the DiagramManager's visualizeJavaFXGraph method.
* This method creates the JavaFX graphView
* by calling {@link DiagramManager#visualizeJavaFXGraph()}.
*
* @return the created graphView {@link SmartGraphPanel}
* @return the created graphView {@link SmartGraphPanel}.
*/
SmartGraphPanel<String, String> visualizeJavaFXGraph();

/**
* This method creates the loaded Diagram's JavaFX graphView by calling
* the DiagramManager's visualizeLoadedJavaFXGraph method.
* // TODO: Write a Javadoc when this is done.
* @param dpi the dpi of the screen?
* @return
*/
String visualizeSvgGraph(int dpi);

/**
* This method creates the loaded Diagram's JavaFX graphView
* by calling {@link DiagramManager#visualizeJavaFXGraph()}.
*
* @return the created graphView
* @return the created {@link SmartGraphPanel}.
*/
SmartGraphPanel<String, String> visualizeLoadedJavaFXGraph();

/**
* This method exports the diagram as an image with the help of PlantUML by calling
* the DiagramManager's exportPlantUMLDiagram method.
* This method exports the diagram as an image with the help of PlantUML
* by calling {@link DiagramManager#exportPlantUMLImage(Path)}.
*
* @param graphSavePath the selected path by the designer where the diagram's image will be saved
* @return the created PlantUML diagram
* @return the exported PlantUML diagram.
*/
File exportPlantUMLDiagram(Path graphSavePath);

/**
* This method saves the PlantUML code to a text file by calling
* the DiagramManager's exportPlantUMLText method.
* This method saves the PlantUML code to a text file
* by calling {@link DiagramManager#exportPlantUMLText(Path)}}.
*
* @param textSavePath the selected path by the designer where the text file will be saved
* @return the created PlantUML text file
* @return the exported PlantUML text file.
*/
File exportPlantUMLText(Path textSavePath);

Expand Down
12 changes: 4 additions & 8 deletions src/main/java/controller/ControllerType.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package controller;

import java.util.Collections;
import java.util.HashMap;
import java.util.Arrays;
import java.util.Map;
import java.util.stream.Collectors;

public enum ControllerType
{
Expand All @@ -12,12 +12,8 @@ public enum ControllerType

static
{
Map<String, ControllerType> map = new HashMap<>();
for (ControllerType controllerType : ControllerType.values())
{
map.put(controllerType.toString().toLowerCase(), controllerType);
}
CONTROLLER_TYPE = Collections.unmodifiableMap(map);
CONTROLLER_TYPE = Arrays.stream(ControllerType.values())
.collect(Collectors.toMap(ControllerType::toString, controllerType -> controllerType));
}

public static ControllerType get(String controllerType)
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/controller/DiagramController.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,12 @@ public SmartGraphPanel<String, String> visualizeJavaFXGraph()
return diagramManager.visualizeJavaFXGraph();
}

@Override
public String visualizeSvgGraph(int dpi)
{
return diagramManager.visualizeSvgGraph(dpi);
}

@Override
public SmartGraphPanel<String, String> visualizeLoadedJavaFXGraph()
{
Expand Down
35 changes: 19 additions & 16 deletions src/main/java/manager/ClassDiagramManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import model.diagram.ClassDiagram;
import model.diagram.ShadowCleaner;
import model.diagram.arrangement.ClassDiagramArrangementManager;
import model.diagram.arrangement.DiagramArrangementManagerInterface;
import model.diagram.arrangement.DiagramArrangementManager;
import model.diagram.arrangement.geometry.DiagramGeometry;
import model.diagram.exportation.CoordinatesUpdater;
import model.diagram.exportation.DiagramExporter;
Expand All @@ -16,6 +16,7 @@
import model.diagram.javafx.JavaFXClassDiagramLoader;
import model.diagram.javafx.JavaFXClassVisualization;
import model.diagram.javafx.JavaFXVisualization;
import model.diagram.svg.PlantUMLClassDiagram;
import org.javatuples.Pair;

import java.io.File;
Expand All @@ -27,7 +28,7 @@ public class ClassDiagramManager implements DiagramManager
{

private ClassDiagram classDiagram;
private DiagramArrangementManagerInterface classDiagramArrangement;
private DiagramArrangementManager classDiagramArrangement;
private Collection<Vertex<String>> vertexCollection;
private SmartGraphPanel<String, String> graphView;

Expand Down Expand Up @@ -76,6 +77,14 @@ public SmartGraphPanel<String, String> visualizeJavaFXGraph()
}


@Override
public String visualizeSvgGraph(int dpi)
{
PlantUMLClassDiagram plantUMLClassDiagram = new PlantUMLClassDiagram(classDiagram);
return plantUMLClassDiagram.toSvg(dpi);
}


@Override
public SmartGraphPanel<String, String> visualizeLoadedJavaFXGraph()
{
Expand Down Expand Up @@ -137,21 +146,13 @@ public void loadDiagram(Path graphSavePath)
}


public ClassDiagram getClassDiagram()
{
return classDiagram;
}

@Override
public SmartGraphPanel<String, String> applyLayout()
{
DiagramGeometry nodesGeometry = classDiagram.getDiagramGeometry();
for (Vertex<String> vertex : vertexCollection)
{
if (!nodesGeometry.containsKey(vertex.element()))
{
continue;
}
if (!nodesGeometry.containsKey(vertex.element())) continue;

Pair<Double, Double> coordinates = nodesGeometry.getVertexGeometry(vertex.element());
graphView.setVertexPosition(vertex, coordinates.getValue0(), coordinates.getValue1());
Expand All @@ -163,13 +164,10 @@ public SmartGraphPanel<String, String> applyLayout()
@Override
public SmartGraphPanel<String, String> applySpecificLayout(String choice)
{
DiagramGeometry nodesGeometry = classDiagramArrangement.applyNewLayout(choice);
DiagramGeometry nodesGeometry = classDiagramArrangement.applyLayout(choice);
for (Vertex<String> vertex : vertexCollection)
{
if (!nodesGeometry.containsKey(vertex.element()))
{
continue;
}
if (!nodesGeometry.containsKey(vertex.element())) continue;

Pair<Double, Double> coordinates = nodesGeometry.getVertexGeometry(vertex.element());
graphView.setVertexPosition(vertex,
Expand All @@ -180,4 +178,9 @@ public SmartGraphPanel<String, String> applySpecificLayout(String choice)
return graphView;
}

public ClassDiagram getClassDiagram()
{
return classDiagram;
}

}
7 changes: 7 additions & 0 deletions src/main/java/manager/DiagramManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,13 @@ public interface DiagramManager
*/
SmartGraphPanel<String, String> visualizeJavaFXGraph();

/**
* TODO: Add Javadoc when this is done.
* @param dpi the screen's dpi?
* @return
*/
String visualizeSvgGraph(int dpi);

/**
* This method is responsible for exporting the diagram to a PlantUML image diagram.
*
Expand Down
19 changes: 14 additions & 5 deletions src/main/java/manager/PackageDiagramManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import com.brunomnsilva.smartgraph.graphview.SmartGraphPanel;
import com.google.gson.JsonParseException;
import model.diagram.PackageDiagram;
import model.diagram.arrangement.DiagramArrangementManagerInterface;
import model.diagram.arrangement.DiagramArrangementManager;
import model.diagram.arrangement.PackageDiagramArrangementManager;
import model.diagram.arrangement.geometry.DiagramGeometry;
import model.diagram.exportation.CoordinatesUpdater;
Expand All @@ -16,6 +16,7 @@
import model.diagram.javafx.JavaFXPackageDiagramLoader;
import model.diagram.javafx.JavaFXPackageVisualization;
import model.diagram.javafx.JavaFXVisualization;
import model.diagram.svg.PlantUMLPackageDiagram;
import org.javatuples.Pair;

import java.io.File;
Expand All @@ -30,9 +31,9 @@ public class PackageDiagramManager implements DiagramManager

private static final Logger logger = Logger.getLogger(Logger.GLOBAL_LOGGER_NAME);

private PackageDiagram packageDiagram;
private DiagramArrangementManagerInterface packageDiagramArrangement;
private Collection<Vertex<String>> vertexCollection;
private PackageDiagram packageDiagram;
private DiagramArrangementManager packageDiagramArrangement;
private Collection<Vertex<String>> vertexCollection;
private SmartGraphPanel<String, String> graphView;


Expand Down Expand Up @@ -78,6 +79,14 @@ public SmartGraphPanel<String, String> visualizeJavaFXGraph()
}


@Override
public String visualizeSvgGraph(int dpi)
{
PlantUMLPackageDiagram plantUMLPackageDiagram = new PlantUMLPackageDiagram(packageDiagram);
return plantUMLPackageDiagram.toSvg(dpi);
}


@Override
public SmartGraphPanel<String, String> visualizeLoadedJavaFXGraph()
{
Expand Down Expand Up @@ -163,7 +172,7 @@ public SmartGraphPanel<String, String> applyLayout()
@Override
public SmartGraphPanel<String, String> applySpecificLayout(String choice)
{
DiagramGeometry nodesGeometry = packageDiagramArrangement.applyNewLayout(choice);
DiagramGeometry nodesGeometry = packageDiagramArrangement.applyLayout(choice);
for (Vertex<String> vertex : vertexCollection)
{
if (!nodesGeometry.containsKey(vertex.element()))
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/manager/SourceProject.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public void createPackageGraph(Path sourcePackagePath,
}

// Only used for testing.
// TODO remove it completely.
// TODO: remove it completely.
protected Interpreter getInterpreter()
{
return interpreter;
Expand Down
9 changes: 3 additions & 6 deletions src/main/java/model/diagram/ClassDiagram.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,10 @@ private List<ClassifierVertex> getChosenNodes(List<String> chosenClassesNames)
Optional<ClassifierVertex> optionalSinkVertex = sinkVertices
.values()
.stream()
.filter(sinkVertex -> sinkVertex.getName().equals(chosenClass))
.filter(it -> it.getName().equals(chosenClass))
.findFirst();
if (optionalSinkVertex.isEmpty())
{
continue;
}
chosenClasses.add(optionalSinkVertex.get());

optionalSinkVertex.ifPresent(chosenClasses::add);
}
return chosenClasses;
}
Expand Down
6 changes: 2 additions & 4 deletions src/main/java/model/diagram/GraphClassDiagramConverter.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,8 @@ public Map<ClassifierVertex, Set<Arc<ClassifierVertex>>> convertGraphToClassDiag
adjacencyList.put(classifierVertex, new HashSet<>());
for (Arc<ClassifierVertex> arc : classifierVertex.getArcs())
{
if (!sinkVertices.contains(arc.targetVertex()))
{
continue;
}
if (!sinkVertices.contains(arc.targetVertex())) continue;

adjacencyList.get(arc.sourceVertex()).add(arc);
}
}
Expand Down
6 changes: 2 additions & 4 deletions src/main/java/model/diagram/GraphPackageDiagramConverter.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,8 @@ public Map<PackageVertex, Set<Arc<PackageVertex>>> convertGraphToPackageDiagram(
adjacencyList.put(vertex, new HashSet<>());
for (Arc<PackageVertex> arc : vertex.getArcs())
{
if (!vertices.contains(arc.targetVertex()))
{
continue;
}
if (!vertices.contains(arc.targetVertex())) continue;

adjacencyList.get(arc.sourceVertex()).add(arc);
}
}
Expand Down
Loading

0 comments on commit 6cd7a48

Please sign in to comment.