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

/*
 * jfrmpaso.java
 *
 * Created on 26-nov-2011, 10:48:50
 */

package vista;

import java.util.Enumeration;
import javax.swing.JOptionPane;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeModel;
import javax.swing.tree.MutableTreeNode;
import javax.swing.tree.TreeNode;
import modelo.CasodeUso;
import modelo.PasoCU;
import modelo.DocumentoReq;


/**
 *
 * @author jmnieves
 */
public class jfrmpaso extends javax.swing.JPanel {
    DocumentoReq auxDocPpal;
    CasodeUso auxCasodeUso;
    jfrmPrincipal jfaux;
    //jfrmCasodeUso jfaux;
    MutableTreeNode auxinsertNode;
    int auxinsertIndex;

    /** Creates new form jfrmpaso */
    public jfrmpaso(jfrmPrincipal jfp, CasodeUso docCasodeUso, MutableTreeNode insertNode, int insertIndex) {
        auxinsertNode=insertNode;
        auxinsertIndex=insertIndex;
        //auxDocPpal=docPpal;
        auxCasodeUso= docCasodeUso;
        jfaux=jfp;
        initComponents();
    }




     private void imprimirNodos(DefaultMutableTreeNode root) {
        jtxaCondicion.append(root.toString()+"\n");

        if(root.getChildCount()>0){
            for(Enumeration e=root.children(); e.hasMoreElements();){
                TreeNode node=(TreeNode) e.nextElement();
                imprimirNodos((DefaultMutableTreeNode) node);
            }
        }
    }


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

        jTabbedPane1 = new javax.swing.JTabbedPane();
        jPanelCondicion = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jradCondicion = new javax.swing.JRadioButton();
        jLabel2 = new javax.swing.JLabel();
        jScrollPane2 = new javax.swing.JScrollPane();
        jtxaCondicion = new javax.swing.JTextArea();
        jPanelAccion = new javax.swing.JPanel();
        jLabel3 = new javax.swing.JLabel();
        jradSistema = new javax.swing.JRadioButton();
        jradActor = new javax.swing.JRadioButton();
        jradInclusionExtension = new javax.swing.JRadioButton();
        jcboxActor = new javax.swing.JComboBox();
        jcboxCU = new javax.swing.JComboBox();
        jLabel4 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jtxaAccionRealizadaSistema = new javax.swing.JTextArea();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jtxtValor = new javax.swing.JTextField();
        jLabel7 = new javax.swing.JLabel();
        jcboxUnidad = new javax.swing.JComboBox();
        jbtaceptar = new javax.swing.JButton();

        jLabel1.setText("Tipo de paso");

