
import java.awt.Color;
import java.text.DecimalFormat;

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

/*
 * MyJPanel.java
 *
 * Created on 24-08-2011, 10:02:16 AM
 */
/**
 * Clase que crea panel con informacion de paneles solares 
 * @author Ariel
 */
public class PanelSolar extends javax.swing.JPanel {

    /** Crea panel de panel solar */
    public PanelSolar() {
        initComponents();
    }

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

        Title = new javax.swing.JLabel();
        PanelIcon = new javax.swing.JLabel();
        PowerLabel = new javax.swing.JLabel();
        PowerText = new javax.swing.JLabel();
        PowerPercentLabel = new javax.swing.JLabel();
        PowerPercentText = new javax.swing.JLabel();
        StateLabel = new javax.swing.JLabel();
        StateText = 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);

        Title.setFont(new java.awt.Font("Arial", 1, 18)); // NOI18N
        Title.setText("Panel Solar");
        add(Title);
        Title.setBounds(40, 10, 110, 40);

        PanelIcon.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resources/panel.jpg"))); // NOI18N
        add(PanelIcon);
        PanelIcon.setBounds(170, 10, 81, 40);

        PowerLabel.setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N
        PowerLabel.setText("Potencia Entregada:");
        add(PowerLabel);
        PowerLabel.setBounds(11, 60, 120, 15);

        PowerText.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        PowerText.setText("0.0 [W]");
        add(PowerText);
        PowerText.setBounds(137, 60, 65, 15);

        PowerPercentLabel.setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N
        PowerPercentLabel.setText("% Potencia Total:");
        add(PowerPercentLabel);
        PowerPercentLabel.setBounds(11, 81, 120, 15);

        PowerPercentText.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        PowerPercentText.setText("0.0 %");
        add(PowerPercentText);
        PowerPercentText.setBounds(137, 81, 65, 15);

        StateLabel.setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N
        StateLabel.setText("Estado Panel:");
        add(StateLabel);
        StateLabel.setBounds(11, 102, 120, 15);

        StateText.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        StateText.setForeground(new java.awt.Color(0, 140, 0));
        StateText.setText("Conectado");
        add(StateText);
        StateText.setBounds(137, 102, 90, 15);
    }
	
     /**
	* Actualiza valores mostrados por pantalla.
	* @param power Potencia entregada o recibida por la bateria. 
	* @param percent Porcentaje de potencia entregado por la bateria.
	* @param conected Estado de conexion de bateria.
	* @param level Nivel de carga bateria.
	*/	   
    public void updateValues(float power, float percent, boolean conected) {
        // Estado
        if (conected == false) {
            StateText.setText("Desconectada");
            StateText.setForeground(Color.red);
        }
        else {
            StateText.setText("Conectada");
            StateText.setForeground(new java.awt.Color(0, 140, 0)); //green
        }

        // Potencia
        PowerText.setText( power + " [W]");
        
        // Porcentaje potencia
        DecimalFormat format = new DecimalFormat("###.00");
        PowerPercentText.setText( format.format(percent) + " %");
    }
	// </editor-fold>//GEN-END:initComponents

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel PanelIcon;
    private javax.swing.JLabel PowerLabel;
    private javax.swing.JLabel PowerPercentLabel;
    private javax.swing.JLabel PowerPercentText;
    private javax.swing.JLabel PowerText;
    private javax.swing.JLabel StateLabel;
    private javax.swing.JLabel StateText;
    private javax.swing.JLabel Title;
    // End of variables declaration//GEN-END:variables
	
}
