Skip to content

Commit

Permalink
Add log4j2 logger
Browse files Browse the repository at this point in the history
  • Loading branch information
dimanyfantakis committed Apr 6, 2024
1 parent 5d61f33 commit 378240e
Show file tree
Hide file tree
Showing 42 changed files with 524 additions and 467 deletions.
10 changes: 10 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,16 @@
<artifactId>maven-assembly-plugin</artifactId>
<version>3.6.0</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.17.1</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.17.1</version>
</dependency>
</dependencies>
<build>
<plugins>
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/controller/DiagramController.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
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 @@ -47,7 +48,7 @@ public SmartGraphPanel<String, String> applyLayout()
@Override
public SmartGraphPanel<String, String> applySpecificLayout(String choice)
{
return diagramManager.applySpecificLayout(choice);
return diagramManager.applySpecificLayout(LayoutAlgorithmType.get(choice));
}

@Override
Expand Down
15 changes: 5 additions & 10 deletions src/main/java/manager/ClassDiagramManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import model.diagram.ShadowCleaner;
import model.diagram.arrangement.ClassDiagramArrangementManager;
import model.diagram.arrangement.DiagramArrangementManagerInterface;
import model.diagram.arrangement.algorithms.LayoutAlgorithmType;
import model.diagram.arrangement.geometry.DiagramGeometry;
import model.diagram.exportation.CoordinatesUpdater;
import model.diagram.exportation.DiagramExporter;
Expand Down Expand Up @@ -148,10 +149,7 @@ 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 @@ -161,15 +159,12 @@ public SmartGraphPanel<String, String> applyLayout()
}

