Refresh attributes in MazeAppModel at maze loading

model:
* Add initModelFromMaze() to refresh the model attributes, such as
  arrival, departure, previous, etc, at maze change
This commit is contained in:
regar42 committed 2017-12-23 21:21:47 +01:00
1 parent 97f9aa4ba0
commit 80ffabdd69
1 file changed
+8 -1
+8 -1
View File
@@ -14,7 +14,7 @@ import maze.Maze;
public class MazeAppModel extends Observable { public class MazeAppModel extends Observable {
private String filename; private String filename;
private Maze maze; private Maze maze;
private VertexInterface departure; private VertexInterface departure;
private VertexInterface arrival; private VertexInterface arrival;
@@ -25,10 +25,16 @@ public class MazeAppModel extends Observable {
public MazeAppModel() { public MazeAppModel() {
maze = new Maze(Maze.emptyMaze(10)); maze = new Maze(Maze.emptyMaze(10));
initModelFromMaze();
}
private void initModelFromMaze() {
departure = maze.getDeparture(); departure = maze.getDeparture();
arrival = maze.getArrival(); arrival = maze.getArrival();
boxList = maze.getVertexes(); boxList = maze.getVertexes();
if (departure == null || arrival == null) { if (departure == null || arrival == null) {
previous = null;
shortest = null;
return; return;
} }
previous = (Previous) Dijkstra.dijkstra(maze, departure); previous = (Previous) Dijkstra.dijkstra(maze, departure);
@@ -38,6 +44,7 @@ public class MazeAppModel extends Observable {
public void loadMaze(String filename) { public void loadMaze(String filename) {
this.filename = new String(filename); this.filename = new String(filename);
maze = new Maze(this.filename); maze = new Maze(this.filename);
initModelFromMaze();
modified = true; modified = true;
setChanged(); setChanged();
notifyObservers(MazeAppModelMessage.MazeRenewal); notifyObservers(MazeAppModelMessage.MazeRenewal);