/*
 * PainelFerramentaAgentes.java
 *
 * Created on 28 de Novembro de 2008, 05:38
 */
package ambienteGrafico.componentes;

import algoritmo.Agente;
import algoritmo.ConjuntoDeAgentes;
import algoritmo.EspacoDeBusca;
import algoritmo.Sensor;

import algoritmo.SensorDeVizinhanca;
import algoritmo.SensorFotografico;
import ambienteGrafico.ferramentas.FerramentaInserirAgente;
import ambienteGrafico.ferramentas.FerramentaSelecionarAgente;
import auxiliar.Conversor;
import java.awt.image.BufferedImage;
import java.text.DecimalFormat;
import java.util.Vector;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JTextField;

/**
 *
 * @author  Marília
 */
public class PainelFerramentaAgentes extends MeuPainel {//javax.swing.JPanel {

    private Canvas canvas = null;

    //Possiveis Listeners para o canvas:
    private FerramentaInserirAgente ferramentaInserirAgente = null;
    private FerramentaSelecionarAgente ferramentaSelecionarAgente = null;

    /** Creates new form PainelFerramentaAgentes */
    public PainelFerramentaAgentes(Canvas canvas) {
        super.mudarLookAndFeel();
        initComponents();
        this.canvas = canvas;
        inicializarListeners();
    }

