
/*
  <ARQ.L> (actual versión: '2.0' o 'v2.0') es un software destinado al registro y procesamiento de información referida a material lítico. Se trata de una vesión digital basada en la propuesta teórico-metodológica del Lic. Carlos Aschero [1975,1983,2020-2021].

    Copyright (C) 2020-2021. Aschero Carlos y Agustina Ponce.

    Este programa es software gratuito; puedes redistribuirlo y / o modificarlo
    bajo los términos de la Licencia Pública General GNU publicada por Free
    Fundación de software; ya sea la versión 2 de la licencia, o (a su elección)
    cualquier versión posterior.

    Este programa se distribuye con la esperanza de que sea útil, pero SIN
    CUALQUIER GARANTIA; incluso sin la garantía implícita de COMERCIABILIDAD o
    APTITUD PARA UN PROPÓSITO PARTICULAR. Consulte la Licencia pública general GNU para
    más detalles.

    Debería haber recibido una copia de la Licencia Pública General GNU junto con
    con este programa; si no es así, escriba a Free Software Foundation, Inc., 59
    Temple Place, Suite 330, Boston, MA 02111-1307 EE. UU.

Para contactarse con el equipo de ARQ.L, escriba un correo electrónico a la dirección:
arqlsoftware@gmail.com


 */
package arql2020;

import Calculos_automaticos.Calculos;
import Calculos_automaticos.Muestras;
import Calculos_automaticos.prueba;
import static arql2020.ARQL2020.ventanamuestra;
import static arql2020.DT_frame.arbol_DT;
import static arql2020.DT_frame.selectednodeparaeliminar;
import static arql2020.Internal_DT_contalon.btn_eliminarregistro_Dt_contalon;
import static arql2020.Internal_DT_sintalon.btn_eliminarregistro_Dt_sintalon;
import static arql2020.Internal_Formatizados.btn_eliminar_formatizados;
import static arql2020.Internal_Nucleos.btn_eliminar_nucleo;
import static arql2020.Internal_estandard.btn_eliminar_estandar;
import static arql2020.Internal_puntas.btn_eliminarpuntas;
import clases.Cargar_procedencia_formularios;
import clases.InteraccionesBD;
import clases.conexion;
import java.util.Enumeration;
import javax.swing.JOptionPane;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeModel;
import javax.swing.tree.TreeNode;
import javax.swing.tree.TreePath;

/**
 *
 * @author chuen
 */
public class FORMATIZADOS_frame extends javax.swing.JFrame {

public static   DefaultMutableTreeNode selectednode;
public static   DefaultTreeModel model;
public static DefaultMutableTreeNode selectednode3;
public static boolean editando=false;
   
    public FORMATIZADOS_frame() {
        initComponents();
        this.setExtendedState(MAXIMIZED_BOTH);
        model = (DefaultTreeModel) jTree1.getModel();
    }

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

        popup = new javax.swing.JPopupMenu();
        Segmental_Estandard = new javax.swing.JMenuItem();
        Punta = new javax.swing.JMenuItem();
        nucleo = new javax.swing.JMenuItem();
        jSeparator3 = new javax.swing.JPopupMenu.Separator();
        Modificar = new javax.swing.JMenu();
        editar_datos = new javax.swing.JMenuItem();
        jScrollPane1 = new javax.swing.JScrollPane();
        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        f_zona_ambiental = new javax.swing.JTextField();
        f_localidad = new javax.swing.JTextField();
        f_sitio = new javax.swing.JTextField();
        f_capa = new javax.swing.JTextField();
        f_estructura_arq = new javax.swing.JTextField();
        f_denominacion_estructuraPl = new javax.swing.JTextField();
        f_tipo_estructuraPl = new javax.swing.JTextField();
        f_cuadro = new javax.swing.JTextField();
        f_microsector = new javax.swing.JTextField();
        jLabel11 = new javax.swing.JLabel();
        f_piso_capa_estruc_arq = new javax.swing.JTextField();
        jLabel12 = new javax.swing.JLabel();
        f_episodio_estructuraPl = new javax.swing.JTextField();
        jLabel13 = new javax.swing.JLabel();
        f_siglasitio = new javax.swing.JTextField();
        jScrollPane2 = new javax.swing.JScrollPane();
        jPanel2 = new javax.swing.JPanel();
        jPanel3 = new javax.swing.JPanel();
        jButton1 = new javax.swing.JButton();
        contraer = new javax.swing.JButton();
        expandir = new javax.swing.JButton();
        jLabel14 = new javax.swing.JLabel();
        jScrollPane3 = new javax.swing.JScrollPane();
        jTree1 = new javax.swing.JTree();
        jButton2 = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();
        txt_cargar_solo = new javax.swing.JTextField();
        jButton4 = new javax.swing.JButton();
        jButton5 = new javax.swing.JButton();
        txt_n_piezascargadas = new javax.swing.JLabel();
        txt_Npiezas = new javax.swing.JTextField();
        Escritorio = new javax.swing.JDesktopPane();
        jMenuBar1 = new javax.swing.JMenuBar();
        jMenu1 = new javax.swing.JMenu();
        jMenuItem3 = new javax.swing.JMenuItem();
        jMenu2 = new javax.swing.JMenu();
        jMenuItem1 = new javax.swing.JMenuItem();
        jMenu3 = new javax.swing.JMenu();
        jMenuItem5 = new javax.swing.JMenuItem();
        jMenu4 = new javax.swing.JMenu();
        jMenuItem6 = new javax.swing.JMenuItem();

