Add UI to the project #29

Manually merged
regar42 merged 45 commits from mvc into master 2018-01-03 11:03:09 +00:00
12 changed files with 36 additions and 69 deletions
Showing only changes of commit 7d5b2938fc - Show all commits

No files matched your search

+1
View File
@@ -6,3 +6,4 @@ EEEWWWWW
EWWWWAWW EWWWWAWW
EWWEEEWW EWWEEEWW
EEEEWWWW EEEEWWWW
EEEEWWWW
+2 -4
View File
@@ -1,5 +1,5 @@
import java.util.ArrayList; import java.util.ArrayList;
import model.MazeAppModel;
import dijkstra.*; import dijkstra.*;
import maze.*; import maze.*;
import ui.*; import ui.*;
@@ -18,9 +18,7 @@ public class MainTest {
System.out.println(vertex); System.out.println(vertex);
} }
mazeTest.saveToTextFile("data/labyOutput.txt"); MazeApp app = new MazeApp();
new MazeApp();
} }
+4 -1
View File
@@ -2,9 +2,11 @@ package model;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Observable; import java.util.Observable;
import java.util.Observer;
import dijkstra.VertexInterface; import dijkstra.VertexInterface;
import dijkstra.Dijkstra; import dijkstra.Dijkstra;
import dijkstra.Previous;
public class MazeAppModel extends Observable { public class MazeAppModel extends Observable {
@@ -15,12 +17,13 @@ public class MazeAppModel extends Observable {
private ArrayList<VertexInterface> shortest = previous.getShortestPathTo(arrival); private ArrayList<VertexInterface> shortest = previous.getShortestPathTo(arrival);
private ArrayList<VertexInterface> boxList = maze.getVertexes(); private ArrayList<VertexInterface> boxList = maze.getVertexes();
private Boolean modified = false; private Boolean modified = false;
private ArrayList<Observer> listObserver = new ArrayList<Observer>();
public void setMaze(Maze maze) { public void setMaze(Maze maze) {
this.maze = maze; this.maze = maze;
modified = true; modified = true;
setChanged(); setChanged();
notifyObservers(); notifyObservers(maze);
} }
public Maze getMaze() { public Maze getMaze() {
-13
View File
@@ -1,13 +0,0 @@
package model;
import java.util.ArrayList;
import java.util.Hashtable;
import dijkstra.VertexInterface;
public class Previous extends dijkstra.Previous {
public Previous(Hashtable<VertexInterface, VertexInterface> hashPrevious, ArrayList<VertexInterface> shortestPath) {
super(hashPrevious, shortestPath);
}
}
-7
View File
@@ -8,11 +8,4 @@ public class ArrivalDrawingBox extends DrawingBox {
public ArrivalDrawingBox(MazeApp mazeApp, Color color) { public ArrivalDrawingBox(MazeApp mazeApp, Color color) {
super(mazeApp, color); super(mazeApp, color);
} }
@Override
protected final void paintComponent(Graphics g) {
super.paintComponent(g);
setBackground(Color.RED);
}
} }
-7
View File
@@ -8,11 +8,4 @@ public class DepartureDrawingBox extends DrawingBox {
public DepartureDrawingBox(MazeApp mazeApp, Color color) { public DepartureDrawingBox(MazeApp mazeApp, Color color) {
super(mazeApp, color); super(mazeApp, color);
} }
@Override
protected final void paintComponent(Graphics g) {
super.paintComponent(g);
setBackground(Color.GREEN);
}
} }
+9 -6
View File
@@ -17,20 +17,23 @@ public abstract class DrawingBox extends JPanel {
this.mazeApp = mazeApp; this.mazeApp = mazeApp;
this.color = color; this.color = color;
setBackground(color); setOpaque(true);
setPreferredSize(new Dimension(40,40)); setPreferredSize(new Dimension(50,50));
setBorder(BorderFactory.createLineBorder(Color.orange)); setBorder(BorderFactory.createLineBorder(Color.BLACK, 2));
} }
@Override @Override
protected void paintComponent(Graphics g) { public void paintComponent(Graphics g) {
super.paintComponent(g); super.paintComponent(g);
setBackground(color); setBackground(color);
} }
public void notifyForUpdates(Object param) { public void notifyForUpdates(Object param) {
this.repaint();
}
repaint(); public void setColor(Color color) {
this.color = color;
} }
} }
+15 -15
View File
@@ -22,57 +22,57 @@ public class DrawingPanelGrid extends JPanel {
this.dimensionY = maze.getDimensionY(); this.dimensionY = maze.getDimensionY();
this.drawingBoxMatrix = new DrawingBox[dimensionX][dimensionY]; this.drawingBoxMatrix = new DrawingBox[dimensionX][dimensionY];
setLayout(new GridLayout(this.dimensionX, this.dimensionY)); setLayout(new GridLayout(this.dimensionY, this.dimensionX)); //inverted coordinates
initFromMaze(maze); initFromMaze(maze);
setPreferredSize(new Dimension(256, 256));
} }
private void initFromMaze(Maze maze) { private void initFromMaze(Maze maze) {
for (int i = 0; i < dimensionX; i++) { for (int i = 0; i < dimensionY; i++) {
for (int j = 0; j < dimensionY; j++) { for (int j = 0; j < dimensionX; j++) {
if (maze.getMaze()[j][i].isWalkable()) { if (maze.getMaze()[j][i].isWalkable()) {
if (maze.getMaze()[j][i].isDeparture()) { if (maze.getMaze()[j][i].isDeparture()) {
add(new DepartureDrawingBox(mazeApp, Color.GREEN));
drawingBoxMatrix[j][i] = new DepartureDrawingBox(mazeApp, Color.GREEN); drawingBoxMatrix[j][i] = new DepartureDrawingBox(mazeApp, Color.GREEN);
} }
else if (maze.getMaze()[j][i].isArrival()) { else if (maze.getMaze()[j][i].isArrival()) {
add(new ArrivalDrawingBox(mazeApp, Color.RED));
drawingBoxMatrix[j][i] = new ArrivalDrawingBox(mazeApp, Color.RED); drawingBoxMatrix[j][i] = new ArrivalDrawingBox(mazeApp, Color.RED);
} }
else { else {
add(new EmptyDrawingBox(mazeApp, Color.BLACK));
drawingBoxMatrix[j][i] = new EmptyDrawingBox(mazeApp, Color.BLACK); drawingBoxMatrix[j][i] = new EmptyDrawingBox(mazeApp, Color.BLACK);
} }
} }
else { else {
add(new WallDrawingBox(mazeApp, Color.WHITE));
drawingBoxMatrix[j][i] = new WallDrawingBox(mazeApp, Color.WHITE); drawingBoxMatrix[j][i] = new WallDrawingBox(mazeApp, Color.WHITE);
} }
add(drawingBoxMatrix[j][i]);
} }
} }
} }
public void notifyForUpdates(Object param) { public void notifyForUpdates(Object param) {
if (param instanceof Maze) {
maze = (Maze) param;
for (int i = 0; i < dimensionX; i++) { for (int j = 0; j < dimensionX; j++) {
for (int j = 0; j < dimensionY; j++) { for (int i = 0; i < dimensionY; i++) {
if (maze.getMaze()[j][i].isWalkable()) { if (maze.getMaze()[j][i].isWalkable()) {
if (maze.getMaze()[j][i].isDeparture()) { if (maze.getMaze()[j][i].isDeparture()) {
drawingBoxMatrix[j][i].notifyForUpdates(); drawingBoxMatrix[j][i].setColor(Color.GREEN);
} }
else if (maze.getMaze()[j][i].isArrival()) { else if (maze.getMaze()[j][i].isArrival()) {
drawingBoxMatrix[j][i].notifyForUpdates(); drawingBoxMatrix[j][i].setColor(Color.RED);
} }
else { else {
drawingBoxMatrix[j][i].notifyForUpdates(); drawingBoxMatrix[j][i].setColor(Color.BLACK);
} }
} }
else { else {
drawingBoxMatrix[j][i].notifyForUpdates(); drawingBoxMatrix[j][i].setColor(Color.WHITE);
} }
} }
} }
repaint();
}
} }
} }
-7
View File
@@ -8,11 +8,4 @@ public class EmptyDrawingBox extends DrawingBox {
public EmptyDrawingBox(MazeApp mazeApp, Color color) { public EmptyDrawingBox(MazeApp mazeApp, Color color) {
super(mazeApp, color); super(mazeApp, color);
} }
@Override
protected final void paintComponent(Graphics g) {
super.paintComponent(g);
setBackground(Color.WHITE);
}
} }
+5 -1
View File
@@ -12,12 +12,15 @@ public class MazeApp extends JFrame
private final MazeMenuBar mazeMenuBar; private final MazeMenuBar mazeMenuBar;
private final WindowPanel windowPanel; private final WindowPanel windowPanel;
private MazeAppModel mazeAppModel = new MazeAppModel(); private MazeAppModel mazeAppModel;
public MazeApp() { public MazeApp() {
super("Maze Solving Application"); super("Maze Solving Application");
this.mazeAppModel = new MazeAppModel();
mazeAppModel.addObserver(this);
setJMenuBar(mazeMenuBar = new MazeMenuBar(this)); setJMenuBar(mazeMenuBar = new MazeMenuBar(this));
setContentPane(windowPanel = new WindowPanel(this)); setContentPane(windowPanel = new WindowPanel(this));
@@ -34,6 +37,7 @@ public class MazeApp extends JFrame
@Override @Override
public void update(Observable obs, Object param) { public void update(Observable obs, Object param) {
System.out.println("New maze detected");
windowPanel.notifyForUpdates(param); windowPanel.notifyForUpdates(param);
} }
} }
-7
View File
@@ -8,11 +8,4 @@ public class WallDrawingBox extends DrawingBox {
public WallDrawingBox(MazeApp mazeApp, Color color) { public WallDrawingBox(MazeApp mazeApp, Color color) {
super(mazeApp, color); super(mazeApp, color);
} }
@Override
protected final void paintComponent(Graphics g) {
super.paintComponent(g);
setBackground(Color.BLACK);
}
} }
-1
View File
@@ -16,7 +16,6 @@ public class WindowPanel extends JPanel
} }
public void notifyForUpdates(Object param) { public void notifyForUpdates(Object param) {
drawingPanelGrid.notifyForUpdates(param); drawingPanelGrid.notifyForUpdates(param);
} }