Skip to content

Commit

Permalink
Merge pull request #38 from DAINTINESS-Group/svg
Browse files Browse the repository at this point in the history
Add functionality to view the SVG diagram of PlantUML
  • Loading branch information
dimanyfantakis authored Apr 7, 2024
2 parents ffc3ac0 + fce757c commit 37172ba
Show file tree
Hide file tree
Showing 82 changed files with 1,089 additions and 886 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>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
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
9 changes: 7 additions & 2 deletions src/main/java/controller/DiagramController.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import manager.DiagramManager;
import manager.DiagramManagerFactory;
import manager.SourceProject;
import model.diagram.arrangement.algorithms.LayoutAlgorithmType;

import java.io.File;
import java.nio.file.Path;
Expand Down Expand Up @@ -48,7 +47,7 @@ public SmartGraphPanel<String, String> applyLayout()
@Override
public SmartGraphPanel<String, String> applySpecificLayout(String choice)
{
return diagramManager.applySpecificLayout(LayoutAlgorithmType.get(choice));
return diagramManager.applySpecificLayout(choice);
}

@Override
Expand All @@ -75,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
49 changes: 31 additions & 18 deletions src/main/java/manager/ClassDiagramManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
import model.diagram.ClassDiagram;
import model.diagram.ShadowCleaner;
import model.diagram.arrangement.ClassDiagramArrangementManager;
import model.diagram.arrangement.DiagramArrangementManagerInterface;
import model.diagram.arrangement.algorithms.LayoutAlgorithmType;
import model.diagram.arrangement.DiagramArrangementManager;
import model.diagram.arrangement.geometry.DiagramGeometry;
import model.diagram.exportation.CoordinatesUpdater;
import model.diagram.exportation.DiagramExporter;
Expand All @@ -17,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,10 +27,10 @@
public class ClassDiagramManager implements DiagramManager
{

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


public ClassDiagramManager()
Expand All @@ -44,6 +44,7 @@ public SourceProject createSourceProject(Path sourcePackagePath)
{
SourceProject sourceProject = new SourceProject();
sourceProject.createClassGraph(sourcePackagePath, classDiagram);

return sourceProject;
}

Expand All @@ -63,6 +64,7 @@ public DiagramGeometry arrangeDiagram()
classDiagramArrangement = new ClassDiagramArrangementManager(classDiagram);
DiagramGeometry diagramGeometry = classDiagramArrangement.arrangeDiagram();
classDiagram.setDiagramGeometry(diagramGeometry);

return diagramGeometry;
}

Expand All @@ -73,10 +75,20 @@ public SmartGraphPanel<String, String> visualizeJavaFXGraph()
JavaFXVisualization javaFXVisualization = new JavaFXClassVisualization(classDiagram);
graphView = javaFXVisualization.createGraphView();
vertexCollection = javaFXVisualization.getVertexCollection();

return graphView;
}


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

return plantUMLClassDiagram.toSvg(dpi);
}


@Override
public SmartGraphPanel<String, String> visualizeLoadedJavaFXGraph()
{
Expand All @@ -85,6 +97,7 @@ public SmartGraphPanel<String, String> visualizeLoadedJavaFXGraph()

graphView = javaFXVisualization.getLoadedGraph();
vertexCollection = javaFXVisualization.getVertexCollection();

return graphView;
}

Expand All @@ -94,6 +107,7 @@ public File exportDiagramToGraphML(Path graphMLSavePath)
{
classDiagram.setGraphMLDiagramGeometry(classDiagramArrangement.arrangeGraphMLDiagram());
DiagramExporter diagramExporter = new GraphMLClassDiagramExporter(classDiagram);

return diagramExporter.exportDiagram(graphMLSavePath);
}

Expand All @@ -102,6 +116,7 @@ public File exportDiagramToGraphML(Path graphMLSavePath)
public File exportPlantUMLImage(Path plantUMLSavePath)
{
DiagramExporter diagramExporter = new PlantUMLClassDiagramImageExporter(classDiagram);

return diagramExporter.exportDiagram(plantUMLSavePath);
}

Expand All @@ -110,6 +125,7 @@ public File exportPlantUMLImage(Path plantUMLSavePath)
public File exportPlantUMLText(Path textSavePath)
{
DiagramExporter diagramExporter = new PlantUMLClassDiagramTextExporter(classDiagram);

return diagramExporter.exportDiagram(textSavePath);
}

Expand All @@ -119,30 +135,22 @@ public File saveDiagram(Path graphSavePath)
{
CoordinatesUpdater coordinatesUpdater = new CoordinatesUpdater(classDiagram);
coordinatesUpdater.updateClassCoordinates(vertexCollection, graphView);

DiagramExporter diagramExporter = new JavaFXClassDiagramExporter(classDiagram);

return diagramExporter.exportDiagram(graphSavePath);
}


@Override
public void loadDiagram(Path graphSavePath)
{
JavaFXClassDiagramLoader javaFXClassDiagramLoader = new JavaFXClassDiagramLoader(graphSavePath);

classDiagram = new ClassDiagram();
classDiagram.createDiagram(javaFXClassDiagramLoader.loadDiagram());

classDiagram.createDiagram(JavaFXClassDiagramLoader.loadDiagram(graphSavePath));
ShadowCleaner shadowCleaner = new ShadowCleaner(classDiagram);
classDiagram.setDiagram(shadowCleaner.shadowWeakRelationships());
}


public ClassDiagram getClassDiagram()
{
return classDiagram;
}

@Override
public SmartGraphPanel<String, String> applyLayout()
{
Expand All @@ -159,9 +167,9 @@ public SmartGraphPanel<String, String> applyLayout()
}

@Override
public SmartGraphPanel<String, String> applySpecificLayout(LayoutAlgorithmType algorithmType)
public SmartGraphPanel<String, String> applySpecificLayout(String choice)
{
DiagramGeometry nodesGeometry = classDiagramArrangement.applyLayout(algorithmType);
DiagramGeometry nodesGeometry = classDiagramArrangement.applyLayout(choice);
for (Vertex<String> vertex : vertexCollection)
{
if (!nodesGeometry.containsKey(vertex.element())) continue;
Expand All @@ -175,4 +183,9 @@ public SmartGraphPanel<String, String> applySpecificLayout(LayoutAlgorithmType a
return graphView;
}

public ClassDiagram getClassDiagram()
{
return classDiagram;
}

}
9 changes: 8 additions & 1 deletion src/main/java/manager/DiagramManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,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 All @@ -91,7 +98,7 @@ public interface DiagramManager
SmartGraphPanel<String, String> applyLayout();

// TODO JavaDoc
SmartGraphPanel<String, String> applySpecificLayout(LayoutAlgorithmType algorithmType);
SmartGraphPanel<String, String> applySpecificLayout(String algorithmType);

// TODO JavaDoc
SmartGraphPanel<String, String> visualizeLoadedJavaFXGraph();
Expand Down
Loading

0 comments on commit 37172ba

Please sign in to comment.