/*
 * Created on 02.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.util.HashMap;

import javax.swing.JLabel;
import javax.swing.JPanel;

import PrintGame.Action;

/**
 * @author auguan@sbox
 *
 * TODO To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
public class ActionRulePanel extends JPanel {

    private DirectionChoosePanel dir_choose_panel_ ;
    private CurrentSensorPanel sensor_panel_;
    private ConditionChoosePanel cond_panel_;
    /**
     * 
     */
    public ActionRulePanel() {
        super();
        // TODO Auto-generated constructor stub
    }
    public ActionRulePanel( String header, HashMap brick_images ) {
     
       
       
        dir_choose_panel_ = new DirectionChoosePanel( brick_images );
       sensor_panel_ = new CurrentSensorPanel( brick_images );
       cond_panel_ = new ConditionChoosePanel( brick_images );
       initComponents();
     

    }
    public ActionRulePanel(String header, HashMap brick_images, int preset_direction,
                                                                int preset_current_sensor,
                                                                int preset_state) {
        System.out.println(">>"+preset_direction+"-"+preset_current_sensor+"-"+preset_state);
        dir_choose_panel_ = new DirectionChoosePanel( brick_images, preset_direction );
        sensor_panel_ = new CurrentSensorPanel( brick_images, preset_current_sensor );
        cond_panel_ = new ConditionChoosePanel( brick_images,preset_state );
        initComponents();
        
    }
    
    private void initComponents() {
        JLabel top_label = new JLabel();
        JLabel info_label = new JLabel();
        
        this.setLayout( null );
        this.add( top_label );
        this.add( info_label );
        this.add( dir_choose_panel_ );
        this.add( sensor_panel_ );
        this.add( cond_panel_);
        top_label.setText( "Robotersteuerung:" );
        top_label.setForeground( Color.white );
        top_label.setBounds(5,2,150,15);    
        info_label.setText( "Gehe:" );
        info_label.setBounds(10,20,140,20);
        info_label.setForeground(Color.white);
        dir_choose_panel_.setBounds(50,20,20,20);
        sensor_panel_.setBounds( 75,20,20,20);
        cond_panel_.setBounds( 100,25,30,15);
        this.setBackground( Color.DARK_GRAY );
        this.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED));
        
        repaint();
    }
    
    public Action getAction()
    {
        // FIXXXXXXXXXXXXXXXXXXXXXXXXXXXME
        // Achtung im Moment wird die Direction falsch !!! übergeben
        // absolute vs relative richtung !!!
        // Da ich die aktuelle Direction nicht auslesen kann ! das ist ja dynamisch!
        // Wie soll das gelösst werden z.B. Pfeil nach oben == richtung beibehalten usw
//        public final static int MOVE_AHEAD = 1;
//        public final static int MOVE_BACK  = 2;
//        public final static int MOVE_LEFT  = 3;
//        public final static int MOVE_RIGHT = 4;
        int direction=0;
        switch(dir_choose_panel_.getInternalState())
        {
          case DirectionChoosePanel.UP : direction = Action.MOVE_AHEAD;break;
          case DirectionChoosePanel.RIGHT : direction = Action.MOVE_RIGHT;break;
          case DirectionChoosePanel.LEFT : direction = Action.MOVE_LEFT;break;
          case DirectionChoosePanel.DOWN : direction = Action.MOVE_BACK;
        }
        
        Action ret_action = new Action( cond_panel_.getInternalState(),
                                        sensor_panel_.getInternalState(),
                                        direction);
        return ret_action;
        
    }
//  Start MouseListener interface ***********************************************************  
// muss hier noch den DropListener Einbauen !!! scheiße
//  End MouseListener interface ***********************************************************  
  
}
