Add UI to the project #29
No files matched your search
@@ -1,30 +1,8 @@
|
||||
import java.util.ArrayList;
|
||||
import dijkstra.*;
|
||||
import maze.*;
|
||||
import ui.*;
|
||||
|
||||
public class MainTest {
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
Maze mazeTest = new Maze("data/labyrinthe.txt") ;
|
||||
System.out.println(mazeTest);
|
||||
mazeTest.saveToTextFile("data/labyOutput.txt");
|
||||
VertexInterface departure = mazeTest.getDeparture();
|
||||
VertexInterface arrival = mazeTest.getArrival();
|
||||
|
||||
Previous previous = (Previous) Dijkstra.dijkstra(mazeTest, departure);
|
||||
|
||||
ArrayList<VertexInterface> shortest = previous.getShortestPathTo(arrival);
|
||||
|
||||
//Print shortest path to arrival
|
||||
System.out.println(arrival);
|
||||
for (VertexInterface vertex : shortest) {
|
||||
System.out.println(vertex);
|
||||
}
|
||||
|
||||
MazeApp app = new MazeApp();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
+194
-26
@@ -43,51 +43,89 @@ public class Maze
|
||||
}
|
||||
|
||||
public Maze(Box[][] newMaze) {
|
||||
this.dimensionX = newMaze[0].length;
|
||||
this.dimensionY = newMaze.length;
|
||||
if (dimensionY > 0) {
|
||||
this.dimensionX = newMaze[0].length;
|
||||
}
|
||||
else {
|
||||
this.dimensionX = 0;
|
||||
}
|
||||
this.maze = matrixDeepCopy(newMaze);
|
||||
}
|
||||
|
||||
private Box[][] matrixDeepCopy (Box[][] original) {
|
||||
int numberOfLines = 0;
|
||||
int numberOfRows = 0;
|
||||
Box[][] copy;
|
||||
/*
|
||||
* We first get the dimensions of the matrix
|
||||
*/
|
||||
for (Box[] lineBoxes: original) {
|
||||
numberOfLines++;
|
||||
private Box[][] matrixDeepCopy(Box[][] original,
|
||||
Box[][] destination,
|
||||
int numberOfLines,
|
||||
int numberOfRows,
|
||||
int lineOffset,
|
||||
int rowOffset)
|
||||
{
|
||||
if (destination == null) {
|
||||
destination = new Box[numberOfLines][numberOfRows];
|
||||
}
|
||||
if (numberOfLines > 0) {
|
||||
for (Box box: original[0]) {
|
||||
numberOfRows++;
|
||||
if (original.length < 1) {
|
||||
return destination;
|
||||
}
|
||||
}
|
||||
copy = new Box[numberOfLines][numberOfRows];
|
||||
|
||||
/*
|
||||
* Now we proceed to the deep copy of each box
|
||||
*/
|
||||
for (int line = 0; line < numberOfLines; line++) {
|
||||
for (int row = 0; row < numberOfRows; row++) {
|
||||
for (int line = lineOffset; line < lineOffset + numberOfLines; line++) {
|
||||
for (int row = rowOffset; row < rowOffset + numberOfRows; row++) {
|
||||
Box box = original[line][row];
|
||||
if (box.isWalkable()) {
|
||||
if (box.isDeparture()) {
|
||||
copy[line][row] = new DBox(box.getLabel(), box.getY(), box.getX(), this);
|
||||
destination[line][row] = new DBox(box.getLabel(), box.getY(), box.getX(), this);
|
||||
}
|
||||
else if (box.isArrival()) {
|
||||
copy[line][row] = new ABox(box.getLabel(), box.getY(), box.getX(), this);
|
||||
destination[line][row] = new ABox(box.getLabel(), box.getY(), box.getX(), this);
|
||||
}
|
||||
else {
|
||||
copy[line][row] = new EBox(box.getLabel(), box.getY(), box.getX(), this);
|
||||
destination[line][row] = new EBox(box.getLabel(), box.getY(), box.getX(), this);
|
||||
}
|
||||
}
|
||||
else {
|
||||
copy[line][row] = new WBox(box.getLabel(), box.getY(), box.getX(), this);
|
||||
destination[line][row] = new WBox(box.getLabel(), box.getY(), box.getX(), this);
|
||||
}
|
||||
}
|
||||
}
|
||||
return copy;
|
||||
return destination;
|
||||
}
|
||||
|
||||
private Box[][] matrixDeepCopy(Box[][] original,
|
||||
int numberOfLines,
|
||||
int numberOfRows,
|
||||
int lineOffset,
|
||||
int rowOffset,
|
||||
int numberOfDestLines,
|
||||
int numberOfDestRows) {
|
||||
return matrixDeepCopy(original,
|
||||
new Box[numberOfDestLines][numberOfDestRows],
|
||||
numberOfLines,
|
||||
numberOfRows,
|
||||
lineOffset,
|
||||
rowOffset);
|
||||
}
|
||||
|
||||
private Box[][] matrixDeepCopy(Box [][] original,
|
||||
int numberOfLines,
|
||||
int numberOfRows,
|
||||
int lineOffset,
|
||||
int rowOffset) {
|
||||
return matrixDeepCopy(original,
|
||||
numberOfLines,
|
||||
numberOfRows,
|
||||
lineOffset,
|
||||
rowOffset,
|
||||
numberOfLines,
|
||||
numberOfRows);
|
||||
}
|
||||
|
||||
private Box[][] matrixDeepCopy(Box[][] original, int numberOfLines, int numberOfRows) {
|
||||
return matrixDeepCopy(original, numberOfLines, numberOfRows, 0, 0);
|
||||
}
|
||||
|
||||
private Box[][] matrixDeepCopy(Box[][] original) {
|
||||
if (original.length < 1) {
|
||||
return null;
|
||||
}
|
||||
return matrixDeepCopy(original, original.length, original[0].length);
|
||||
}
|
||||
|
||||
public static Maze emptyMaze(int dimension) {
|
||||
@@ -130,6 +168,136 @@ public class Maze
|
||||
return new Maze(numberOfLines, numberOfRows, maze);
|
||||
}
|
||||
|
||||
public void addEmptyColumn(int posColumn) {
|
||||
Box[][] newMaze = matrixDeepCopy(maze,
|
||||
dimensionY,
|
||||
posColumn,
|
||||
0,
|
||||
0,
|
||||
dimensionY,
|
||||
dimensionX + 1);
|
||||
for (int line = 0; line < dimensionY; line++) {
|
||||
newMaze[line][posColumn] = new EBox("E", line, posColumn, this);
|
||||
}
|
||||
for (int line = 0; line < dimensionY; line++) {
|
||||
for (int row = posColumn; row < dimensionX; row++) {
|
||||
Box box = maze[line][row];
|
||||
if (box.isWalkable()) {
|
||||
if (box.isDeparture()) {
|
||||
newMaze[line][row + 1] = new DBox(box.getLabel(), box.getY(), box.getX() + 1, this);
|
||||
}
|
||||
else if (box.isArrival()) {
|
||||
newMaze[line][row + 1] = new ABox(box.getLabel(), box.getY(), box.getX() + 1, this);
|
||||
}
|
||||
else {
|
||||
newMaze[line][row + 1] = new EBox(box.getLabel(), box.getY(), box.getX() + 1, this);
|
||||
}
|
||||
}
|
||||
else {
|
||||
newMaze[line][row + 1] = new WBox(box.getLabel(), box.getY(), box.getX() + 1, this);
|
||||
}
|
||||
}
|
||||
}
|
||||
maze = newMaze;
|
||||
dimensionX = dimensionX + 1;
|
||||
}
|
||||
|
||||
public void delColumn(int posColumn) {
|
||||
Box[][] newMaze = matrixDeepCopy(maze,
|
||||
dimensionY,
|
||||
posColumn,
|
||||
0,
|
||||
0,
|
||||
dimensionY,
|
||||
dimensionX - 1);
|
||||
for (int line = 0; line < dimensionY; line++) {
|
||||
for (int row = posColumn + 1; row < dimensionX; row++) {
|
||||
Box box = maze[line][row];
|
||||
if (box.isWalkable()) {
|
||||
if (box.isDeparture()) {
|
||||
newMaze[line][row - 1] = new DBox(box.getLabel(), box.getY(), box.getX() - 1, this);
|
||||
}
|
||||
else if (box.isArrival()) {
|
||||
newMaze[line][row - 1] = new ABox(box.getLabel(), box.getY(), box.getX() - 1, this);
|
||||
}
|
||||
else {
|
||||
newMaze[line][row - 1] = new EBox(box.getLabel(), box.getY(), box.getX() - 1, this);
|
||||
}
|
||||
}
|
||||
else {
|
||||
newMaze[line][row - 1] = new WBox(box.getLabel(), box.getY(), box.getX() - 1, this);
|
||||
}
|
||||
}
|
||||
}
|
||||
maze = newMaze;
|
||||
dimensionX = dimensionX - 1;
|
||||
}
|
||||
|
||||
public void addEmptyLine(int posLine) {
|
||||
Box[][] newMaze = matrixDeepCopy(maze,
|
||||
posLine,
|
||||
dimensionX,
|
||||
0,
|
||||
0,
|
||||
dimensionY + 1,
|
||||
dimensionX);
|
||||
for (int row = 0; row < dimensionX; row++) {
|
||||
newMaze[posLine][row] = new EBox("E", posLine, row, this);
|
||||
}
|
||||
for (int line = posLine; line < dimensionY; line++) {
|
||||
for (int row = 0; row < dimensionX; row++) {
|
||||
Box box = maze[line][row];
|
||||
if (box.isWalkable()) {
|
||||
if (box.isDeparture()) {
|
||||
newMaze[line + 1][row] = new DBox(box.getLabel(), box.getY() + 1, box.getX(), this);
|
||||
}
|
||||
else if (box.isArrival()) {
|
||||
newMaze[line + 1][row] = new ABox(box.getLabel(), box.getY() + 1, box.getX(), this);
|
||||
}
|
||||
else {
|
||||
newMaze[line + 1][row] = new EBox(box.getLabel(), box.getY() + 1, box.getX(), this);
|
||||
}
|
||||
}
|
||||
else {
|
||||
newMaze[line + 1][row] = new WBox(box.getLabel(), box.getY() + 1, box.getX(), this);
|
||||
}
|
||||
}
|
||||
}
|
||||
dimensionY = dimensionY + 1;
|
||||
maze = newMaze;
|
||||
}
|
||||
|
||||
public void delLine(int posLine) {
|
||||
Box[][] newMaze = matrixDeepCopy(maze,
|
||||
posLine,
|
||||
dimensionX,
|
||||
0,
|
||||
0,
|
||||
dimensionY - 1,
|
||||
dimensionX);
|
||||
for (int line = posLine + 1; line < dimensionY; line++) {
|
||||
for (int row = 0; row < dimensionX; row++) {
|
||||
Box box = maze[line][row];
|
||||
if (box.isWalkable()) {
|
||||
if (box.isDeparture()) {
|
||||
newMaze[line - 1][row] = new DBox(box.getLabel(), box.getY() - 1, box.getX(), this);
|
||||
}
|
||||
else if (box.isArrival()) {
|
||||
newMaze[line - 1][row] = new ABox(box.getLabel(), box.getY() - 1, box.getX(), this);
|
||||
}
|
||||
else {
|
||||
newMaze[line - 1][row] = new EBox(box.getLabel(), box.getY() - 1, box.getX(), this);
|
||||
}
|
||||
}
|
||||
else {
|
||||
newMaze[line - 1][row] = new WBox(box.getLabel(), box.getY() - 1, box.getX(), this);
|
||||
}
|
||||
}
|
||||
}
|
||||
maze = newMaze;
|
||||
dimensionY = dimensionY - 1;
|
||||
}
|
||||
|
||||
public int getCost(VertexInterface start, VertexInterface end) {
|
||||
|
||||
Box startBox = (Box) start ;
|
||||
|
||||
+31
-38
@@ -134,59 +134,52 @@ public class MazeAppModel extends Observable {
|
||||
|
||||
public void newClearMaze(int numberOfLines, int numberOfRows) {
|
||||
|
||||
Box[][] newClearMaze = new Box[numberOfLines][numberOfRows];
|
||||
|
||||
for (int line = 0; line < numberOfLines; line++) {
|
||||
for (int row = 0; row < numberOfRows; row++) {
|
||||
newClearMaze[line][row] = new EBox("E", line, row, this.maze);
|
||||
}
|
||||
}
|
||||
this.maze = new Maze(newClearMaze);
|
||||
maze = new Maze(Maze.emptyMaze(numberOfLines, numberOfRows));
|
||||
initModelFromMaze();
|
||||
saved = false;
|
||||
}
|
||||
|
||||
public void addEmptyColumn() {
|
||||
|
||||
Box[][] previousMaze = maze.getMaze();
|
||||
int numberOfLines = maze.getDimensionY();
|
||||
int numberOfRows = maze.getDimensionX()+1;
|
||||
|
||||
newClearMaze(numberOfLines, numberOfRows);
|
||||
|
||||
for (int line = 0; line < numberOfLines; line++) {
|
||||
for (int row = 0; row < numberOfRows; row++) {
|
||||
if (row == numberOfRows-1) {
|
||||
maze.getMaze()[line][row] = new EBox("E", line, row, maze);
|
||||
} else {
|
||||
maze.getMaze()[line][row] = previousMaze[line][row];
|
||||
}
|
||||
}
|
||||
addEmptyColumn(maze.getDimensionX());
|
||||
}
|
||||
|
||||
public void addEmptyColumn(int posColumn) {
|
||||
maze.addEmptyColumn(posColumn);
|
||||
initModelFromMaze();
|
||||
saved = false;
|
||||
}
|
||||
|
||||
public void delColumn(int posColumn) {
|
||||
maze.delColumn(posColumn);
|
||||
initModelFromMaze();
|
||||
saved = false;
|
||||
}
|
||||
|
||||
public void delColumn() {
|
||||
delColumn(maze.getDimensionX() - 1);
|
||||
}
|
||||
|
||||
public void addEmptyLine() {
|
||||
|
||||
Box[][] previousMaze = maze.getMaze();
|
||||
int numberOfLines = maze.getDimensionY()+1;
|
||||
int numberOfRows = maze.getDimensionX();
|
||||
|
||||
newClearMaze(numberOfLines, numberOfRows);
|
||||
|
||||
for (int line = 0; line < numberOfLines; line++) {
|
||||
for (int row = 0; row < numberOfRows; row++) {
|
||||
if (line == numberOfLines-1) {
|
||||
maze.getMaze()[line][row] = new EBox("E", line, row, maze);
|
||||
} else {
|
||||
maze.getMaze()[line][row] = previousMaze[line][row];
|
||||
}
|
||||
}
|
||||
addEmptyLine(maze.getDimensionY());
|
||||
}
|
||||
|
||||
public void addEmptyLine(int posLine) {
|
||||
maze.addEmptyLine(posLine);
|
||||
initModelFromMaze();
|
||||
saved = false;
|
||||
}
|
||||
|
||||
public void delLine(int posLine) {
|
||||
maze.delLine(posLine);
|
||||
initModelFromMaze();
|
||||
saved = false;
|
||||
}
|
||||
|
||||
public void delLine() {
|
||||
delLine(maze.getDimensionY() - 1);
|
||||
}
|
||||
|
||||
public void clearMaze() {
|
||||
newClearMaze(maze.getDimensionY(), maze.getDimensionX());
|
||||
}
|
||||
}
|
||||
@@ -9,17 +9,30 @@ public class AddLineMenuItem extends JMenuItem
|
||||
implements ActionListener {
|
||||
|
||||
private final MazeApp mazeApp;
|
||||
private final int lineNum;
|
||||
|
||||
public AddLineMenuItem(MazeApp mazeApp) {
|
||||
|
||||
super("Add line");
|
||||
this.mazeApp = mazeApp;
|
||||
lineNum = -1;
|
||||
addActionListener(this);
|
||||
}
|
||||
|
||||
public AddLineMenuItem(MazeApp mazeApp, int lineNum) {
|
||||
super("Add line");
|
||||
this.mazeApp = mazeApp;
|
||||
this.lineNum = lineNum;
|
||||
addActionListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent arg0) {
|
||||
|
||||
this.mazeApp.getMazeAppModel().addEmptyLine();
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if (lineNum == -1) {
|
||||
mazeApp.addEmptyLine();
|
||||
}
|
||||
else {
|
||||
mazeApp.addEmptyLine(lineNum);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,25 +3,37 @@ package ui;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
|
||||
import javax.swing.Action;
|
||||
import javax.swing.Icon;
|
||||
import javax.swing.JMenuItem;
|
||||
|
||||
public class AddRowMenuItem extends JMenuItem
|
||||
implements ActionListener {
|
||||
|
||||
private final MazeApp mazeApp;
|
||||
private final int rowNum;
|
||||
|
||||
public AddRowMenuItem(MazeApp mazeApp) {
|
||||
|
||||
super("Add row");
|
||||
this.mazeApp = mazeApp;
|
||||
rowNum = -1;
|
||||
addActionListener(this);
|
||||
}
|
||||
|
||||
public AddRowMenuItem(MazeApp mazeApp, int rowNum) {
|
||||
|
||||
super("Add row");
|
||||
this.mazeApp = mazeApp;
|
||||
this.rowNum = rowNum;
|
||||
addActionListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent arg0) {
|
||||
|
||||
this.mazeApp.getMazeAppModel().addEmptyColumn();
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if (rowNum == -1) {
|
||||
mazeApp.addEmptyColumn();
|
||||
}
|
||||
else {
|
||||
mazeApp.addEmptyColumn(rowNum);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -9,6 +9,10 @@ public class BoxTypeEditionMenu extends JPopupMenu {
|
||||
JMenuItem setEBox;
|
||||
JMenuItem setDBox;
|
||||
JMenuItem setABox;
|
||||
JMenuItem addRow;
|
||||
JMenuItem addLine;
|
||||
JMenuItem delRow;
|
||||
JMenuItem delLine;
|
||||
|
||||
public BoxTypeEditionMenu(MazeApp mazeApp, int boxLine, int boxRow) {
|
||||
add(setEBox = new SetEBoxMenuItem(mazeApp, boxLine, boxRow));
|
||||
@@ -21,5 +25,10 @@ public class BoxTypeEditionMenu extends JPopupMenu {
|
||||
setWBox.setEnabled(box.isWalkable());
|
||||
setDBox.setEnabled(! box.isDeparture());
|
||||
setABox.setEnabled(! box.isArrival());
|
||||
|
||||
add(addRow = new AddRowMenuItem(mazeApp, boxRow));
|
||||
add(addLine = new AddLineMenuItem(mazeApp, boxLine));
|
||||
add(delRow = new DelRowMenuItem(mazeApp, boxRow));
|
||||
add(delLine = new DelLineMenuItem(mazeApp, boxLine));
|
||||
}
|
||||
}
|
||||
@@ -3,8 +3,6 @@ package ui;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
|
||||
import javax.swing.Action;
|
||||
import javax.swing.Icon;
|
||||
import javax.swing.JMenuItem;
|
||||
import javax.swing.KeyStroke;
|
||||
|
||||
@@ -23,13 +21,6 @@ public class ClearMazeMenuItem extends JMenuItem
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
|
||||
int numberOfLines = mazeApp.getMazeAppModel()
|
||||
.getMaze().getDimensionY();
|
||||
int numberOfRows = mazeApp.getMazeAppModel()
|
||||
.getMaze().getDimensionX();
|
||||
this.mazeApp.getMazeAppModel()
|
||||
.newClearMaze(numberOfLines, numberOfRows);
|
||||
System.out.println("test");
|
||||
mazeApp.clearMaze();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package ui;
|
||||
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
|
||||
import javax.swing.JMenuItem;
|
||||
|
||||
public class DelLineMenuItem extends JMenuItem
|
||||
implements ActionListener {
|
||||
|
||||
private final MazeApp mazeApp;
|
||||
private final int lineNum;
|
||||
|
||||
public DelLineMenuItem(MazeApp mazeApp) {
|
||||
|
||||
super("Delete line");
|
||||
this.mazeApp = mazeApp;
|
||||
lineNum = -1;
|
||||
addActionListener(this);
|
||||
}
|
||||
|
||||
public DelLineMenuItem(MazeApp mazeApp, int lineNum) {
|
||||
super("Delete line");
|
||||
this.mazeApp = mazeApp;
|
||||
this.lineNum = lineNum;
|
||||
addActionListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if (lineNum == -1) {
|
||||
mazeApp.delLine();
|
||||
}
|
||||
else {
|
||||
mazeApp.delLine(lineNum);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package ui;
|
||||
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
|
||||
import javax.swing.JMenuItem;
|
||||
|
||||
public class DelRowMenuItem extends JMenuItem
|
||||
implements ActionListener {
|
||||
|
||||
private final MazeApp mazeApp;
|
||||
private final int rowNum;
|
||||
|
||||
public DelRowMenuItem(MazeApp mazeApp) {
|
||||
super("Delete row");
|
||||
this.mazeApp = mazeApp;
|
||||
rowNum = -1;
|
||||
addActionListener(this);
|
||||
}
|
||||
|
||||
public DelRowMenuItem(MazeApp mazeApp, int rowNum) {
|
||||
super("Delete row");
|
||||
this.mazeApp = mazeApp;
|
||||
this.rowNum = rowNum;
|
||||
addActionListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if (rowNum == -1) {
|
||||
mazeApp.delColumn();
|
||||
}
|
||||
else {
|
||||
mazeApp.delColumn(rowNum);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -87,4 +87,41 @@ public class MazeApp extends JFrame
|
||||
mazeAppModel.setPathDrawn(false);
|
||||
this.repaint();
|
||||
}
|
||||
|
||||
public void addEmptyColumn(int posColumn) {
|
||||
mazeAppModel.addEmptyColumn(posColumn);
|
||||
}
|
||||
|
||||
public void addEmptyColumn() {
|
||||
mazeAppModel.addEmptyColumn();
|
||||
}
|
||||
|
||||
public void delColumn(int posColumn) {
|
||||
mazeAppModel.delColumn(posColumn);
|
||||
}
|
||||
|
||||
public void delColumn() {
|
||||
mazeAppModel.delColumn();
|
||||
}
|
||||
|
||||
public void addEmptyLine(int posLine) {
|
||||
mazeAppModel.addEmptyLine(posLine);
|
||||
}
|
||||
|
||||
public void addEmptyLine() {
|
||||
mazeAppModel.addEmptyLine();
|
||||
}
|
||||
|
||||
public void delLine(int posLine) {
|
||||
mazeAppModel.delLine(posLine);
|
||||
}
|
||||
|
||||
public void delLine() {
|
||||
mazeAppModel.delLine();
|
||||
}
|
||||
|
||||
public void clearMaze() {
|
||||
mazeAppModel.clearMaze();
|
||||
this.repaint();
|
||||
}
|
||||
}
|
||||
@@ -11,6 +11,8 @@ public class MazeMenu extends JMenu {
|
||||
private final ClearMazeMenuItem clearMazeMenuItem;
|
||||
private final AddRowMenuItem addRowMenuItem;
|
||||
private final AddLineMenuItem addLineMenuItem;
|
||||
private final DelRowMenuItem delRowMenuItem;
|
||||
private final DelLineMenuItem delLineMenuItem;
|
||||
|
||||
public MazeMenu(MazeApp mazeApp) {
|
||||
|
||||
@@ -23,5 +25,7 @@ public class MazeMenu extends JMenu {
|
||||
add(clearMazeMenuItem = new ClearMazeMenuItem(mazeApp));
|
||||
add(addRowMenuItem = new AddRowMenuItem(mazeApp));
|
||||
add(addLineMenuItem = new AddLineMenuItem(mazeApp));
|
||||
add(delRowMenuItem = new DelRowMenuItem(mazeApp));
|
||||
add(delLineMenuItem = new DelLineMenuItem(mazeApp));
|
||||
}
|
||||
}
|
||||
@@ -15,23 +15,17 @@ import javax.swing.JSpinner;
|
||||
import javax.swing.SpinnerModel;
|
||||
import javax.swing.SpinnerNumberModel;
|
||||
import javax.swing.SpringLayout;
|
||||
import javax.swing.event.ChangeEvent;
|
||||
import javax.swing.event.ChangeListener;
|
||||
|
||||
public class NewMazeSpinnerBox extends JPanel
|
||||
implements ActionListener,
|
||||
ChangeListener {
|
||||
implements ActionListener {
|
||||
|
||||
private final MazeApp mazeApp;
|
||||
private JDialog spinnerDialog;
|
||||
private int numberOfLines;
|
||||
private int numberOfRows;
|
||||
private SpinnerModel lineSpinnerModel;
|
||||
private SpinnerModel rowSpinnerModel;
|
||||
|
||||
public NewMazeSpinnerBox(MazeApp mazeApp) {
|
||||
|
||||
|
||||
this.mazeApp = mazeApp;
|
||||
JPanel spinnerDialog = new JPanel(new SpringLayout());
|
||||
String[] labels = {"Number of lines :", "Number of rows :"};
|
||||
@@ -44,7 +38,6 @@ public class NewMazeSpinnerBox extends JPanel
|
||||
initialValue, //min
|
||||
maximumValue, //max
|
||||
1);
|
||||
this.lineSpinnerModel.addChangeListener(this);
|
||||
JSpinner lineSpinner = addLabeledSpinner(this, labels[0], lineSpinnerModel);
|
||||
|
||||
this.rowSpinnerModel =
|
||||
@@ -52,8 +45,7 @@ public class NewMazeSpinnerBox extends JPanel
|
||||
initialValue, //min
|
||||
maximumValue, //max
|
||||
1);
|
||||
this.rowSpinnerModel.addChangeListener(this);
|
||||
JSpinner rowSpinner = addLabeledSpinner(this, labels[0], rowSpinnerModel);
|
||||
JSpinner rowSpinner = addLabeledSpinner(this, labels[1], rowSpinnerModel);
|
||||
}
|
||||
|
||||
static protected JSpinner addLabeledSpinner(Container c,
|
||||
@@ -76,7 +68,7 @@ public class NewMazeSpinnerBox extends JPanel
|
||||
spinnerDialog.setLayout(new BorderLayout());
|
||||
spinnerDialog.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
|
||||
|
||||
spinnerDialog.add(new NewMazeSpinnerBox(this.mazeApp),
|
||||
spinnerDialog.add(this,
|
||||
BorderLayout.CENTER);
|
||||
|
||||
JButton OKButton = new JButton("OK");
|
||||
@@ -89,13 +81,9 @@ public class NewMazeSpinnerBox extends JPanel
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
mazeApp.getMazeAppModel(
|
||||
).newClearMaze((int) lineSpinnerModel.getValue(),
|
||||
(int) rowSpinnerModel.getValue());
|
||||
spinnerDialog.dispose();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stateChanged(ChangeEvent arg0) {
|
||||
this.mazeApp.getMazeAppModel()
|
||||
.newClearMaze((int) this.lineSpinnerModel.getValue(),
|
||||
(int) this.rowSpinnerModel.getValue());
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user