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

/*
 * jfrmCasodeUso.java
 *
 * Created on 22-nov-2011, 17:05:03
 */

package vista;

import java.awt.Component;
import javax.swing.JOptionPane;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeModel;
import javax.swing.tree.MutableTreeNode;
import modelo.CasodeUso;
import modelo.DocumentoReq;

/**
 *
 * @author acc_local
 */
public class jfrmCasodeUso extends javax.swing.JFrame {
    DocumentoReq auxDocPpal;
    jfrmPrincipal jfaux;
    MutableTreeNode auxinsertNode;
    int auxinsertIndex;

    /** Creates new form jfrmCasodeUso */
    public jfrmCasodeUso(jfrmPrincipal jf, DocumentoReq docPpal, MutableTreeNode insertNode, int insertIndex) {
        auxinsertNode=insertNode;
        auxinsertIndex=insertIndex;
        jfaux=jf;
        auxDocPpal=docPpal;
        initComponents();
    }

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

        jTabCU = new javax.swing.JTabbedPane();
        jpanGeneral = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jtxtNombreCU = new javax.swing.JTextField();
        jchbesAbstracto = new javax.swing.JCheckBox();
        jLabel2 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jtxaEventoActivacion = new javax.swing.JTextArea();
        jtxtFrecuencia = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        jtxtUnidadFrecuencia = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        jpanPrePost = new javax.swing.JPanel();
        jLabel5 = new javax.swing.JLabel();
        jScrollPane2 = new javax.swing.JScrollPane();
        jtxaPrecondicion = new javax.swing.JTextArea();
        jLabel6 = new javax.swing.JLabel();
        jScrollPane3 = new javax.swing.JScrollPane();
        jtxaPostcondicion = new javax.swing.JTextArea();
        jpanPrioridad = new javax.swing.JPanel();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        jTextField1 = new javax.swing.JTextField();
        jTextField2 = new javax.swing.JTextField();
        jTextField3 = new javax.swing.JTextField();
        jTextField4 = new javax.swing.JTextField();
        jbtnAceptar = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jLabel1.setText("Nombre:");

