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

/*
 * JFrameUltimosMovimientos.java
 *
 * Created on 10-dic-2009, 18:47:03
 */

package javacgc;

import java.util.ArrayList;
import java.util.Iterator;
import javax.swing.DefaultListModel;
import javax.swing.ListSelectionModel;

/**
 *
 * @author Administrador
 */
public class JFrameUltimosMovimientos extends javax.swing.JFrame {
        Producto p=new Producto();
    /** Creates new form JFrameUltimosMovimientos */
    public JFrameUltimosMovimientos(Producto pro) {
        p=pro;
        initComponents();
        ArrayList<Movimiento> a=p.buscarMovs();
        if(a==null){jTextArea1.setText("No existe el producto solicitado");}//esto es para comprobar que tengamos guardado el producto correctamnte
        DefaultListModel dlm = new DefaultListModel();
        jlstUltMov.setModel(dlm);
        jlstUltMov.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        Iterator iterador = a.listIterator();

        while( iterador.hasNext() ) {
            Movimiento m= (Movimiento) iterador.next();
            dlm.addElement(m.getId()+"    "+m.getConceptobreve()+" "+m.getFechaOperacion());
        }
    }

    /** This method is called from wictathin 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() {

        jLabel1 = new javax.swing.JLabel();
        jbttnseleccionar = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        jlstUltMov = new javax.swing.JList();
        jScrollPane2 = new javax.swing.JScrollPane();
        jTextArea1 = new javax.swing.JTextArea();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        jLabel1.setText("Ultimos Movimientos: ");

        jbttnseleccionar.setText("Seleccionar");
        jbttnseleccionar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbttnseleccionarActionPerformed(evt);
            }
        });

        jlstUltMov.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        jScrollPane1.setViewportView(jlstUltMov);

        jTextArea1.setColumns(20);
        jTextArea1.setRows(5);
        jScrollPane2.setViewportView(jTextArea1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 313, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGap(15, 15, 15)
                                .addComponent(jLabel1))
                            .addGroup(layout.createSequentialGroup()
                                .addContainerGap()
                                .addComponent(jbttnseleccionar)))
                        .addGap(18, 18, 18)
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 213, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(51, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(28, 28, 28)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 143, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(29, 29, 29))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addGap(42, 42, 42)
                        .addComponent(jbttnseleccionar)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(36, 36, 36))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

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

        String cadena=(String)jlstUltMov.getSelectedValue();
        Movimiento m= p.buscarMov(Integer.valueOf(cadena.substring(0,5)));
        jTextArea1.setText(m.getId()+"  "+m.getConceptobreve()+" "+m.getFechaOperacion()+"  "+m.getImporte());

        //aki muestra lo del area
    }//GEN-LAST:event_jbttnseleccionarActionPerformed

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
               // new JFrameUltimosMovimientos().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel jLabel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JTextArea jTextArea1;
    private javax.swing.JButton jbttnseleccionar;
    private javax.swing.JList jlstUltMov;
    // End of variables declaration//GEN-END:variables

}
