/*
 * Programa.java
 *
 * Created on 27 de Novembro de 2008, 19:58
 */
package ambienteGrafico.principal;

import algoritmo.EspacoDeBusca;
import ambienteGrafico.componentes.Canvas;
import ambienteGrafico.componentes.PainelFerramentaAmbiente;
import ambienteGrafico.componentes.PainelFerramentas;
import ambienteGrafico.componentes.PainelFerramentaAgentes;
import ambienteGrafico.componentes.PainelFerramentaSimulacao;
import ambienteGrafico.ferramentas.*;


import java.awt.Cursor;
import java.awt.Dimension;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.imageio.ImageIO;
import javax.swing.JFileChooser;
import javax.swing.JPanel;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;

import org.jdesktop.layout.GroupLayout;
import org.jdesktop.swingx.JXGlassBox;
import org.jvnet.substance.skin.SubstanceAutumnLookAndFeel;

/**
 *
 * @author  Marília
 */
public class Programa extends javax.swing.JFrame {

    PainelFerramentas painelFerramentas = null;

    /** Creates new form Programa */
    public Programa() {
        apagarImagensSensorFotografico();//tem q vir antes de init,antes de instanciar o canvas, se não apaga a "imagem ideal"
        initComponents();
        adicionarPainelFerramentasAoCanvas();
        setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
        setDefaultCloseOperation(javax.swing.JFrame.EXIT_ON_CLOSE);
    }

    public void adicionarPainelFerramentasAoCanvas() {
        Canvas canvas = (Canvas) pn_Centro;
        painelFerramentas = new PainelFerramentas(canvas);
        painelFerramentas.setVisible(false);

        org.jdesktop.layout.GroupLayout pn_CentroLayout = (GroupLayout) pn_Centro.getLayout();

        pn_CentroLayout.setHorizontalGroup(
                pn_CentroLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING).add(org.jdesktop.layout.GroupLayout.TRAILING, pn_CentroLayout.createSequentialGroup().addContainerGap(647, Short.MAX_VALUE).add(painelFerramentas, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 150, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE).addContainerGap()));

