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

/*
 * jfrmReunion.java
 *
 * Created on 11-ene-2012, 18:09:35
 */

package vista;

import javax.swing.JOptionPane;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeModel;
import javax.swing.tree.MutableTreeNode;
import modelo.DocumentoReq;
import modelo.Reunion;

/**
 *
 * @author Ruben
 */
public class jfrmReunion extends javax.swing.JFrame {
    DocumentoReq auxDocPpal;
    jfrmPrincipal jfaux;
    MutableTreeNode auxinsertNode;
    int auxinsertIndex;
    
    public jfrmReunion(jfrmPrincipal jf, DocumentoReq docPpal, MutableTreeNode insertNode, int insertIndex) {
        auxinsertNode=insertNode;
        auxinsertIndex=insertIndex;
        jfaux=jf;
        auxDocPpal=docPpal;
        initComponents();
        jtxpComentarios.setText("PD");
    }

    /** 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() {

        jTabReunion = new javax.swing.JTabbedPane();
        jpanGeneral = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jtxtNombre = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        jtxtAutores = new javax.swing.JTextField();
        jtxtFuentes = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        jpanResultado = new javax.swing.JPanel();
        jLabel5 = new javax.swing.JLabel();
        jScrollPane2 = new javax.swing.JScrollPane();
        jtxaResultado = new javax.swing.JTextArea();
        jpanComentarios = new javax.swing.JPanel();
        jLabel6 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jtxpComentarios = new javax.swing.JTextPane();
        jpanDetalles = new javax.swing.JPanel();
        jLabel4 = new javax.swing.JLabel();
        jtxtLugar = new javax.swing.JTextField();
        jLabel11 = new javax.swing.JLabel();
        jScrollPane3 = new javax.swing.JScrollPane();
        jtxaAsistentes = new javax.swing.JTextArea();
        jbtnAceptar = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Nueva reunión");
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosed(java.awt.event.WindowEvent evt) {
                formWindowClosed(evt);
            }
        });

        jLabel1.setText("Nombre:");

        jtxtNombre.setText("Prueba Reunion");

        jLabel2.setText("Autores:");

        jtxtAutores.setText("PD");

        jtxtFuentes.setText("PD");

        jLabel3.setText("Fuentes:");

        javax.swing.GroupLayout jpanGeneralLayout = new javax.swing.GroupLayout(jpanGeneral);
        jpanGeneral.setLayout(jpanGeneralLayout);
        jpanGeneralLayout.setHorizontalGroup(
            jpanGeneralLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jpanGeneralLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jpanGeneralLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jpanGeneralLayout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addGap(12, 12, 12)
                        .addComponent(jtxtNombre, javax.swing.GroupLayout.DEFAULT_SIZE, 322, Short.MAX_VALUE))
                    .addGroup(jpanGeneralLayout.createSequentialGroup()
                        .addComponent(jLabel2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jtxtAutores, javax.swing.GroupLayout.DEFAULT_SIZE, 329, Short.MAX_VALUE))
                    .addGroup(jpanGeneralLayout.createSequentialGroup()
                        .addComponent(jLabel3)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jtxtFuentes, javax.swing.GroupLayout.DEFAULT_SIZE, 328, Short.MAX_VALUE)))
                .addContainerGap())
        );
        jpanGeneralLayout.setVerticalGroup(
            jpanGeneralLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jpanGeneralLayout.createSequentialGroup()
                .addGap(32, 32, 32)
                .addGroup(jpanGeneralLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(jtxtNombre, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jpanGeneralLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(jtxtAutores, javax.swing.GroupLayout.PREFERRED_SIZE, 87, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jpanGeneralLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(jtxtFuentes, javax.swing.GroupLayout.PREFERRED_SIZE, 87, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(12, Short.MAX_VALUE))
        );

        jTabReunion.addTab("General", jpanGeneral);

        jLabel5.setText("Resultado : ");

        jtxaResultado.setColumns(20);
        jtxaResultado.setRows(5);
        jtxaResultado.setText("PD");
        jScrollPane2.setViewportView(jtxaResultado);

        javax.swing.GroupLayout jpanResultadoLayout = new javax.swing.GroupLayout(jpanResultado);
        jpanResultado.setLayout(jpanResultadoLayout);
        jpanResultadoLayout.setHorizontalGroup(
            jpanResultadoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jpanResultadoLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jpanResultadoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 375, Short.MAX_VALUE)
                    .addComponent(jLabel5))
                .addContainerGap())
        );
        jpanResultadoLayout.setVerticalGroup(
            jpanResultadoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jpanResultadoLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel5)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 218, Short.MAX_VALUE)
                .addContainerGap())
        );

        jTabReunion.addTab("Resultado", jpanResultado);

        jLabel6.setText("Comentarios: ");

        jScrollPane1.setViewportView(jtxpComentarios);

        javax.swing.GroupLayout jpanComentariosLayout = new javax.swing.GroupLayout(jpanComentarios);
        jpanComentarios.setLayout(jpanComentariosLayout);
        jpanComentariosLayout.setHorizontalGroup(
            jpanComentariosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jpanComentariosLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jpanComentariosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 375, Short.MAX_VALUE)
                    .addComponent(jLabel6))
                .addContainerGap())
        );
        jpanComentariosLayout.setVerticalGroup(
            jpanComentariosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jpanComentariosLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel6)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 218, Short.MAX_VALUE)
                .addContainerGap())
        );

        jTabReunion.addTab("Comentarios", jpanComentarios);

        jLabel4.setText("Lugar : ");

        jtxtLugar.setText("PD");

        jLabel11.setText("Asistentes");

        jtxaAsistentes.setColumns(20);
        jtxaAsistentes.setRows(5);
        jtxaAsistentes.setText("PD");
        jScrollPane3.setViewportView(jtxaAsistentes);

        javax.swing.GroupLayout jpanDetallesLayout = new javax.swing.GroupLayout(jpanDetalles);
        jpanDetalles.setLayout(jpanDetallesLayout);
        jpanDetallesLayout.setHorizontalGroup(
            jpanDetallesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jpanDetallesLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jpanDetallesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jpanDetallesLayout.createSequentialGroup()
                        .addComponent(jLabel4)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jtxtLugar, javax.swing.GroupLayout.DEFAULT_SIZE, 334, Short.MAX_VALUE))
                    .addGroup(jpanDetallesLayout.createSequentialGroup()
                        .addComponent(jLabel11)
                        .addGap(163, 163, 163))
                    .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 357, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );
        jpanDetallesLayout.setVerticalGroup(
            jpanDetallesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jpanDetallesLayout.createSequentialGroup()
                .addGap(28, 28, 28)
                .addGroup(jpanDetallesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(jtxtLugar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addComponent(jLabel11)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 148, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(21, Short.MAX_VALUE))
        );

        jTabReunion.addTab("Detalles", jpanDetalles);

        jbtnAceptar.setText("Aceptar");
        jbtnAceptar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtnAceptarActionPerformed(evt);
            }
        });

        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.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jTabReunion, javax.swing.GroupLayout.DEFAULT_SIZE, 400, Short.MAX_VALUE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(167, 167, 167)
                        .addComponent(jbtnAceptar)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jTabReunion, javax.swing.GroupLayout.PREFERRED_SIZE, 288, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jbtnAceptar)
                .addContainerGap(21, Short.MAX_VALUE))
        );

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

    private void formWindowClosed(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosed
        jfaux.setEnabled(true);
        this.dispose();
    }//GEN-LAST:event_formWindowClosed

    private void jbtnAceptarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtnAceptarActionPerformed
       if(comprobarTexto())
        {
            Reunion newReunion= auxDocPpal.nuevoReunion("Reu " +jtxtNombre.getText(),jtxtAutores.getText(),jtxtFuentes.getText(),jtxaResultado.getText(),jtxtLugar.getText(),jtxpComentarios.getText(),jtxaAsistentes.getText());
            MutableTreeNode node=new DefaultMutableTreeNode(newReunion.getNombre());
            DefaultTreeModel model =(DefaultTreeModel) jfaux.getJtreDocumento().getModel();
            model.insertNodeInto(node, auxinsertNode, auxinsertIndex);
            mostrarmensaje("Insertada la Reunion "+newReunion.getNombre());
            jfaux.setEnabled(true);
            jfaux.update(null, evt);
            this.dispose();
        }
        else
        {
            mostrarmensaje("Debes rellenar todos los campos!!");
        }
    }//GEN-LAST:event_jbtnAceptarActionPerformed


    private boolean comprobarTexto()
    {
        if(jtxtNombre.getText().equals("") ||
                jtxaResultado.getText().equals("") ||
                jtxtLugar.getText().equals("") ||
                jtxpComentarios.getText().equals("") ||
                jtxaAsistentes.getText().equals("") ||
                jtxtAutores.getText().equals("") ||
                jtxtFuentes.getText().equals(""))
        {
            return false;
        }
        return true;
    }
    /**
    * @param args the command line arguments
    */
   /* public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new jfrmReunion().setVisible(true);
            }
        });
    }*/

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JTabbedPane jTabReunion;
    private javax.swing.JButton jbtnAceptar;
    private javax.swing.JPanel jpanComentarios;
    private javax.swing.JPanel jpanDetalles;
    private javax.swing.JPanel jpanGeneral;
    private javax.swing.JPanel jpanResultado;
    private javax.swing.JTextArea jtxaAsistentes;
    private javax.swing.JTextArea jtxaResultado;
    private javax.swing.JTextPane jtxpComentarios;
    private javax.swing.JTextField jtxtAutores;
    private javax.swing.JTextField jtxtFuentes;
    private javax.swing.JTextField jtxtLugar;
    private javax.swing.JTextField jtxtNombre;
    // End of variables declaration//GEN-END:variables

    private void mostrarmensaje(String mensaje) {
         JOptionPane.showMessageDialog(this, mensaje, "Advertencia",
                                JOptionPane.WARNING_MESSAGE);
    }
}