        popup.setFont(new java.awt.Font("Segoe UI", 1, 14)); // NOI18N
        popup.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        popup.setMinimumSize(new java.awt.Dimension(10, 6));

        Segmental_Estandard.setBackground(new java.awt.Color(163, 204, 204));
        Segmental_Estandard.setFont(new java.awt.Font("Segoe UI", 1, 14)); // NOI18N
        Segmental_Estandard.setText("Agregar ficha de descripción segmental estandar");
        Segmental_Estandard.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                Segmental_EstandardActionPerformed(evt);
            }
        });
        popup.add(Segmental_Estandard);

        Punta.setBackground(new java.awt.Color(255, 255, 153));
        Punta.setFont(new java.awt.Font("Segoe UI", 1, 14)); // NOI18N
        Punta.setText("Agregar ficha de punta de proyectil");
        Punta.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                PuntaActionPerformed(evt);
            }
        });
        popup.add(Punta);

        nucleo.setBackground(new java.awt.Color(255, 204, 102));
        nucleo.setFont(new java.awt.Font("Segoe UI", 1, 14)); // NOI18N
        nucleo.setText("Agregar ficha de núcleo");
        nucleo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                nucleoActionPerformed(evt);
            }
        });
        popup.add(nucleo);
        popup.add(jSeparator3);

        Modificar.setBackground(new java.awt.Color(204, 204, 204));
        Modificar.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        Modificar.setForeground(new java.awt.Color(255, 0, 0));
        Modificar.setText("Modificar datos");
        Modificar.setFont(new java.awt.Font("Segoe UI", 1, 14)); // NOI18N

        editar_datos.setFont(new java.awt.Font("Segoe UI", 1, 14)); // NOI18N
        editar_datos.setText("Editar");
        editar_datos.setToolTipText("");
        editar_datos.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                editar_datosActionPerformed(evt);
            }
        });
        Modificar.add(editar_datos);

        popup.add(Modificar);

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Útiles y núcleos");
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowActivated(java.awt.event.WindowEvent evt) {
                formWindowActivated(evt);
            }
            public void windowClosing(java.awt.event.WindowEvent evt) {
                formWindowClosing(evt);
            }
            public void windowOpened(java.awt.event.WindowEvent evt) {
                formWindowOpened(evt);
            }
        });

        jPanel1.setBackground(new java.awt.Color(0, 0, 0));

        jLabel1.setBackground(new java.awt.Color(255, 255, 255));
        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel1.setForeground(new java.awt.Color(255, 255, 255));
        jLabel1.setText("PROCEDENCIA");

        jLabel2.setBackground(new java.awt.Color(255, 255, 255));
        jLabel2.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel2.setForeground(new java.awt.Color(255, 255, 255));
        jLabel2.setText("Zona ambiental");

        jLabel3.setBackground(new java.awt.Color(255, 255, 255));
        jLabel3.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel3.setForeground(new java.awt.Color(255, 255, 255));
        jLabel3.setText("Localidad");

        jLabel4.setBackground(new java.awt.Color(255, 255, 255));
        jLabel4.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel4.setForeground(new java.awt.Color(255, 255, 255));
        jLabel4.setText("Sitio");

        jLabel5.setBackground(new java.awt.Color(255, 255, 255));
        jLabel5.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel5.setForeground(new java.awt.Color(255, 255, 255));
        jLabel5.setText("Capa o nivel");

        jLabel6.setBackground(new java.awt.Color(255, 255, 255));
        jLabel6.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel6.setForeground(new java.awt.Color(255, 255, 0));
        jLabel6.setText("Estructura arq.");

        jLabel7.setBackground(new java.awt.Color(255, 255, 255));
        jLabel7.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel7.setForeground(new java.awt.Color(255, 102, 0));
        jLabel7.setText("Tipo de estruc. en pl.");

        jLabel8.setBackground(new java.awt.Color(255, 255, 255));
        jLabel8.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel8.setForeground(new java.awt.Color(255, 102, 0));
        jLabel8.setText("Denominación de estructura en planta");

        jLabel9.setBackground(new java.awt.Color(255, 255, 255));
        jLabel9.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel9.setForeground(new java.awt.Color(0, 255, 204));
        jLabel9.setText("Microsector");

        jLabel10.setBackground(new java.awt.Color(255, 255, 255));
        jLabel10.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel10.setForeground(new java.awt.Color(0, 255, 204));
        jLabel10.setText("Cuadro");

        f_zona_ambiental.setEditable(false);
        f_zona_ambiental.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N

        f_localidad.setEditable(false);
        f_localidad.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N

        f_sitio.setEditable(false);
        f_sitio.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N

        f_capa.setEditable(false);
        f_capa.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N

        f_estructura_arq.setEditable(false);
        f_estructura_arq.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N

        f_denominacion_estructuraPl.setEditable(false);
        f_denominacion_estructuraPl.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N

        f_tipo_estructuraPl.setEditable(false);
        f_tipo_estructuraPl.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N

        f_cuadro.setEditable(false);
        f_cuadro.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N

        f_microsector.setEditable(false);
        f_microsector.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N

        jLabel11.setBackground(new java.awt.Color(255, 255, 255));
        jLabel11.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel11.setForeground(new java.awt.Color(255, 255, 0));
        jLabel11.setText("Piso o sucbapa de la est. arq.");

        f_piso_capa_estruc_arq.setEditable(false);
        f_piso_capa_estruc_arq.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N

        jLabel12.setBackground(new java.awt.Color(255, 255, 255));
        jLabel12.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel12.setForeground(new java.awt.Color(255, 102, 0));
        jLabel12.setText("Episodio de estruc. en pl.");

        f_episodio_estructuraPl.setEditable(false);
        f_episodio_estructuraPl.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N

        jLabel13.setBackground(new java.awt.Color(255, 255, 255));
        jLabel13.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel13.setForeground(new java.awt.Color(255, 255, 255));
        jLabel13.setText("Sigla sitio");

        f_siglasitio.setEditable(false);
        f_siglasitio.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel2)
                    .addComponent(jLabel3)
                    .addComponent(jLabel4)
                    .addComponent(jLabel5)
                    .addComponent(jLabel7)
                    .addComponent(jLabel8)
                    .addComponent(jLabel9)
                    .addComponent(jLabel10)
                    .addComponent(f_zona_ambiental, javax.swing.GroupLayout.PREFERRED_SIZE, 305, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(f_localidad, javax.swing.GroupLayout.PREFERRED_SIZE, 305, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(f_sitio, javax.swing.GroupLayout.PREFERRED_SIZE, 305, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(f_capa, javax.swing.GroupLayout.PREFERRED_SIZE, 305, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(f_estructura_arq, javax.swing.GroupLayout.PREFERRED_SIZE, 305, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(f_denominacion_estructuraPl, javax.swing.GroupLayout.PREFERRED_SIZE, 305, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(f_tipo_estructuraPl, javax.swing.GroupLayout.PREFERRED_SIZE, 305, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(f_cuadro, javax.swing.GroupLayout.PREFERRED_SIZE, 305, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(f_microsector, javax.swing.GroupLayout.PREFERRED_SIZE, 305, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(96, 96, 96)
                        .addComponent(jLabel1))
                    .addComponent(jLabel11)
                    .addComponent(f_piso_capa_estruc_arq, javax.swing.GroupLayout.PREFERRED_SIZE, 305, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel6)
                    .addComponent(jLabel12)
                    .addComponent(f_episodio_estructuraPl, javax.swing.GroupLayout.PREFERRED_SIZE, 305, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel13)
                    .addComponent(f_siglasitio, javax.swing.GroupLayout.PREFERRED_SIZE, 305, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(119, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addGap(27, 27, 27)
                .addComponent(jLabel2)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(f_zona_ambiental, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(4, 4, 4)
                .addComponent(jLabel3)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(f_localidad, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(3, 3, 3)
                .addComponent(jLabel4)
                .addGap(2, 2, 2)
                .addComponent(f_sitio, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel13)
                .addGap(2, 2, 2)
                .addComponent(f_siglasitio, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel5)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(f_capa, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(12, 12, 12)
                .addComponent(jLabel6)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(f_estructura_arq, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jLabel11)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(f_piso_capa_estruc_arq, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(11, 11, 11)
                .addComponent(jLabel8)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(f_denominacion_estructuraPl, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel7)
                .addGap(9, 9, 9)
                .addComponent(f_tipo_estructuraPl, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jLabel12)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(f_episodio_estructuraPl, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jLabel10)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(f_cuadro, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jLabel9)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(f_microsector, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(46, Short.MAX_VALUE))
        );

        jScrollPane1.setViewportView(jPanel1);

        jPanel2.setBackground(new java.awt.Color(255, 255, 255));

        jPanel3.setBackground(new java.awt.Color(255, 255, 255));

        jButton1.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jButton1.setText("+Gral");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        contraer.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        contraer.setText("-");
        contraer.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                contraerActionPerformed(evt);
            }
        });

        expandir.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        expandir.setText("+");
        expandir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                expandirActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 97, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(contraer)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(expandir)
                .addContainerGap())
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(contraer)
                        .addComponent(expandir))
                    .addComponent(jButton1))
                .addGap(51, 51, 51))
        );

        jLabel14.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel14.setText("Piezas");

        jTree1.setFont(new java.awt.Font("Tahoma", 0, 16)); // NOI18N
        javax.swing.tree.DefaultMutableTreeNode treeNode1 = new javax.swing.tree.DefaultMutableTreeNode("root");
        jTree1.setModel(new javax.swing.tree.DefaultTreeModel(treeNode1));
        jTree1.setComponentPopupMenu(popup);
        jTree1.setExpandsSelectedPaths(false);
        jTree1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jTree1MouseClicked(evt);
            }
        });
        jScrollPane3.setViewportView(jTree1);

        jButton2.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jButton2.setText("Buscar");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        jButton3.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jButton3.setText("Muestra");
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });

        txt_cargar_solo.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N

        jButton4.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jButton4.setText("Ok");
        jButton4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton4ActionPerformed(evt);
            }
        });

        jButton5.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jButton5.setText("Todas las piezas");
        jButton5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton5ActionPerformed(evt);
            }
        });

        txt_n_piezascargadas.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        txt_n_piezascargadas.setText("N:");

        txt_Npiezas.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane3)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(jLabel14)
                        .addGap(20, 20, 20)
                        .addComponent(txt_cargar_solo)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jButton4))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addGroup(jPanel2Layout.createSequentialGroup()
                                .addComponent(jButton2)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jButton3, javax.swing.GroupLayout.PREFERRED_SIZE, 120, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jButton5))
                            .addGroup(jPanel2Layout.createSequentialGroup()
                                .addGap(28, 28, 28)
                                .addComponent(txt_n_piezascargadas)
                                .addGap(18, 18, 18)
                                .addComponent(txt_Npiezas)
                                .addGap(59, 59, 59)))
                        .addGap(0, 0, Short.MAX_VALUE)))
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton2)
                    .addComponent(jButton3)
                    .addComponent(jButton5))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 21, Short.MAX_VALUE)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel14)
                    .addComponent(txt_cargar_solo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButton4))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txt_Npiezas, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txt_n_piezascargadas))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 236, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, 44, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        jScrollPane2.setViewportView(jPanel2);

        javax.swing.GroupLayout EscritorioLayout = new javax.swing.GroupLayout(Escritorio);
        Escritorio.setLayout(EscritorioLayout);
        EscritorioLayout.setHorizontalGroup(
            EscritorioLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 612, Short.MAX_VALUE)
        );
        EscritorioLayout.setVerticalGroup(
            EscritorioLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 0, Short.MAX_VALUE)
        );

        jMenuBar1.setFont(new java.awt.Font("Segoe UI", 0, 14)); // NOI18N

        jMenu1.setText("Ir...");
        jMenu1.setFont(new java.awt.Font("Segoe UI", 0, 14)); // NOI18N

        jMenuItem3.setFont(new java.awt.Font("Segoe UI", 0, 14)); // NOI18N
        jMenuItem3.setText("Inicio");
        jMenuItem3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem3ActionPerformed(evt);
            }
        });
        jMenu1.add(jMenuItem3);

        jMenuBar1.add(jMenu1);

        jMenu2.setText("Procedencia");
        jMenu2.setFont(new java.awt.Font("Segoe UI", 0, 14)); // NOI18N

        jMenuItem1.setFont(new java.awt.Font("Segoe UI", 0, 14)); // NOI18N
        jMenuItem1.setText("Editar procedencia");
        jMenuItem1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem1ActionPerformed(evt);
            }
        });
        jMenu2.add(jMenuItem1);

        jMenuBar1.add(jMenu2);

        jMenu3.setForeground(new java.awt.Color(255, 0, 0));
        jMenu3.setText("TABLAS");
        jMenu3.setFont(new java.awt.Font("Segoe UI", 0, 14)); // NOI18N

        jMenuItem5.setFont(new java.awt.Font("Segoe UI", 0, 14)); // NOI18N
        jMenuItem5.setText("De Desechos de Talla");
        jMenuItem5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem5ActionPerformed(evt);
            }
        });
        jMenu3.add(jMenuItem5);

        jMenuBar1.add(jMenu3);

        jMenu4.setForeground(new java.awt.Color(204, 0, 0));
        jMenu4.setText("Análisis predeterminados");
        jMenu4.setFont(new java.awt.Font("Segoe UI", 1, 14)); // NOI18N

        jMenuItem6.setFont(new java.awt.Font("Segoe UI", 0, 14)); // NOI18N
        jMenuItem6.setText("Ir a centro de analisis");
        jMenuItem6.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem6ActionPerformed(evt);
            }
        });
        jMenu4.add(jMenuItem6);

        jMenuBar1.add(jMenu4);

        setJMenuBar(jMenuBar1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(Escritorio)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jScrollPane2)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 704, Short.MAX_VALUE))
            .addComponent(Escritorio)
        );

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

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

       Escritorio.removeAll();
       Internal_Formatizados form = new Internal_Formatizados();
       Escritorio.add(form);
       form.show();
       selectednodeparaeliminar=null;
       btn_eliminar_formatizados.setEnabled(false);
    }//GEN-LAST:event_jButton1ActionPerformed

    private void jMenuItem3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem3ActionPerformed
        presentacion pres = new presentacion();
        pres.setVisible(true);
        this.dispose();
    }//GEN-LAST:event_jMenuItem3ActionPerformed

    private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem1ActionPerformed
