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

/*
 * PainelFerramentaObstaculos.java
 *
 * Created on 08/04/2009, 17:21:56
 */

package ambienteGrafico.componentes;

import algoritmo.Obstaculo;
import algoritmo.ConjuntoDeObstaculos;
import algoritmo.EspacoDeBusca;
import ambienteGrafico.ferramentas.FerramentaInserirObstaculo;
import ambienteGrafico.ferramentas.FerramentaSelecionarObstaculo;
import java.awt.Cursor;
import java.awt.Image;
import java.awt.Point;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.MouseEvent;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.imageio.ImageIO;
import javax.swing.JCheckBox;
import javax.swing.JFrame;
import javax.swing.JTextField;
import javax.swing.DefaultListModel;
import javax.swing.JList;
/**
 *
 * @author Marília
 */
public class PainelFerramentaObstaculos extends MeuPainel {

   private Canvas canvas = null;

    //Possiveis Listeners para o canvas:
    private FerramentaInserirObstaculo ferramentaInserirObstaculo = null;
    private FerramentaSelecionarObstaculo ferramentaSelecionarObstaculo = null;

    private JList listaObstaculos = null;
	private DefaultListModel listModel = null;

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

    private void inicializarListeners(){
        ferramentaInserirObstaculo = new FerramentaInserirObstaculo(this);
        ferramentaSelecionarObstaculo = new FerramentaSelecionarObstaculo(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() {

        jPanel1 = new MeuPainel();
        bt_Navio = new MyJButton(); ;
        bt_SelecionarObstaculo = new MyJButton(); ;
        bt_Plataforma = new MyJButton(); ;
        bt_AreaProibida = new MyJButton(); ;
        bt_InserirObstaculosPadroes = new MyJButton(); ;
        jPanel2 = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        tf_ID = new javax.swing.JTextField();
        tf_Posicao = new javax.swing.JTextField();
        tf_Tamanho = new javax.swing.JTextField();
        tf_RaioRepulsao = new javax.swing.JTextField();
        chb_ObstaculoAtivo = new javax.swing.JCheckBox();
        bt_MudarRaioDeRepulsao = new javax.swing.JButton();
        chb_MostrarAreasRepulsao = new javax.swing.JCheckBox();
        sp_ListaObstaculos = new javax.swing.JScrollPane();
        jLabel1 = new javax.swing.JLabel();

        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_Navio.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagens/ItensAmbiente/Barco1.gif"))); // NOI18N
        bt_Navio.setToolTipText("Adicionar Navio");
        bt_Navio.setIconTextGap(0);
        bt_Navio.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bt_NavioActionPerformed(evt);
            }
        });

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

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

