--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <groupId>Main</groupId>
+ <artifactId>PathVisualizer</artifactId>
+ <version>1.0-SNAPSHOT</version>
+
+ <name>PathVisualizer</name>
+ <!-- FIXME change it to the project's website -->
+ <url>http://www.example.com</url>
+
+ <properties>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ <maven.compiler.source>1.7</maven.compiler.source>
+ <maven.compiler.target>1.7</maven.compiler.target>
+ </properties>
+
+ <dependencies>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>4.11</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
+ <plugins>
+ <!-- clean lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle -->
+ <plugin>
+ <artifactId>maven-clean-plugin</artifactId>
+ <version>3.1.0</version>
+ </plugin>
+ <!-- default lifecycle, jar packaging: see https://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging -->
+ <plugin>
+ <artifactId>maven-resources-plugin</artifactId>
+ <version>3.0.2</version>
+ </plugin>
+ <plugin>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <version>3.8.0</version>
+ </plugin>
+ <plugin>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <version>2.22.1</version>
+ </plugin>
+ <plugin>
+ <artifactId>maven-jar-plugin</artifactId>
+ <version>3.0.2</version>
+ </plugin>
+ <plugin>
+ <artifactId>maven-install-plugin</artifactId>
+ <version>2.5.2</version>
+ </plugin>
+ <plugin>
+ <artifactId>maven-deploy-plugin</artifactId>
+ <version>2.8.2</version>
+ </plugin>
+ <!-- site lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#site_Lifecycle -->
+ <plugin>
+ <artifactId>maven-site-plugin</artifactId>
+ <version>3.7.1</version>
+ </plugin>
+ <plugin>
+ <artifactId>maven-project-info-reports-plugin</artifactId>
+ <version>3.0.0</version>
+ </plugin>
+ </plugins>
+ </pluginManagement>
+ </build>
+</project>
--- /dev/null
+package Main;
+
+public class App {
+
+ public static void main(String[] args) {
+ new Map();
+ }
+
+}
--- /dev/null
+/* TODO
+ * aggiungere una sorta di menu dove scegliere:
+ * - velocità di riproduzione
+ * - tipo di algoritmo:
+ * + a*
+ * + dijkstra
+ * + greedy best-first search
+ * + swarm
+ * + convergent swarm
+ * + bidirectional swarm
+ * + breadth-first search
+ * + depth-first search
+ * zoommare sulla griglia
+ */
+package Main;
+
+import javax.swing.JFrame;
+import javax.swing.JPanel;
+import javax.swing.SwingUtilities;
+
+import java.awt.Color;
+import java.awt.Graphics;
+import java.awt.event.MouseListener;
+import java.awt.event.MouseEvent;
+import java.awt.event.MouseMotionListener;
+import java.util.ArrayList;
+import java.util.List;
+import java.awt.event.KeyEvent;
+import java.awt.event.KeyListener;
+
+class Map extends JPanel implements MouseListener, MouseMotionListener, KeyListener {
+ private JFrame window;
+ private int size = 30;
+ private char key = (char) 0;
+
+ private Node startNode, endNode;
+ private List<Node> barriers = new ArrayList<>();
+
+ public Map() {
+ addMouseListener(this);
+ addKeyListener(this);
+ setFocusable(true);
+ addMouseMotionListener(this);
+
+ // Settings up the window
+ window = new JFrame();
+ window.setContentPane(this);
+ window.setTitle("Pathfinding Algorithm Visualizer");
+ window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
+ window.pack();
+ window.setVisible(true);
+
+ this.revalidate();
+ this.repaint();
+ }
+
+ public void paintComponent(Graphics g) {
+ super.paintComponent(g);
+
+ // Draws the grid
+ g.setColor(Color.lightGray);
+ for (int i = 0; i < this.getWidth(); i += size) {
+ for (int j = 0; j < this.getHeight(); j += size) {
+ g.drawRect(i, j, size, size);
+ }
+ }
+
+ // Draws start node
+ if (startNode != null) {
+ g.setColor(new Color(117, 110, 202));
+ g.fillRect(startNode.getX() + 1, startNode.getY() + 1, size - 1, size - 1);
+ }
+
+ // Draws end node
+ if (endNode != null) {
+ g.setColor(new Color(204, 36, 29));
+ g.fillRect(endNode.getX() + 1, endNode.getY() + 1, size - 1, size - 1);
+ }
+
+ // Draws barrier nodes
+ g.setColor(new Color(40, 40, 40));
+ for (Node node : barriers) {
+ g.fillRect(node.getX() + 1, node.getY() + 1, size - 1, size - 1);
+ }
+ }
+
+ // Drawing on the grid
+ public void mapDrawing(MouseEvent e) {
+ if (SwingUtilities.isLeftMouseButton(e)) {
+ if (key == 's') {
+ int posX = e.getX() % size;
+ int posY = e.getY() % size;
+
+ if (startNode == null) {
+ startNode = new Node(e.getX() - posX, e.getY() - posY);
+ } else {
+ startNode.setX(e.getX() - posX);
+ startNode.setY(e.getY() - posY);
+ }
+
+ repaint();
+ }
+
+ else if (key == 'e') {
+ int posX = e.getX() % size;
+ int posY = e.getY() % size;
+
+ if (endNode == null) {
+ endNode = new Node(e.getX() - posX, e.getY() - posY);
+ } else {
+ endNode.setX(e.getX() - posX);
+ endNode.setY(e.getY() - posY);
+ }
+
+ repaint();
+ }
+
+ else {
+ int posX = e.getX() % size;
+ int posY = e.getY() % size;
+
+ barriers.add(new Node(e.getX() - posX, e.getY() - posY));
+
+ repaint();
+ }
+ }
+ // TODO cancellare le barriere col tasto destro del mouse
+ }
+
+ @Override
+ public void keyPressed(KeyEvent e) {
+ key = e.getKeyChar();
+ // TODO far partire/fermare l'algoritmo con il tasto invio
+ }
+
+ @Override
+ public void keyReleased(KeyEvent e) {
+ key = (char) 0;
+ }
+
+ @Override
+ public void mousePressed(MouseEvent e) {
+ mapDrawing(e);
+ }
+
+ @Override
+ public void mouseDragged(MouseEvent e) {
+ mapDrawing(e);
+ }
+
+ @Override
+ public void keyTyped(KeyEvent e) {}
+
+ @Override
+ public void mouseClicked(MouseEvent e) {}
+
+ @Override
+ public void mouseReleased(MouseEvent e) {}
+
+ @Override
+ public void mouseEntered(MouseEvent e) {}
+
+ @Override
+ public void mouseExited(MouseEvent e) {}
+
+ @Override
+ public void mouseMoved(MouseEvent e) {}
+}
--- /dev/null
+package Main;
+
+public class Node {
+ private int x, y;
+
+ public Node(int x, int y) {
+ this.x = x;
+ this.y = y;
+ }
+
+ public int getY() {
+ return y;
+ }
+
+ public void setY(int y) {
+ this.y = y;
+ }
+
+ public int getX() {
+ return x;
+ }
+
+ public void setX(int x) {
+ this.x = x;
+ }
+}
--- /dev/null
+package Main;
+
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Test;
+
+/**
+ * Unit test for simple App.
+ */
+public class AppTest
+{
+ /**
+ * Rigorous Test :-)
+ */
+ @Test
+ public void shouldAnswerWithTrue()
+ {
+ assertTrue( true );
+ }
+}
--- /dev/null
+#Created by Apache Maven 3.8.1
+groupId=Main
+artifactId=PathVisualizer
+version=1.0-SNAPSHOT
--- /dev/null
+Main/Node.class
+Main/Map.class
+Main/App.class
--- /dev/null
+/home/leo/Docs/Proj/PathVisualizer/src/main/java/Main/Map.java
+/home/leo/Docs/Proj/PathVisualizer/src/main/java/Main/Node.java
+/home/leo/Docs/Proj/PathVisualizer/src/main/java/Main/App.java
--- /dev/null
+Main/AppTest.class
--- /dev/null
+/home/leo/Docs/Proj/PathVisualizer/src/test/java/Main/AppTest.java
--- /dev/null
+-------------------------------------------------------------------------------
+Test set: Main.AppTest
+-------------------------------------------------------------------------------
+Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.028 s - in Main.AppTest
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<testsuite xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://maven.apache.org/surefire/maven-surefire-plugin/xsd/surefire-test-report.xsd" name="Main.AppTest" time="0.028" tests="1" errors="0" skipped="0" failures="0">
+ <properties>
+ <property name="awt.toolkit" value="sun.awt.X11.XToolkit"/>
+ <property name="java.specification.version" value="11"/>
+ <property name="sun.cpu.isalist" value=""/>
+ <property name="sun.jnu.encoding" value="UTF-8"/>
+ <property name="java.class.path" value="/home/leo/Docs/Proj/PathVisualizer/target/test-classes:/home/leo/Docs/Proj/PathVisualizer/target/classes:/home/leo/.m2/repository/junit/junit/4.11/junit-4.11.jar:/home/leo/.m2/repository/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3.jar:"/>
+ <property name="java.vm.vendor" value="AdoptOpenJDK"/>
+ <property name="sun.arch.data.model" value="64"/>
+ <property name="java.vendor.url" value="https://adoptopenjdk.net/"/>
+ <property name="user.timezone" value=""/>
+ <property name="user.country.format" value="IT"/>
+ <property name="java.vm.specification.version" value="11"/>
+ <property name="os.name" value="Linux"/>
+ <property name="sun.java.launcher" value="SUN_STANDARD"/>
+ <property name="user.country" value="GB"/>
+ <property name="sun.boot.library.path" value="/opt/openjdk-bin-11.0.11_p9/lib"/>
+ <property name="sun.java.command" value="/home/leo/Docs/Proj/PathVisualizer/target/surefire/surefirebooter16417584190550890545.jar /home/leo/Docs/Proj/PathVisualizer/target/surefire 2021-06-17T11-55-55_292-jvmRun1 surefire4864576372469895393tmp surefire_01966433911489221877tmp"/>
+ <property name="jdk.debug" value="release"/>
+ <property name="surefire.test.class.path" value="/home/leo/Docs/Proj/PathVisualizer/target/test-classes:/home/leo/Docs/Proj/PathVisualizer/target/classes:/home/leo/.m2/repository/junit/junit/4.11/junit-4.11.jar:/home/leo/.m2/repository/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3.jar:"/>
+ <property name="sun.cpu.endian" value="little"/>
+ <property name="user.home" value="/home/leo"/>
+ <property name="user.language" value="en"/>
+ <property name="java.specification.vendor" value="Oracle Corporation"/>
+ <property name="java.version.date" value="2021-04-20"/>
+ <property name="java.home" value="/opt/openjdk-bin-11.0.11_p9"/>
+ <property name="file.separator" value="/"/>
+ <property name="basedir" value="/home/leo/Docs/Proj/PathVisualizer"/>
+ <property name="java.vm.compressedOopsMode" value="Zero based"/>
+ <property name="line.separator" value=" "/>
+ <property name="java.specification.name" value="Java Platform API Specification"/>
+ <property name="java.vm.specification.vendor" value="Oracle Corporation"/>
+ <property name="java.awt.graphicsenv" value="sun.awt.X11GraphicsEnvironment"/>
+ <property name="surefire.real.class.path" value="/home/leo/Docs/Proj/PathVisualizer/target/surefire/surefirebooter16417584190550890545.jar"/>
+ <property name="sun.management.compiler" value="HotSpot 64-Bit Tiered Compilers"/>
+ <property name="java.runtime.version" value="11.0.11+9"/>
+ <property name="user.name" value="leo"/>
+ <property name="path.separator" value=":"/>
+ <property name="os.version" value="5.12.10-gentoo-LeoKernel"/>
+ <property name="java.runtime.name" value="OpenJDK Runtime Environment"/>
+ <property name="file.encoding" value="UTF-8"/>
+ <property name="java.vm.name" value="OpenJDK 64-Bit Server VM"/>
+ <property name="java.vendor.version" value="AdoptOpenJDK-11.0.11+9"/>
+ <property name="localRepository" value="/home/leo/.m2/repository"/>
+ <property name="java.vendor.url.bug" value="https://github.com/AdoptOpenJDK/openjdk-support/issues"/>
+ <property name="java.io.tmpdir" value="/tmp"/>
+ <property name="java.version" value="11.0.11"/>
+ <property name="user.dir" value="/home/leo/Docs/Proj/PathVisualizer"/>
+ <property name="os.arch" value="amd64"/>
+ <property name="java.vm.specification.name" value="Java Virtual Machine Specification"/>
+ <property name="java.awt.printerjob" value="sun.print.PSPrinterJob"/>
+ <property name="user.language.format" value="it"/>
+ <property name="sun.os.patch.level" value="unknown"/>
+ <property name="java.library.path" value="/usr/java/packages/lib:/usr/lib64:/lib64:/lib:/usr/lib"/>
+ <property name="java.vm.info" value="mixed mode"/>
+ <property name="java.vendor" value="AdoptOpenJDK"/>
+ <property name="java.vm.version" value="11.0.11+9"/>
+ <property name="sun.io.unicode.encoding" value="UnicodeLittle"/>
+ <property name="java.class.version" value="55.0"/>
+ </properties>
+ <testcase name="shouldAnswerWithTrue" classname="Main.AppTest" time="0.001"/>
+</testsuite>
\ No newline at end of file