        jchbesAbstracto.setText("CU Abstracto");
        jchbesAbstracto.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jchbesAbstractoActionPerformed(evt);
            }
        });

        jLabel2.setText("Evento de activacion:");

        jtxaEventoActivacion.setColumns(20);
        jtxaEventoActivacion.setRows(5);
        jScrollPane1.setViewportView(jtxaEventoActivacion);

        jLabel4.setText("veces al ");

        jtxtUnidadFrecuencia.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jtxtUnidadFrecuenciaActionPerformed(evt);
            }
        });

        jLabel3.setText("Frecuencia:");

        javax.swing.GroupLayout jpanGeneralLayout = new javax.swing.GroupLayout(jpanGeneral);
        jpanGeneral.setLayout(jpanGeneralLayout);
        jpanGeneralLayout.setHorizontalGroup(
            jpanGeneralLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jpanGeneralLayout.createSequentialGroup()
                .addGap(51, 51, 51)
                .addGroup(jpanGeneralLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jpanGeneralLayout.createSequentialGroup()
                        .addComponent(jLabel3)
                        .addGap(4, 4, 4)
                        .addComponent(jtxtFrecuencia, javax.swing.GroupLayout.PREFERRED_SIZE, 43, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jLabel4)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jtxtUnidadFrecuencia, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jLabel2)
                    .addComponent(jchbesAbstracto, javax.swing.GroupLayout.PREFERRED_SIZE, 199, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jpanGeneralLayout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jtxtNombreCU, javax.swing.GroupLayout.PREFERRED_SIZE, 236, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(58, Short.MAX_VALUE))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jpanGeneralLayout.createSequentialGroup()
                .addGap(39, 39, 39)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 329, Short.MAX_VALUE)
                .addGap(22, 22, 22))
        );
        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(jtxtNombreCU, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jchbesAbstracto)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel2)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 23, Short.MAX_VALUE)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addGroup(jpanGeneralLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jtxtFrecuencia, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel4)
                    .addComponent(jtxtUnidadFrecuencia, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel3))
                .addGap(16, 16, 16))
        );

        jTabCU.addTab("General", jpanGeneral);

        jLabel5.setText("Precondicion:");

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

        jLabel6.setText("Postcondicion:");

        jtxaPostcondicion.setColumns(20);
        jtxaPostcondicion.setRows(5);
        jScrollPane3.setViewportView(jtxaPostcondicion);

        javax.swing.GroupLayout jpanPrePostLayout = new javax.swing.GroupLayout(jpanPrePost);
        jpanPrePost.setLayout(jpanPrePostLayout);
        jpanPrePostLayout.setHorizontalGroup(
            jpanPrePostLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jpanPrePostLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jpanPrePostLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(jScrollPane3, javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 337, Short.MAX_VALUE)
                    .addComponent(jLabel5, javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel6, javax.swing.GroupLayout.Alignment.LEADING))
                .addContainerGap(43, Short.MAX_VALUE))
        );
        jpanPrePostLayout.setVerticalGroup(
            jpanPrePostLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jpanPrePostLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel5)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 66, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel6)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 71, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(36, 36, 36))
        );

        jTabCU.addTab("Pre/Post", jpanPrePost);

        jLabel7.setText("Importancia:");

        jLabel8.setText("Urgencia:");

        jLabel9.setText("Estado de desarrollo:");

        jLabel10.setText("Estabilidad:");

        jTextField1.setText("jTextField1");

        jTextField2.setText("jTextField2");

        jTextField3.setText("jTextField3");

        jTextField4.setText("jTextField4");

        javax.swing.GroupLayout jpanPrioridadLayout = new javax.swing.GroupLayout(jpanPrioridad);
        jpanPrioridad.setLayout(jpanPrioridadLayout);
        jpanPrioridadLayout.setHorizontalGroup(
            jpanPrioridadLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jpanPrioridadLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jpanPrioridadLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel7)
                    .addComponent(jLabel8)
                    .addComponent(jLabel9)
                    .addComponent(jLabel10))
                .addGap(22, 22, 22)
                .addGroup(jpanPrioridadLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jTextField4)
                    .addComponent(jTextField3)
                    .addComponent(jTextField2)
                    .addComponent(jTextField1, javax.swing.GroupLayout.DEFAULT_SIZE, 200, Short.MAX_VALUE))
                .addContainerGap(56, Short.MAX_VALUE))
        );
        jpanPrioridadLayout.setVerticalGroup(
            jpanPrioridadLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jpanPrioridadLayout.createSequentialGroup()
                .addGap(49, 49, 49)
                .addGroup(jpanPrioridadLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel7)
                    .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jpanPrioridadLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel8)
                    .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jpanPrioridadLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel9)
                    .addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jpanPrioridadLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel10)
                    .addComponent(jTextField4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(83, Short.MAX_VALUE))
        );

        jTabCU.addTab("Prioridad", jpanPrioridad);

        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()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jTabCU, javax.swing.GroupLayout.DEFAULT_SIZE, 395, Short.MAX_VALUE)
                        .addContainerGap())
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(jbtnAceptar)
                        .addGap(164, 164, 164))))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(20, Short.MAX_VALUE)
                .addComponent(jTabCU, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jbtnAceptar)
                .addContainerGap())
        );

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

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

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

    private void jbtnAceptarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtnAceptarActionPerformed
        CasodeUso newCU= auxDocPpal.nuevoCU(jtxtNombreCU.getText(),jchbesAbstracto.isSelected(),jtxaEventoActivacion.getText(),Integer.parseInt(jtxtFrecuencia.getText()),jtxtUnidadFrecuencia.getText(),jtxaPrecondicion.getText(),jtxaPostcondicion.getText());
        MutableTreeNode node=new DefaultMutableTreeNode("CU " + newCU.getNombre());
        DefaultTreeModel model =(DefaultTreeModel) jfaux.getJtreDocumento().getModel();
        model.insertNodeInto(node, auxinsertNode, auxinsertIndex);
        mostrarmensaje("Insertado el CU "+newCU.getNombre());
        jfaux.setEnabled(true);
        this.dispose();

    }//GEN-LAST:event_jbtnAceptarActionPerformed

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

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    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.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JTabbedPane jTabCU;
    private javax.swing.JTextField jTextField1;
    private javax.swing.JTextField jTextField2;
    private javax.swing.JTextField jTextField3;
    private javax.swing.JTextField jTextField4;
    private javax.swing.JButton jbtnAceptar;
    private javax.swing.JCheckBox jchbesAbstracto;
    private javax.swing.JPanel jpanGeneral;
    private javax.swing.JPanel jpanPrePost;
    private javax.swing.JPanel jpanPrioridad;
    private javax.swing.JTextArea jtxaEventoActivacion;
    private javax.swing.JTextArea jtxaPostcondicion;
    private javax.swing.JTextArea jtxaPrecondicion;
    private javax.swing.JTextField jtxtFrecuencia;
    private javax.swing.JTextField jtxtNombreCU;
    private javax.swing.JTextField jtxtUnidadFrecuencia;
    // End of variables declaration//GEN-END:variables


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