        bt_AreaProibida.setBackground(new java.awt.Color(255, 255, 102));
        bt_AreaProibida.setForeground(new java.awt.Color(255, 255, 153));
        bt_AreaProibida.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagens/ItensAmbiente/iconeAreaRestrita.GIF"))); // NOI18N
        bt_AreaProibida.setToolTipText("Adicionar Area Proibida");
        bt_AreaProibida.setIconTextGap(0);
        bt_AreaProibida.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bt_AreaProibidaActionPerformed(evt);
            }
        });

        bt_InserirObstaculosPadroes.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagens/IconeObstaculo.gif"))); // NOI18N
        bt_InserirObstaculosPadroes.setToolTipText("Adicionar Conjunto de Obstáculos Padrões");
        bt_InserirObstaculosPadroes.setIconTextGap(0);
        bt_InserirObstaculosPadroes.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bt_InserirObstaculosPadroesActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(bt_SelecionarObstaculo, javax.swing.GroupLayout.Alignment.LEADING, 0, 0, Short.MAX_VALUE)
                    .addComponent(bt_Navio, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 28, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(bt_InserirObstaculosPadroes, javax.swing.GroupLayout.PREFERRED_SIZE, 28, Short.MAX_VALUE)
                    .addComponent(bt_Plataforma, javax.swing.GroupLayout.PREFERRED_SIZE, 28, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(bt_AreaProibida, javax.swing.GroupLayout.PREFERRED_SIZE, 28, Short.MAX_VALUE)
                .addGap(55, 55, 55))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(bt_Navio, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 9, Short.MAX_VALUE)
                        .addComponent(bt_SelecionarObstaculo, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(bt_Plataforma, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(bt_InserirObstaculosPadroes, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(bt_AreaProibida, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Configurações do Obstáculo", 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

        jLabel2.setText("ID:");

        jLabel3.setText("Tamanho:");

        jLabel4.setText("Posicao:");

        jLabel5.setText("R. Repulsao:");

        tf_ID.setEditable(false);
        tf_ID.setText("0");

        tf_Posicao.setText("(0,0)");

        tf_Tamanho.setText("(0,0)");

        tf_RaioRepulsao.setText("0");
        tf_RaioRepulsao.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                tf_RaioRepulsaoActionPerformed(evt);
            }
        });

        chb_ObstaculoAtivo.setSelected(true);
        chb_ObstaculoAtivo.setText("Obstáculo Ativo");
        chb_ObstaculoAtivo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                chb_ObstaculoAtivoActionPerformed(evt);
            }
        });

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

        chb_MostrarAreasRepulsao.setSelected(true);
        chb_MostrarAreasRepulsao.setText("Mostrar Areas Repulsão");
        chb_MostrarAreasRepulsao.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                chb_MostrarAreasRepulsaoActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(chb_ObstaculoAtivo, javax.swing.GroupLayout.DEFAULT_SIZE, 145, Short.MAX_VALUE)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel5)
                            .addComponent(jLabel4)
                            .addComponent(jLabel3)
                            .addComponent(jLabel2))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addComponent(tf_ID, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 75, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(tf_Tamanho, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 75, Short.MAX_VALUE)
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel2Layout.createSequentialGroup()
                                .addComponent(tf_RaioRepulsao, javax.swing.GroupLayout.PREFERRED_SIZE, 43, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(bt_MudarRaioDeRepulsao, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(tf_Posicao, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 75, Short.MAX_VALUE)))
                    .addComponent(chb_MostrarAreasRepulsao, javax.swing.GroupLayout.DEFAULT_SIZE, 145, Short.MAX_VALUE))
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(tf_ID, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(tf_Posicao, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(tf_Tamanho, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5)
                    .addComponent(tf_RaioRepulsao, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(bt_MudarRaioDeRepulsao))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(chb_ObstaculoAtivo)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(chb_MostrarAreasRepulsao))
        );

        listModel = new DefaultListModel();
        listaObstaculos = new JList(listModel);
        listaObstaculos.setSelectedIndex(0);
        listaObstaculos.setVisibleRowCount(10);
        listaObstaculos.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        listaObstaculos.addMouseListener(new ListaDeObstaculosListener());
        sp_ListaObstaculos.getViewport().setView(listaObstaculos);
        //Adicionar na lista os obstaculos default
        listModel.addElement("Obstaculo 0");
        listModel.addElement("Obstaculo 1");
        listModel.addElement("Obstaculo 2");

        jLabel1.setForeground(new java.awt.Color(1, 1, 1));
        jLabel1.setText("Lista de Obstáculos");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(jPanel2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jLabel1))
                    .addComponent(sp_ListaObstaculos, javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 167, Short.MAX_VALUE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 88, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(sp_ListaObstaculos, javax.swing.GroupLayout.PREFERRED_SIZE, 99, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void bt_NavioActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bt_NavioActionPerformed

        double[] tamanhoNavioObstaculo = {15,30};
        double raioAreaRepulsao = 80;//50
        ferramentaInserirObstaculo.setTamanhoObstaculo(tamanhoNavioObstaculo);
        ferramentaInserirObstaculo.setRaioAreaRepulsaoDoObstaculo(raioAreaRepulsao);
        ferramentaInserirObstaculo.mudarFiguraObstaculo("/imagens/ItensAmbiente/Barco1.png");
        try {
            Image img = ImageIO.read(getClass().getResource("/imagens/ItensAmbiente/Barco1.png"));
            Cursor cursor = Toolkit.getDefaultToolkit().createCustomCursor(img, new Point(16, 16),"Obstaculo");
            ferramentaInserirObstaculo.setCursor(cursor);
        } catch (IOException ex) {
            ex.printStackTrace();//
        }
        this.canvas.mudarFerramenta(ferramentaInserirObstaculo);
}//GEN-LAST:event_bt_NavioActionPerformed

    private void bt_SelecionarObstaculoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bt_SelecionarObstaculoActionPerformed
        this.canvas.mudarFerramenta(ferramentaSelecionarObstaculo);
}//GEN-LAST:event_bt_SelecionarObstaculoActionPerformed

    private void tf_RaioRepulsaoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tf_RaioRepulsaoActionPerformed
        // TODO add your handling code here:
}//GEN-LAST:event_tf_RaioRepulsaoActionPerformed

    private void bt_PlataformaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bt_PlataformaActionPerformed
        double[] tamanhoPlataformaObstaculo = {100,150};
        double raioAreaRepulsao = 150;//120
        ferramentaInserirObstaculo.setTamanhoObstaculo(tamanhoPlataformaObstaculo);
        ferramentaInserirObstaculo.setRaioAreaRepulsaoDoObstaculo(raioAreaRepulsao);
      
        ferramentaInserirObstaculo.mudarFiguraObstaculo("/imagens/ItensAmbiente/Plataforma.png");
        try {
            Image img = ImageIO.read(getClass().getResource("/imagens/ItensAmbiente/Plataforma.png"));
            Cursor cursor = Toolkit.getDefaultToolkit().createCustomCursor(img, new Point(16, 16),"Obstaculo");
            ferramentaInserirObstaculo.setCursor(cursor);
        } catch (IOException ex) {
            ex.printStackTrace();//
        }
        this.canvas.mudarFerramenta(ferramentaInserirObstaculo);
}//GEN-LAST:event_bt_PlataformaActionPerformed

    private void chb_ObstaculoAtivoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_chb_ObstaculoAtivoActionPerformed
        if (!tf_ID.getText().equalsIgnoreCase("")) {

            EspacoDeBusca espacoDeBusca = EspacoDeBusca.getInstance();
            ConjuntoDeObstaculos conjuntoDeObstaculos = espacoDeBusca.getObstaculos();
            int obstaculoId = Integer.parseInt(tf_ID.getText());
            conjuntoDeObstaculos.get(obstaculoId).setAtivo(chb_ObstaculoAtivo.isSelected());

        }
    }//GEN-LAST:event_chb_ObstaculoAtivoActionPerformed

    private void bt_AreaProibidaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bt_AreaProibidaActionPerformed
        double[] tamanhoAreaProibida = {100,100};
        double raioAreaRepulsao = 100;
        ferramentaInserirObstaculo.setTamanhoObstaculo(tamanhoAreaProibida);
        ferramentaInserirObstaculo.setRaioAreaRepulsaoDoObstaculo(raioAreaRepulsao);
        ferramentaInserirObstaculo.mudarFiguraObstaculo("/imagens/ItensAmbiente/iconeAreaRestrita.gif");
        try {
            Image img = ImageIO.read(getClass().getResource("/imagens/ItensAmbiente/iconeAreaRestrita.gif"));
            Cursor cursor = Toolkit.getDefaultToolkit().createCustomCursor(img, new Point(16, 16),"Obstaculo");
            ferramentaInserirObstaculo.setCursor(cursor);
        } catch (IOException ex) {
            ex.printStackTrace();//
        }
        this.canvas.mudarFerramenta(ferramentaInserirObstaculo);
}//GEN-LAST:event_bt_AreaProibidaActionPerformed

    private void bt_MudarRaioDeRepulsaoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bt_MudarRaioDeRepulsaoActionPerformed
       if (!tf_ID.getText().equalsIgnoreCase("")) {

            EspacoDeBusca espacoDeBusca = EspacoDeBusca.getInstance();
            ConjuntoDeObstaculos conjuntoDeObstaculos = espacoDeBusca.getObstaculos();
            int obstaculoId = Integer.parseInt(tf_ID.getText());
            double valorRaioRepulsao = Double.parseDouble(tf_RaioRepulsao.getText());
            conjuntoDeObstaculos.get(obstaculoId).setRaioAreaRepulsao(valorRaioRepulsao);

        }
    }//GEN-LAST:event_bt_MudarRaioDeRepulsaoActionPerformed

    private void bt_InserirObstaculosPadroesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bt_InserirObstaculosPadroesActionPerformed
         EspacoDeBusca espacoDeBusca = EspacoDeBusca.getInstance();
         espacoDeBusca.adicionarObstaculosPadroes();
         //Pintar os obstáculos
         Obstaculo obstaculo;
         for(int i=0; i<espacoDeBusca.getObstaculos().getNumObstaculos();i++){
                obstaculo = espacoDeBusca.getObstaculos().get(i);
                if(obstaculo.isAtivo()){
                    this.canvas.pintarAreaRepulsaoDoObstaculo(obstaculo,null);
                }
         }
         this.canvas.repaint();
        
}//GEN-LAST:event_bt_InserirObstaculosPadroesActionPerformed

    private void chb_MostrarAreasRepulsaoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_chb_MostrarAreasRepulsaoActionPerformed
        EspacoDeBusca espacoDeBusca = EspacoDeBusca.getInstance();
         //Pintar os obstáculos
         Obstaculo obstaculo;
         for(int i=0; i<espacoDeBusca.getObstaculos().getNumObstaculos();i++){
                obstaculo = espacoDeBusca.getObstaculos().get(i);
                obstaculo.setMostrarAreaRepulsao(chb_MostrarAreasRepulsao.isSelected());
                if(obstaculo.isAtivo()){
                    this.canvas.pintarAreaRepulsaoDoObstaculo(obstaculo,null);
                }
         }
         this.canvas.repaint();
}//GEN-LAST:event_chb_MostrarAreasRepulsaoActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton bt_AreaProibida;
    private javax.swing.JButton bt_InserirObstaculosPadroes;
    private javax.swing.JButton bt_MudarRaioDeRepulsao;
    private javax.swing.JButton bt_Navio;
    private javax.swing.JButton bt_Plataforma;
    private javax.swing.JButton bt_SelecionarObstaculo;
    private javax.swing.JCheckBox chb_MostrarAreasRepulsao;
    private javax.swing.JCheckBox chb_ObstaculoAtivo;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JScrollPane sp_ListaObstaculos;
    private javax.swing.JTextField tf_ID;
    private javax.swing.JTextField tf_Posicao;
    private javax.swing.JTextField tf_RaioRepulsao;
    private javax.swing.JTextField tf_Tamanho;
    // End of variables declaration//GEN-END:variables

    public JTextField getTf_RaioRepulsao() {
        return tf_RaioRepulsao;
    }

    public JTextField getTf_ID() {
        return tf_ID;
    }

    public JTextField getTf_Posicao() {
        return tf_Posicao;
    }

    public JTextField getTf_Tamanho() {
        return tf_Tamanho;
    }

    public JCheckBox getChb_ObstaculoAtivo() {
        return chb_ObstaculoAtivo;
    }
    
    public DefaultListModel getListModel() {
        return listModel;
    }

    public JList getListaObstaculos() {
        return listaObstaculos;
    }

    public FerramentaInserirObstaculo getFerramentaInserirObstaculo() {
        return ferramentaInserirObstaculo;
    }

    public FerramentaSelecionarObstaculo getFerramentaSelecionarObstaculo() {
        return ferramentaSelecionarObstaculo;
    }

    public Canvas getCanvas() {
        return canvas;
    }
    
    /***********CLASSE INTERNA**********/
	class ListaDeObstaculosListener implements java.awt.event.MouseListener, java.awt.event.ActionListener{

        @Override
        public void mouseClicked(MouseEvent e) {
            int indice = listaObstaculos.getSelectedIndex();
            System.out.println("Obstaculo selecionado:"+indice);
            EspacoDeBusca espacoDeBusca = EspacoDeBusca.getInstance();
            ConjuntoDeObstaculos obstaculos = espacoDeBusca.getObstaculos();
            Obstaculo obstaculo = obstaculos.get(indice);
            obstaculo.setMostrarAreaRepulsao(!obstaculo.isMostrarAreaRepulsao());
            tf_ID.setText(obstaculo.getId()+"");
            tf_Posicao.setText("("+obstaculo.getPosicao()[0]+","+obstaculo.getPosicao()[1]+")");
            tf_Tamanho.setText("("+obstaculo.getTamanho()[0]+","+obstaculo.getTamanho()[1]+")");
            tf_RaioRepulsao.setText(""+obstaculo.getRaioAreaRepulsao());
            chb_ObstaculoAtivo.setSelected(obstaculo.isAtivo());
            
            //Desenha a área de repulsão na tela
            canvas.pintarAreaRepulsaoDoObstaculo(obstaculo,null);
        }

        @Override
        public void mousePressed(MouseEvent e) {

        }

        @Override
        public void mouseReleased(MouseEvent e) {

        }

        @Override
        public void mouseEntered(MouseEvent e) {

        }

        @Override
        public void mouseExited(MouseEvent e) {

        }

        @Override
        public void actionPerformed(ActionEvent e) {

        }

    }
}
