/*
 * PainelFerramentaAmbiente.java
 *
 * Created on 18 de Dezembro de 2008, 19:00
 */

package ambienteGrafico.componentes;

import algoritmo.EspacoDeBusca;
import javax.swing.JFrame;

/**
 *
 * @author  Marília
 */
public class PainelFerramentaAmbiente extends MeuPainel {

    private Canvas canvas = null;
    /** Creates new form PainelFerramentaAmbiente */
    public PainelFerramentaAmbiente(Canvas canvas) {
        super.mudarLookAndFeel();
        initComponents();
        this.canvas = canvas;
    }

    /** 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 PainelCores(this);
        jPanel2 = new javax.swing.JPanel();
        tf_valorCorrenteza = new javax.swing.JTextField();
        lb_metrosPorSegundos = new javax.swing.JLabel();
        tf_direcaoCorrenteza = new javax.swing.JTextField();
        lb_simboloGraus = new javax.swing.JLabel();
        js_direcaoCorrenteza = new javax.swing.JSlider();
        bt_AtribuirVelocidade = new javax.swing.JButton();
        painelFerramentas = new PainelFerramentasDesenho(this);
        pn_AtributosEspacoBusca = new javax.swing.JPanel();
        lb_DimensaoX = new javax.swing.JLabel();
        lb_DimensaoY = new javax.swing.JLabel();
        tf_DimensaoX = new javax.swing.JTextField();
        tf_DimensaoY = new javax.swing.JTextField();
        lb_RotuloMetroX = new javax.swing.JLabel();
        lb_RotuloMetroY = new javax.swing.JLabel();
        bt_AtribuirDimensoes = new javax.swing.JButton();

        setLayout(null);

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 140, Short.MAX_VALUE)
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 90, Short.MAX_VALUE)
        );

        add(jPanel1);
        jPanel1.setBounds(0, 120, 140, 90);

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Correnteza", 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

        tf_valorCorrenteza.setText("1");
        tf_valorCorrenteza.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                tf_valorCorrentezaActionPerformed(evt);
            }
        });

        lb_metrosPorSegundos.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        lb_metrosPorSegundos.setText("m/s");

        tf_direcaoCorrenteza.setText("90");
        tf_direcaoCorrenteza.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                tf_direcaoCorrentezaActionPerformed(evt);
            }
        });

        lb_simboloGraus.setText("º");

        js_direcaoCorrenteza.setMaximum(360);
        js_direcaoCorrenteza.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                js_direcaoCorrentezaStateChanged(evt);
            }
        });

        bt_AtribuirVelocidade.setText("Atribuir");
        bt_AtribuirVelocidade.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bt_AtribuirVelocidadeActionPerformed(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, false)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(tf_valorCorrenteza, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(lb_metrosPorSegundos, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(tf_direcaoCorrenteza, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(lb_simboloGraus))
                    .addComponent(js_direcaoCorrenteza, 0, 0, Short.MAX_VALUE)
                    .addComponent(bt_AtribuirVelocidade, javax.swing.GroupLayout.PREFERRED_SIZE, 82, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(31, Short.MAX_VALUE))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(tf_valorCorrenteza, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(lb_metrosPorSegundos, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(tf_direcaoCorrenteza, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(lb_simboloGraus)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(js_direcaoCorrenteza, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(bt_AtribuirVelocidade))
        );

        add(jPanel2);
        jPanel2.setBounds(0, 210, 140, 110);

        javax.swing.GroupLayout painelFerramentasLayout = new javax.swing.GroupLayout(painelFerramentas);
        painelFerramentas.setLayout(painelFerramentasLayout);
        painelFerramentasLayout.setHorizontalGroup(
            painelFerramentasLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 140, Short.MAX_VALUE)
        );
        painelFerramentasLayout.setVerticalGroup(
            painelFerramentasLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 120, Short.MAX_VALUE)
        );

        add(painelFerramentas);
        painelFerramentas.setBounds(0, 0, 140, 120);

        pn_AtributosEspacoBusca.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Dimensões do Ambiente", 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

        lb_DimensaoX.setText("Dimensão X:");

        lb_DimensaoY.setText("Dimensão Y:");

        tf_DimensaoX.setText("1027");
        tf_DimensaoX.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                tf_DimensaoXActionPerformed(evt);
            }
        });

        tf_DimensaoY.setText("655");
        tf_DimensaoY.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                tf_DimensaoYActionPerformed(evt);
            }
        });

        lb_RotuloMetroX.setText("m");

        lb_RotuloMetroY.setText("m");

        bt_AtribuirDimensoes.setText("Atribuir");
        bt_AtribuirDimensoes.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bt_AtribuirDimensoesActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout pn_AtributosEspacoBuscaLayout = new javax.swing.GroupLayout(pn_AtributosEspacoBusca);
        pn_AtributosEspacoBusca.setLayout(pn_AtributosEspacoBuscaLayout);
        pn_AtributosEspacoBuscaLayout.setHorizontalGroup(
            pn_AtributosEspacoBuscaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pn_AtributosEspacoBuscaLayout.createSequentialGroup()
                .addGroup(pn_AtributosEspacoBuscaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(pn_AtributosEspacoBuscaLayout.createSequentialGroup()
                        .addComponent(lb_DimensaoX)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(tf_DimensaoX, javax.swing.GroupLayout.PREFERRED_SIZE, 45, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(pn_AtributosEspacoBuscaLayout.createSequentialGroup()
                        .addComponent(lb_DimensaoY)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(tf_DimensaoY)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(pn_AtributosEspacoBuscaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(pn_AtributosEspacoBuscaLayout.createSequentialGroup()
                        .addComponent(lb_RotuloMetroY, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGap(10, 10, 10))
                    .addGroup(pn_AtributosEspacoBuscaLayout.createSequentialGroup()
                        .addComponent(lb_RotuloMetroX, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addContainerGap())))
            .addComponent(bt_AtribuirDimensoes, javax.swing.GroupLayout.PREFERRED_SIZE, 82, javax.swing.GroupLayout.PREFERRED_SIZE)
        );
        pn_AtributosEspacoBuscaLayout.setVerticalGroup(
            pn_AtributosEspacoBuscaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pn_AtributosEspacoBuscaLayout.createSequentialGroup()
                .addGroup(pn_AtributosEspacoBuscaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lb_DimensaoX)
                    .addComponent(tf_DimensaoX, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lb_RotuloMetroX))
                .addGap(12, 12, 12)
                .addGroup(pn_AtributosEspacoBuscaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lb_DimensaoY)
                    .addComponent(tf_DimensaoY, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lb_RotuloMetroY))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(bt_AtribuirDimensoes)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        add(pn_AtributosEspacoBusca);
        pn_AtributosEspacoBusca.setBounds(0, 320, 140, 110);
    }// </editor-fold>//GEN-END:initComponents

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

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

    private void bt_AtribuirVelocidadeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bt_AtribuirVelocidadeActionPerformed
        EspacoDeBusca espacoDeBusca = EspacoDeBusca.getInstance();
        double[] veloCorrentezaPolar = new double[2];
        veloCorrentezaPolar[0]= Double.parseDouble(tf_valorCorrenteza.getText());
        veloCorrentezaPolar[1]= Double.parseDouble(tf_direcaoCorrenteza.getText());
        espacoDeBusca.setVeloCorrentezaPolar(veloCorrentezaPolar);
}//GEN-LAST:event_bt_AtribuirVelocidadeActionPerformed

    private void js_direcaoCorrentezaStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_js_direcaoCorrentezaStateChanged
        if (!js_direcaoCorrenteza.getValueIsAdjusting()) {
            int valorDirecao = (int)js_direcaoCorrenteza.getValue();
            tf_direcaoCorrenteza.setText(valorDirecao+"");
        }
}//GEN-LAST:event_js_direcaoCorrentezaStateChanged

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

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

    private void bt_AtribuirDimensoesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bt_AtribuirDimensoesActionPerformed
        EspacoDeBusca espacoDeBusca = EspacoDeBusca.getInstance();
        int[] dimensaoDoEspaco = new int[2];
        dimensaoDoEspaco[0]= Integer.parseInt(tf_DimensaoX.getText());
        dimensaoDoEspaco[1]= Integer.parseInt(tf_DimensaoY.getText());
        espacoDeBusca.setLimiteMaxCoordX(dimensaoDoEspaco[0]);
        espacoDeBusca.setLimiteMaxCoordX(dimensaoDoEspaco[1]);
}//GEN-LAST:event_bt_AtribuirDimensoesActionPerformed


     public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                JFrame frame =  new JFrame();
                PainelFerramentaAmbiente panel = new PainelFerramentaAmbiente(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();
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton bt_AtribuirDimensoes;
    private javax.swing.JButton bt_AtribuirVelocidade;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JSlider js_direcaoCorrenteza;
    private javax.swing.JLabel lb_DimensaoX;
    private javax.swing.JLabel lb_DimensaoY;
    private javax.swing.JLabel lb_RotuloMetroX;
    private javax.swing.JLabel lb_RotuloMetroY;
    private javax.swing.JLabel lb_metrosPorSegundos;
    private javax.swing.JLabel lb_simboloGraus;
    private javax.swing.JPanel painelFerramentas;
    private javax.swing.JPanel pn_AtributosEspacoBusca;
    private javax.swing.JTextField tf_DimensaoX;
    private javax.swing.JTextField tf_DimensaoY;
    private javax.swing.JTextField tf_direcaoCorrenteza;
    private javax.swing.JTextField tf_valorCorrenteza;
    // End of variables declaration//GEN-END:variables

    public Canvas getCanvas() {
        return canvas;
    }


}
