keys are bound to maze display
and get focus when mous mouse over it
This commit is contained in:
@@ -497,10 +497,9 @@ public class Display extends JFrame
|
||||
JButton button = new JButton(direction);
|
||||
button.addActionListener(goAction);
|
||||
KeyStroke keystroke = KeyStroke.getKeyStroke(key);
|
||||
panel.getInputMap().put(keystroke, actionName);
|
||||
panel.getActionMap().put(actionName, goAction);
|
||||
controlPanel.getInputMap().put(keystroke, actionName);
|
||||
controlPanel.getActionMap().put(actionName, goAction);
|
||||
// attach keys to maze
|
||||
maze.getInputMap().put(keystroke, actionName);
|
||||
maze.getActionMap().put(actionName, goAction);
|
||||
return button;
|
||||
}
|
||||
|
||||
@@ -681,14 +680,19 @@ public class Display extends JFrame
|
||||
// not set by default for debug, will show any path
|
||||
boolean showAll = false;
|
||||
|
||||
Position getPosition(int x, int y)
|
||||
{
|
||||
int pX = (int) ((double) (x - cp.getOffsetX()) / cp.getWidth());
|
||||
int pY = (int) ((double) (y - cp.getOffsetY()) / cp.getHeight());
|
||||
return new Position(pX,pY);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseDragged(MouseEvent e) {
|
||||
// should find the cell ...
|
||||
DirectionPosition last = null;
|
||||
int pX = (int) ((double) (e.getX() - cp.getOffsetX()) / cp.getWidth());
|
||||
int pY = (int) ((double) (e.getY() - cp.getOffsetY()) / cp.getHeight());
|
||||
short path = 0;
|
||||
Position newPosition = new Position(pX,pY);
|
||||
Position newPosition = getPosition(e.getX(),e.getY());
|
||||
if (drawingPath == null )
|
||||
{
|
||||
drawingPath = new LinkedList<>();
|
||||
@@ -724,6 +728,11 @@ public class Display extends JFrame
|
||||
@Override
|
||||
public void mouseMoved(MouseEvent e) {
|
||||
// System.out.println("Mouse moved (" + e.getX() + ',' + e.getY() + ')');
|
||||
Position newPosition = getPosition(e.getX(),e.getY());
|
||||
if ( ( newPosition.getX() >= 0 ) && ( newPosition.getY() >= 0 ) )
|
||||
{
|
||||
requestFocus();
|
||||
}
|
||||
}
|
||||
|
||||
public void setShowAll(boolean showall )
|
||||
@@ -821,6 +830,10 @@ public class Display extends JFrame
|
||||
{
|
||||
this.map = map;
|
||||
solvedPath=null;
|
||||
// could be kept
|
||||
drawingPath=null;
|
||||
sX=0;
|
||||
sY=0;
|
||||
}
|
||||
|
||||
public void setWallSize(int size)
|
||||
|
||||
Reference in New Issue
Block a user