]> git.leonardobizzoni.com Git - astar-visualizer/commitdiff
Added basic control menu
authorLeonardoBizzoni <leo2002714@gmail.com>
Fri, 18 Jun 2021 10:45:13 +0000 (12:45 +0200)
committerLeonardoBizzoni <leo2002714@gmail.com>
Fri, 18 Jun 2021 10:45:13 +0000 (12:45 +0200)
src/main/java/Main/ControlPanel.java [new file with mode: 0644]
src/main/java/Main/Map.java
target/PathVisualizer-1.0-SNAPSHOT.jar
target/classes/Main/ControlPanel$1.class [new file with mode: 0644]
target/classes/Main/ControlPanel.class [new file with mode: 0644]
target/classes/Main/Map.class
target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst
target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst
target/surefire-reports/Main.AppTest.txt
target/surefire-reports/TEST-Main.AppTest.xml

diff --git a/src/main/java/Main/ControlPanel.java b/src/main/java/Main/ControlPanel.java
new file mode 100644 (file)
index 0000000..6c57821
--- /dev/null
@@ -0,0 +1,79 @@
+package Main;
+
+import java.awt.Color;
+import java.awt.Insets;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+
+import javax.swing.JButton;
+import javax.swing.JComboBox;
+import javax.swing.JOptionPane;
+
+public class ControlPanel {
+    private Map map;
+
+    private JButton toggleRunBtn;
+    private JComboBox<String> algo;
+
+    public ControlPanel(Map map) {
+        this.map = map;
+
+        algo = new JComboBox<>(new String[] { "Select an algorithm", "A*", "Dijkstra", "Breadth-first search"});
+        algo.setVisible(true);
+
+        toggleRunBtn = new JButton("Run");
+        toggleRunBtn.setVisible(true);
+        toggleRunBtn.setMargin(new Insets(0, 0, 0, 0));
+        toggleRunBtn.setBackground(Color.white);
+        toggleRunBtn.addActionListener(new ActionListener() {
+            @Override
+            public void actionPerformed(ActionEvent e) {
+
+                if (toggleRunBtn.getText().equals("Run")) {
+                    switch (algo.getItemAt(algo.getSelectedIndex())) {
+
+                    case ("A*"):
+                        System.out.println("A* selected");
+                        // AStar.start();
+                        break;
+
+                    case ("Dijkstra"):
+                        System.out.println("Dijkstra selected");
+                        // AStar.start();
+                        break;
+
+                    case ("Greedy best-first search"):
+                        System.out.println("Greedy best-first search selected");
+                        // AStar.start();
+                        break;
+
+                    case ("Breadth-first search"):
+                        System.out.println("Breadth-first search selected");
+                        // AStar.start();
+                        break;
+
+                    default:
+                        JOptionPane.showMessageDialog(null,
+                                "You must select an algorithm before starting the pathfinder", "Algorithm not selected",
+                                JOptionPane.ERROR_MESSAGE);
+                        return;
+                    }
+
+                    toggleRunBtn.setText("Stop");
+                }
+
+                else {
+                    toggleRunBtn.setText("Run");
+                }
+            }
+        });
+
+        map.add(algo);
+        map.add(toggleRunBtn);
+    }
+
+    public void renderMenu() {
+        algo.setBounds(10,10, algo.getWidth(), algo.getHeight());
+        toggleRunBtn.setBounds(220, 10, 48, 24);
+    }
+}
index 912cf19cb4046022dfa66cae085b81e531a8516f..36f8ff2be9274356a02eafe4968a9f724b039028 100644 (file)
@@ -4,12 +4,7 @@
  * - 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;
@@ -31,9 +26,11 @@ class Map extends JPanel implements MouseListener, MouseMotionListener, KeyListe
     private JFrame window;
     private int size = 30;
     private char key = (char) 0;
+    private ControlPanel menu = new ControlPanel(this);
 
     public Map() {
         this.setBackground(new Color(40, 40, 40));
+
         addMouseListener(this);
         addKeyListener(this);
         setFocusable(true);
@@ -79,6 +76,8 @@ class Map extends JPanel implements MouseListener, MouseMotionListener, KeyListe
         for (Node node : PathfinderUtils.barriers) {
             g.fillRect(node.getX() + 1, node.getY() + 1, size - 1, size - 1);
         }
+
+        menu.renderMenu();
     }
 
     // Drawing on the grid
