Skip to content

Commit

Permalink
rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
dimanyfantakis committed Apr 6, 2024
1 parent 061d38e commit 9bef7f7
Show file tree
Hide file tree
Showing 36 changed files with 165 additions and 205 deletions.
3 changes: 1 addition & 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 Down
8 changes: 8 additions & 0 deletions src/main/java/manager/ClassDiagramManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -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,6 +75,7 @@ public SmartGraphPanel<String, String> visualizeJavaFXGraph()
JavaFXVisualization javaFXVisualization = new JavaFXClassVisualization(classDiagram);
graphView = javaFXVisualization.createGraphView();
vertexCollection = javaFXVisualization.getVertexCollection();

return graphView;
}

Expand All @@ -93,6 +96,7 @@ public SmartGraphPanel<String, String> visualizeLoadedJavaFXGraph()

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

return graphView;
}

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

return diagramExporter.exportDiagram(graphMLSavePath);
}

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

return diagramExporter.exportDiagram(plantUMLSavePath);
}

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

return diagramExporter.exportDiagram(textSavePath);
}

Expand All @@ -129,6 +136,7 @@ public File saveDiagram(Path graphSavePath)
coordinatesUpdater.updateClassCoordinates(vertexCollection, graphView);

DiagramExporter diagramExporter = new JavaFXClassDiagramExporter(classDiagram);

return diagramExporter.exportDiagram(graphSavePath);
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/manager/DiagramManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -98,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
17 changes: 4 additions & 13 deletions src/main/java/manager/DiagramType.java
Original file line number Diff line number Diff line change
@@ -1,26 +1,17 @@
package manager;

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

public enum DiagramType
{
CLASS,
PACKAGE;

public static final Map<String, DiagramType> DIAGRAM_TYPE;
public static final Map<String, DiagramType> DIAGRAM_TYPE = Arrays.stream(DiagramType.values())
.collect(Collectors.toMap(DiagramType::toString, it -> it));

static
{
Map<String, DiagramType> map = new HashMap<>();
for (DiagramType diagramType : DiagramType.values())
{
map.put(diagramType.toString().toLowerCase(), diagramType);
}

DIAGRAM_TYPE = Collections.unmodifiableMap(map);
}

public static DiagramType get(String diagramType)
{
Expand Down
17 changes: 7 additions & 10 deletions src/main/java/manager/PackageDiagramManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import model.diagram.PackageDiagram;
import model.diagram.arrangement.DiagramArrangementManager;
import model.diagram.arrangement.PackageDiagramArrangementManager;
import model.diagram.arrangement.algorithms.LayoutAlgorithmType;
import model.diagram.arrangement.geometry.DiagramGeometry;
import model.diagram.exportation.CoordinatesUpdater;
import model.diagram.exportation.DiagramExporter;
Expand All @@ -17,8 +16,7 @@
import model.diagram.javafx.JavaFXPackageDiagramLoader;
import model.diagram.javafx.JavaFXPackageVisualization;
import model.diagram.javafx.JavaFXVisualization;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import model.diagram.svg.PlantUMLPackageDiagram;
import org.javatuples.Pair;

import java.io.File;
Expand All @@ -29,8 +27,6 @@
public class PackageDiagramManager implements DiagramManager
{

private static final Logger logger = LogManager.getLogger(PackageDiagramManager.class);

private PackageDiagram packageDiagram;
private DiagramArrangementManager packageDiagramArrangement;
private Collection<Vertex<String>> vertexCollection;
Expand Down Expand Up @@ -95,6 +91,7 @@ public SmartGraphPanel<String, String> visualizeLoadedJavaFXGraph()

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

return graphView;
}

Expand All @@ -104,6 +101,7 @@ public File exportDiagramToGraphML(Path graphMLSavePath)
{
packageDiagram.setGraphMLDiagramGeometry(packageDiagramArrangement.arrangeGraphMLDiagram());
DiagramExporter diagramExporter = new GraphMLPackageDiagramExporter(packageDiagram);

return diagramExporter.exportDiagram(graphMLSavePath);
}

Expand All @@ -112,6 +110,7 @@ public File exportDiagramToGraphML(Path graphMLSavePath)
public File exportPlantUMLImage(Path plantUMLSavePath)
{
DiagramExporter diagramExporter = new PlantUMLPackageDiagramImageExporter(packageDiagram);

return diagramExporter.exportDiagram(plantUMLSavePath);
}

Expand All @@ -120,6 +119,7 @@ public File exportPlantUMLImage(Path plantUMLSavePath)
public File exportPlantUMLText(Path textSavePath)
{
DiagramExporter diagramExporter = new PlantUMLPackageDiagramTextExporter(packageDiagram);

return diagramExporter.exportDiagram(textSavePath);
}

Expand All @@ -131,6 +131,7 @@ public File saveDiagram(Path graphSavePath)
coordinatesUpdater.updatePackageCoordinates(vertexCollection, graphView);

DiagramExporter diagramExporter = new JavaFXPackageDiagramExporter(packageDiagram);

return diagramExporter.exportDiagram(graphSavePath);
}

Expand All @@ -156,11 +157,7 @@ public SmartGraphPanel<String, String> applyLayout()
DiagramGeometry nodesGeometry = packageDiagram.getDiagramGeometry();
for (Vertex<String> vertex : vertexCollection)
{
if (!nodesGeometry.containsKey(vertex.element()))
{
logger.debug("Vertex: {} not in vertices collection.", 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 Down
4 changes: 2 additions & 2 deletions src/main/java/model/diagram/ClassDiagram.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ private void createGraphNodes(List<String> chosenFileNames)
int nodeId = 0;
for (ClassifierVertex classifierVertex : getChosenNodes(chosenFileNames))
{
graphNodes.put(classifierVertex, nodeId);
nodeId++;
graphNodes.put(classifierVertex, nodeId++);
}
}

Expand All @@ -67,6 +66,7 @@ private List<ClassifierVertex> getChosenNodes(List<String> chosenClassesNames)

optionalSinkVertex.ifPresent(chosenClasses::add);
}

return chosenClasses;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public Map<ClassifierVertex, Set<Arc<ClassifierVertex>>> convertGraphToClassDiag
adjacencyList.get(arc.sourceVertex()).add(arc);
}
}

