Skip to content

Commit

Permalink
Merge branch 'svg' of github-dimanyfadakis:DAINTINESS-Group/ObjectOri…
Browse files Browse the repository at this point in the history
…entedArchitectureDiagrammer into svg
  • Loading branch information
dimanyfantakis committed Apr 7, 2024
2 parents 9bef7f7 + 6cd7a48 commit fce757c
Show file tree
Hide file tree
Showing 36 changed files with 287 additions and 303 deletions.
15 changes: 6 additions & 9 deletions src/main/java/manager/ClassDiagramManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@
public class ClassDiagramManager implements DiagramManager
{

private ClassDiagram classDiagram;
private DiagramArrangementManager 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 Down Expand Up @@ -84,6 +84,7 @@ public SmartGraphPanel<String, String> visualizeJavaFXGraph()
public String visualizeSvgGraph(int dpi)
{
PlantUMLClassDiagram plantUMLClassDiagram = new PlantUMLClassDiagram(classDiagram);

return plantUMLClassDiagram.toSvg(dpi);
}

Expand Down Expand Up @@ -134,7 +135,6 @@ public File saveDiagram(Path graphSavePath)
{
CoordinatesUpdater coordinatesUpdater = new CoordinatesUpdater(classDiagram);
coordinatesUpdater.updateClassCoordinates(vertexCollection, graphView);

DiagramExporter diagramExporter = new JavaFXClassDiagramExporter(classDiagram);

return diagramExporter.exportDiagram(graphSavePath);
Expand All @@ -144,11 +144,8 @@ public File saveDiagram(Path 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());
}
Expand Down
15 changes: 7 additions & 8 deletions src/main/java/manager/PackageDiagramManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -139,18 +139,11 @@ public File saveDiagram(Path graphSavePath)
@Override
public void loadDiagram(Path graphSavePath) throws JsonParseException
{
JavaFXPackageDiagramLoader javaFXPackageDiagramLoader = new JavaFXPackageDiagramLoader(graphSavePath);

packageDiagram = new PackageDiagram();
packageDiagram.createDiagram(javaFXPackageDiagramLoader.loadDiagram());
packageDiagram.createDiagram(JavaFXPackageDiagramLoader.loadDiagram(graphSavePath));
}


public PackageDiagram getPackageDiagram()
{
return packageDiagram;
}

@Override
public SmartGraphPanel<String, String> applyLayout()
{
Expand All @@ -166,6 +159,7 @@ public SmartGraphPanel<String, String> applyLayout()
return graphView;
}


@Override
public SmartGraphPanel<String, String> applySpecificLayout(String choice)
{
Expand All @@ -181,4 +175,9 @@ public SmartGraphPanel<String, String> applySpecificLayout(String choice)
return graphView;
}

public PackageDiagram getPackageDiagram()
{
return packageDiagram;
}

}
32 changes: 19 additions & 13 deletions src/main/java/manager/SourceProject.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,38 +2,44 @@

import model.diagram.ClassDiagram;
import model.diagram.PackageDiagram;
import model.graph.ClassifierVertex;
import model.graph.PackageVertex;
import parser.Interpreter;

import java.nio.file.Path;
import java.util.Map;