@@ -178,7 +177,6 @@ class Map extends JPanel implements MouseListener, MouseMotionListener, KeyListe
     @Override
     public void keyPressed(KeyEvent e) {
         key = e.getKeyChar();
-        // TODO far partire/fermare l'algoritmo con il tasto invio
     }
 
     @Override
@@ -213,4 +211,5 @@ class Map extends JPanel implements MouseListener, MouseMotionListener, KeyListe
 
     @Override
     public void mouseMoved(MouseEvent e) {}
+
 }
index bf40587b1fa9d81903156ac14c690018aa04c22a..f6745016c95ba1301b57088bc64760982bdb25f1 100644 (file)
Binary files a/target/PathVisualizer-1.0-SNAPSHOT.jar and b/target/PathVisualizer-1.0-SNAPSHOT.jar differ
diff --git a/target/classes/Main/ControlPanel$1.class b/target/classes/Main/ControlPanel$1.class
new file mode 100644 (file)
index 0000000..fa3a702
Binary files /dev/null and b/target/classes/Main/ControlPanel$1.class differ
diff --git a/target/classes/Main/ControlPanel.class b/target/classes/Main/ControlPanel.class
new file mode 100644 (file)
index 0000000..340d99e
Binary files /dev/null and b/target/classes/Main/ControlPanel.class differ
index d1fe5a22435903ecc65abdb02597ee593dc34156..f08455046d96f4cffd047e12075a8a0ad5cc47d8 100644 (file)
Binary files a/target/classes/Main/Map.class and b/target/classes/Main/Map.class differ
index 0fc7d3519657f2a41b5cfdf810bc51840672edf8..6b22cb60e04447a5f837f7d4382be4e7994f5f1b 100644 (file)
@@ -1,4 +1,6 @@
+Main/ControlPanel$1.class
 Main/Node.class
+Main/ControlPanel.class
 Main/Map.class
 Main/App.class
 Main/PathfinderUtils.class
index c09b5f3cdaeacc955ef26ef6df3feef495c77d71..b97cf8ab4f3f2add7be70a8e610725e483ed539d 100644 (file)
@@ -1,3 +1,4 @@
+/home/leo/Docs/Proj/PathVisualizer/src/main/java/Main/ControlPanel.java
 /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
index 815c74ad10b30c04bd7a1d49279b7996993b7d2d..b957bda8238ef9b90bcd0a3991fdea68dda3099d 100644 (file)
@@ -1,4 +1,4 @@
 -------------------------------------------------------------------------------
 Test set: Main.AppTest
 -------------------------------------------------------------------------------
-Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.027 s - in Main.AppTest
+Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.026 s - in Main.AppTest
index 50af6480ce5f887fb82ba79f95ffa16437900a04..9f3f13dafd1e42b725da51f55ed88dec4505bf8d 100644 (file)
@@ -1,5 +1,5 @@
 <?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.027" tests="1" errors="0" skipped="0" failures="0">
+<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.026" 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"/>
@@ -16,7 +16,7 @@
     <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/surefirebooter514838881418717725.jar /home/leo/Docs/Proj/PathVisualizer/target/surefire 2021-06-17T18-00-26_353-jvmRun1 surefire13060722636073724137tmp surefire_07869077185134568567tmp"/>
+    <property name="sun.java.command" value="/home/leo/Docs/Proj/PathVisualizer/target/surefire/surefirebooter6228058189104108718.jar /home/leo/Docs/Proj/PathVisualizer/target/surefire 2021-06-18T12-26-30_233-jvmRun1 surefire16797671742172820636tmp surefire_018142986162871324276tmp"/>
     <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"/>
@@ -32,7 +32,7 @@
     <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/surefirebooter514838881418717725.jar"/>
+    <property name="surefire.real.class.path" value="/home/leo/Docs/Proj/PathVisualizer/target/surefire/surefirebooter6228058189104108718.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"/>
@@ -59,5 +59,5 @@
     <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.002"/>
+  <testcase name="shouldAnswerWithTrue" classname="Main.AppTest" time="0.001"/>
 </testsuite>
\ No newline at end of file