//
//  HumanHandPanel.java
//  cribbage
//
import javax.swing.*;
import javax.swing.border.*;
import java.awt.*;
import java.awt.event.*;

public class HumanHandPanel extends HandPanel implements MouseListener
{	
	Cribbage gameManager;
	
	// Constructor
	public HumanHandPanel(String name, Cribbage gameManager) {
		super(name);
		this.gameManager = gameManager;
		
		// Setup our layout
		BoxLayout mainLayout = new BoxLayout(this, BoxLayout.Y_AXIS);
		FlowLayout infoLayout = new FlowLayout(FlowLayout.RIGHT,0,0);
		FlowLayout handLayout = new FlowLayout(FlowLayout.CENTER,5,0);
		handFrame.setLayout(handLayout);
		infoFrame.setLayout(infoLayout);
		this.setLayout(mainLayout);
		this.setPreferredSize(new Dimension(380,125));
		scoreArea.setBorder(BorderFactory.createEmptyBorder(4,20,0,0));
		scoreArea.setFont(new Font("Helvitica",Font.PLAIN,12));
		noticeArea.setBorder(BorderFactory.createEmptyBorder(5,0,0,0));
		noticeArea.setFont(new Font("Helvitica",Font.PLAIN,10));
		infoFrame.add(noticeArea);
		infoFrame.add(scoreArea);
		add(infoFrame); 
		add(handFrame);
   }
   
	// Mutators
	public void putCard(Card playedCard) {	
		// Add the new card
		ImageIcon cardImage = CardGraphics.getCardGraphic(playedCard);
		cards[numCards] = new JLabel(cardImage);
		cards[numCards].setBorder(LineBorder.createBlackLineBorder());
		cards[numCards].addMouseListener(this);
		handFrame.add( cards[numCards] );
		numCards++;
	}
	
	public void disableCards() {
		for (int i=0; i < numCards; i++)
			cards[i].removeMouseListener(this);
	}
	
	public void enableCards() {
		for (int i=0; i < numCards; i++)
			cards[i].addMouseListener(this);
	}
	
	
	public void mouseClicked (MouseEvent e) {
		for (int i = 0; i < numCards; i++)
			if(e.getSource().equals(cards[i])) {
				gameManager.finishedSelection(i);
				break;
			}
	}
	
	public void mouseEntered (MouseEvent e) {}
	public void mouseExited (MouseEvent e) {}
	public void mousePressed (MouseEvent e) {}
	public void mouseReleased (MouseEvent e) {}
}