return adjacencyList;
}

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/model/diagram/PackageDiagram.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,10 @@ public List<PackageVertex> getChosenNodes(List<String> chosenPackagesNames)
.stream()
.filter(it -> it.getName().equals(chosenPackage))
.findFirst();
if (vertex.isEmpty()) continue;

chosenPackages.add(vertex.get());
vertex.ifPresent(chosenPackages::add);
}

return chosenPackages;
}

Expand Down
3 changes: 1 addition & 2 deletions src/main/java/model/diagram/ShadowCleaner.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ public Map<ClassifierVertex, Set<Arc<ClassifierVertex>>> shadowWeakRelationships
Map<ClassifierVertex, List<Arc<ClassifierVertex>>> shadowedArcs = new HashMap<>();
for (Arc<ClassifierVertex> arc : arcs)
{
shadowedArcs.computeIfAbsent(arc.targetVertex(),
sinkVertex -> new ArrayList<>()).add(arc);
shadowedArcs.computeIfAbsent(arc.targetVertex(), k -> new ArrayList<>()).add(arc);
}

for (Map.Entry<ClassifierVertex, List<Arc<ClassifierVertex>>> arc : shadowedArcs.entrySet())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,51 +14,45 @@
import model.graph.ClassifierVertex;
import org.javatuples.Pair;

import java.awt.Dimension;
import java.awt.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;