        jradCondicion.setText("Este paso es condicional");
        jradCondicion.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jradCondicionActionPerformed(evt);
            }
        });

        jLabel2.setText("Condición");

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

        javax.swing.GroupLayout jPanelCondicionLayout = new javax.swing.GroupLayout(jPanelCondicion);
        jPanelCondicion.setLayout(jPanelCondicionLayout);
        jPanelCondicionLayout.setHorizontalGroup(
            jPanelCondicionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelCondicionLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanelCondicionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 432, Short.MAX_VALUE)
                    .addComponent(jLabel1)
                    .addGroup(jPanelCondicionLayout.createSequentialGroup()
                        .addGap(10, 10, 10)
                        .addComponent(jradCondicion))
                    .addComponent(jLabel2))
                .addContainerGap())
        );
        jPanelCondicionLayout.setVerticalGroup(
            jPanelCondicionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelCondicionLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jradCondicion)
                .addGap(18, 18, 18)
                .addComponent(jLabel2)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 145, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(72, Short.MAX_VALUE))
        );

        jTabbedPane1.addTab("Condición", jPanelCondicion);

        jLabel3.setText("Tipo de Acción");

        jradSistema.setText("Acción del sistema");
        jradSistema.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jradSistemaActionPerformed(evt);
            }
        });

        jradActor.setText("Acción de un actor");

        jradInclusionExtension.setText("Inclusión/extensión");

        jcboxActor.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));

        jcboxCU.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));

        jLabel4.setText("Acción(es) realizada(s) por el sistema/ un actor");

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

        jLabel5.setText("Rendimiento");

        jLabel6.setText("Valor");

        jtxtValor.setText("jTextField1");
        jtxtValor.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jtxtValorActionPerformed(evt);
            }
        });

        jLabel7.setText("Unidad");

        jcboxUnidad.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));

        javax.swing.GroupLayout jPanelAccionLayout = new javax.swing.GroupLayout(jPanelAccion);
        jPanelAccion.setLayout(jPanelAccionLayout);
        jPanelAccionLayout.setHorizontalGroup(
            jPanelAccionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelAccionLayout.createSequentialGroup()
                .addGroup(jPanelAccionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanelAccionLayout.createSequentialGroup()
                        .addGap(19, 19, 19)
                        .addGroup(jPanelAccionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanelAccionLayout.createSequentialGroup()
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jradActor))
                            .addComponent(jradInclusionExtension))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanelAccionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jcboxCU, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jcboxActor, 0, 192, Short.MAX_VALUE)))
                    .addGroup(jPanelAccionLayout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jLabel4))
                    .addGroup(jPanelAccionLayout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 432, Short.MAX_VALUE))
                    .addGroup(jPanelAccionLayout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jLabel5))
                    .addGroup(jPanelAccionLayout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(jPanelAccionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanelAccionLayout.createSequentialGroup()
                                .addGap(10, 10, 10)
                                .addComponent(jradSistema))
                            .addComponent(jLabel3)))
                    .addGroup(jPanelAccionLayout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jLabel6)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jtxtValor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(59, 59, 59)
                        .addComponent(jLabel7)
                        .addGap(27, 27, 27)
                        .addComponent(jcboxUnidad, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        jPanelAccionLayout.setVerticalGroup(
            jPanelAccionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelAccionLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel3)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jradSistema)
                .addGap(7, 7, 7)
                .addGroup(jPanelAccionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jcboxActor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jradActor))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanelAccionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jradInclusionExtension)
                    .addComponent(jcboxCU, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel4)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 55, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel5)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanelAccionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel6)
                    .addGroup(jPanelAccionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jtxtValor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel7)
                        .addComponent(jcboxUnidad, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(67, Short.MAX_VALUE))
        );

        jTabbedPane1.addTab("Acción", jPanelAccion);

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

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.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(jTabbedPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 457, Short.MAX_VALUE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(201, 201, 201)
                        .addComponent(jbtaceptar)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jTabbedPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 333, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(34, 34, 34)
                .addComponent(jbtaceptar)
                .addGap(37, 37, 37))
        );
    }// </editor-fold>//GEN-END:initComponents

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

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

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

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

        PasoCU newpaso= auxDocPpal.nuevoPaso(jradCondicion.isSelected(),jtxaCondicion.getText(),jradSistema.isSelected(),jradActor.isSelected(),jradInclusionExtension.isSelected(),jtxaAccionRealizadaSistema.getText(),Integer.parseInt(jtxtValor.getText()),Integer.parseInt(jcboxUnidad.getName()));
        MutableTreeNode node=new DefaultMutableTreeNode("Nuevo_Paso " + newpaso.getNombreCU());
        DefaultTreeModel model =(DefaultTreeModel) jfaux.getJtreDocumento().getModel();
        model.insertNodeInto(node, auxinsertNode, auxinsertIndex);
        mostrarmensaje("Insertado el Paso"+newpaso.getNombreCU());
        jfaux.setEnabled(true);
        //this.dispose();

}//GEN-LAST:event_jbtaceptarActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel jLabel1;
    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.JPanel jPanelAccion;
    private javax.swing.JPanel jPanelCondicion;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JTabbedPane jTabbedPane1;
    private javax.swing.JButton jbtaceptar;
    private javax.swing.JComboBox jcboxActor;
    private javax.swing.JComboBox jcboxCU;
    private javax.swing.JComboBox jcboxUnidad;
    private javax.swing.JRadioButton jradActor;
    private javax.swing.JRadioButton jradCondicion;
    private javax.swing.JRadioButton jradInclusionExtension;
    private javax.swing.JRadioButton jradSistema;
    private javax.swing.JTextArea jtxaAccionRealizadaSistema;
    private javax.swing.JTextArea jtxaCondicion;
    private javax.swing.JTextField jtxtValor;
    // End of variables declaration//GEN-END:variables


     private void mostrarmensaje(String mensaje) {
         JOptionPane.showMessageDialog(this, mensaje, "Paso Añadido",
                                JOptionPane.WARNING_MESSAGE);
     }
}