Procedencia_scroll p = new Procedencia_scroll();
p.setVisible(true);
    }//GEN-LAST:event_jMenuItem1ActionPerformed

    private void jTree1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTree1MouseClicked
        //este convierte en nodo una ultima rama
//        selectednode = (DefaultMutableTreeNode) jTree1.getLastSelectedPathComponent();
//        path.setText(selectednode.toString());
//
//        TreePath parentPath = jTree1.getSelectionPath();
//        ultimo.setText(parentPath.toString());
    }//GEN-LAST:event_jTree1MouseClicked

    private void jMenuItem5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem5ActionPerformed
        DT_frame dt = new DT_frame();
        dt.setVisible(true);
        this.dispose();
    }//GEN-LAST:event_jMenuItem5ActionPerformed

    private void jMenuItem6ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem6ActionPerformed
        Calculos calc = new Calculos();
        calc.setVisible(true);
        this.dispose();
    }//GEN-LAST:event_jMenuItem6ActionPerformed

 
    
   

    
    
    public static void expandirultimarama(){


int j = jTree1.getRowCount();
       int i = 0;
       while(i < j) {
           jTree1.expandRow(i);
           i += 1;
           j = jTree1.getRowCount();
       }

//
//if (selectednode.getLevel()==1){
//     
//TreeNode raiz = (TreeNode)jTree1.getModel().getRoot();
//String comparacion = selectednode.toString();
//int index =0;
//if (raiz.getChildCount() >= 0) {
//for (Enumeration e=raiz.children(); e.hasMoreElements(); ) {
//TreeNode n = (TreeNode)e.nextElement();
//index = index +1;
//if(selectednode.equals(n)){
//     jTree1.expandRow(index);
//}
//}
//}
//}
//if(selectednode.getLevel()==2){
//
//TreeNode raiz = (TreeNode)jTree1.getModel().getRoot();
//TreeNode padre = selectednode.getParent();
//
//String comparacion = padre.toString();
//int index =0;
//int index2 =0;
//if (raiz.getChildCount() >= 0) {
//for (Enumeration e=raiz.children(); e.hasMoreElements(); ) {
//TreeNode n = (TreeNode)e.nextElement();
//index = index +1;
//if(padre.equals(n)){
//     jTree1.expandRow(index);
//     if (padre.getChildCount() >= 0) {
//for (Enumeration e2=padre.children(); e2.hasMoreElements(); ) {
//TreeNode n2 = (TreeNode)e2.nextElement();
//index2 = index2 +1;
//if(n2.toString().contains("Núcleo")){
// 
//  DefaultMutableTreeNode nodo = selectednode;
//  TreePath path = new TreePath(nodo.getPath()); 
//   jTree1.expandPath(path);   
//     
//     
//}
//}
//}
//     
//}
//}
//}
//}
    
    

// TreeNode padre = selectednode.getParent();
//jTree1.expandPath(parentPath);           
//        
}
    
    public void obtenercodigodenodoseleccionado(){
    //obtener codigo
        selectednode = (DefaultMutableTreeNode) jTree1.getLastSelectedPathComponent();

        Object cod = new Object();

        cod = selectednode.toString();
        //Ver el código de ese nucleo
        String string = cod.toString();
        String[] parts = string.split("/");
        String part1 = parts[0]; // 004
        String part2 = parts[1]; // 034556
        
        
        JOptionPane.showMessageDialog(null, "el codigo es: " +part2);
}
    private void PuntaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_PuntaActionPerformed