public class SourceProject
{

private final Interpreter interpreter = new Interpreter();
private final Interpreter interpreter;


public void createClassGraph(Path sourcePackagePath,
ClassDiagram classDiagram)
public SourceProject()
{
interpreter.parseProject(sourcePackagePath);
interpreter.convertTreeToGraph();
classDiagram.setSinkVertices(interpreter.getSinkVertices());
interpreter = new Interpreter();
}


public void createPackageGraph(Path sourcePackagePath,
PackageDiagram packageDiagram)
public Map<Path, ClassifierVertex> createClassGraph(Path sourcePackagePath,
ClassDiagram classDiagram)
{
interpreter.parseProject(sourcePackagePath);
interpreter.convertTreeToGraph();
packageDiagram.setVertices(interpreter.getVertices());
Map<Path, ClassifierVertex> sinkVertices = interpreter.getSinkVertices();
classDiagram.setSinkVertices(sinkVertices);
return sinkVertices;
}

// Only used for testing.
// TODO: remove it completely.
protected Interpreter getInterpreter()

public Map<Path, PackageVertex> createPackageGraph(Path sourcePackagePath,
PackageDiagram packageDiagram)
{
return interpreter;
interpreter.parseProject(sourcePackagePath);
interpreter.convertTreeToGraph();
Map<Path, PackageVertex> vertices = interpreter.getVertices();
packageDiagram.setVertices(vertices);
return vertices;
}

}
4 changes: 1 addition & 3 deletions src/main/java/model/diagram/ClassDiagram.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,7 @@ private List<ClassifierVertex> getChosenNodes(List<String> chosenClassesNames)
List<ClassifierVertex> chosenClasses = new ArrayList<>();
for (String chosenClass : chosenClassesNames)
{
Optional<ClassifierVertex> optionalSinkVertex = sinkVertices
.values()
.stream()
Optional<ClassifierVertex> optionalSinkVertex = sinkVertices.values().stream()
.filter(it -> it.getName().equals(chosenClass))
.findFirst();

Expand Down
3 changes: 1 addition & 2 deletions src/main/java/model/diagram/PackageDiagram.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,7 @@ public List<PackageVertex> getChosenNodes(List<String> chosenPackagesNames)
List<PackageVertex> chosenPackages = new ArrayList<>();
for (String chosenPackage : chosenPackagesNames)
{
Optional<PackageVertex> vertex = vertices.values()
.stream()
Optional<PackageVertex> vertex = vertices.values().stream()
.filter(it -> it.getName().equals(chosenPackage))
.findFirst();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import model.graph.ClassifierVertex;
import org.javatuples.Pair;

import java.awt.*;
import java.awt.Dimension;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,8 @@ public class PlantUMLClassDiagramImageExporter implements DiagramExporter

public PlantUMLClassDiagramImageExporter(ClassDiagram diagram)
{
PlantUMLClassifierVertex plantUMLClassifierVertex = new PlantUMLClassifierVertex();
StringBuilder plantUMLNodeBuffer = plantUMLClassifierVertex.convertSinkVertex(diagram);
PlantUMLClassifierVertexArc plantUMLEdge = new PlantUMLClassifierVertexArc();
StringBuilder plantUMLEdgeBuffer = plantUMLEdge.convertSinkVertexArc(diagram);
StringBuilder plantUMLNodeBuffer = PlantUMLClassifierVertex.convertSinkVertices(diagram);
StringBuilder plantUMLEdgeBuffer = PlantUMLClassifierVertexArc.convertSinkVertexArcs(diagram);
bufferBody = plantUMLNodeBuffer
.append("\n\n")
.append(plantUMLEdgeBuffer)
Expand All @@ -47,7 +45,7 @@ public File exportDiagram(Path exportPath)
}


private void exportImage(File plantUMLFile, String plantCode)
private static void exportImage(File plantUMLFile, String plantCode)
{
try (ByteArrayOutputStream png = new ByteArrayOutputStream())
{
Expand Down Expand Up @@ -86,7 +84,7 @@ private void exportImage(File plantUMLFile, String plantCode)
}


private String wrapWidthChanger(String plantCode, int wrapWidth)
private static String wrapWidthChanger(String plantCode, int wrapWidth)
{
String updatedString;
// if (counter == 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,8 @@ public class PlantUMLClassDiagramTextExporter implements DiagramExporter

public PlantUMLClassDiagramTextExporter(ClassDiagram classDiagram)
{
PlantUMLClassifierVertex plantUMLClassifierVertex = new PlantUMLClassifierVertex();
StringBuilder plantUMLNodeBuffer = plantUMLClassifierVertex.convertSinkVertex(classDiagram);
PlantUMLClassifierVertexArc plantUMLEdge = new PlantUMLClassifierVertexArc();
StringBuilder plantUMLEdgeBuffer = plantUMLEdge.convertSinkVertexArc(classDiagram);
StringBuilder plantUMLNodeBuffer = PlantUMLClassifierVertex.convertSinkVertices(classDiagram);
StringBuilder plantUMLEdgeBuffer = PlantUMLClassifierVertexArc.convertSinkVertexArcs(classDiagram);
bufferBody = plantUMLNodeBuffer
.append("\n\n")
.append(plantUMLEdgeBuffer)
Expand All @@ -42,7 +40,7 @@ public File exportDiagram(Path exportPath)
}


private void writeFile(File plantUMLFile, String plantCode)
private static void writeFile(File plantUMLFile, String plantCode)
{
try (BufferedWriter writer = new BufferedWriter(new FileWriter(plantUMLFile)))
{
Expand All @@ -56,7 +54,7 @@ private void writeFile(File plantUMLFile, String plantCode)
}


private String getClassText()
private static String getClassText()
{
return """
@startuml
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,10 @@ public class PlantUMLPackageDiagramImageExporter implements DiagramExporter
private final StringBuilder bufferBody;


public PlantUMLPackageDiagramImageExporter(PackageDiagram diagram)
public PlantUMLPackageDiagramImageExporter(PackageDiagram packageDiagram)
{
PlantUMLPackageVertex plantUMLPackageVertex = new PlantUMLPackageVertex(diagram);
StringBuilder plantUMLNodeBuffer = plantUMLPackageVertex.convertVertex();
PlantUMLPackageVertexArc plantUMLEdge = new PlantUMLPackageVertexArc(diagram);
StringBuilder plantUMLEdgeBuffer = plantUMLEdge.convertVertexArc();
StringBuilder plantUMLNodeBuffer = PlantUMLPackageVertex.convertVertices(packageDiagram);
StringBuilder plantUMLEdgeBuffer = PlantUMLPackageVertexArc.convertVertexArcs(packageDiagram);
bufferBody = plantUMLNodeBuffer
.append("\n\n")
.append(plantUMLEdgeBuffer)
Expand All @@ -46,7 +44,7 @@ public File exportDiagram(Path exportPath)
}


private void exportImage(File plantUMLFile, String plantCode)
private static void exportImage(File plantUMLFile, String plantCode)
{
try (ByteArrayOutputStream png = new ByteArrayOutputStream())
{
Expand All @@ -58,7 +56,7 @@ private void exportImage(File plantUMLFile, String plantCode)
BufferedImage convImg = ImageIO.read(in);
int width = convImg.getWidth();
int wrapWidth = 150;
//int stringChangerCounter = 0;

if (width == 4096)
{
try (ByteArrayOutputStream newPng = new ByteArrayOutputStream())
Expand All @@ -69,7 +67,6 @@ private void exportImage(File plantUMLFile, String plantCode)
data = newPng.toByteArray();
in = new ByteArrayInputStream(data);
convImg = ImageIO.read(in);
width = convImg.getWidth();
}
catch (IOException e)
{
Expand All @@ -87,7 +84,7 @@ private void exportImage(File plantUMLFile, String plantCode)
}


private String wrapWidthChanger(String plantCode, int wrapWidth)
private static String wrapWidthChanger(String plantCode, int wrapWidth)
{
String updatedString;
int indexOfNewLine = plantCode.indexOf("\n");
Expand All @@ -100,7 +97,7 @@ private String wrapWidthChanger(String plantCode, int wrapWidth)
// POP UP MESSAGE CAN BE ADDED TO INFORM THE USER THAT THE IMAGE HE //
// REQUESTED IS OVER 4096x4096 SO WE REDUCE THE WRAPWIDTH TO REDUCE //
// EXTRACTED IMAGE'S WIDTH. NOW THE USER CAN SEE MORE CLASSES. //
// }else { //
// } else { //
// String[] lines = plantCode.split("\n"); //
// lines[1] = "skinparam wrapWidth " + wrapWidth; //
// updatedString = String.join("\n", lines); //
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,8 @@ public class PlantUMLPackageDiagramTextExporter implements DiagramExporter

public PlantUMLPackageDiagramTextExporter(PackageDiagram diagram)
{
PlantUMLPackageVertex plantUMLPackageVertex = new PlantUMLPackageVertex(diagram);
StringBuilder plantUMLNodeBuffer = plantUMLPackageVertex.convertVertex();
PlantUMLPackageVertexArc plantUMLEdge = new PlantUMLPackageVertexArc(diagram);
StringBuilder plantUMLEdgeBuffer = plantUMLEdge.convertVertexArc();
StringBuilder plantUMLNodeBuffer = PlantUMLPackageVertex.convertVertices(diagram);
StringBuilder plantUMLEdgeBuffer = PlantUMLPackageVertexArc.convertVertexArcs(diagram);
bufferBody = plantUMLNodeBuffer
.append("\n\n")
.append(plantUMLEdgeBuffer)
Expand All @@ -43,7 +41,7 @@ public File exportDiagram(Path exportPath)
}


private void writeFile(File plantUMLFile, String plantCode)
private static void writeFile(File plantUMLFile, String plantCode)
{
try (BufferedWriter writer = new BufferedWriter(new FileWriter(plantUMLFile)))
{
Expand Down
12 changes: 2 additions & 10 deletions src/main/java/model/diagram/javafx/JavaFXClassDiagramLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,8 @@ public class JavaFXClassDiagramLoader
{
private static final Logger logger = LogManager.getLogger(JavaFXClassDiagramLoader.class);

private final Path graphSavePath;


public JavaFXClassDiagramLoader(Path graphSavePath)
{
this.graphSavePath = graphSavePath;
}


public Set<ClassifierVertex> loadDiagram() throws JsonParseException
public static Set<ClassifierVertex> loadDiagram(Path graphSavePath) throws JsonParseException
{
Set<ClassifierVertex> sinkVertices = new HashSet<>();
try
Expand All @@ -56,7 +48,7 @@ public Set<ClassifierVertex> loadDiagram() throws JsonParseException
}


private void deserializeArcs(Set<ClassifierVertex> sinkVertices)
private static void deserializeArcs(Set<ClassifierVertex> sinkVertices)
{
for (ClassifierVertex classifierVertex : sinkVertices)
{
Expand Down
Loading

0 comments on commit fce757c

Please sign in to comment.