/*
 * PainelFerramentasDesenho.java
 *
 * Created on 27 de Dezembro de 2008, 09:51
 */

package ambienteGrafico.componentes;

import ambienteGrafico.ferramentas.FerramentaDesenharLinha;
import ambienteGrafico.ferramentas.FerramentaNula;
import javax.swing.JFrame;

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

    private MeuPainel painelPai = null;
    private Canvas painelCanvas = null;

    //Possiveis Listeners para o canvas:
    private FerramentaDesenharLinha ferramentaDesenharLinha  = null;
    //private FerramentaDesenharPincel ferramentaDesenharPincel = null;
    //private FerramentaDesenharRetangulo ferramentaDesenhaRetangulo = null;

    /** Creates new form PainelFerramentasDesenho */
    public PainelFerramentasDesenho(MeuPainel painelPai) {
        super.mudarLookAndFeel();
        initComponents();
        this.painelPai = painelPai;
        inicializarListeners();
    }

    private void inicializarListeners(){
        //ferramentaDesenharLinha = new FerramentaDesenharLinha(this);
        //ferramentaDesenharPincel = new FerramentaDesenharPincel(this);
        //ferramentaDesenhaRetangulo = new FerramentaDesenhaRetangulo(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() {

        bt_Linha = new MyJButton(); ;
        bt_Pincel1 = new MyJButton(); ;
        bt_Retangulo1 = new MyJButton(); ;
        jSlider1 = new javax.swing.JSlider();
        jLabel1 = new javax.swing.JLabel();

        setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Ferramentas de desenho", 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
        setPreferredSize(new java.awt.Dimension(150, 100));
        setLayout(null);

        bt_Linha.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagens/IconeLinha.gif"))); // NOI18N
        bt_Linha.setIconTextGap(0);
        bt_Linha.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bt_LinhaActionPerformed(evt);
            }
        });
        add(bt_Linha);
        bt_Linha.setBounds(70, 20, 28, 28);

        bt_Pincel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagens/IconePincel.gif"))); // NOI18N
        bt_Pincel1.setIconTextGap(0);
        bt_Pincel1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bt_Pincel1ActionPerformed(evt);
            }
        });
        add(bt_Pincel1);
        bt_Pincel1.setBounds(10, 20, 28, 28);

        bt_Retangulo1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagens/IconeRetangulo.gif"))); // NOI18N
        bt_Retangulo1.setIconTextGap(0);
        bt_Retangulo1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bt_Retangulo1ActionPerformed(evt);
            }
        });
        add(bt_Retangulo1);
        bt_Retangulo1.setBounds(40, 20, 28, 28);
        add(jSlider1);
        jSlider1.setBounds(10, 80, 100, 25);

        jLabel1.setText("10 px");
        add(jLabel1);
        jLabel1.setBounds(110, 80, 30, 30);
    }// </editor-fold>//GEN-END:initComponents

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

    mudarFerramentaPrincipal();
    painelCanvas.adicionarFerramentaDeDesenho(ferramentaDesenharLinha);
}//GEN-LAST:event_bt_LinhaActionPerformed

private void bt_Pincel1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bt_Pincel1ActionPerformed
    mudarFerramentaPrincipal();
    //painelCanvas.adicionarFerramentaDeDesenho(ferramentaDesenharPincel);
}//GEN-LAST:event_bt_Pincel1ActionPerformed

private void bt_Retangulo1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bt_Retangulo1ActionPerformed
    mudarFerramentaPrincipal();
    //painelCanvas.adicionarFerramentaDeDesenho(ferramentaDesenharRetangulo);
}//GEN-LAST:event_bt_Retangulo1ActionPerformed

private void mudarFerramentaPrincipal(){
    //muda para ferramenta de inserção de alvos
    if(this.painelPai instanceof PainelFerramentaAlvos){
        PainelFerramentaAlvos painelFerramentaAlvos = ((PainelFerramentaAlvos)painelPai);
        PainelCores painelCores = (PainelCores) painelFerramentaAlvos.getPainelCores();
        painelCanvas = painelFerramentaAlvos.getCanvas();

        painelFerramentaAlvos.getFerramentaInserirAlvo().setCorTexturaAlvo( (java.awt.Color)painelCores.getCorSelecionada());
        painelFerramentaAlvos.getFerramentaInserirAlvo().setEmParaleloComFerramentasDeDesenho(true);
        painelCanvas.mudarFerramenta(painelFerramentaAlvos.getFerramentaInserirAlvo());
    }
    //muda para ferramenta de desenho do ambiente
    else if(this.painelPai instanceof PainelFerramentaAmbiente){
        painelCanvas = ((PainelFerramentaAlvos)painelPai).getCanvas();
        painelCanvas.mudarFerramenta(new FerramentaNula(null));
    }
}

public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                JFrame frame =  new JFrame();
               
                PainelFerramentasDesenho panel = new PainelFerramentasDesenho(null);
                panel.setPreferredSize(new java.awt.Dimension(150,100));
                panel.setVisible(true);

                frame.setContentPane(panel);
                frame.setVisible(true);
                frame.setSize(new java.awt.Dimension(150,300));
                frame.pack();
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton bt_Linha;
    private javax.swing.JButton bt_Pincel1;
    private javax.swing.JButton bt_Retangulo1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JSlider jSlider1;
    // End of variables declaration//GEN-END:variables

}