int contador= 0;
        selectednode = (DefaultMutableTreeNode) jTree1.getLastSelectedPathComponent();
        int nivel = selectednode.getLevel();

//ve si está en nivel de pieza
        if (nivel == 1) {
// ve si la pieza contiene registros            
            if (selectednode.getDepth() == 0) {

// si es que contiene registros, verifica si es que hay una ficha de este tipo, para la ficha no se repita                
            } else {
//                System.out.println("get child count: " +selectednode.getChildCount() );
                if (selectednode.getChildCount() > 0) {

                    for (Enumeration e = selectednode.children(); e.hasMoreElements();) {
                        TreeNode n = (TreeNode) e.nextElement();
                        String ficha = n.toString();

                        if (ficha.contains("PP-")) {
                            contador = contador + 1;
                        }
                    }
                }
//si es que no contiene fichas de este tipo, te habilita el formulario
                if (contador == 0) {
        Escritorio.removeAll();
        Internal_puntas punta = new Internal_puntas();
        Escritorio.add(punta);
        punta.show();
 
        expandirultimarama();
        
        punta.p1_txt_codigopieza.setText(selectednode.toString());
        selectednodeparaeliminar = selectednode;
        editando=false;
        punta.btn_eliminarpuntas.setEnabled(false);
//si es que ya existe un formulario, entonces te ofrece la advertencia
                } else {
                    JOptionPane.showMessageDialog(null, "Ya existe una ficha de punta de proyectil para la pieza " + selectednode);
                }

            }
        }




        
        
    }//GEN-LAST:event_PuntaActionPerformed

    private void Segmental_EstandardActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_Segmental_EstandardActionPerformed
