
package locadora.ui;
/*
 * JCadastraVideo.java
 *
 * Created on 11 de Outubro de 2004, 11:24
 */

/**
 *
 * @author  Rafael
 */
import javax.swing.*;
import locadora.core.*;
import locadora.main.*;
import locadora.ui.*;
import locadora.factory.Factory;

public class JCadastraVideo extends javax.swing.JInternalFrame implements IRecebeSelecao{
    
    /** Creates new form JCadastraVideo */
    Video video;
    JNumeroField tfValor;
    
    public JCadastraVideo() {
        initComponents();
        init();
        this.setSize(400,400);
        
        loadObject(new Video());
    }
    
    public void init()
    {
        tfValor = new JNumeroField();
        tfValor.setTipoMonetario(true);
        getContentPane().add(tfValor);
        tfValor.setBounds(35, 156, 46, 19);
        tfValor.updateUI();
        
    }
    
    public void setSelecionado(Object obj)
    {
           video.setFilme((Filme) obj);
           loadObject(video);
    }
    
    /** 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.
     */
    private void initComponents() {//GEN-BEGIN:initComponents
        jLabel1 = new javax.swing.JLabel();
        cbTipoVideo = new javax.swing.JComboBox();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jPanel1 = new javax.swing.JPanel();
        btnSalvar = new javax.swing.JButton();
        btnCancelar = new javax.swing.JButton();
        tfFilme = new javax.swing.JTextField();
        btnProcurarFilme = new javax.swing.JButton();

        getContentPane().setLayout(null);

        setClosable(true);
        setTitle("Cadastrar V\u00eddeo");
        jLabel1.setText("Filme");
        getContentPane().add(jLabel1);
        jLabel1.setBounds(24, 20, 48, 14);

        cbTipoVideo.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "VHS", "DVD" }));
        getContentPane().add(cbTipoVideo);
        cbTipoVideo.setBounds(22, 94, 96, 22);

        jLabel2.setText("Tipo de V\u00eddeo");
        getContentPane().add(jLabel2);
        jLabel2.setBounds(22, 78, 88, 14);

        jLabel3.setText("Pre\u00e7o do Aluguel");
        getContentPane().add(jLabel3);
        jLabel3.setBounds(22, 136, 116, 14);

        jPanel1.setLayout(null);

        jPanel1.setBorder(new javax.swing.border.EtchedBorder());
        btnSalvar.setText("Salvar");
        btnSalvar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSalvarActionPerformed(evt);
            }
        });

        jPanel1.add(btnSalvar);
        btnSalvar.setBounds(12, 12, 102, 23);

        btnCancelar.setText("Cancelar");
        btnCancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCancelarActionPerformed(evt);
            }
        });

        jPanel1.add(btnCancelar);
        btnCancelar.setBounds(116, 12, 108, 23);

        getContentPane().add(jPanel1);
        jPanel1.setBounds(152, 194, 232, 48);

        getContentPane().add(tfFilme);
        tfFilme.setBounds(24, 36, 170, 19);

        btnProcurarFilme.setText("...");
        btnProcurarFilme.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnProcurarFilmeActionPerformed(evt);
            }
        });

        getContentPane().add(btnProcurarFilme);
        btnProcurarFilme.setBounds(208, 34, 20, 23);

        pack();
    }//GEN-END:initComponents

    private void btnCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCancelarActionPerformed
        this.setVisible(false);
    }//GEN-LAST:event_btnCancelarActionPerformed

    private void btnSalvarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSalvarActionPerformed
        video = (Video) getObject();
        Main.factory.save(video);
       this.setVisible(false);
        
    }//GEN-LAST:event_btnSalvarActionPerformed

    private void btnProcurarFilmeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnProcurarFilmeActionPerformed
        JListagem list;
        list = new JListagem(null,true);
         list.setReceptor(this);
        Factory fac = Main.factory;
        list.setObject(fac.getFilmes());
        list.setVisible(true);
       
        
    }//GEN-LAST:event_btnProcurarFilmeActionPerformed
    
    public void loadObject(Object obj)
    {
        //Main.factory.init();
        video = (Video) obj;
        if(video.getFilme()!=null)
            tfFilme.setText(video.getFilme().toString());
        else
            tfFilme.setText("");
        cbTipoVideo.setSelectedIndex(video.getTipo());
       try{
             tfValor.setValor(video.getValorDiaria());
       }
       catch(Exception e)
       {
           e.printStackTrace();
       }
        
    }
    
    public Object getObject()
    {
        video.setTipo(cbTipoVideo.getSelectedIndex());
        try
        {
        video.setValorDiaria(tfValor.getValor());
        }
        catch(Exception e)
        {
            e.printStackTrace();
        }
        return video;
    }
    
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnCancelar;
    private javax.swing.JButton btnProcurarFilme;
    private javax.swing.JButton btnSalvar;
    private javax.swing.JComboBox cbTipoVideo;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JTextField tfFilme;
    // End of variables declaration//GEN-END:variables
    
}
