Merge branch 'menuBar' into mvc
This commit was merged in pull request #17.
This commit is contained in:
commit
083962eec5
16 files changed
+140
-55
No files matched your search
+8
-8
@@ -1,8 +1,8 @@
|
|||||||
WEWWEEEE
|
WEEEEEWW
|
||||||
EDEWEWWE
|
EDWWWEEW
|
||||||
EWEEEWWE
|
WEEWWWEE
|
||||||
EWWEWWEE
|
WWEEEEEW
|
||||||
EWWEWWEW
|
EEEWWWWW
|
||||||
EEWEWAEW
|
EWWWWAWW
|
||||||
WEEEWWWW
|
EWWEEEWW
|
||||||
WWEWWWWW
|
EEEEWWWW
|
||||||
+6
-6
@@ -7,19 +7,19 @@ import ui.*;
|
|||||||
public class MainTest {
|
public class MainTest {
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
|
||||||
Maze mazeTest = new Maze("data/labyrinthe.txt") ;
|
Maze mazeTest = new Maze("data/labyrinthe.txt") ;
|
||||||
|
|
||||||
Previous previous = (Previous) Dijkstra.dijkstra(mazeTest, mazeTest.getMaze()[1][1]);
|
Previous previous = (Previous) Dijkstra.dijkstra(mazeTest, mazeTest.getMaze()[1][1]);
|
||||||
|
|
||||||
ArrayList<VertexInterface> shortest = previous.getShortestPathTo(mazeTest.getMaze()[5][5]);
|
ArrayList<VertexInterface> shortest = previous.getShortestPathTo(mazeTest.getMaze()[5][5]);
|
||||||
|
|
||||||
for (VertexInterface vertex : shortest) {
|
for (VertexInterface vertex : shortest) {
|
||||||
System.out.println(vertex);
|
System.out.println(vertex);
|
||||||
}
|
}
|
||||||
|
|
||||||
mazeTest.saveToTextFile("data/labyOutput.txt");
|
mazeTest.saveToTextFile("data/labyOutput.txt");
|
||||||
|
|
||||||
new MazeApp();
|
new MazeApp();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,8 @@
|
|||||||
|
package model;
|
||||||
|
|
||||||
|
public class Maze extends maze.Maze {
|
||||||
|
|
||||||
|
public Maze(String filename) {
|
||||||
|
super(filename);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,16 +1,28 @@
|
|||||||
package model;
|
package model;
|
||||||
|
|
||||||
import maze.Maze;
|
import java.util.Observable;
|
||||||
|
|
||||||
public class MazeAppModel {
|
public class MazeAppModel extends Observable {
|
||||||
|
|
||||||
private Maze maze = new Maze("data/labyrinthe.txt");
|
private Maze maze = new Maze("data/labyrinthe.txt");
|
||||||
|
private boolean modified = false;
|
||||||
|
|
||||||
public void setMaze(Maze maze) {
|
public void setMaze(Maze maze) {
|
||||||
this.maze = maze;
|
this.maze = maze;
|
||||||
|
modified = true;
|
||||||
|
setChanged();
|
||||||
|
notifyObservers();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Maze getMaze() {
|
public Maze getMaze() {
|
||||||
return maze;
|
return maze;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
public boolean isModified() {
|
||||||
|
return modified;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void saveToFile() {
|
||||||
|
maze.saveToTextFile("data/labyOutput.txt");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -7,5 +7,4 @@ public class ArrivalDrawingBox extends DrawingBox {
|
|||||||
public ArrivalDrawingBox(MazeApp mazeApp, Color color) {
|
public ArrivalDrawingBox(MazeApp mazeApp, Color color) {
|
||||||
super(mazeApp, color);
|
super(mazeApp, color);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -7,5 +7,4 @@ public class DepartureDrawingBox extends DrawingBox {
|
|||||||
public DepartureDrawingBox(MazeApp mazeApp, Color color) {
|
public DepartureDrawingBox(MazeApp mazeApp, Color color) {
|
||||||
super(mazeApp, color);
|
super(mazeApp, color);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -9,12 +9,12 @@ public abstract class DrawingBox extends JPanel {
|
|||||||
|
|
||||||
private final MazeApp mazeApp;
|
private final MazeApp mazeApp;
|
||||||
private Color color;
|
private Color color;
|
||||||
|
|
||||||
public DrawingBox(MazeApp mazeApp, Color color) {
|
public DrawingBox(MazeApp mazeApp, Color color) {
|
||||||
|
|
||||||
this.mazeApp = mazeApp;
|
this.mazeApp = mazeApp;
|
||||||
this.color = color;
|
this.color = color;
|
||||||
|
|
||||||
setBackground(color);
|
setBackground(color);
|
||||||
setPreferredSize(new Dimension(40,40));
|
setPreferredSize(new Dimension(40,40));
|
||||||
setBorder(BorderFactory.createLineBorder(Color.orange));
|
setBorder(BorderFactory.createLineBorder(Color.orange));
|
||||||
|
|||||||
@@ -12,25 +12,25 @@ public class DrawingPanelGrid extends JPanel {
|
|||||||
private Maze maze;
|
private Maze maze;
|
||||||
private int dimensionX;
|
private int dimensionX;
|
||||||
private int dimensionY;
|
private int dimensionY;
|
||||||
|
|
||||||
public DrawingPanelGrid(MazeApp mazeApp) {
|
public DrawingPanelGrid(MazeApp mazeApp) {
|
||||||
|
|
||||||
this.mazeApp = mazeApp;
|
this.mazeApp = mazeApp;
|
||||||
this.maze = mazeApp.getMazeAppModel().getMaze();
|
this.maze = mazeApp.getMazeAppModel().getMaze();
|
||||||
this.dimensionX = maze.getDimensionX();
|
this.dimensionX = maze.getDimensionX();
|
||||||
this.dimensionY = maze.getDimensionY();
|
this.dimensionY = maze.getDimensionY();
|
||||||
|
|
||||||
setLayout(new GridLayout(this.dimensionX, this.dimensionY));
|
setLayout(new GridLayout(this.dimensionX, this.dimensionY));
|
||||||
initFromMaze(maze);
|
initFromMaze(maze);
|
||||||
|
|
||||||
setPreferredSize(new Dimension(256, 256));
|
setPreferredSize(new Dimension(256, 256));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initFromMaze(Maze maze) {
|
private void initFromMaze(Maze maze) {
|
||||||
|
|
||||||
int dimensionX = maze.getDimensionX();
|
int dimensionX = maze.getDimensionX();
|
||||||
int dimensionY = maze.getDimensionY();
|
int dimensionY = maze.getDimensionY();
|
||||||
|
|
||||||
for (int i = 0; i < dimensionX; i++) {
|
for (int i = 0; i < dimensionX; i++) {
|
||||||
for (int j = 0; j < dimensionY; j++) {
|
for (int j = 0; j < dimensionY; j++) {
|
||||||
if (maze.getMaze()[j][i].isWalkable()) {
|
if (maze.getMaze()[j][i].isWalkable()) {
|
||||||
@@ -49,6 +49,5 @@ public class DrawingPanelGrid extends JPanel {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -7,5 +7,4 @@ public class EmptyDrawingBox extends DrawingBox {
|
|||||||
public EmptyDrawingBox(MazeApp mazeApp, Color color) {
|
public EmptyDrawingBox(MazeApp mazeApp, Color color) {
|
||||||
super(mazeApp, color);
|
super(mazeApp, color);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -6,14 +6,14 @@ public class FileMenu extends JMenu {
|
|||||||
|
|
||||||
private final MazeApp mazeApp;
|
private final MazeApp mazeApp;
|
||||||
private final QuitMenuItem quitMenuItem;
|
private final QuitMenuItem quitMenuItem;
|
||||||
|
private final LoadMazeMenuItem loadMazeMenuItem;
|
||||||
|
|
||||||
public FileMenu(MazeApp mazeApp) {
|
public FileMenu(MazeApp mazeApp) {
|
||||||
|
|
||||||
super("File");
|
super("File");
|
||||||
this.mazeApp = mazeApp;
|
this.mazeApp = mazeApp;
|
||||||
|
|
||||||
add(quitMenuItem = new QuitMenuItem(mazeApp));
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
add(quitMenuItem = new QuitMenuItem(mazeApp));
|
||||||
|
add(loadMazeMenuItem = new LoadMazeMenuItem(mazeApp));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
package ui;
|
||||||
|
|
||||||
|
import javax.swing.JFileChooser;
|
||||||
|
import javax.swing.JMenuItem;
|
||||||
|
import javax.swing.JOptionPane;
|
||||||
|
import javax.swing.filechooser.FileNameExtensionFilter;
|
||||||
|
|
||||||
|
import model.MazeAppModel;
|
||||||
|
import model.Maze;
|
||||||
|
|
||||||
|
import java.awt.event.ActionEvent;
|
||||||
|
import java.awt.event.ActionListener;
|
||||||
|
|
||||||
|
public class LoadMazeMenuItem extends JMenuItem
|
||||||
|
implements ActionListener {
|
||||||
|
|
||||||
|
private final MazeApp mazeApp;
|
||||||
|
|
||||||
|
public LoadMazeMenuItem(MazeApp mazeApp) {
|
||||||
|
|
||||||
|
super("Load maze");
|
||||||
|
this.mazeApp = mazeApp;
|
||||||
|
addActionListener(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void actionPerformed(ActionEvent evt) {
|
||||||
|
|
||||||
|
MazeAppModel mazeAppModel = mazeApp.getMazeAppModel();
|
||||||
|
JFileChooser fileChooser = new JFileChooser();
|
||||||
|
FileNameExtensionFilter filter = new FileNameExtensionFilter(
|
||||||
|
"Text files", "txt");
|
||||||
|
fileChooser.setFileFilter(filter);
|
||||||
|
int returnVal = fileChooser.showOpenDialog(mazeApp);
|
||||||
|
if(returnVal == JFileChooser.APPROVE_OPTION) {
|
||||||
|
System.out.println("You chose to open this file: " +
|
||||||
|
fileChooser.getSelectedFile().getName());
|
||||||
|
}
|
||||||
|
String filename = fileChooser.getSelectedFile().getPath();
|
||||||
|
mazeApp.getMazeAppModel().setMaze(new Maze(filename));
|
||||||
|
}
|
||||||
|
}
|
||||||
+6
-6
@@ -5,24 +5,24 @@ import maze.Maze;
|
|||||||
import model.MazeAppModel;
|
import model.MazeAppModel;
|
||||||
|
|
||||||
public class MazeApp extends JFrame {
|
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 = new MazeAppModel();
|
||||||
|
|
||||||
public MazeApp() {
|
public MazeApp() {
|
||||||
|
|
||||||
super("Maze Solving Application");
|
super("Maze Solving Application");
|
||||||
|
|
||||||
setJMenuBar(mazeMenuBar = new MazeMenuBar(this));
|
setJMenuBar(mazeMenuBar = new MazeMenuBar(this));
|
||||||
setContentPane(windowPanel = new WindowPanel(this)) ;
|
setContentPane(windowPanel = new WindowPanel(this)) ;
|
||||||
|
|
||||||
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||||
|
|
||||||
pack();
|
pack();
|
||||||
setVisible(true);
|
setVisible(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public MazeAppModel getMazeAppModel() {
|
public MazeAppModel getMazeAppModel() {
|
||||||
return mazeAppModel;
|
return mazeAppModel;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,13 +6,12 @@ public class MazeMenuBar extends JMenuBar {
|
|||||||
|
|
||||||
private final MazeApp mazeApp;
|
private final MazeApp mazeApp;
|
||||||
private final FileMenu fileMenu;
|
private final FileMenu fileMenu;
|
||||||
|
|
||||||
public MazeMenuBar(MazeApp mazeApp) {
|
public MazeMenuBar(MazeApp mazeApp) {
|
||||||
|
|
||||||
super();
|
super();
|
||||||
this.mazeApp = mazeApp;
|
this.mazeApp = mazeApp;
|
||||||
|
|
||||||
add(fileMenu = new FileMenu(mazeApp));
|
add(fileMenu = new FileMenu(mazeApp));
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,15 +1,46 @@
|
|||||||
package ui;
|
package ui;
|
||||||
|
|
||||||
import javax.swing.JMenuItem;
|
import java.awt.event.ActionEvent;
|
||||||
|
import java.awt.event.ActionListener;
|
||||||
|
|
||||||
public class QuitMenuItem extends JMenuItem {
|
import javax.swing.JMenuItem;
|
||||||
|
import javax.swing.JOptionPane;
|
||||||
|
|
||||||
|
import model.MazeAppModel;
|
||||||
|
|
||||||
|
public class QuitMenuItem extends JMenuItem
|
||||||
|
implements ActionListener {
|
||||||
|
|
||||||
private final MazeApp mazeApp;
|
private final MazeApp mazeApp;
|
||||||
|
|
||||||
public QuitMenuItem(MazeApp mazeApp) {
|
public QuitMenuItem(MazeApp mazeApp) {
|
||||||
|
|
||||||
super("Quit");
|
super("Quit");
|
||||||
this.mazeApp = mazeApp;
|
this.mazeApp = mazeApp;
|
||||||
|
addActionListener(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void actionPerformed(ActionEvent evt) {
|
||||||
|
|
||||||
|
MazeAppModel mazeAppModel = mazeApp.getMazeAppModel();
|
||||||
|
|
||||||
|
if (mazeAppModel.isModified()) {
|
||||||
|
int response = JOptionPane.showInternalOptionDialog(this,
|
||||||
|
"Maze not saved. Save it ?",
|
||||||
|
"Quit application",
|
||||||
|
JOptionPane.YES_NO_CANCEL_OPTION,
|
||||||
|
JOptionPane.WARNING_MESSAGE,
|
||||||
|
null,null,null);
|
||||||
|
switch (response) {
|
||||||
|
case JOptionPane.CANCEL_OPTION:
|
||||||
|
return;
|
||||||
|
case JOptionPane.OK_OPTION:
|
||||||
|
mazeAppModel.saveToFile();
|
||||||
|
break;
|
||||||
|
case JOptionPane.NO_OPTION:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
System.exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -7,5 +7,4 @@ public class WallDrawingBox extends DrawingBox {
|
|||||||
public WallDrawingBox(MazeApp mazeApp, Color color) {
|
public WallDrawingBox(MazeApp mazeApp, Color color) {
|
||||||
super(mazeApp, color);
|
super(mazeApp, color);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -7,12 +7,11 @@ import java.awt.*;
|
|||||||
public class WindowPanel extends JPanel
|
public class WindowPanel extends JPanel
|
||||||
{
|
{
|
||||||
private final DrawingPanelGrid drawingPanelGrid;
|
private final DrawingPanelGrid drawingPanelGrid;
|
||||||
|
|
||||||
public WindowPanel(MazeApp mazeApp) {
|
public WindowPanel(MazeApp mazeApp) {
|
||||||
|
|
||||||
setLayout(new BorderLayout());
|
setLayout(new BorderLayout());
|
||||||
|
|
||||||
add(drawingPanelGrid = new DrawingPanelGrid(mazeApp), BorderLayout.CENTER);
|
add(drawingPanelGrid = new DrawingPanelGrid(mazeApp), BorderLayout.CENTER);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user