/*
 * 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 java.io.File;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
import javax.swing.filechooser.FileNameExtensionFilter;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeModel;
import javax.swing.tree.MutableTreeNode;
import modelo.*;


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

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

        SimpleDateFormat sdf = new SimpleDateFormat("dd - MM - yyyy");
        Calendar cal = Calendar.getInstance(); // hoy
        //System.out.println("Hoy es " + sdf.format(cal.getTime()));

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

        jTabGrafico = new javax.swing.JTabbedPane();
        jpanGeneral = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jtxtGrafico = new javax.swing.JTextField();
        jLabel11 = new javax.swing.JLabel();
        jDateReuG = new com.toedter.calendar.JDateChooser();
        jpanDetalle = new javax.swing.JPanel();
        jLabel5 = new javax.swing.JLabel();
        jtxtbuscar = new javax.swing.JTextField();
        jbtnbuscar = new javax.swing.JButton();
        jpanRastreabilidad = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jtxaTrazasDesde = new javax.swing.JTextArea();
        jScrollPane2 = new javax.swing.JScrollPane();
        jtxaTrazasHacia = new javax.swing.JTextArea();
        jLabel3 = new javax.swing.JLabel();
        jpanComentarios = new javax.swing.JPanel();
        jLabel8 = new javax.swing.JLabel();
        jtxtComentarios = new javax.swing.JTextField();
        jbtnAceptar = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jLabel1.setText("Nombre:");

        jtxtGrafico.setText("Prueba de Grafico");
        jtxtGrafico.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jtxtGraficoActionPerformed(evt);
            }
        });

        jLabel11.setText("Fecha");

        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, false)
                    .addGroup(jpanGeneralLayout.createSequentialGroup()
                        .addGap(158, 158, 158)
                        .addComponent(jLabel11)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jDateReuG, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jpanGeneralLayout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jtxtGrafico)))
                .addGap(382, 382, 382))
        );
        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(jtxtGrafico, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jpanGeneralLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel11)
                    .addComponent(jDateReuG, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(202, Short.MAX_VALUE))
        );

        jTabGrafico.addTab("General", jpanGeneral);

        jLabel5.setText("Fichero Grafico");

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

        javax.swing.GroupLayout jpanDetalleLayout = new javax.swing.GroupLayout(jpanDetalle);
        jpanDetalle.setLayout(jpanDetalleLayout);
        jpanDetalleLayout.setHorizontalGroup(
            jpanDetalleLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jpanDetalleLayout.createSequentialGroup()
                .addGroup(jpanDetalleLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jpanDetalleLayout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jLabel5))
                    .addGroup(jpanDetalleLayout.createSequentialGroup()
                        .addGap(39, 39, 39)
                        .addComponent(jtxtbuscar, javax.swing.GroupLayout.PREFERRED_SIZE, 321, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(36, 36, 36)
                        .addComponent(jbtnbuscar, javax.swing.GroupLayout.PREFERRED_SIZE, 44, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(280, Short.MAX_VALUE))
        );
        jpanDetalleLayout.setVerticalGroup(
            jpanDetalleLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jpanDetalleLayout.createSequentialGroup()
                .addGap(25, 25, 25)
                .addComponent(jLabel5)
                .addGap(18, 18, 18)
                .addGroup(jpanDetalleLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jtxtbuscar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jbtnbuscar, javax.swing.GroupLayout.PREFERRED_SIZE, 27, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(196, Short.MAX_VALUE))
        );

        jTabGrafico.addTab("Detalle", jpanDetalle);

        jLabel2.setText("Trazas desde este objeto");

        jtxaTrazasDesde.setColumns(20);
        jtxaTrazasDesde.setRows(5);
        jtxaTrazasDesde.setText("PD");
        jScrollPane1.setViewportView(jtxaTrazasDesde);

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

        jLabel3.setText("Trazas hacia este objeto");

        javax.swing.GroupLayout jpanRastreabilidadLayout = new javax.swing.GroupLayout(jpanRastreabilidad);
        jpanRastreabilidad.setLayout(jpanRastreabilidadLayout);
        jpanRastreabilidadLayout.setHorizontalGroup(
            jpanRastreabilidadLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jpanRastreabilidadLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jpanRastreabilidadLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jpanRastreabilidadLayout.createSequentialGroup()
                        .addGroup(jpanRastreabilidadLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jScrollPane2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 340, Short.MAX_VALUE)
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jpanRastreabilidadLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 339, Short.MAX_VALUE)
                                .addComponent(jLabel2, javax.swing.GroupLayout.Alignment.LEADING)))
                        .addContainerGap(370, Short.MAX_VALUE))
                    .addGroup(jpanRastreabilidadLayout.createSequentialGroup()
                        .addComponent(jLabel3)
                        .addContainerGap(592, Short.MAX_VALUE))))
        );
        jpanRastreabilidadLayout.setVerticalGroup(
            jpanRastreabilidadLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jpanRastreabilidadLayout.createSequentialGroup()
                .addGap(20, 20, 20)
                .addComponent(jLabel2)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 87, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 32, Short.MAX_VALUE)
                .addComponent(jLabel3)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 74, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(22, 22, 22))
        );

        jTabGrafico.addTab("Rastreabilidad", jpanRastreabilidad);

        jLabel8.setText("Comentarios");

        jtxtComentarios.setText("PD");
        jtxtComentarios.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jtxtComentariosActionPerformed(evt);
            }
        });

        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)
                    .addGroup(jpanComentariosLayout.createSequentialGroup()
                        .addGap(10, 10, 10)
                        .addComponent(jtxtComentarios, javax.swing.GroupLayout.PREFERRED_SIZE, 349, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jLabel8))
                .addContainerGap(351, Short.MAX_VALUE))
        );
        jpanComentariosLayout.setVerticalGroup(
            jpanComentariosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jpanComentariosLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel8)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jtxtComentarios, javax.swing.GroupLayout.PREFERRED_SIZE, 196, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(53, Short.MAX_VALUE))
        );

        jTabGrafico.addTab("Comentarios", jpanComentarios);

        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(jTabGrafico)
                        .addContainerGap())
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(jbtnAceptar)
                        .addGap(168, 168, 168))))
        );
        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(jTabGrafico, javax.swing.GroupLayout.PREFERRED_SIZE, 308, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(30, 30, 30)
                .addComponent(jbtnAceptar)
                .addGap(35, 35, 35))
        );

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

    private void jbtnAceptarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtnAceptarActionPerformed
        
        MutableTreeNode node=new DefaultMutableTreeNode("GR "+jtxtGrafico.getText());
        DefaultTreeModel model =(DefaultTreeModel) jfaux.getJtreDocumento().getModel();
        model.insertNodeInto(node, auxinsertNode, auxinsertIndex);
        Grafico nuevoGrafico= auxDocPpal.nuevoGrafico(jDateReuG.getDate(),jtxtGrafico.getText(),jtxtbuscar.getText(),jtxaTrazasDesde.getText(),jtxaTrazasHacia.getText(),jtxtComentarios.getText());//mostrarmensaje("Insertado el CU "+newCU.getNombre());
        //this.setEnabled(false);
        jfaux.setEnabled(true);
        this.dispose();

    }//GEN-LAST:event_jbtnAceptarActionPerformed

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

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

    private void jbtnbuscarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtnbuscarActionPerformed
        FileNameExtensionFilter filter = new FileNameExtensionFilter ("Grafico jpg","jpg");

        //se crea el fileChooser
        JFileChooser fileChooser = new JFileChooser();
        //fileChooser.addChoosableFileFilter(filter);
        //se añade el filtro
        fileChooser.setFileFilter(filter);
        //tituelo de la ventana
        fileChooser.setDialogTitle("Insertar Grafico");
        //se crea un nuevo file donde se especifica la ruta de destino
        File ruta = new File("Ruta de destino");
        //coloca la ruta donde se abrira el fileChooser
        fileChooser.setCurrentDirectory(ruta);
        int result = fileChooser.showOpenDialog(null);
        if (result == JFileChooser.APPROVE_OPTION)
        {
        File file = fileChooser.getSelectedFile();
        jtxtbuscar.setText("file:///"+String.valueOf(file));
        }
    }//GEN-LAST:event_jbtnbuscarActionPerformed

    /**
    * @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 com.toedter.calendar.JDateChooser jDateReuG;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JTabbedPane jTabGrafico;
    private javax.swing.JButton jbtnAceptar;
    private javax.swing.JButton jbtnbuscar;
    private javax.swing.JPanel jpanComentarios;
    private javax.swing.JPanel jpanDetalle;
    private javax.swing.JPanel jpanGeneral;
    private javax.swing.JPanel jpanRastreabilidad;
    private javax.swing.JTextArea jtxaTrazasDesde;
    private javax.swing.JTextArea jtxaTrazasHacia;
    private javax.swing.JTextField jtxtComentarios;
    private javax.swing.JTextField jtxtGrafico;
    private javax.swing.JTextField jtxtbuscar;
    // End of variables declaration//GEN-END:variables


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