int contador= 0;
        selectednode = (DefaultMutableTreeNode) jTree1.getLastSelectedPathComponent();
        int nivel = selectednode.getLevel();

//ve si está en nivel de pieza
        if (nivel == 1) {
        Escritorio.removeAll();
        
        Internal_estandard estandard = new Internal_estandard();
        Escritorio.add(estandard);
        estandard.show();
        estandard.s0_txt_codigopieza.setText(selectednode.toString());
        selectednodeparaeliminar = selectednode;
        editando=false;
        btn_eliminar_estandar.setEnabled(false);
                } 

    }//GEN-LAST:event_Segmental_EstandardActionPerformed

    private void formWindowOpened(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowOpened
//Cargar_procedencia_formularios cp = new Cargar_procedencia_formularios();
//cp.setearprocedencia(f_zona_ambiental, f_localidad, f_sitio, f_siglasitio, f_capa, f_estructura_arq, f_piso_capa_estruc_arq, f_denominacion_estructuraPl, f_tipo_estructuraPl, f_episodio_estructuraPl, f_cuadro, f_microsector);
//InteraccionesBD inter = new InteraccionesBD();
//inter.cargartodaslashojasFormatizados(jTree1, "FORMATIZADOS","ID_FORMATIZADOS","PIEZA", "Gen");
//if(ARQL2020.zona_ambiental.equals("zona ambiental")){
//    JOptionPane.showMessageDialog(null, "Recuerde indicar la procedencia antes de cargar las fichas");
//}
    }//GEN-LAST:event_formWindowOpened

    private void formWindowActivated(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowActivated
Cargar_procedencia_formularios cp = new Cargar_procedencia_formularios();
cp.setearprocedencia(f_zona_ambiental, f_localidad, f_sitio, f_siglasitio, f_capa, f_estructura_arq, f_piso_capa_estruc_arq, f_denominacion_estructuraPl, f_tipo_estructuraPl, f_episodio_estructuraPl, f_cuadro, f_microsector);

    }//GEN-LAST:event_formWindowActivated

    private void editar_datosActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_editar_datosActionPerformed
