}
private class MouseClickListener extends MouseAdapter {
@Override
public void mouseClicked(MouseEvent e) {
final PilePanel panelPressed = gamePanel.determinePanelPressed(e);
// Determine: fromPanel or toPanel?
if (fromPanel == null) {
fromPanel = panelPressed;
fromPanel.toggleSelected();
} else {
if (fromPanel == panelPressed) {
// Double click: try moving to a foundation.
fromPanel.toggleSelected();
for (PilePanel foundationPanel : gamePanel.getFoundationPanels()) {
if (game.move(fromPanel.getPile(), foundationPanel.getPile())) {
fromPanel.repaint();
foundationPanel.repaint();
showDialogs();
break;
}
}
} else {
// Try moving to other cell.
if (game.move(fromPanel.getPile(), panelPressed.getPile())) {
fromPanel.toggleSelected();
fromPanel.repaint();
panelPressed.repaint();
showDialogs();
} else
fromPanel.toggleSelected();
}
fromPanel = null;