/*
 * Created on 13.09.2004
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
package TUGLaby;



import java.awt.Color;
import java.awt.Graphics;
import java.awt.Image;
import java.util.HashMap;

import javax.swing.JPanel;

/**
 * @author user
 *
 * TODO To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
public class DirectionChoosePanel extends JPanel {
    private HashMap brick_images_;
    /**
     * 
     */
    private Image current_image_;
    private int internal_state_;
    public final static int UP = 1;
    public final static int RIGHT = 2;
    public final static int DOWN = 3;
    public final static int LEFT = 4;
    public final static int STATE_COUNT = 4;
    
    public DirectionChoosePanel( HashMap brick_images) {
        super();
        // TODO Auto-generated constructor stub
        brick_images_ = brick_images;
        internal_state_  = UP;
        current_image_ = (Image) brick_images_.get("ARROW_UP");
        initMouseListener();
    }
    public DirectionChoosePanel( HashMap brick_images, int init_state) {
        super();
        // TODO Auto-generated constructor stub
        brick_images_ = brick_images;
        setInternalState( init_state );

        initMouseListener();
    }
    public void paintComponent(Graphics g) {
        super.paintComponent(g);
       
        g.drawImage( current_image_, 0,0, this);
        
    }
    private void setInternalState( int new_state ) {
        
        if( (new_state >= UP) && (new_state <=LEFT))
            internal_state_ = new_state;
        paintState();
    }
    public int getInternalState()
    {
        return internal_state_;
    }
    private void paintState() {
        switch( internal_state_ )
        {
          case UP :  current_image_ = (Image) brick_images_.get("ARROW_UP"); break;
          case RIGHT :  current_image_ = (Image) brick_images_.get("ARROW_RIGHT"); break;
          case DOWN :  current_image_ = (Image) brick_images_.get("ARROW_DOWN"); break;
          case LEFT :  current_image_ = (Image) brick_images_.get("ARROW_LEFT"); break;
        }
        DirectionChoosePanel.this.repaint();
    }
    private void initMouseListener()
    {
      this.addMouseListener(new java.awt.event.MouseAdapter()
      {
        public void mouseClicked(java.awt.event.MouseEvent evt)
        { 
            internal_state_ = (( internal_state_++ ) % STATE_COUNT)+1;
            //System.out.println("Internal State: "+internal_state_ );
           paintState();
        }
      });
    }
}
