/*
 * Created on 15.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.awt.LayoutManager;
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 ConditionChoosePanel extends JPanel {

    /**
     * 
     */
    
    private HashMap brick_images_;

    /**
     *  
     */
    private Image current_image_;

    private int internal_state_;

    public final static int NONE = 0;
    public final static int GREEN = 1;
    public final static int BLUE = 2;
    
    public final static int STATE_COUNT = 3;
    public ConditionChoosePanel(HashMap brick_images) {
        super();
        // TODO Auto-generated constructor stub
        brick_images_ = brick_images;
        this.setBackground(Color.green);
        internal_state_ = NONE;
        current_image_ = (Image) brick_images_.get("COND_NONE");
        this.setToolTipText("Anklicken um den Zustand zu ändern.");
        initMouseListener();
    }

    public int getInternalState() {
        return internal_state_;
    }

    public void paintComponent(Graphics g) {
        super.paintComponent(g);

        g.drawImage(current_image_, 0, 0, this);

    }

    private void initMouseListener() {
        this.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                internal_state_ = (( internal_state_+1 ) % STATE_COUNT);
                //System.out.println("Internal State: "+internal_state_ );
                switch( internal_state_ )
                {
                  case NONE :  current_image_ = (Image) brick_images_.get("COND_NONE"); break;
                  case BLUE :  current_image_ = (Image) brick_images_.get("COND_BLUE"); break;
                  case GREEN :  current_image_ = (Image) brick_images_.get("COND_GREEN"); break;
                  
                }
                ConditionChoosePanel.this.repaint();
            }
        });
    }

}
