
import java.awt.Color;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * InfoPanel.java
 *
 * Created on 10-09-2011, 08:06:25 PM
 */
/**
 * Clase que crea panel con informacion general del vehiculo
 * @author USM
 */
public class InfoPanel extends javax.swing.JPanel {

    /** Crea panel de informacion */
    public InfoPanel() {
        initComponents();
    }

    /** Metodo llamado por el constructor para inicializar el panel.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        TitleText = new javax.swing.JLabel();
        SpeedLabel = new javax.swing.JLabel();
        BreakLabel = new javax.swing.JLabel();
        PowerLabel = new javax.swing.JLabel();
        StateText = new javax.swing.JLabel();
        SpeedText = new javax.swing.JLabel();
        PowerText = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();

        setBackground(new java.awt.Color(255, 255, 255));
        setMaximumSize(new java.awt.Dimension(260, 130));
        setMinimumSize(new java.awt.Dimension(260, 130));
        setPreferredSize(new java.awt.Dimension(260, 130));
        setLayout(null);

        TitleText.setFont(new java.awt.Font("Arial", 1, 18));
        TitleText.setText("Información General");
        add(TitleText);
        TitleText.setBounds(10, 10, 210, 30);

        SpeedLabel.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        SpeedLabel.setText("Velocidad:");
        add(SpeedLabel);
        SpeedLabel.setBounds(10, 79, 56, 15);

        BreakLabel.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        BreakLabel.setText("Freno Regenerativo:");
        add(BreakLabel);
        BreakLabel.setBounds(10, 100, 111, 15);

        PowerLabel.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        PowerLabel.setText("Potencia Recibida:");
        PowerLabel.setMaximumSize(new java.awt.Dimension(120, 15));
        add(PowerLabel);
        PowerLabel.setBounds(10, 58, 120, 15);

        StateText.setFont(new java.awt.Font("Tahoma", 0, 12));
        StateText.setForeground(new java.awt.Color(0, 140, 0));
        StateText.setText("Conectado");
        add(StateText);
        StateText.setBounds(130, 100, 80, 15);

        SpeedText.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        SpeedText.setText("0.0 [Km/h]");
        add(SpeedText);
        SpeedText.setBounds(130, 79, 80, 15);

        PowerText.setFont(new java.awt.Font("Tahoma", 0, 12));
        PowerText.setText("0.0 [W]");
        add(PowerText);
        PowerText.setBounds(130, 58, 70, 15);

        jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resources/info.png"))); // NOI18N
        add(jLabel1);
        jLabel1.setBounds(200, 10, 50, 50);
    }// </editor-fold>//GEN-END:initComponents

	// private void StateTextMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_StateTextMouseClicked
        // if(StateText.getText().equals("Conectado")) {
            // StateText.setText("Desconectado");
            // StateText.setForeground(Color.red);
        // }
        // else {
            // StateText.setText("Conectado");
            // StateText.setForeground(new java.awt.Color(0, 140, 0)); // Green
        // }
	// }//GEN-LAST:event_StateTextMouseClicked

	// private void SpeedTextMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_SpeedTextMouseClicked
		// Speed = Speed + 10;
		// SpeedText.setText( Speed + " [Km/h]");
	// }//GEN-LAST:event_SpeedTextMouseClicked

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel BreakLabel;
    private javax.swing.JLabel PowerLabel;
    private javax.swing.JLabel PowerText;
    private javax.swing.JLabel SpeedLabel;
    private javax.swing.JLabel SpeedText;
    private javax.swing.JLabel StateText;
    private javax.swing.JLabel TitleText;
    private javax.swing.JLabel jLabel1;
    // End of variables declaration//GEN-END:variables
    private int Speed;
    /**
	* Actualiza valores mostrados por pantalla.
	* @param power Potencia entregada o recibida por motor. 
	* @param speed Velocidad instantanea de vehiculo.
	* @param conected Estado de conexion.
	*/	
    public void updateValues(float power, float speed, boolean conected) {
        // Estado
        if (conected == false) {
            StateText.setText("Desconectado");
            StateText.setForeground(Color.red);
        }
        else {
            StateText.setText("Conectado");
            StateText.setForeground(new java.awt.Color(0, 140, 0)); //green
        }
        
        // Velocidad
        SpeedText.setText( speed + " [Km/h]");
        
        // Potencia
        if (power > 0)
            PowerLabel.setText("Potencia Recibida: ");
        else
            PowerLabel.setText("Potencia Entregada:");
        
        PowerText.setText( Math.abs(power) + " [W]");
    }

}