    private void inicializarListeners() {
        ferramentaInserirAgente = new FerramentaInserirAgente(this);
        ferramentaSelecionarAgente = new FerramentaSelecionarAgente(this);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        pn_velocConfig = new javax.swing.JPanel();
        jPanel1 = new MeuPainel();
        bt_InserirAgente = new MyJButton(); ;
        bt_SelecionarAgente = new MyJButton(); ;
        pn_AtributosAgente = new javax.swing.JPanel();
        lb_IdAgente = new javax.swing.JLabel();
        tf_IdAgente = new javax.swing.JTextField();
        lb_Posicao = new javax.swing.JLabel();
        tf_Posicao = new javax.swing.JTextField();
        lb_VelocPolar = new javax.swing.JLabel();
        tf_VelocPolar = new javax.swing.JTextField();
        lb_VelocCart = new javax.swing.JLabel();
        tf_VelocCart = new javax.swing.JTextField();
        lb_TamanhoAgente = new javax.swing.JLabel();
        tf_TamanhoAgente = new javax.swing.JTextField();
        lb_raioCurvaMax = new javax.swing.JLabel();
        tf_raioCurvaMax = new javax.swing.JTextField();
        lb_RotuloMetrosRaioCurvaMax = new javax.swing.JLabel();
        chb_MostrarTrajetoria = new javax.swing.JCheckBox();
        jPanel3 = new javax.swing.JPanel();
        tb_NumSolucoesParaCompartilhar = new javax.swing.JLabel();
        tf_NumSolucoesParaComunicar = new javax.swing.JTextField();
        bt_NumSolucoesParaCompartilhar = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        tf_MemoriaSolucoes = new javax.swing.JTextField();
        bt_MemoriaSolucoes = new javax.swing.JButton();
        jPanel2 = new javax.swing.JPanel();
        cb_Sensor = new javax.swing.JComboBox();
        lb_AlcanceSensor = new javax.swing.JLabel();
        tf_AlcanceSensor = new javax.swing.JTextField();
        lb_RotuloMetrosAlcanceSensor = new javax.swing.JLabel();
        chb_MostrarSensor = new javax.swing.JCheckBox();
        bt_AtribuirSensor = new javax.swing.JButton();
        bt_MostrarVizinhos = new javax.swing.JButton();
        bt_AtribuirATodosAgentes = new javax.swing.JButton();
        bt_ConstruirMapa = new javax.swing.JButton();

        setPreferredSize(new java.awt.Dimension(200, 300));
        setLayout(null);

        pn_velocConfig.setBackground(new java.awt.Color(153, 153, 255));
        pn_velocConfig.setLayout(new java.awt.CardLayout());
        add(pn_velocConfig);
        pn_velocConfig.setBounds(0, 0, 0, 0);

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Objetos e Marcações", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 0, 11), new java.awt.Color(0, 0, 0))); // NOI18N
        jPanel1.setPreferredSize(new java.awt.Dimension(200, 100));

        bt_InserirAgente.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagens/IconePrincipalAgente.gif"))); // NOI18N
        bt_InserirAgente.setToolTipText("Adicionar Alvo");
        bt_InserirAgente.setIconTextGap(0);
        bt_InserirAgente.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bt_InserirAgenteActionPerformed(evt);
            }
        });

        bt_SelecionarAgente.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagens/IconeSelecionar.gif"))); // NOI18N
        bt_SelecionarAgente.setToolTipText("Selecionar Agente");
        bt_SelecionarAgente.setIconTextGap(0);
        bt_SelecionarAgente.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bt_SelecionarAgenteActionPerformed(evt);
            }
        });

        org.jdesktop.layout.GroupLayout jPanel1Layout = new org.jdesktop.layout.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel1Layout.createSequentialGroup()
                .add(bt_InserirAgente, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 28, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(bt_SelecionarAgente, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 31, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .add(119, 119, 119))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel1Layout.createSequentialGroup()
                .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)
                    .add(bt_InserirAgente, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 28, Short.MAX_VALUE)
                    .add(bt_SelecionarAgente, 0, 28, Short.MAX_VALUE))
                .add(42, 42, 42))
        );

        add(jPanel1);
        jPanel1.setBounds(0, 0, 150, 60);

        pn_AtributosAgente.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Atributos do Agente", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 0, 11), new java.awt.Color(0, 0, 0))); // NOI18N
        pn_AtributosAgente.setLayout(null);

        lb_IdAgente.setText("Id:");
        pn_AtributosAgente.add(lb_IdAgente);
        lb_IdAgente.setBounds(10, 20, 60, 20);

        tf_IdAgente.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                tf_IdAgenteFocusGained(evt);
            }
        });
        pn_AtributosAgente.add(tf_IdAgente);
        tf_IdAgente.setBounds(80, 20, 65, 20);

        lb_Posicao.setText("Posicao:");
        pn_AtributosAgente.add(lb_Posicao);
        lb_Posicao.setBounds(10, 40, 60, 20);

        tf_Posicao.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                tf_PosicaoFocusGained(evt);
            }
        });
        pn_AtributosAgente.add(tf_Posicao);
        tf_Posicao.setBounds(80, 40, 65, 20);

        lb_VelocPolar.setText("Veloc Polar:");
        pn_AtributosAgente.add(lb_VelocPolar);
        lb_VelocPolar.setBounds(10, 100, 56, 20);

        tf_VelocPolar.setText("(0,0°)");
        tf_VelocPolar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                tf_VelocPolarActionPerformed(evt);
            }
        });
        tf_VelocPolar.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                tf_VelocPolarFocusGained(evt);
            }
        });
        pn_AtributosAgente.add(tf_VelocPolar);
        tf_VelocPolar.setBounds(80, 100, 65, 20);

        lb_VelocCart.setText("Veloc Cart:");
        pn_AtributosAgente.add(lb_VelocCart);
        lb_VelocCart.setBounds(10, 120, 60, 20);

        tf_VelocCart.setText("(0,0)");
        tf_VelocCart.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                tf_VelocCartActionPerformed(evt);
            }
        });
        tf_VelocCart.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                tf_VelocCartFocusGained(evt);
            }
        });
        pn_AtributosAgente.add(tf_VelocCart);
        tf_VelocCart.setBounds(80, 120, 65, 20);

        lb_TamanhoAgente.setText("Tamanho:");
        pn_AtributosAgente.add(lb_TamanhoAgente);
        lb_TamanhoAgente.setBounds(10, 60, 60, 20);

        tf_TamanhoAgente.setText("(0,0)");
        tf_TamanhoAgente.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                tf_TamanhoAgenteActionPerformed(evt);
            }
        });
        pn_AtributosAgente.add(tf_TamanhoAgente);
        tf_TamanhoAgente.setBounds(80, 60, 65, 20);

        lb_raioCurvaMax.setText("Raio Curva Max:");
        pn_AtributosAgente.add(lb_raioCurvaMax);
        lb_raioCurvaMax.setBounds(10, 80, 80, 20);

        tf_raioCurvaMax.setText("2");
        pn_AtributosAgente.add(tf_raioCurvaMax);
        tf_raioCurvaMax.setBounds(90, 80, 30, 20);

        lb_RotuloMetrosRaioCurvaMax.setText("m");
        pn_AtributosAgente.add(lb_RotuloMetrosRaioCurvaMax);
        lb_RotuloMetrosRaioCurvaMax.setBounds(120, 80, 10, 20);

        chb_MostrarTrajetoria.setSelected(true);
        chb_MostrarTrajetoria.setText("Mostrar Trajetória");
        chb_MostrarTrajetoria.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                chb_MostrarTrajetoriaActionPerformed(evt);
            }
        });
        pn_AtributosAgente.add(chb_MostrarTrajetoria);
        chb_MostrarTrajetoria.setBounds(10, 380, 120, 23);

        jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Comunicação", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 0, 11), new java.awt.Color(0, 0, 0))); // NOI18N

        tb_NumSolucoesParaCompartilhar.setText("Nº Solu.");

        tf_NumSolucoesParaComunicar.setText("10");

        bt_NumSolucoesParaCompartilhar.setText("ok");
        bt_NumSolucoesParaCompartilhar.setToolTipText("número de soluções para compartilhar");
        bt_NumSolucoesParaCompartilhar.setMargin(new java.awt.Insets(2, 4, 2, 4));
        bt_NumSolucoesParaCompartilhar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bt_NumSolucoesParaCompartilharActionPerformed(evt);
            }
        });

        jLabel1.setText("Memoria");

        bt_MemoriaSolucoes.setText("Show");
        bt_MemoriaSolucoes.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bt_MemoriaSolucoesActionPerformed(evt);
            }
        });

        org.jdesktop.layout.GroupLayout jPanel3Layout = new org.jdesktop.layout.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel3Layout.createSequentialGroup()
                .add(jPanel3Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jLabel1)
                    .add(tb_NumSolucoesParaCompartilhar))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jPanel3Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(tf_NumSolucoesParaComunicar, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 37, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(tf_MemoriaSolucoes, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 37, Short.MAX_VALUE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jPanel3Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)
                    .add(bt_MemoriaSolucoes, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 28, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(bt_NumSolucoesParaCompartilhar, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 28, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .add(22, 22, 22))
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel3Layout.createSequentialGroup()
                .add(jPanel3Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(tb_NumSolucoesParaCompartilhar)
                    .add(tf_NumSolucoesParaComunicar, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 22, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(bt_NumSolucoesParaCompartilhar))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .add(jPanel3Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel1)
                    .add(tf_MemoriaSolucoes, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(bt_MemoriaSolucoes)))
        );

        pn_AtributosAgente.add(jPanel3);
        jPanel3.setBounds(10, 140, 130, 80);

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Sensores", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 0, 11), new java.awt.Color(0, 0, 0))); // NOI18N

        String[] stringSensorComboBox = new String[] { "Sensor de Vizinhança", "Sensor Fotografico","Sensor AntiColisao" };
        cb_Sensor.setModel(new javax.swing.DefaultComboBoxModel(stringSensorComboBox));
        cb_Sensor.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cb_SensorActionPerformed(evt);
            }
        });

        lb_AlcanceSensor.setText("Diâmetro:");

        tf_AlcanceSensor.setText("200");

        lb_RotuloMetrosAlcanceSensor.setText("m");

        chb_MostrarSensor.setText("Mostrar Sensor ");
        chb_MostrarSensor.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                chb_MostrarSensorActionPerformed(evt);
            }
        });

        bt_AtribuirSensor.setText("Atribuir");
        bt_AtribuirSensor.setMargin(new java.awt.Insets(2, 2, 2, 2));
        bt_AtribuirSensor.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bt_AtribuirSensorActionPerformed(evt);
            }
        });

        bt_MostrarVizinhos.setText("Vizinhos");
        bt_MostrarVizinhos.setIconTextGap(0);
        bt_MostrarVizinhos.setMargin(new java.awt.Insets(2, 2, 2, 2));
        bt_MostrarVizinhos.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bt_MostrarVizinhosActionPerformed(evt);
            }
        });

        bt_AtribuirATodosAgentes.setText("Todos");
        bt_AtribuirATodosAgentes.setIconTextGap(0);
        bt_AtribuirATodosAgentes.setMargin(new java.awt.Insets(2, 2, 2, 2));
        bt_AtribuirATodosAgentes.setMinimumSize(new java.awt.Dimension(10, 23));
        bt_AtribuirATodosAgentes.setPreferredSize(new java.awt.Dimension(20, 23));
        bt_AtribuirATodosAgentes.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bt_AtribuirATodosAgentesActionPerformed(evt);
            }
        });

        bt_ConstruirMapa.setText("Mapa");
        bt_ConstruirMapa.setMargin(new java.awt.Insets(2, 4, 2, 4));
        bt_ConstruirMapa.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bt_ConstruirMapaActionPerformed(evt);
            }
        });

        org.jdesktop.layout.GroupLayout jPanel2Layout = new org.jdesktop.layout.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel2Layout.createSequentialGroup()
                .add(jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jPanel2Layout.createSequentialGroup()
                        .add(lb_AlcanceSensor)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(tf_AlcanceSensor, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 40, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(lb_RotuloMetrosAlcanceSensor))
                    .add(chb_MostrarSensor)
                    .add(cb_Sensor, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 114, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(jPanel2Layout.createSequentialGroup()
                        .add(jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(bt_AtribuirSensor, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 50, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                            .add(bt_MostrarVizinhos, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 60, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(bt_ConstruirMapa, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 48, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                            .add(bt_AtribuirATodosAgentes, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 48, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))))
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel2Layout.createSequentialGroup()
                .add(cb_Sensor, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(lb_AlcanceSensor)
                    .add(tf_AlcanceSensor, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(lb_RotuloMetrosAlcanceSensor))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(chb_MostrarSensor)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(bt_AtribuirSensor)
                    .add(bt_AtribuirATodosAgentes, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(bt_MostrarVizinhos)
                    .add(bt_ConstruirMapa))
                .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pn_AtributosAgente.add(jPanel2);
        jPanel2.setBounds(10, 220, 130, 160);

        add(pn_AtributosAgente);
        pn_AtributosAgente.setBounds(0, 60, 150, 530);
    }// </editor-fold>//GEN-END:initComponents

    private void bt_ConstruirMapaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bt_ConstruirMapaActionPerformed
       if (!tf_IdAgente.getText().equalsIgnoreCase("")) {

        EspacoDeBusca espacoDeBusca = EspacoDeBusca.getInstance();
        ConjuntoDeAgentes conjuntoDeAgentes = espacoDeBusca.getAgentes();
        double alcanceSensor = Double.parseDouble(tf_AlcanceSensor.getText());

        int agenteId = Integer.parseInt(tf_IdAgente.getText());

        Agente agente = conjuntoDeAgentes.get(agenteId);
        BufferedImage mapa = ((SensorFotografico)agente.getSensorFitness()).construirMapa();
        JOptionPane.showMessageDialog(this.getParent().getParent(), new javax.swing.ImageIcon(mapa),null,JOptionPane.PLAIN_MESSAGE,null);
    }
}//GEN-LAST:event_bt_ConstruirMapaActionPerformed

    private void chb_MostrarSensorActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_chb_MostrarSensorActionPerformed
        EspacoDeBusca espacoDeBusca = EspacoDeBusca.getInstance();
        ConjuntoDeAgentes conjuntoDeAgentes = espacoDeBusca.getAgentes();
        Sensor sensor;
        boolean mostrarSensor = chb_MostrarSensor.isSelected();
        Agente agente;
        for (int k = 0; k < conjuntoDeAgentes.getNumAgentes(); k++) {
            agente = conjuntoDeAgentes.get(k);
            sensor = agente.getSensorDeVizinhanca();
            sensor.setMostrarSensor(mostrarSensor);

            sensor = agente.getSensorFitness();
            sensor.setMostrarSensor(mostrarSensor);

            sensor = agente.getSensorAntiColisao();
            sensor.setMostrarSensor(mostrarSensor);

        }
    }//GEN-LAST:event_chb_MostrarSensorActionPerformed

private void tf_VelocPolarFocusGained(java.awt.event.FocusEvent evt) {                                  
                                        
    /*pn_velocConfig.setVisible(true);
    pn_VelocPolarConfig.setVisible(true);
    pn_VelocCartConfig.setVisible(false);
    System.out.println("Esconde lpn_velocCartConfig");*/
}                                                        
                   

private void tf_VelocCartFocusGained(java.awt.event.FocusEvent evt) {                                         
    /*pn_velocConfig.setVisible(true);
    pn_VelocPolarConfig.setVisible(false);
    pn_VelocCartConfig.setVisible(true);
    System.out.println("Esconde lpn_velocPolarConfig");*/
}                                        

private void tf_IdAgenteFocusGained(java.awt.event.FocusEvent evt) {                                        
    /*pn_velocConfig.setVisible(false);
    pn_VelocPolarConfig.setVisible(false);
    pn_VelocCartConfig.setVisible(false);
    System.out.println("Esconde pn_velocConfig");*/
}                                       

private void tf_PosicaoFocusGained(java.awt.event.FocusEvent evt) {                                       
    /*pn_velocConfig.setVisible(false);
    pn_VelocPolarConfig.setVisible(false);
    pn_VelocCartConfig.setVisible(false);
    System.out.println("Esconde pn_velocConfig");*/
}                                      

private void tf_VelocPolarActionPerformed(java.awt.event.ActionEvent evt) {                                              
    //Ação ao apertar enter no componente tf_VelocPolar
    boolean atualizaCoord1 = false;
    boolean atualizaCoord2 = false;
    String texto = tf_VelocPolar.getText();
    if (texto.contains(",") && texto.contains("(") && texto.contains("°)")) {

        String[] temp = texto.split(",");
        String mod = temp[0].substring(1);
        String[] ang = temp[1].split("°");
        int valorModulo = Integer.parseInt(mod);
        int valorAngulo = Integer.parseInt(ang[0]);

     


        //Atualiza as coordenadas cartesianas
        if (atualizaCoord1 && atualizaCoord2) {
            //Cria onjetos DecimalFormat para fazer com que apareça apenas 2 casas decimais na GUI
            DecimalFormat df_vx = new DecimalFormat("#.##");
            DecimalFormat df_vy = new DecimalFormat("#.##");
            double vx = valorModulo * Math.cos(Math.toRadians(valorAngulo));
            double vy = valorModulo * Math.sin(Math.toRadians(valorAngulo));
            int vxInt = (int) vx;
            int vyInt = (int) vy;
          
            tf_VelocCart.setText("(" + df_vx.format(vx) + "," + df_vy.format(vy) + ")");
        }

    } else {
        JOptionPane.showMessageDialog(pn_velocConfig, "Entrada mal formatada!\n" +
                "A entrada deve seguir o padrão: (mod,ang°)");
    }
}                                             

private void tf_VelocCartActionPerformed(java.awt.event.ActionEvent evt) {                                             
    //Ação ao apertar enter no componente tf_VelocCart
    boolean atualizaCoordPolar = false;

    String texto = tf_VelocCart.getText();
    if (texto.contains(",") && texto.contains("(") && texto.contains(")")) {

        String[] temp = texto.split(",");
        String vx = temp[0].substring(1);
        String vy = temp[1].substring(0, temp[1].length() - 1);
        int valorVx = Integer.parseInt(vx);
        int valorVy = Integer.parseInt(vy);

        double[] velocPolar = Conversor.coordCartesianaParaPolar(valorVx, valorVy);
        double moduloV = velocPolar[0];
        double anguloV = velocPolar[1];
        System.out.println("valorVy: " + valorVy + "  valorVx: " + valorVx);
        System.out.println("anguloV: " + anguloV);


      
        //Atualiza as coordenadas polares
        if (atualizaCoordPolar) {
            int mod = (int) moduloV;
            int ang = (int) anguloV;
           
            tf_VelocPolar.setText("(" + mod + "," + ang + "°)");
        }

    } else {
        JOptionPane.showMessageDialog(pn_velocConfig, "Entrada mal formatada!\n" +
                "A entrada deve seguir o padrão: (Vx,Vy)");
    }
}                                            

private void bt_InserirAgenteActionPerformed(java.awt.event.ActionEvent evt) {                                                 
    double[] tamanhoPadraoAgente = {16, 16};////////////////////////////////////
    double[] velocidadePadraoAgente = {5, 0};// 5m/s e 0º
    ferramentaInserirAgente.setTamanhoPadraoAgente(tamanhoPadraoAgente);
    ferramentaInserirAgente.setVelocidadePolarPadraoAgente(velocidadePadraoAgente);
    this.canvas.mudarFerramenta(ferramentaInserirAgente);
}                                                

private void bt_SelecionarAgenteActionPerformed(java.awt.event.ActionEvent evt) {                                                    
    this.canvas.mudarFerramenta(ferramentaSelecionarAgente);
}                                                   

private void tf_TamanhoAgenteActionPerformed(java.awt.event.ActionEvent evt) {                                                 
    // TODO add your handling code here:
}                                                

private void bt_AtribuirSensorActionPerformed(java.awt.event.ActionEvent evt) {                                                  

    if (!tf_IdAgente.getText().equalsIgnoreCase("")) {

        EspacoDeBusca espacoDeBusca = EspacoDeBusca.getInstance();
        ConjuntoDeAgentes conjuntoDeAgentes = espacoDeBusca.getAgentes();
        double alcanceSensor = Double.parseDouble(tf_AlcanceSensor.getText());

        int agenteId = Integer.parseInt(tf_IdAgente.getText());

        Sensor sensor;
        if (cb_Sensor.getSelectedIndex() == 0) {//Sensor de Vizinhança
            sensor = conjuntoDeAgentes.get(agenteId).getSensorDeVizinhanca();
            sensor.setMostrarSensor(chb_MostrarSensor.isSelected());
            sensor.setSensorDiametro(alcanceSensor);
        }
        if (cb_Sensor.getSelectedIndex() == 1) {
            sensor = conjuntoDeAgentes.get(agenteId).getSensorFitness();
            sensor.setMostrarSensor(chb_MostrarSensor.isSelected());
            sensor.setSensorDiametro(alcanceSensor);
        }
        if (cb_Sensor.getSelectedIndex() == 2) {
            sensor = conjuntoDeAgentes.get(agenteId).getSensorAntiColisao();
            sensor.setMostrarSensor(chb_MostrarSensor.isSelected());
            sensor.setSensorDiametro(alcanceSensor);
        }
    }


}                                                 

private void cb_SensorActionPerformed(java.awt.event.ActionEvent evt) {                                          
    if (!tf_IdAgente.getText().equalsIgnoreCase("")) {
        EspacoDeBusca espacoDeBusca = EspacoDeBusca.getInstance();
        ConjuntoDeAgentes conjuntoDeAgentes = espacoDeBusca.getAgentes();
        int agenteId = Integer.parseInt(tf_IdAgente.getText());
        Sensor sensor;

        if (cb_Sensor.getSelectedIndex() == 0) {//Sensor de Vizinhança
            sensor = conjuntoDeAgentes.get(agenteId).getSensorDeVizinhanca();
            tf_AlcanceSensor.setText(sensor.getSensorDiametro() + "");

        }
        if (cb_Sensor.getSelectedIndex() == 1) {

            sensor = conjuntoDeAgentes.get(agenteId).getSensorFitness();
            tf_AlcanceSensor.setText(sensor.getSensorDiametro() + "");

        }
        if (cb_Sensor.getSelectedIndex() == 2) {

            sensor = conjuntoDeAgentes.get(agenteId).getSensorAntiColisao();
            tf_AlcanceSensor.setText(sensor.getSensorDiametro() + "");

        }
    }
}                                         

private void bt_AtribuirATodosAgentesActionPerformed(java.awt.event.ActionEvent evt) {                                                         
    EspacoDeBusca espacoDeBusca = EspacoDeBusca.getInstance();
    ConjuntoDeAgentes conjuntoDeAgentes = espacoDeBusca.getAgentes();
    double alcanceSensor = Double.parseDouble(tf_AlcanceSensor.getText());

    Sensor sensor;
    for (int k = 0; k < conjuntoDeAgentes.getNumAgentes(); k++) {
        if (cb_Sensor.getSelectedIndex() == 0) {//Sensor de Vizinhança
            sensor = conjuntoDeAgentes.get(k).getSensorDeVizinhanca();
            sensor.setMostrarSensor(chb_MostrarSensor.isSelected());
            sensor.setSensorDiametro(alcanceSensor);
        }
        if (cb_Sensor.getSelectedIndex() == 1) {
            sensor = conjuntoDeAgentes.get(k).getSensorFitness();
            sensor.setMostrarSensor(chb_MostrarSensor.isSelected());
            sensor.setSensorDiametro(alcanceSensor);
        }
        if (cb_Sensor.getSelectedIndex() == 2) {
            sensor = conjuntoDeAgentes.get(k).getSensorAntiColisao();
            sensor.setMostrarSensor(chb_MostrarSensor.isSelected());
            sensor.setSensorDiametro(alcanceSensor);
        }
    }
}                                                        

private void bt_MostrarVizinhosActionPerformed(java.awt.event.ActionEvent evt) {                                                   
    if (!tf_IdAgente.getText().equalsIgnoreCase("")) {

        EspacoDeBusca espacoDeBusca = EspacoDeBusca.getInstance();
        ConjuntoDeAgentes conjuntoDeAgentes = espacoDeBusca.getAgentes();
        int agenteId = Integer.parseInt(tf_IdAgente.getText());
        SensorDeVizinhanca sensorDeVizinhanca = conjuntoDeAgentes.get(agenteId).getSensorDeVizinhanca();
        double[] posicao = conjuntoDeAgentes.get(agenteId).getPosicao();
        ConjuntoDeAgentes idsVizinhos = sensorDeVizinhanca.sensorResponse(posicao);
        StringBuffer vizinhos = new StringBuffer();
        vizinhos.append("Vizinhos do agente ");
        vizinhos.append(agenteId);
        vizinhos.append(":\n");
        for (int v = 0; v < idsVizinhos.getNumAgentes(); v++) {
            vizinhos.append("id: ");
            vizinhos.append(idsVizinhos.get(v).getIdAgente());
            vizinhos.append("\n");
        }
         System.out.println(vizinhos);
        JOptionPane.showMessageDialog(this.getParent().getParent().getParent(), vizinhos);
    }
}                                                  

private void chb_MostrarTrajetoriaActionPerformed(java.awt.event.ActionEvent evt) {                                                      
    
        EspacoDeBusca espacoDeBusca = EspacoDeBusca.getInstance();
        ConjuntoDeAgentes conjuntoDeAgentes = espacoDeBusca.getAgentes();
        Agente agente;
        for(int i = 0;i<conjuntoDeAgentes.getNumAgentes();i++){
            agente = conjuntoDeAgentes.get(i);
            agente.setMostrarTrajetoria(chb_MostrarTrajetoria.isSelected());
        }
       
}                                                     

private void bt_NumSolucoesParaCompartilharActionPerformed(java.awt.event.ActionEvent evt) {                                                               
        EspacoDeBusca espacoDeBusca = EspacoDeBusca.getInstance();
        ConjuntoDeAgentes conjuntoDeAgentes = espacoDeBusca.getAgentes();
        Agente agente;
        int numero = Integer.parseInt(tf_NumSolucoesParaComunicar.getText());
        for(int i = 0;i<conjuntoDeAgentes.getNumAgentes();i++){
            agente = conjuntoDeAgentes.get(i);
            agente.setNumeroMaxDeSolucoesParaTransmitir(numero);
        }
}                                                              

private void bt_MemoriaSolucoesActionPerformed(java.awt.event.ActionEvent evt) {
     if (!tf_IdAgente.getText().equalsIgnoreCase("")) {
        EspacoDeBusca espacoDeBusca = EspacoDeBusca.getInstance();
        ConjuntoDeAgentes conjuntoDeAgentes = espacoDeBusca.getAgentes();
        int agenteId = Integer.parseInt(tf_IdAgente.getText());
        int tamMemoria = conjuntoDeAgentes.get(agenteId).getMemoriaDeSolucoes().getNumSolucoes();
        tf_MemoriaSolucoes.setText(tamMemoria+"");
     }
}

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton bt_AtribuirATodosAgentes;
    private javax.swing.JButton bt_AtribuirSensor;
    private javax.swing.JButton bt_ConstruirMapa;
    private javax.swing.JButton bt_InserirAgente;
    private javax.swing.JButton bt_MemoriaSolucoes;
    private javax.swing.JButton bt_MostrarVizinhos;
    private javax.swing.JButton bt_NumSolucoesParaCompartilhar;
    private javax.swing.JButton bt_SelecionarAgente;
    private javax.swing.JComboBox cb_Sensor;
    private javax.swing.JCheckBox chb_MostrarSensor;
    private javax.swing.JCheckBox chb_MostrarTrajetoria;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JLabel lb_AlcanceSensor;
    private javax.swing.JLabel lb_IdAgente;
    private javax.swing.JLabel lb_Posicao;
    private javax.swing.JLabel lb_RotuloMetrosAlcanceSensor;
    private javax.swing.JLabel lb_RotuloMetrosRaioCurvaMax;
    private javax.swing.JLabel lb_TamanhoAgente;
    private javax.swing.JLabel lb_VelocCart;
    private javax.swing.JLabel lb_VelocPolar;
    private javax.swing.JLabel lb_raioCurvaMax;
    private javax.swing.JPanel pn_AtributosAgente;
    private javax.swing.JPanel pn_velocConfig;
    private javax.swing.JLabel tb_NumSolucoesParaCompartilhar;
    private javax.swing.JTextField tf_AlcanceSensor;
    private javax.swing.JTextField tf_IdAgente;
    private javax.swing.JTextField tf_MemoriaSolucoes;
    private javax.swing.JTextField tf_NumSolucoesParaComunicar;
    private javax.swing.JTextField tf_Posicao;
    private javax.swing.JTextField tf_TamanhoAgente;
    private javax.swing.JTextField tf_VelocCart;
    private javax.swing.JTextField tf_VelocPolar;
    private javax.swing.JTextField tf_raioCurvaMax;
    // End of variables declaration//GEN-END:variables

    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                JFrame frame = new JFrame();
                PainelFerramentaAgentes panel = new PainelFerramentaAgentes(null);
                panel.setPreferredSize(new java.awt.Dimension(200, 300));
                panel.setVisible(true);
                frame.setContentPane(panel);
                frame.setVisible(true);
                frame.setSize(new java.awt.Dimension(200, 300));
                frame.pack();
            }
        });
    }

    public JTextField getTf_IdAgente() {
        return tf_IdAgente;
    }

    public void setTf_IdAgente(JTextField tf_IdAgente) {
        this.tf_IdAgente = tf_IdAgente;
    }

    public JTextField getTf_Posicao() {
        return tf_Posicao;
    }

    public void setTf_Posicao(JTextField tf_Posicao) {
        this.tf_Posicao = tf_Posicao;
    }

    public JTextField getTf_VelocCart() {
        return tf_VelocCart;
    }

    public void setTf_VelocCart(JTextField tf_VelocCart) {
        this.tf_VelocCart = tf_VelocCart;
    }

    public JTextField getTf_VelocPolar() {
        return tf_VelocPolar;
    }

    public void setTf_VelocPolar(JTextField tf_VelocPolar) {
        this.tf_VelocPolar = tf_VelocPolar;
    }

    public JTextField getTf_TamanhoAgente() {
        return tf_TamanhoAgente;
    }

    public void setTf_TamanhoAgente(JTextField tf_TamanhoAgente) {
        this.tf_TamanhoAgente = tf_TamanhoAgente;
    }
}
