Continuing gradual process of collecting state from various GUI components and handlers and aggregating it in PlayerController.
Removed references to Refree from some handlers, replacing them with direct use of PlayerController (Law of Demeter).
This commit is contained in:
@@ -1,8 +1,6 @@
|
||||
package view;
|
||||
|
||||
import java.awt.GridLayout;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.awt.event.MouseListener;
|
||||
import java.net.URL;
|
||||
|
||||
import javax.security.auth.Refreshable;
|
||||
@@ -10,46 +8,13 @@ import javax.swing.ImageIcon;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JPanel;
|
||||
|
||||
import controller.BoardPanelMouseListener;
|
||||
|
||||
import model.Board;
|
||||
import model.Referee;
|
||||
|
||||
public class BoardPanel extends JPanel implements Refreshable {
|
||||
private class BoardPanelMouseListener implements MouseListener {
|
||||
|
||||
private final int col;
|
||||
private final int row;
|
||||
|
||||
public BoardPanelMouseListener(int r, int c) {
|
||||
row = r;
|
||||
col = c;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
referee.getPlayer().setCell(row, col);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseEntered(MouseEvent arg0) {
|
||||
// Nothing.
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseExited(MouseEvent arg0) {
|
||||
// Nothing.
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mousePressed(MouseEvent arg0) {
|
||||
// Nothing.
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseReleased(MouseEvent arg0) {
|
||||
// Nothing.
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static final URL BLUE_ICON = BoardPanel.class
|
||||
.getResource("/img/blue.png");
|
||||
@@ -74,7 +39,12 @@ public class BoardPanel extends JPanel implements Refreshable {
|
||||
for (int r = 0; r < Board.NUM_ROWS; r++) {
|
||||
for (int c = 0; c < Board.NUM_COLS; c++) {
|
||||
board[r][c] = new JLabel(new ImageIcon(NONE_ICON));
|
||||
board[r][c].addMouseListener(new BoardPanelMouseListener(r, c));
|
||||
BoardPanelMouseListener bpml = new BoardPanelMouseListener(r, c, referee.getPlayer());
|
||||
|
||||
//separate listener on each JLabel? This should probably be changed.
|
||||
board[r][c].addMouseListener(bpml);
|
||||
board[r][c].addMouseWheelListener(bpml);
|
||||
|
||||
add(board[r][c]);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user