int contador= 0;
        selectednode3 = (DefaultMutableTreeNode) jTree1.getLastSelectedPathComponent();
             
        int nivel = selectednode3.getLevel();
//        System.out.println("level:" +nivel);
//        System.out.println("depht:" +selectednode2.getDepth());



        if (nivel == 2) {
            if (selectednode3.getDepth() == 0) {
                String ficha = selectednode3.toString();
                System.out.println("ficha sintalon:" + ficha);
                    String[] parts = ficha.split("/");
                    String partecodigoarq = parts[0];
                    String codigoinv = parts[1];
                    
                    String[] parts2 = partecodigoarq.split("-");
                    String tipoficha= parts2[0];
                    String codigoarq_l= parts2[1];
                    System.out.println("codigo arql: " +tipoficha + " codigoarq 2: " +codigoarq_l);
                    
                    if(tipoficha.equals("Gen")){
//                        System.out.println("codigo arq 1: " + codigoarq_l);
                        Escritorio.removeAll();
                        Internal_Formatizados form = new Internal_Formatizados();
                        Escritorio.add(form);
                        form.show();
                        form.cargaridFormatizados(Integer.parseInt(codigoarq_l));

                      Cargar_procedencia_formularios cp = new Cargar_procedencia_formularios();
                      cp.setearprocedencia(f_zona_ambiental, f_localidad, f_sitio, f_siglasitio, f_capa, f_estructura_arq, f_piso_capa_estruc_arq, f_denominacion_estructuraPl, f_tipo_estructuraPl, f_episodio_estructuraPl, f_cuadro, f_microsector);
                    selectednodeparaeliminar = selectednode3;
                    btn_eliminar_formatizados.setEnabled(true);
                    }
                    if(tipoficha.equals("Seg")){
//                        System.out.println("codigo arq 1: " + codigoarq_l);
                        Escritorio.removeAll();
                        Internal_estandard estandard = new Internal_estandard();
                        Escritorio.add(estandard);
                        estandard.show();
                        estandard.cargaridEstandar(Integer.parseInt(codigoarq_l));
                        
                      Cargar_procedencia_formularios cp = new Cargar_procedencia_formularios();
                      cp.setearprocedencia(f_zona_ambiental, f_localidad, f_sitio, f_siglasitio, f_capa, f_estructura_arq, f_piso_capa_estruc_arq, f_denominacion_estructuraPl, f_tipo_estructuraPl, f_episodio_estructuraPl, f_cuadro, f_microsector);
                      selectednodeparaeliminar = selectednode3;
                      editando=true;
                      btn_eliminar_estandar.setEnabled(true);
                    }
                    if(tipoficha.equals("PP")){
//                        System.out.println("codigo arq 1: " + codigoarq_l);
                        Escritorio.removeAll();
                        Internal_puntas punta = new Internal_puntas();
                        Escritorio.add(punta);
                        punta.show();
                        punta.cargaridPuntas(Integer.parseInt(codigoarq_l));
                        
                      Cargar_procedencia_formularios cp = new Cargar_procedencia_formularios();
                      cp.setearprocedencia(f_zona_ambiental, f_localidad, f_sitio, f_siglasitio, f_capa, f_estructura_arq, f_piso_capa_estruc_arq, f_denominacion_estructuraPl, f_tipo_estructuraPl, f_episodio_estructuraPl, f_cuadro, f_microsector);
                      selectednodeparaeliminar = selectednode3;
                      editando=true;
                      btn_eliminarpuntas.setEnabled(true);
                    }
                    if(tipoficha.equals("Nu")){
//                        System.out.println("codigo arq 1: " + codigoarq_l);
                        Escritorio.removeAll();
                        Internal_Nucleos nucleo2 = new Internal_Nucleos();
                        Escritorio.add(nucleo2);
                        nucleo2.show();
                        nucleo2.cardaridNucleos(Integer.parseInt(codigoarq_l));
                        
                      Cargar_procedencia_formularios cp = new Cargar_procedencia_formularios();
                      cp.setearprocedencia(f_zona_ambiental, f_localidad, f_sitio, f_siglasitio, f_capa, f_estructura_arq, f_piso_capa_estruc_arq, f_denominacion_estructuraPl, f_tipo_estructuraPl, f_episodio_estructuraPl, f_cuadro, f_microsector);
                      selectednodeparaeliminar = selectednode3;
                      editando=true;
                      btn_eliminar_nucleo.setEnabled(true);
                    }


            }
        }
    }//GEN-LAST:event_editar_datosActionPerformed

    private void nucleoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_nucleoActionPerformed
 int contador= 0;
        selectednode = (DefaultMutableTreeNode) jTree1.getLastSelectedPathComponent();
        int nivel = selectednode.getLevel();