        pn_CentroLayout.setVerticalGroup(
                pn_CentroLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING).add(pn_CentroLayout.createSequentialGroup().addContainerGap().add(painelFerramentas, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 591, Short.MAX_VALUE).addContainerGap()));
    }

    /** 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_Centro = new Canvas();
        jToolBar1 = new javax.swing.JToolBar();
        bt_Alvo = new javax.swing.JButton();
        bt_Obstaculo = new javax.swing.JButton();
        javax.swing.ImageIcon icon = new javax.swing.ImageIcon("images/IconePrincipalAgente.gif");
        bt_Agente = new javax.swing.JButton(icon);
        bt_Ambiente = new javax.swing.JButton();
        bt_Simular = new javax.swing.JButton();
        jMenuBar1 = new javax.swing.JMenuBar();
        jMenu1 = new javax.swing.JMenu();
        jMenuItem12 = new javax.swing.JMenuItem();
        jMenuItem1 = new javax.swing.JMenuItem();
        jMenuItem11 = new javax.swing.JMenuItem();
        menuItem_ExecutarListaSimulacoes = new javax.swing.JMenuItem();
        jMenuItem3 = new javax.swing.JMenuItem();
        jMenuItem4 = new javax.swing.JMenuItem();
        jMenuItem2 = new javax.swing.JMenuItem();
        menuItem_AbrirDir = new javax.swing.JMenuItem();
        jMenuItem5 = new javax.swing.JMenuItem();
        jMenu2 = new javax.swing.JMenu();
        jMenuItem6 = new javax.swing.JMenuItem();
        jMenuItem7 = new javax.swing.JMenuItem();
        jMenuItem8 = new javax.swing.JMenuItem();
        jMenuItem9 = new javax.swing.JMenuItem();
        jMenuItem10 = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));

        pn_Centro.setBackground(new java.awt.Color(255, 255, 255));
        pn_Centro.setMinimumSize(new java.awt.Dimension(500, 300));
        pn_Centro.setPreferredSize(new java.awt.Dimension(300, 300));

        org.jdesktop.layout.GroupLayout pn_CentroLayout = new org.jdesktop.layout.GroupLayout(pn_Centro);
        pn_Centro.setLayout(pn_CentroLayout);
        pn_CentroLayout.setHorizontalGroup(
            pn_CentroLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(0, 800, Short.MAX_VALUE)
        );
        pn_CentroLayout.setVerticalGroup(
            pn_CentroLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(0, 613, Short.MAX_VALUE)
        );

        getContentPane().add(pn_Centro, java.awt.BorderLayout.CENTER);

        jToolBar1.setRollover(true);
        jToolBar1.setPreferredSize(new java.awt.Dimension(100, 50));

        bt_Alvo.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagens/IconeAlvoFlexa.gif"))); // NOI18N
        bt_Alvo.setToolTipText("Alvo");
        bt_Alvo.setFocusable(false);
        bt_Alvo.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        bt_Alvo.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        bt_Alvo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bt_AlvoActionPerformed(evt);
            }
        });
        jToolBar1.add(bt_Alvo);

        bt_Obstaculo.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagens/IconeObstaculo.gif"))); // NOI18N
        bt_Obstaculo.setToolTipText("Obstáculo");
        bt_Obstaculo.setFocusable(false);
        bt_Obstaculo.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        bt_Obstaculo.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        bt_Obstaculo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bt_ObstaculoActionPerformed(evt);
            }
        });
        jToolBar1.add(bt_Obstaculo);

        bt_Agente.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagens/IconePrincipalAgente.gif"))); // NOI18N
        bt_Agente.setText("");
        bt_Agente.setToolTipText("Agente");
        bt_Agente.setFocusable(false);
        bt_Agente.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        bt_Agente.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        bt_Agente.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bt_AgenteActionPerformed(evt);
            }
        });
        jToolBar1.add(bt_Agente);

        bt_Ambiente.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagens/IconePrincipalAmbiente.gif"))); // NOI18N
        bt_Ambiente.setText("");
        bt_Ambiente.setToolTipText("Ambiente");
        bt_Ambiente.setFocusable(false);
        bt_Ambiente.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        bt_Ambiente.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        bt_Ambiente.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bt_AmbienteActionPerformed(evt);
            }
        });
        jToolBar1.add(bt_Ambiente);

        bt_Simular.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagens/IconePlaySimular.png"))); // NOI18N
        bt_Simular.setFocusable(false);
        bt_Simular.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        bt_Simular.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        bt_Simular.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bt_SimularActionPerformed(evt);
            }
        });
        jToolBar1.add(bt_Simular);

        getContentPane().add(jToolBar1, java.awt.BorderLayout.NORTH);

        jMenu1.setText("Arquivo");

        jMenuItem12.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_N, java.awt.event.InputEvent.CTRL_MASK));
        jMenuItem12.setText("Novo");
        jMenuItem12.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem12ActionPerformed(evt);
            }
        });
        jMenu1.add(jMenuItem12);

        jMenuItem1.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_I, java.awt.event.InputEvent.CTRL_MASK));
        jMenuItem1.setText("Carregar Imagem");
        jMenuItem1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem1ActionPerformed(evt);
            }
        });
        jMenu1.add(jMenuItem1);

        jMenuItem11.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_SPACE, java.awt.event.InputEvent.CTRL_MASK));
        jMenuItem11.setText("Simulação Aleatória");
        jMenuItem11.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem11ActionPerformed(evt);
            }
        });
        jMenu1.add(jMenuItem11);

        menuItem_ExecutarListaSimulacoes.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_ENTER, java.awt.event.InputEvent.CTRL_MASK));
        menuItem_ExecutarListaSimulacoes.setText("Exec. Lista Simulações");
        menuItem_ExecutarListaSimulacoes.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menuItem_ExecutarListaSimulacoesActionPerformed(evt);
            }
        });
        jMenu1.add(menuItem_ExecutarListaSimulacoes);

        jMenuItem3.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_S, java.awt.event.InputEvent.CTRL_MASK));
        jMenuItem3.setText("Salvar");
        jMenu1.add(jMenuItem3);

        jMenuItem4.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_S, java.awt.event.InputEvent.SHIFT_MASK | java.awt.event.InputEvent.CTRL_MASK));
        jMenuItem4.setText("Salvar Como");
        jMenu1.add(jMenuItem4);

        jMenuItem2.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_O, java.awt.event.InputEvent.CTRL_MASK));
        jMenuItem2.setText("Abrir ");
        jMenu1.add(jMenuItem2);

        menuItem_AbrirDir.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_D, java.awt.event.InputEvent.CTRL_MASK));
        menuItem_AbrirDir.setText("Abrir Diretório ");
        menuItem_AbrirDir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menuItem_AbrirDirActionPerformed(evt);
            }
        });
        jMenu1.add(menuItem_AbrirDir);

        jMenuItem5.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_ESCAPE, 0));
        jMenuItem5.setText("Sair");
        jMenu1.add(jMenuItem5);

        jMenuBar1.add(jMenu1);

        jMenu2.setText("Editar");

        jMenuItem6.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_Z, java.awt.event.InputEvent.CTRL_MASK));
        jMenuItem6.setText("Desfazer");
        jMenu2.add(jMenuItem6);

        jMenuItem7.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_Y, java.awt.event.InputEvent.CTRL_MASK));
        jMenuItem7.setText("Refazer");
        jMenu2.add(jMenuItem7);

        jMenuItem8.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_X, java.awt.event.InputEvent.CTRL_MASK));
        jMenuItem8.setText("Recortar");
        jMenu2.add(jMenuItem8);

        jMenuItem9.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_C, java.awt.event.InputEvent.CTRL_MASK));
        jMenuItem9.setText("Copiar");
        jMenu2.add(jMenuItem9);

        jMenuItem10.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_V, java.awt.event.InputEvent.CTRL_MASK));
        jMenuItem10.setText("Colar");
        jMenu2.add(jMenuItem10);

        jMenuBar1.add(jMenu2);

        setJMenuBar(jMenuBar1);

        pack();
    }// </editor-fold>//GEN-END:initComponents
//
private void bt_AgenteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bt_AgenteActionPerformed
        if (pn_Centro instanceof Canvas) {
            Canvas canvas = (Canvas) pn_Centro;
            //PainelFerramentas painelFerramentas = (PainelFerramentas) pn_Ferramenta;
            boolean visible = painelFerramentas.isVisible();

            //vê se o panel pai e filho estão visíveis
            if (visible && painelFerramentas.getPainelFerramentaAgentes().isVisible()) {
                painelFerramentas.ocutarPainelFerramentas();
            } else {
                painelFerramentas.mostrarFerramentaAgente();
                PainelFerramentaAgentes pn_PropriedadesAgentes = painelFerramentas.getPainelFerramentaAgentes();
                canvas.mudarFerramenta(new FerramentaNula(null));
            }

        }
}//GEN-LAST:event_bt_AgenteActionPerformed

private void bt_SimularActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bt_SimularActionPerformed
    if (pn_Centro instanceof Canvas) {
        Canvas canvas = (Canvas) pn_Centro;
        boolean visible = painelFerramentas.isVisible();

        //vê se o panel pai e filho estão visíveis
        if (visible && painelFerramentas.getPainelFerramentaSimulacao().isVisible()) {
            painelFerramentas.ocutarPainelFerramentas();
        } else {
            painelFerramentas.mostrarFerramentaSimulacao();
            PainelFerramentaSimulacao pn_FerramentaSimulacao = painelFerramentas.getPainelFerramentaSimulacao();
            canvas.mudarFerramenta(new FerramentaSimulacao(pn_FerramentaSimulacao));
        }
    }
}//GEN-LAST:event_bt_SimularActionPerformed

private void bt_AmbienteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bt_AmbienteActionPerformed
    if (pn_Centro instanceof Canvas) {
        Canvas canvas = (Canvas) pn_Centro;
        //PainelFerramentas painelFerramentas = (PainelFerramentas)pn_Ferramenta;
        boolean visible = painelFerramentas.isVisible();
        if (visible && painelFerramentas.getPainelFerramentaAmbiente().isVisible()) {
            painelFerramentas.ocutarPainelFerramentas();
        } else {
            painelFerramentas.mostrarFerramentaAmbiente();
            PainelFerramentaAmbiente pn_FerramentaAmbiente = painelFerramentas.getPainelFerramentaAmbiente();
            canvas.mudarFerramenta(new FerramentaNula(null));
        }
    }
}//GEN-LAST:event_bt_AmbienteActionPerformed

private void bt_AlvoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bt_AlvoActionPerformed
    if (pn_Centro instanceof Canvas) {
        Canvas canvas = (Canvas) pn_Centro;
        //PainelFerramentas painelFerramentas = (PainelFerramentas)pn_Ferramenta;
        boolean visible = painelFerramentas.isVisible();
        if (visible && painelFerramentas.getPainelFerramentaAlvos().isVisible()) {
            painelFerramentas.ocutarPainelFerramentas();
        } else {
            painelFerramentas.mostrarFerramentaAlvos();
            canvas.mudarFerramenta(new FerramentaNula(null));
        }
    }
}//GEN-LAST:event_bt_AlvoActionPerformed

private void bt_ObstaculoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bt_ObstaculoActionPerformed
    if (pn_Centro instanceof Canvas) {
        Canvas canvas = (Canvas) pn_Centro;
        //PainelFerramentas painelFerramentas = (PainelFerramentas)pn_Ferramenta;
        boolean visible = painelFerramentas.isVisible();
        if (visible && painelFerramentas.getPainelFerramentaObstaculos().isVisible()) {
            painelFerramentas.ocutarPainelFerramentas();
        } else {
            painelFerramentas.mostrarFerramentaObstaculos();
            canvas.mudarFerramenta(new FerramentaNula(null));
        }
    }
}//GEN-LAST:event_bt_ObstaculoActionPerformed

private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem1ActionPerformed
        EspacoDeBusca espBusca = EspacoDeBusca.getInstance();
        //Carregar imagem

        try {
            JFileChooser chooser = new JFileChooser();
            File f = new File(new File("src/imagens/Exemplos de Ambientes/ModeloAmbiente1420x800comTubos.jpg").getCanonicalPath());
            chooser.setSelectedFile(f);
            chooser.showOpenDialog(null);

            File nomaImagem = chooser.getSelectedFile();
            espBusca.getCanvas().limparImagem(nomaImagem);
            espBusca.getCanvas().repaint();
        } catch (IOException ex) {
            Logger.getLogger(Programa.class.getName()).log(Level.SEVERE, null, ex);
            File nomaImagem = null;
            espBusca.getCanvas().limparImagem(nomaImagem);
            espBusca.getCanvas().repaint();
        }
}//GEN-LAST:event_jMenuItem1ActionPerformed

private void jMenuItem11ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem11ActionPerformed
        //Simulação
        EspacoDeBusca espBusca = EspacoDeBusca.getInstance();
        if( !espBusca.isExecucaoFinalizada()){
            espBusca.setExecucaoFinalizada(true);
        }
        espBusca.clear();
        espBusca.setCicloAtual(0);
        espBusca.setExecucaoFinalizada(false);
        espBusca.adicionarAgentesAleatoriamente(4);
        espBusca.estabelecerObjetivoDaExecucao(2);//explorar ambiente
        //espBusca.estabelecerMelhorSolucaoPossivel(); caso a condição de parada seja a numero 1

        try {
            //restart a imagem
            BufferedImage imPrincipal = ImageIO.read(getClass().getResource("/imagens/Exemplos de Ambientes/ModeloAmbiente1420x800comTubos.jpg"));
            espBusca.getCanvas().setImagemPrincipal(imPrincipal);
            espBusca.getCanvas().setImagemAmbiente(espBusca.getCanvas().getCopia(imPrincipal));
        } catch (IOException ex) {
            Logger.getLogger(Programa.class.getName()).log(Level.SEVERE, null, ex);
        }
        espBusca.getCanvas().repaint();
        espBusca.getCanvas().startAnimation();
}//GEN-LAST:event_jMenuItem11ActionPerformed

private void jMenuItem12ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem12ActionPerformed
        //Novo projeto
        EspacoDeBusca espBusca = EspacoDeBusca.getInstance();
        if (!espBusca.isExecucaoFinalizada()) {
            espBusca.setExecucaoFinalizada(true);
        }
        espBusca.clear();
        espBusca.setCicloAtual(0);
        espBusca.setExecucaoFinalizada(false);
        espBusca.getCanvas().limparImagem(null);
        espBusca.getCanvas().repaint();
        System.out.println("Imagem PRETA");
}//GEN-LAST:event_jMenuItem12ActionPerformed

private void menuItem_AbrirDirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuItem_AbrirDirActionPerformed
        try {
            String workingDirectory = System.getProperty("user.dir");
            Runtime.getRuntime().exec("explorer " + workingDirectory);
        } catch (IOException ex) {
            Logger.getLogger(Programa.class.getName()).log(Level.SEVERE, null, ex);
        }
}//GEN-LAST:event_menuItem_AbrirDirActionPerformed

private void menuItem_ExecutarListaSimulacoesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuItem_ExecutarListaSimulacoesActionPerformed
        ThreadExecutarSimulacao simulacoes = new ThreadExecutarSimulacao();
        simulacoes.run();
}//GEN-LAST:event_menuItem_ExecutarListaSimulacoesActionPerformed

private void apagarImagensSensorFotografico() {


    File diretorio = new File ("images/Sensor Fotografico");

        if (diretorio.listFiles() != null) {
            File[] files = diretorio.listFiles();
            for (int i = 0; i < files.length; i++) {
                files[i].delete();
            }
        }
}

/**
 * @param args the command line arguments
 */
    public static void main(String args[]) {
        //Look and feel
        setDefaultLookAndFeelDecorated(true);
        try {
            UIManager.setLookAndFeel(new SubstanceAutumnLookAndFeel());
        } catch (UnsupportedLookAndFeelException e) {
            e.printStackTrace();
        }
//Fim codigo look and feel

        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                Programa programa = new Programa();
                programa.setVisible(true);
                programa.setSize(new Dimension(1027, 655));

                


            /*/////////////
            JXCollapsiblePane cp = new JXCollapsiblePane();

            // JXCollapsiblePane can be used like any other container
            cp.setLayout(new BorderLayout());

            // the Controls panel with a textfield to filter the tree
            JPanel controls = new JPanel(new FlowLayout(FlowLayout.LEFT, 4, 0));
            controls.add(new JLabel("Search:"));
            controls.add(new JTextField(10));
            controls.add(new JButton("Refresh"));
            controls.setBorder(new TitledBorder("Filters"));
            cp.add("Center", controls);

            JXFrame frame = new JXFrame();
            frame.setLayout(new BorderLayout());

            // Put the "Controls" first
            frame.add("North", cp);

            // Then the tree - we assume the Controls would somehow filter the tree
            JScrollPane scroll = new JScrollPane(new JTree());
            frame.add("Center", scroll);

            javax.swing.ImageIcon icon = new javax.swing.ImageIcon("images/IconePrincipalAgente.gif");
            Action toggleAction = cp.getActionMap().get(JXCollapsiblePane.TOGGLE_ACTION);
            toggleAction.putValue(JXCollapsiblePane.COLLAPSE_ICON,icon);
            toggleAction.putValue(JXCollapsiblePane.EXPAND_ICON,icon);

            // Show/hide the "Controls"
            JButton toggle = new JButton(toggleAction);

            toggle.setText("");
            frame.add("South", toggle);

            frame.pack();
            frame.setVisible(true);

             *//// ///////

            }
        });

    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton bt_Agente;
    private javax.swing.JButton bt_Alvo;
    private javax.swing.JButton bt_Ambiente;
    private javax.swing.JButton bt_Obstaculo;
    private javax.swing.JButton bt_Simular;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenu jMenu2;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JMenuItem jMenuItem1;
    private javax.swing.JMenuItem jMenuItem10;
    private javax.swing.JMenuItem jMenuItem11;
    private javax.swing.JMenuItem jMenuItem12;
    private javax.swing.JMenuItem jMenuItem2;
    private javax.swing.JMenuItem jMenuItem3;
    private javax.swing.JMenuItem jMenuItem4;
    private javax.swing.JMenuItem jMenuItem5;
    private javax.swing.JMenuItem jMenuItem6;
    private javax.swing.JMenuItem jMenuItem7;
    private javax.swing.JMenuItem jMenuItem8;
    private javax.swing.JMenuItem jMenuItem9;
    private javax.swing.JToolBar jToolBar1;
    private javax.swing.JMenuItem menuItem_AbrirDir;
    private javax.swing.JMenuItem menuItem_ExecutarListaSimulacoes;
    private javax.swing.JPanel pn_Centro;
    // End of variables declaration//GEN-END:variables

	
}