public class ClassDiagramArrangementManager implements DiagramArrangementManager
{

public static final LayoutAlgorithmType DEFAULT_LAYOUT_ALGORITHM = LayoutAlgorithmType.SUGIYAMA;
public static final int HEIGHT = 1500;
public static final int WIDTH = 1000;
private final ClassDiagram classDiagram;
private final Graph<String, String> graph;
public static final LayoutAlgorithmType DEFAULT_LAYOUT_ALGORITHM = LayoutAlgorithmType.SUGIYAMA;
public static final int HEIGHT = 1500;
public static final int WIDTH = 1000;
private final ClassDiagram classDiagram;


public ClassDiagramArrangementManager(ClassDiagram classDiagram)
{
this.classDiagram = classDiagram;
graph = createGraphWithStrings();
}


@Override
public Map<Integer, Pair<Double, Double>> arrangeGraphMLDiagram()
{
Map<Integer, Pair<Double, Double>> nodesGeometryGraphML = new HashMap<>();
Graph<Integer, String> graph = createGraph();
AbstractLayout<Integer, String> layout = new SpringLayout<>(graph);
Graph<Integer, String> graph = createGraph(classDiagram);
AbstractLayout<Integer, String> layout = new SpringLayout<>(graph);
layout.setSize(new Dimension(WIDTH, HEIGHT));
for (Integer i : classDiagram.getGraphNodes().values())
{
nodesGeometryGraphML.put(i, new Pair<>(layout.getX(i), layout.getY(i)));
}

return nodesGeometryGraphML;
return classDiagram.getGraphNodes().values().stream()
.collect(Collectors.toMap(it -> it, it -> new Pair<>(layout.getX(it), layout.getY(it))));
}


@Override
public DiagramGeometry arrangeDiagram()
{
LayoutAlgorithm layoutAlgorithm = LayoutAlgorithmFactory.createLayoutAlgorithm(DEFAULT_LAYOUT_ALGORITHM);
return layoutAlgorithm.arrangeDiagram(graph);
return layoutAlgorithm.arrangeDiagram(createGraphWithStrings(classDiagram));
}


Expand All @@ -67,23 +61,21 @@ public DiagramGeometry applyLayout(String algorithmType)
{
LayoutAlgorithmType algorithmEnumType = LayoutAlgorithmType.get(algorithmType);
LayoutAlgorithm layout = LayoutAlgorithmFactory.createLayoutAlgorithm(algorithmEnumType);
return layout.arrangeDiagram(graph);
return layout.arrangeDiagram(createGraphWithStrings(classDiagram));
}


private Graph<Integer, String> createGraph()
private static Graph<Integer, String> createGraph(ClassDiagram classDiagram)
{
Graph<Integer, String> graph = new SparseGraph<>();
for (Integer nodeId : classDiagram.getGraphNodes().values())
{
graph.addVertex(nodeId);
}

List<Arc<ClassifierVertex>> arcs = new ArrayList<>();
for (Set<Arc<ClassifierVertex>> arcSet : classDiagram.getDiagram().values())
{
arcs.addAll(arcSet);
}
List<Arc<ClassifierVertex>> arcs = classDiagram.getDiagram().values().stream()
.flatMap(Collection::stream)
.collect(Collectors.toCollection(ArrayList::new));

for (Arc<ClassifierVertex> arc : arcs)
{
Expand All @@ -97,19 +89,17 @@ private Graph<Integer, String> createGraph()
}


private Graph<String, String> createGraphWithStrings()
private static Graph<String, String> createGraphWithStrings(ClassDiagram classDiagram)
{
Graph<String, String> graph = new SparseGraph<>();
for (ClassifierVertex vertex : classDiagram.getGraphNodes().keySet())
{
graph.addVertex(vertex.getName());
}

List<Arc<ClassifierVertex>> arcs = new ArrayList<>();
for (Set<Arc<ClassifierVertex>> arcSet : classDiagram.getDiagram().values())
{
arcs.addAll(arcSet);
}
List<Arc<ClassifierVertex>> arcs = classDiagram.getDiagram().values().stream()
.flatMap(Collection::stream)
.collect(Collectors.toCollection(ArrayList::new));

for (Arc<ClassifierVertex> arc : arcs)
{
Expand Down
Loading

0 comments on commit 9bef7f7

Please sign in to comment.