Add a context menu to edit boxes type

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
This commit is contained in:
regar42 committed 2017-12-29 12:04:15 +01:00
1 parent 37def85f5b
commit 81df80e7ea
7 files changed
+196 -34

No files matched your search

+25
View File
@@ -0,0 +1,25 @@
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());
}
}