Fix paintShortestPath and move it into MazeDrawing

model:
* Add getShortest() to MazeAppModel, which returns the list of vertexes
  on the shortest path from departure to arrival
ui:
* Move paintShortestPath from MazeApp to MazeDrawing
* Fix a bug in paintShortestPath where a switch between width and height
  caused ellipses to be mislocated (probably still the same confusion
  between the x and y axes)
This commit is contained in:
regar42 committed 2017-12-24 19:09:14 +01:00
1 parent b5eb6b0b8c
commit 1e934b05e6
3 files changed
+19 -13

No files matched your search

+4
View File
@@ -36,6 +36,10 @@ public class MazeAppModel extends Observable {
return maze;
}
public ArrayList<VertexInterface> getShortest() {
return shortest;
}
public boolean isModified() {
return modified;
}
-13
View File
@@ -41,17 +41,4 @@ public class MazeApp extends JFrame
System.out.println("New maze detected");
windowPanel.notifyForUpdates(param);
}
public void paintShortestPath(Graphics2D g, int width, int height) {
g.setColor(Color.ORANGE);
int dimensionX = maze.getDimensionX();
int dimensionY = maze.getDimensionY();
int boxWidth = width/dimensionX;
int boxHeight = height/dimensionY;
for (VertexInterface vertex : shortest) {
EBox box = (EBox) vertex;
g.fillOval(box.getX()*boxHeight, box.getY()*boxWidth, boxWidth, boxHeight);
}
}
}
+15
View File
@@ -7,6 +7,8 @@ import java.awt.Graphics2D;
import java.awt.GridLayout;
import javax.swing.JPanel;
import maze.Maze;
import maze.EBox;
import dijkstra.VertexInterface;
public class MazeDrawing extends JPanel {
@@ -38,4 +40,17 @@ public class MazeDrawing extends JPanel {
this.repaint();
}
}
public void paintShortestPath(Graphics2D g, int width, int height) {
g.setColor(Color.ORANGE);
int dimensionX = mazeApp.getMazeAppModel().getMaze().getDimensionX();
int dimensionY = mazeApp.getMazeAppModel().getMaze().getDimensionY();
int boxWidth = width / dimensionX;
int boxHeight = height / dimensionY;
for (VertexInterface vertex : mazeApp.getMazeAppModel().getShortest()) {
EBox box = (EBox) vertex;
g.fillOval(box.getX()*boxWidth, box.getY()*boxHeight, boxWidth, boxHeight);
}
}
}