//ve si está en nivel de pieza
        if (nivel == 1) {
        Escritorio.removeAll();
        
        Internal_Nucleos nucleo2 = new Internal_Nucleos();
        Escritorio.add(nucleo2);
        nucleo2.show();
        nucleo2.n0_txt_codigopieza.setText(selectednode.toString());

        selectednodeparaeliminar = selectednode;
        editando=false;
        btn_eliminar_nucleo.setEnabled(false);
                } 
    }//GEN-LAST:event_nucleoActionPerformed

    private void contraerActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_contraerActionPerformed
      DefaultTreeModel model = (DefaultTreeModel) jTree1.getModel();
      model.reload();
      
  
    }//GEN-LAST:event_contraerActionPerformed

    private void expandirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_expandirActionPerformed
       DefaultTreeModel model = (DefaultTreeModel) jTree1.getModel();
      model.reload();
      
      
int j = jTree1.getRowCount();
       int i = 0;
       while(i < j) {
           jTree1.expandRow(i);
           i += 1;
           j = jTree1.getRowCount();
       }
       
    }//GEN-LAST:event_expandirActionPerformed

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
    String entradaUsuario = JOptionPane.showInputDialog("Introduzca el numero del ROTULO de la pieza buscada");
    InteraccionesBD inter = new InteraccionesBD();
    if(entradaUsuario == null){
        
    }else{
    String codigoarql= inter.obtener_id_por_rotulo("FORMATIZADOS", "ID_FORMATIZADOS", entradaUsuario, "PIEZA");
    Buscar_rotulos busc = new Buscar_rotulos();
    busc.setVisible(true);
    
    busc.txt_busqueda.setText(entradaUsuario);
    String resultados = "LA PIEZA CON EL RÓTULO INDIVIDUAL: " + entradaUsuario + ": \n" +codigoarql; 
    busc.txt_resultado_busqueda.setText(resultados);
        }

    }//GEN-LAST:event_jButton2ActionPerformed

    private void formWindowClosing(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosing


        try {
    conexion c = new conexion();
    c.getConexion();
    c.closeconnection();
    c.apagar();
        } catch (Exception e) {
        }
    }//GEN-LAST:event_formWindowClosing

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
ventanamuestra= "UTILES";
Muestras mu = new Muestras();
mu.setVisible(true);
    }//GEN-LAST:event_jButton3ActionPerformed

    private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed
 Cargar_procedencia_formularios cp = new Cargar_procedencia_formularios();
