]> git.leonardobizzoni.com Git - astar-visualizer/commitdiff
Initial commit with basic funtionality
authorLeonardoBizzoni <leo2002714@gmail.com>
Thu, 17 Jun 2021 10:05:10 +0000 (12:05 +0200)
committerLeonardoBizzoni <leo2002714@gmail.com>
Thu, 17 Jun 2021 10:05:10 +0000 (12:05 +0200)
17 files changed:
pom.xml [new file with mode: 0644]
src/main/java/Main/App.java [new file with mode: 0644]
src/main/java/Main/Map.java [new file with mode: 0644]
src/main/java/Main/Node.java [new file with mode: 0644]
src/test/java/Main/AppTest.java [new file with mode: 0644]
target/PathVisualizer-1.0-SNAPSHOT.jar [new file with mode: 0644]
target/classes/Main/App.class [new file with mode: 0644]
target/classes/Main/Map.class [new file with mode: 0644]
target/classes/Main/Node.class [new file with mode: 0644]
target/maven-archiver/pom.properties [new file with mode: 0644]
target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst [new file with mode: 0644]
target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst [new file with mode: 0644]
target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/createdFiles.lst [new file with mode: 0644]
target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst [new file with mode: 0644]
target/surefire-reports/Main.AppTest.txt [new file with mode: 0644]
target/surefire-reports/TEST-Main.AppTest.xml [new file with mode: 0644]
target/test-classes/Main/AppTest.class [new file with mode: 0644]

diff --git a/pom.xml b/pom.xml
new file mode 100644 (file)
index 0000000..d6aede7
--- /dev/null
+++ b/pom.xml
@@ -0,0 +1,75 @@
+<?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>
diff --git a/src/main/java/Main/App.java b/src/main/java/Main/App.java
new file mode 100644 (file)
index 0000000..5e562da
--- /dev/null
@@ -0,0 +1,9 @@
+package Main;
+
+public class App {
+
+    public static void main(String[] args) {
+        new Map();
+    }
+    
+}
diff --git a/src/main/java/Main/Map.java b/src/main/java/Main/Map.java
new file mode 100644 (file)
index 0000000..4c24ad5
--- /dev/null
@@ -0,0 +1,168 @@
+/* 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) {}
+}
diff --git a/src/main/java/Main/Node.java b/src/main/java/Main/Node.java
new file mode 100644 (file)
index 0000000..479a5fb
--- /dev/null
@@ -0,0 +1,26 @@
+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;
+    }
+}
diff --git a/src/test/java/Main/AppTest.java b/src/test/java/Main/AppTest.java
new file mode 100644 (file)
index 0000000..4960c68
--- /dev/null
@@ -0,0 +1,20 @@
+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 );
+    }
+}
diff --git a/target/PathVisualizer-1.0-SNAPSHOT.jar b/target/PathVisualizer-1.0-SNAPSHOT.jar
new file mode 100644 (file)
index 0000000..406f8f9
Binary files /dev/null and b/target/PathVisualizer-1.0-SNAPSHOT.jar differ
diff --git a/target/classes/Main/App.class b/target/classes/Main/App.class
new file mode 100644 (file)
index 0000000..5d655f5
Binary files /dev/null and b/target/classes/Main/App.class differ
diff --git a/target/classes/Main/Map.class b/target/classes/Main/Map.class
new file mode 100644 (file)
index 0000000..34b60c5
Binary files /dev/null and b/target/classes/Main/Map.class differ
diff --git a/target/classes/Main/Node.class b/target/classes/Main/Node.class
new file mode 100644 (file)
index 0000000..8ff1fb2
Binary files /dev/null and b/target/classes/Main/Node.class differ
diff --git a/target/maven-archiver/pom.properties b/target/maven-archiver/pom.properties
new file mode 100644 (file)
index 0000000..10b2555
--- /dev/null
@@ -0,0 +1,4 @@
+#Created by Apache Maven 3.8.1
+groupId=Main
+artifactId=PathVisualizer
+version=1.0-SNAPSHOT
diff --git a/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst b/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst
new file mode 100644 (file)
index 0000000..37eadb9
--- /dev/null
@@ -0,0 +1,3 @@
+Main/Node.class
+Main/Map.class
+Main/App.class
diff --git a/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst b/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst
new file mode 100644 (file)
index 0000000..35be478
--- /dev/null
@@ -0,0 +1,3 @@
+/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
diff --git a/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/createdFiles.lst b/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/createdFiles.lst
new file mode 100644 (file)
index 0000000..5783d8a
--- /dev/null
@@ -0,0 +1 @@
+Main/AppTest.class
diff --git a/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst b/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst
new file mode 100644 (file)
index 0000000..e6a42ce
--- /dev/null
@@ -0,0 +1 @@
+/home/leo/Docs/Proj/PathVisualizer/src/test/java/Main/AppTest.java
diff --git a/target/surefire-reports/Main.AppTest.txt b/target/surefire-reports/Main.AppTest.txt
new file mode 100644 (file)
index 0000000..9c021fa
--- /dev/null
@@ -0,0 +1,4 @@
+-------------------------------------------------------------------------------
+Test set: Main.AppTest
+-------------------------------------------------------------------------------
+Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.028 s - in Main.AppTest
diff --git a/target/surefire-reports/TEST-Main.AppTest.xml b/target/surefire-reports/TEST-Main.AppTest.xml
new file mode 100644 (file)
index 0000000..afe46ad
--- /dev/null
@@ -0,0 +1,63 @@
+<?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="&#10;"/>
+    <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
diff --git a/target/test-classes/Main/AppTest.class b/target/test-classes/Main/AppTest.class
new file mode 100644 (file)
index 0000000..6b3f4e2
Binary files /dev/null and b/target/test-classes/Main/AppTest.class differ