--- /dev/null
+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);
+ }
+}
* - 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;
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);
for (Node node : PathfinderUtils.barriers) {
g.fillRect(node.getX() + 1, node.getY() + 1, size - 1, size - 1);
}
+
+ menu.renderMenu();
}
// Drawing on the grid
@Override
public void keyPressed(KeyEvent e) {
key = e.getKeyChar();
- // TODO far partire/fermare l'algoritmo con il tasto invio
}
@Override
@Override
public void mouseMoved(MouseEvent e) {}
+
}
+Main/ControlPanel$1.class
Main/Node.class
+Main/ControlPanel.class
Main/Map.class
Main/App.class
Main/PathfinderUtils.class
+/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
-------------------------------------------------------------------------------
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
<?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"/>
<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"/>
<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"/>
<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