cp.setearprocedencia(f_zona_ambiental, f_localidad, f_sitio, f_siglasitio, f_capa, f_estructura_arq, f_piso_capa_estruc_arq, f_denominacion_estructuraPl, f_tipo_estructuraPl, f_episodio_estructuraPl, f_cuadro, f_microsector);
InteraccionesBD inter = new InteraccionesBD();
inter.cargartodaslashojasFormatizadosWHERE(jTree1, " FORMATIZADOS f ","ID_FORMATIZADOS","PIEZA", "Gen");
if(ARQL2020.zona_ambiental.equals("Sin datos_ZA")){
    JOptionPane.showMessageDialog(null, "Recuerde indicar la procedencia antes de cargar las fichas");
}
    }//GEN-LAST:event_jButton4ActionPerformed

    private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton5ActionPerformed
Cargar_procedencia_formularios cp = new Cargar_procedencia_formularios();
cp.setearprocedencia(f_zona_ambiental, f_localidad, f_sitio, f_siglasitio, f_capa, f_estructura_arq, f_piso_capa_estruc_arq, f_denominacion_estructuraPl, f_tipo_estructuraPl, f_episodio_estructuraPl, f_cuadro, f_microsector);
InteraccionesBD inter = new InteraccionesBD();
inter.cargartodaslashojasFormatizados(jTree1, "FORMATIZADOS","ID_FORMATIZADOS","PIEZA", "Gen");
if(ARQL2020.zona_ambiental.equals("Sin datos_ZA")){
    JOptionPane.showMessageDialog(null, "Recuerde indicar la procedencia antes de cargar las fichas");
}
    }//GEN-LAST:event_jButton5ActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(FORMATIZADOS_frame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(FORMATIZADOS_frame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(FORMATIZADOS_frame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(FORMATIZADOS_frame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new FORMATIZADOS_frame().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JDesktopPane Escritorio;
    private javax.swing.JMenu Modificar;
    private javax.swing.JMenuItem Punta;
    private javax.swing.JMenuItem Segmental_Estandard;
    private javax.swing.JButton contraer;
    private javax.swing.JMenuItem editar_datos;
    private javax.swing.JButton expandir;
    private javax.swing.JTextField f_capa;
    private javax.swing.JTextField f_cuadro;
    private javax.swing.JTextField f_denominacion_estructuraPl;
    private javax.swing.JTextField f_episodio_estructuraPl;
    private javax.swing.JTextField f_estructura_arq;
    private javax.swing.JTextField f_localidad;
    private javax.swing.JTextField f_microsector;
    private javax.swing.JTextField f_piso_capa_estruc_arq;
    private javax.swing.JTextField f_siglasitio;
    private javax.swing.JTextField f_sitio;
    private javax.swing.JTextField f_tipo_estructuraPl;
    private javax.swing.JTextField f_zona_ambiental;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    private javax.swing.JButton jButton5;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    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.JMenu jMenu1;
    private javax.swing.JMenu jMenu2;
    private javax.swing.JMenu jMenu3;
    private javax.swing.JMenu jMenu4;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JMenuItem jMenuItem1;
    private javax.swing.JMenuItem jMenuItem3;
    private javax.swing.JMenuItem jMenuItem5;
    private javax.swing.JMenuItem jMenuItem6;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JPopupMenu.Separator jSeparator3;
    public static javax.swing.JTree jTree1;
    private javax.swing.JMenuItem nucleo;
    private javax.swing.JPopupMenu popup;
    public static javax.swing.JTextField txt_Npiezas;
    public static javax.swing.JTextField txt_cargar_solo;
    private javax.swing.JLabel txt_n_piezascargadas;
    // End of variables declaration//GEN-END:variables
}