@Override
public SmartGraphPanel<String, String> applySpecificLayout(String choice)
public SmartGraphPanel<String, String> applySpecificLayout(LayoutAlgorithmType algorithmType)
{
DiagramGeometry nodesGeometry = classDiagramArrangement.applyNewLayout(choice);
DiagramGeometry nodesGeometry = classDiagramArrangement.applyLayout(algorithmType);
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 Down
3 changes: 2 additions & 1 deletion src/main/java/manager/DiagramManager.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package manager;

import com.brunomnsilva.smartgraph.graphview.SmartGraphPanel;
import model.diagram.arrangement.algorithms.LayoutAlgorithmType;
import model.diagram.arrangement.geometry.DiagramGeometry;

import java.io.File;
Expand Down Expand Up @@ -90,7 +91,7 @@ public interface DiagramManager
SmartGraphPanel<String, String> applyLayout();

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

// TODO JavaDoc
SmartGraphPanel<String, String> visualizeLoadedJavaFXGraph();
Expand Down
18 changes: 8 additions & 10 deletions src/main/java/manager/PackageDiagramManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import model.diagram.PackageDiagram;
import model.diagram.arrangement.DiagramArrangementManagerInterface;
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 @@ -16,19 +17,19 @@
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 org.javatuples.Pair;

import java.io.File;
import java.nio.file.Path;
import java.util.Collection;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;

public class PackageDiagramManager implements DiagramManager
{

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

private PackageDiagram packageDiagram;
private DiagramArrangementManagerInterface packageDiagramArrangement;
Expand Down Expand Up @@ -149,7 +150,7 @@ public SmartGraphPanel<String, String> applyLayout()
{
if (!nodesGeometry.containsKey(vertex.element()))
{
logger.log(Level.INFO, vertex.element());
logger.debug("Vertex: {} not in vertices collection.", vertex.element());
continue;
}

Expand All @@ -161,15 +162,12 @@ public SmartGraphPanel<String, String> applyLayout()
}

@Override
public SmartGraphPanel<String, String> applySpecificLayout(String choice)
public SmartGraphPanel<String, String> applySpecificLayout(LayoutAlgorithmType algorithmType)
{
DiagramGeometry nodesGeometry = packageDiagramArrangement.applyNewLayout(choice);
DiagramGeometry nodesGeometry = packageDiagramArrangement.applyLayout(algorithmType);
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 Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,9 @@ public DiagramGeometry arrangeDiagram()


@Override
public DiagramGeometry applyNewLayout(String algorithmType)
public DiagramGeometry applyLayout(LayoutAlgorithmType algorithmType)
{
LayoutAlgorithmType algorithmEnumType = LayoutAlgorithmType.get(algorithmType);
LayoutAlgorithm layout = LayoutAlgorithmFactory.createLayoutAlgorithm(algorithmEnumType);
LayoutAlgorithm layout = LayoutAlgorithmFactory.createLayoutAlgorithm(algorithmType);
layout.setGraph(graph);
return layout.arrangeDiagram();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package model.diagram.arrangement;

import model.diagram.arrangement.algorithms.LayoutAlgorithmType;
import org.javatuples.Pair;

import model.diagram.arrangement.geometry.DiagramGeometry;
Expand All @@ -24,6 +25,6 @@ public interface DiagramArrangementManagerInterface
DiagramGeometry arrangeDiagram();

// TODO JavaDoc
DiagramGeometry applyNewLayout(String choice);
DiagramGeometry applyLayout(LayoutAlgorithmType algorithmType);

}
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,9 @@ public DiagramGeometry arrangeDiagram()


@Override
public DiagramGeometry applyNewLayout(String algorithmType)
public DiagramGeometry applyLayout(LayoutAlgorithmType algorithmType)
{
LayoutAlgorithmType algorithmEnumType = LayoutAlgorithmType.get(algorithmType);
LayoutAlgorithm layout = LayoutAlgorithmFactory.createLayoutAlgorithm(algorithmEnumType);
LayoutAlgorithm layout = LayoutAlgorithmFactory.createLayoutAlgorithm(algorithmType);
layout.setGraph(graph);
return layout.arrangeDiagram();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package model.diagram.arrangement.algorithms;

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

public enum LayoutAlgorithmType
{
Expand All @@ -17,17 +18,20 @@ public enum LayoutAlgorithmType

static
{
Map<String, LayoutAlgorithmType> map = new HashMap<>();
for (LayoutAlgorithmType layoutAlgorithmType : LayoutAlgorithmType.values())
{
map.put(layoutAlgorithmType.toString().toLowerCase(), layoutAlgorithmType);
}
Map<String, LayoutAlgorithmType> map = Arrays.stream(LayoutAlgorithmType.values())
.collect(Collectors.toMap(LayoutAlgorithmType::toString, it -> it));

ALGORITHM_TYPE_MAP = Collections.unmodifiableMap(map);
}

public static LayoutAlgorithmType get(String algorithmType)
{
return ALGORITHM_TYPE_MAP.get(algorithmType.toLowerCase());
return ALGORITHM_TYPE_MAP.get(algorithmType);
}

@Override
public String toString()
{
return super.toString().toLowerCase();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,8 @@ public void correctPositions(double x, double y)
double newX = entry.getValue().getValue0() + x;
double newY = entry.getValue().getValue1() + y;
geometryMap.put(entry.getKey(), new Pair<>(entry.getValue().getValue0() + x, entry.getValue().getValue1() + y));
if (newX < minX)
{
minX = newX;
}
if (newY < minY)
{
minY = newY;
}
minX = Math.min(newX, minX);
minY = Math.min(newY, minY);
}
xDifference = minX - MIN_X_WINDOW_VALUE;
yDifference = minY - MIN_Y_WINDOW_VALUE;
Expand Down
11 changes: 7 additions & 4 deletions src/main/java/model/diagram/exportation/GraphMLFile.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package model.diagram.exportation;

import model.diagram.graphml.GraphMLSyntax;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.io.File;
import java.io.FileWriter;
Expand All @@ -9,8 +11,9 @@

public class GraphMLFile
{
private static final Logger logger = LogManager.getLogger(GraphMLFile.class);

private FileWriter graphMLWriter;
private FileWriter graphMLWriter;
private StringBuilder graphMLBuffer;
private File graphMLFile;

Expand All @@ -19,14 +22,14 @@ public void createGraphMLFile(Path graphMLSavePath)
{
try
{
graphMLFile = graphMLSavePath.toFile();
graphMLFile = graphMLSavePath.toFile();
graphMLWriter = new FileWriter(graphMLFile);
graphMLBuffer = new StringBuilder();
graphMLBuffer.append(GraphMLSyntax.getInstance().getGraphMLPrefix());
}
catch (IOException e)
{
e.printStackTrace();
logger.error("Can't write to file: {}", graphMLFile.getAbsoluteFile());
throw new RuntimeException(e);
}
}
Expand All @@ -42,7 +45,7 @@ public void closeGraphMLFile()
}
catch (IOException e)
{
e.printStackTrace();
logger.error("Can't write buffer to file: {}", graphMLFile.getAbsoluteFile());
throw new RuntimeException(e);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import com.google.gson.GsonBuilder;
import model.diagram.ClassDiagram;
import model.graph.ClassifierVertex;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.io.File;
import java.io.FileWriter;
Expand All @@ -12,6 +14,7 @@

public class JavaFXClassDiagramExporter implements DiagramExporter
{
private static final Logger logger = LogManager.getLogger(JavaFXClassDiagramExporter.class);

private final ClassDiagram classDiagram;

Expand All @@ -38,7 +41,7 @@ public File exportDiagram(Path exportPath)
}
catch (IOException e)
{
e.printStackTrace();
logger.error("Failed to write json to file with path: {}", exportPath.toAbsolutePath());
throw new RuntimeException(e);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import com.google.gson.GsonBuilder;
import model.diagram.PackageDiagram;
import model.graph.PackageVertex;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.io.File;
import java.io.FileWriter;
Expand All @@ -12,6 +14,7 @@

public class JavaFXPackageDiagramExporter implements DiagramExporter
{
private static final Logger logger = LogManager.getLogger(JavaFXPackageDiagramExporter.class);

private final PackageDiagram packageDiagram;

Expand All @@ -37,7 +40,7 @@ public File exportDiagram(Path exportPath)
}
catch (IOException e)
{
e.printStackTrace();
logger.error("Failed to write json to file with path: {}", exportPath.toAbsolutePath());
throw new RuntimeException(e);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import model.diagram.plantuml.PlantUMLClassifierVertex;
import model.diagram.plantuml.PlantUMLClassifierVertexArc;
import net.sourceforge.plantuml.SourceStringReader;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
Expand All @@ -16,6 +18,7 @@

public class PlantUMLClassDiagramImageExporter implements DiagramExporter
{
private static final Logger logger = LogManager.getLogger(PlantUMLPackageDiagramImageExporter.class);

private final StringBuilder bufferBody;

Expand Down Expand Up @@ -67,12 +70,17 @@ private void exportImage(File plantUMLFile, String plantCode)
in = new ByteArrayInputStream(data);
convImg = ImageIO.read(in);
}
catch (IOException e)
{
logger.error("Failed to read from input stream");
throw new RuntimeException(e);
}
}
ImageIO.write(convImg, "png", plantUMLFile);
}
catch (IOException e)
{
e.printStackTrace();
logger.error("Failed to write image to file: {}", plantUMLFile.getAbsolutePath());
throw new RuntimeException(e);
}
}
Expand All @@ -81,11 +89,10 @@ private void exportImage(File plantUMLFile, String plantCode)
private String wrapWidthChanger(String plantCode, int wrapWidth)
{
String updatedString;
//if (counter == 0) {
int indexOfNewLine = plantCode.indexOf("\n");
String firstPart = plantCode.substring(0, indexOfNewLine + 1);
String secondPart = plantCode.substring(indexOfNewLine + 1);
updatedString = firstPart + "skinparam wrapWidth " + wrapWidth + "\n" + secondPart;
updatedString = String.format("%sskinparam wrapWidth %d\n%s", firstPart, wrapWidth, secondPart);
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ //
// KEEP REDUCING THE WRAPWIDTH PARAMETER IN ORDER TO FIT PROPERLY THE IMAGE //
// DOESNT WORK PROPERLY, COMMENTED JUST TO KEEP THE IDEA. //
Expand Down
Loading

0 comments on commit 378240e

Please sign in to comment.