diff --git a/src/model/MazeAppModel.java b/src/model/MazeAppModel.java index b782287..ddbd438 100644 --- a/src/model/MazeAppModel.java +++ b/src/model/MazeAppModel.java @@ -20,6 +20,7 @@ public class MazeAppModel extends Observable { private ArrayList shortest = previous.getShortestPathTo(arrival); //private ArrayList boxList = maze.getVertexes(); private Boolean modified = false; + private boolean pathDrawn = false; public void setMaze(Maze maze) { this.maze = new Maze(maze); @@ -44,6 +45,14 @@ public class MazeAppModel extends Observable { return modified; } + public boolean isPathDrawn() { + return pathDrawn; + } + + public void setPathDrawn(boolean pathDrawn) { + this.pathDrawn = pathDrawn; + } + public void saveToFile() { maze.saveToTextFile("data/labyOutput.txt"); } diff --git a/src/ui/ClearShortestPathMenuItem.java b/src/ui/ClearShortestPathMenuItem.java new file mode 100644 index 0000000..e5bff7b --- /dev/null +++ b/src/ui/ClearShortestPathMenuItem.java @@ -0,0 +1,25 @@ +package ui; + +import javax.swing.JMenuItem; + +import model.MazeAppModel; + +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +public class ClearShortestPathMenuItem extends JMenuItem + implements ActionListener { + + private final MazeApp mazeApp; + + public ClearShortestPathMenuItem(MazeApp mazeApp) { + + super("Clear shortest path"); + this.mazeApp = mazeApp; + addActionListener(this); + } + + public void actionPerformed(ActionEvent evt) { + mazeApp.clearShortestPath(); + } +} diff --git a/src/ui/MazeApp.java b/src/ui/MazeApp.java index 13e350d..9a2ce6a 100644 --- a/src/ui/MazeApp.java +++ b/src/ui/MazeApp.java @@ -43,6 +43,12 @@ public class MazeApp extends JFrame } public void drawShortestPath() { + mazeAppModel.setPathDrawn(true); windowPanel.paintShortestPath(); } + + public void clearShortestPath() { + mazeAppModel.setPathDrawn(false); + this.repaint(); + } } diff --git a/src/ui/MazeMenu.java b/src/ui/MazeMenu.java index d8348a6..e257339 100644 --- a/src/ui/MazeMenu.java +++ b/src/ui/MazeMenu.java @@ -6,6 +6,7 @@ public class MazeMenu extends JMenu { private final MazeApp mazeApp; private final DrawShortestPathMenuItem drawMenuItem; + private final ClearShortestPathMenuItem clearMenuItem; public MazeMenu(MazeApp mazeApp) { @@ -13,5 +14,6 @@ public class MazeMenu extends JMenu { this.mazeApp = mazeApp; add(drawMenuItem = new DrawShortestPathMenuItem(mazeApp)); + add(clearMenuItem = new ClearShortestPathMenuItem(mazeApp)); } }