model: * New methods to directly set boxes type instead of only toggling (setXBox methods) * toggleBox now calls setXBox methods ui: * Add a context menu, enabled on right click, to directly choose the type of a box in the maze * Defer the calculation of the box coordinates in the matrix to two new methods, getBoxRow and getBoxLine
26 lines
873 B
Java
26 lines
873 B
Java
package ui;
|
|
|
|
import javax.swing.JPopupMenu;
|
|
import javax.swing.JMenuItem;
|
|
import maze.Box;
|
|
|
|
public class BoxTypeEditionMenu extends JPopupMenu {
|
|
JMenuItem setWBox;
|
|
JMenuItem setEBox;
|
|
JMenuItem setDBox;
|
|
JMenuItem setABox;
|
|
|
|
public BoxTypeEditionMenu(MazeApp mazeApp, int boxLine, int boxRow) {
|
|
add(setEBox = new SetEBoxMenuItem(mazeApp, boxLine, boxRow));
|
|
add(setWBox = new SetWBoxMenuItem(mazeApp, boxLine, boxRow));
|
|
add(setDBox = new SetDBoxMenuItem(mazeApp, boxLine, boxRow));
|
|
add(setABox = new SetABoxMenuItem(mazeApp, boxLine, boxRow));
|
|
Box box = (Box) mazeApp.getMazeAppModel().getMaze().getMaze()[boxLine][boxRow];
|
|
setEBox.setEnabled((box.isWalkable() && (box.isDeparture() ||
|
|
box.isArrival())) || ! box.isWalkable());
|
|
setWBox.setEnabled(box.isWalkable());
|
|
setDBox.setEnabled(! box.isDeparture());
|
|
setABox.setEnabled(! box.isArrival());
|
|
}
|
|
}
|