-The rest of the game engine. I screwed up the commit last time.
This commit is contained in:
236
src/view/TileSelectionPanel.java
Normal file
236
src/view/TileSelectionPanel.java
Normal file
@@ -0,0 +1,236 @@
|
||||
package view;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.GridBagConstraints;
|
||||
import java.awt.GridBagLayout;
|
||||
import java.awt.Insets;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.awt.event.MouseListener;
|
||||
|
||||
import javax.security.auth.RefreshFailedException;
|
||||
import javax.security.auth.Refreshable;
|
||||
import javax.swing.BorderFactory;
|
||||
import javax.swing.ImageIcon;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JPanel;
|
||||
|
||||
import model.Board.TileColor;
|
||||
import model.Referee;
|
||||
|
||||
public class TileSelectionPanel extends JPanel implements Refreshable {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private final JLabel blue = new JLabel(new ImageIcon(BoardPanel.BLUE_ICON));
|
||||
private final JLabel green = new JLabel(
|
||||
new ImageIcon(BoardPanel.GREEN_ICON));
|
||||
private boolean isCurrent = true;
|
||||
private final JLabel red = new JLabel(new ImageIcon(BoardPanel.RED_ICON));
|
||||
private final Referee referee;
|
||||
private final JLabel yellow = new JLabel(new ImageIcon(
|
||||
BoardPanel.YELLOW_ICON));
|
||||
|
||||
public TileSelectionPanel(Referee ref) {
|
||||
referee = ref;
|
||||
|
||||
initLayout();
|
||||
initActions();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCurrent() {
|
||||
return isCurrent;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void refresh() throws RefreshFailedException {
|
||||
TileColor tile = referee.getPlayer().getColor();
|
||||
|
||||
blue.setBorder(BorderFactory.createEmptyBorder(3, 3, 3, 3));
|
||||
green.setBorder(BorderFactory.createEmptyBorder(3, 3, 3, 3));
|
||||
red.setBorder(BorderFactory.createEmptyBorder(3, 3, 3, 3));
|
||||
yellow.setBorder(BorderFactory.createEmptyBorder(3, 3, 3, 3));
|
||||
|
||||
switch (tile) {
|
||||
case GREEN:
|
||||
green.setBorder(BorderFactory.createLineBorder(Color.RED, 3));
|
||||
break;
|
||||
case RED:
|
||||
red.setBorder(BorderFactory.createLineBorder(Color.RED, 3));
|
||||
break;
|
||||
case YELLOW:
|
||||
yellow.setBorder(BorderFactory.createLineBorder(Color.RED, 3));
|
||||
break;
|
||||
default:
|
||||
blue.setBorder(BorderFactory.createLineBorder(Color.RED, 3));
|
||||
break;
|
||||
}
|
||||
|
||||
isCurrent = true;
|
||||
}
|
||||
|
||||
private void initActions() {
|
||||
blue.addMouseListener(new MouseListener() {
|
||||
@Override
|
||||
public void mouseClicked(MouseEvent arg0) {
|
||||
referee.getPlayer().setColor(TileColor.BLUE);
|
||||
isCurrent = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseEntered(MouseEvent arg0) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseExited(MouseEvent arg0) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mousePressed(MouseEvent arg0) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseReleased(MouseEvent arg0) {
|
||||
}
|
||||
});
|
||||
green.addMouseListener(new MouseListener() {
|
||||
@Override
|
||||
public void mouseClicked(MouseEvent arg0) {
|
||||
referee.getPlayer().setColor(TileColor.GREEN);
|
||||
isCurrent = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseEntered(MouseEvent arg0) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseExited(MouseEvent arg0) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mousePressed(MouseEvent arg0) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseReleased(MouseEvent arg0) {
|
||||
}
|
||||
});
|
||||
red.addMouseListener(new MouseListener() {
|
||||
@Override
|
||||
public void mouseClicked(MouseEvent arg0) {
|
||||
referee.getPlayer().setColor(TileColor.RED);
|
||||
isCurrent = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseEntered(MouseEvent arg0) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseExited(MouseEvent arg0) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mousePressed(MouseEvent arg0) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseReleased(MouseEvent arg0) {
|
||||
}
|
||||
});
|
||||
yellow.addMouseListener(new MouseListener() {
|
||||
@Override
|
||||
public void mouseClicked(MouseEvent arg0) {
|
||||
referee.getPlayer().setColor(TileColor.YELLOW);
|
||||
isCurrent = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseEntered(MouseEvent arg0) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseExited(MouseEvent arg0) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mousePressed(MouseEvent arg0) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseReleased(MouseEvent arg0) {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void initLayout() {
|
||||
GridBagLayout layout = new GridBagLayout();
|
||||
GridBagConstraints con;
|
||||
JLabel spacer1 = new JLabel();
|
||||
JLabel spacer2 = new JLabel();
|
||||
|
||||
con = new GridBagConstraints();
|
||||
con.gridheight = 1;
|
||||
con.gridwidth = 1;
|
||||
con.gridx = 0;
|
||||
con.gridy = 0;
|
||||
con.weightx = 1;
|
||||
layout.setConstraints(spacer1, con);
|
||||
|
||||
con = new GridBagConstraints();
|
||||
con.gridheight = 1;
|
||||
con.gridwidth = 1;
|
||||
con.gridx = 1;
|
||||
con.gridy = 0;
|
||||
con.insets = new Insets(5, 5, 5, 5);
|
||||
con.weightx = 0;
|
||||
layout.setConstraints(blue, con);
|
||||
|
||||
con = new GridBagConstraints();
|
||||
con.gridheight = 1;
|
||||
con.gridwidth = 1;
|
||||
con.gridx = 2;
|
||||
con.gridy = 0;
|
||||
con.insets = new Insets(5, 5, 5, 5);
|
||||
con.weightx = 0;
|
||||
layout.setConstraints(green, con);
|
||||
|
||||
con = new GridBagConstraints();
|
||||
con.gridheight = 1;
|
||||
con.gridwidth = 1;
|
||||
con.gridx = 3;
|
||||
con.gridy = 0;
|
||||
con.insets = new Insets(5, 5, 5, 5);
|
||||
con.weightx = 0;
|
||||
layout.setConstraints(red, con);
|
||||
|
||||
con = new GridBagConstraints();
|
||||
con.gridheight = 1;
|
||||
con.gridwidth = 1;
|
||||
con.gridx = 4;
|
||||
con.gridy = 0;
|
||||
con.insets = new Insets(5, 5, 5, 5);
|
||||
con.weightx = 0;
|
||||
layout.setConstraints(yellow, con);
|
||||
|
||||
con = new GridBagConstraints();
|
||||
con.gridheight = 1;
|
||||
con.gridwidth = 1;
|
||||
con.gridx = 5;
|
||||
con.gridy = 0;
|
||||
con.weightx = 1;
|
||||
layout.setConstraints(spacer2, con);
|
||||
|
||||
setLayout(layout);
|
||||
add(spacer1);
|
||||
add(blue);
|
||||
add(green);
|
||||
add(red);
|
||||
add(yellow);
|
||||
add(spacer2);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user