/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package Calculos_automaticos;

import arql2020.ARQL2020;
import static arql2020.ARQL2020.WHERE;
import clases.InteraccionesBD;
import clases.conexion;
import java.awt.BorderLayout;
import java.awt.Color;
import java.beans.PropertyVetoException;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeModel;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.CategoryPlot;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.data.category.DefaultCategoryDataset;

/**
 *
 * @author chuen
 */
public class G_procedimientos_alternativo extends javax.swing.JInternalFrame {

    /**
     * Creates new form F_Formatizacion_utiles1
     */
    public G_procedimientos_alternativo() {
        initComponents();
                    try {
            this.setMaximum(true);
        } catch (PropertyVetoException ex) {
            Logger.getLogger(B_Composicion_puntasfilossup.class.getName()).log(Level.SEVERE, null, ex);
        }
        botones1.add(fila);
        botones1.add(columna);

    }

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

        botones1 = new javax.swing.ButtonGroup();
        botones2 = new javax.swing.ButtonGroup();
        jScrollPane1 = new javax.swing.JScrollPane();
        jPanel1 = new javax.swing.JPanel();
        jpanel = new javax.swing.JPanel();
        fila = new javax.swing.JRadioButton();
        columna = new javax.swing.JRadioButton();
        jScrollPane5 = new javax.swing.JScrollPane();
        tbl2 = new javax.swing.JTable();
        btn_calcular = new javax.swing.JButton();
        jLabel15 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        cbx_mp = new javax.swing.JComboBox<>();
        jButton3 = new javax.swing.JButton();
        txt_sentencia = new javax.swing.JTextField();
        jLabel16 = new javax.swing.JLabel();
        txt_muestra = new javax.swing.JTextField();
        txt_mp_selec = new javax.swing.JTextField();
        jLabel27 = new javax.swing.JLabel();
        btn_info = new javax.swing.JButton();
        btn_arbol = new javax.swing.JButton();
        btn_copiar = new javax.swing.JButton();

        setClosable(true);
        setMaximizable(true);
        setTitle("Procedimientos alternativos de formatización sobre puntas de mano y filos");
        setToolTipText("");
        addInternalFrameListener(new javax.swing.event.InternalFrameListener() {
            public void internalFrameActivated(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameClosed(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameClosing(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameDeactivated(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameDeiconified(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameIconified(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameOpened(javax.swing.event.InternalFrameEvent evt) {
                formInternalFrameOpened(evt);
            }
        });

        jpanel.setBackground(new java.awt.Color(204, 204, 204));
        jpanel.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        jpanel.setLayout(new java.awt.BorderLayout());

        fila.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        fila.setText("Ordenar por fila");

        columna.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        columna.setText("Ordenar por columna");

        tbl2.setFont(new java.awt.Font("Tahoma", 0, 16)); // NOI18N
        tbl2.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {"REDUC.UNIF.BORDES", null, null, null},
                {"LS.INV.LIM.", null, null, null}
            },
            new String [] {
                "PROCED.ALTERN", "FILOS", "PUNTAS DE MANO", "TOTAL"
            }
        ));
        tbl2.setRowHeight(25);
        tbl2.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tbl2MouseClicked(evt);
            }
        });
        jScrollPane5.setViewportView(tbl2);

        btn_calcular.setBackground(new java.awt.Color(204, 255, 0));
        btn_calcular.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/lentes.png"))); // NOI18N
        btn_calcular.setToolTipText("Realizar análisis");
        btn_calcular.addComponentListener(new java.awt.event.ComponentAdapter() {
            public void componentHidden(java.awt.event.ComponentEvent evt) {
                btn_calcularComponentHidden(evt);
            }
        });
        btn_calcular.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_calcularActionPerformed(evt);
            }
        });

        jLabel15.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabel15.setText("Cálculo realizado sobre muestra:");

        jLabel4.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabel4.setText("Materia prima ");

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

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

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

        jLabel16.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabel16.setText("Sentencia:");

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

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

        jLabel27.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabel27.setText("Materia prima:");

        btn_info.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/info.png"))); // NOI18N
        btn_info.setToolTipText("Información sobre el análisis");
        btn_info.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_infoActionPerformed(evt);
            }
        });

        btn_arbol.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/arbol.png"))); // NOI18N
        btn_arbol.setToolTipText("Arbol: CLASES ARTEFACTUALES PRESENTES EN LA MP SELECCIONADA");
        btn_arbol.setEnabled(false);
        btn_arbol.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_arbolActionPerformed(evt);
            }
        });

        btn_copiar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/copiar.png"))); // NOI18N
        btn_copiar.setToolTipText("Copiar valores en el portapapeles");
        btn_copiar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_copiarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(19, 19, 19)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(btn_info, javax.swing.GroupLayout.PREFERRED_SIZE, 39, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(btn_arbol, javax.swing.GroupLayout.PREFERRED_SIZE, 39, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btn_copiar, javax.swing.GroupLayout.PREFERRED_SIZE, 39, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                        .addGroup(jPanel1Layout.createSequentialGroup()
                            .addComponent(jScrollPane5, javax.swing.GroupLayout.PREFERRED_SIZE, 560, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGap(52, 52, 52)
                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(jpanel, javax.swing.GroupLayout.PREFERRED_SIZE, 435, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGroup(jPanel1Layout.createSequentialGroup()
                                    .addComponent(fila)
                                    .addGap(10, 10, 10)
                                    .addComponent(columna))))
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                                .addComponent(jLabel4)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(cbx_mp, javax.swing.GroupLayout.PREFERRED_SIZE, 715, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jButton3, javax.swing.GroupLayout.PREFERRED_SIZE, 237, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addGroup(jPanel1Layout.createSequentialGroup()
                                        .addComponent(btn_calcular, javax.swing.GroupLayout.PREFERRED_SIZE, 39, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGap(18, 18, 18)
                                        .addComponent(jLabel15))
                                    .addComponent(jLabel27))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(jPanel1Layout.createSequentialGroup()
                                        .addComponent(txt_muestra)
                                        .addGap(18, 18, 18)
                                        .addComponent(jLabel16)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(txt_sentencia, javax.swing.GroupLayout.PREFERRED_SIZE, 197, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addComponent(txt_mp_selec, javax.swing.GroupLayout.PREFERRED_SIZE, 784, javax.swing.GroupLayout.PREFERRED_SIZE))))))
                .addGap(0, 59, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(29, 29, 29)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(cbx_mp, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButton3))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(btn_calcular, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel15)
                        .addComponent(txt_sentencia, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel16)
                        .addComponent(txt_muestra, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txt_mp_selec, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel27))
                .addGap(34, 34, 34)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(btn_arbol, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(btn_copiar, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(btn_info, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(fila)
                            .addComponent(columna))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jpanel, javax.swing.GroupLayout.PREFERRED_SIZE, 271, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jScrollPane5, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 303, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(237, Short.MAX_VALUE))
        );

        jScrollPane1.setViewportView(jPanel1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 1144, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 595, Short.MAX_VALUE)
        );

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

    private void tbl2MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tbl2MouseClicked
        int filaselec = tbl2.getSelectedRow();
        int filas = tbl2.getRowCount()-1;
        
        if(filaselec<filas){
             if(fila.isSelected()==true){

            
        Graficos graf = new Graficos();
        graf.generargraficofila2(tbl2, jpanel, tbl2.getValueAt(filaselec,0).toString(), "Filos o puntas de mano");
            
        } }
        
        int col=tbl2.getColumnCount()-1;
        int columnaselec = tbl2.getSelectedColumn();
        if((columnaselec>0)&&(columnaselec<col)){
              if(columna.isSelected()==true){
                         
            Graficos graf = new Graficos();
            graf.generargraficocolumna(tbl2, jpanel, tbl2.getColumnName(columnaselec), "Procedim. altern. form.");
            
        }}
    }//GEN-LAST:event_tbl2MouseClicked

    private void btn_calcularComponentHidden(java.awt.event.ComponentEvent evt) {//GEN-FIRST:event_btn_calcularComponentHidden
        // TODO add your handling code here:
    }//GEN-LAST:event_btn_calcularComponentHidden

    private void btn_calcularActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_calcularActionPerformed
                if(cbx_mp.getSelectedIndex()==0){
                        JOptionPane.showMessageDialog(null, "Seleccione previamente una materia prima");
                    }else{
            
                   
                        jpanel.removeAll();
            
                        txt_muestra.setText(ARQL2020.etiqueta_muestra);
                        txt_sentencia.setText(ARQL2020.WHERE);
                        txt_mp_selec.setText(cbx_mp.getSelectedItem().toString());
                        cargartbl2();     
                        btn_arbol.setEnabled(true);
                    }
    }//GEN-LAST:event_btn_calcularActionPerformed
private void cargartbl2(){
    
    DefaultTableModel dtm = (DefaultTableModel) tbl2.getModel();
        if(dtm.getRowCount()==3){
            dtm.removeRow(2);
            
            
            
        }
        String filos_lsinv = " AND (s.FILO_PUNTA_SUP='Filo') AND (s.LASCADOS_INVERSOS='1-Sí')";
            String filos_redun = " AND (s.FILO_PUNTA_SUP='Filo') AND (s.REDUCCION_UNIFACIAL_RETALLA='1-Sí')";
        String punta_lsinv = " AND (s.FILO_PUNTA_SUP='Punta de mano') AND (s.LASCADOS_INVERSOS='1-Sí')";
            String punta_redun = " AND (s.FILO_PUNTA_SUP='Punta de mano') AND (s.REDUCCION_UNIFACIAL_RETALLA='1-Sí')";
            contar(filos_redun, 0,1);
            contar(filos_lsinv, 1,1);
            contar(punta_redun, 0,2);
            contar(punta_lsinv, 1,2);
            
            tbl2.setValueAt("0", 0, 3);
            tbl2.setValueAt("0", 1, 3);
            
            
            CalculosBD calc = new CalculosBD();
            calc.sumartotalesfila(dtm);
            calc.sumartotalescolumna(dtm);
            calc.porcentajesfilainferior(dtm);
}
private void contar(String condicion, int fila, int col){
   
   
    ResultSet rs = null;
    int cant = 0;
    String consulta = "SELECT COUNT (s.ID_ESTANDAR)  FROM SEGMENTAL_ESTANDAR2 s  \n"  +
        "INNER JOIN \n" +
"FORMATIZADOS f \n" +
"ON f.ID_FORMATIZADOS = s.ID_FORMATIZADOS " 
        +txt_sentencia.getText() + " AND (f.MP='"+txt_mp_selec.getText()+"')  " + condicion;
        
     try {
            conexion c = new conexion();
            c.getConexion();
            
             rs = c.consulta(consulta);

            if(rs.next()){
                cant=rs.getInt("1");
                
            }       
        
        c.closeconnection();
        
     
        } catch (SQLException ex) {
            Logger.getLogger(InteraccionesBD.class.getName()).log(Level.SEVERE, null, ex);
        }
     tbl2.setValueAt(cant, fila, col);
     
     
}

public void arboltbl2(){
Arbol ar = new Arbol();
ar.setVisible(true);
ar.txt_mp.setText(txt_mp_selec.getText());
ar.txt_nota.setText("En las categorías del árbol se incluyen las piezas que contienen todas o alguna de las fichas segmentales estándar que presenta dicha característica.");

DefaultTreeModel model = (DefaultTreeModel) ar.arbol_analisis_FORM.getModel();        
DefaultMutableTreeNode root = (DefaultMutableTreeNode) model.getRoot();
    
String sentencia = txt_sentencia.getText();
String matprim = txt_mp_selec.getText();
CalculosBD calc=new CalculosBD();
String ids= calc.obteneridutiles(txt_sentencia.getText(), txt_mp_selec.getText());

    DiseñoArbol d = new DiseñoArbol(txt_sentencia.getText(), txt_mp_selec.getText());
 

    String filos_SOLO_lsinv = " AND (s.FILO_PUNTA_SUP='Filo') AND (s.LASCADOS_INVERSOS='1-Sí') AND (s.REDUCCION_UNIFACIAL_RETALLA='0-No')";
    String filos_SOLO_red = " AND (s.FILO_PUNTA_SUP='Filo') AND (s.REDUCCION_UNIFACIAL_RETALLA='1-Sí') AND (s.LASCADOS_INVERSOS='0-No')";
    String filos_red_lsinv = " AND (s.FILO_PUNTA_SUP='Filo') AND (s.REDUCCION_UNIFACIAL_RETALLA='1-Sí') AND (s.LASCADOS_INVERSOS='1-Sí')";

    String puntas_SOLO_lsinv = " AND (s.FILO_PUNTA_SUP='Punta de mano') AND (s.LASCADOS_INVERSOS='1-Sí') AND (s.REDUCCION_UNIFACIAL_RETALLA='0-No')";
    String puntas_SOLO_red = " AND (s.FILO_PUNTA_SUP='Punta de mano') AND (s.REDUCCION_UNIFACIAL_RETALLA='1-Sí') AND (s.LASCADOS_INVERSOS='0-No')";
    String puntas_red_lsinv = " AND (s.FILO_PUNTA_SUP='Punta de mano') AND (s.REDUCCION_UNIFACIAL_RETALLA='1-Sí') AND (s.LASCADOS_INVERSOS='1-Sí')";
    

    DefaultMutableTreeNode filos = new DefaultMutableTreeNode("Filos");
    DefaultMutableTreeNode puntas = new DefaultMutableTreeNode("Puntas de mano");
    
    ArrayList<Integer> ids_arbol = solicitarids(filos_SOLO_lsinv);
    DefaultMutableTreeNode hoja_categoriaA = d.armarcarpetaconpiezas(ids_arbol, "Filos (solo ls.inv.lim.)");
    filos.add(hoja_categoriaA);

    ids_arbol = solicitarids(filos_SOLO_red);
    hoja_categoriaA = d.armarcarpetaconpiezas(ids_arbol, "Filos (solo red.unif.bordes.retalla)");
    filos.add(hoja_categoriaA);

    ids_arbol = solicitarids(filos_red_lsinv);
    hoja_categoriaA = d.armarcarpetaconpiezas(ids_arbol, "Filos (red.unif.bordes.retalla & ls.inv.lim.)");
    filos.add(hoja_categoriaA);

    ids_arbol = solicitarids(puntas_SOLO_lsinv);
    hoja_categoriaA = d.armarcarpetaconpiezas(ids_arbol, "Puntas de mano(solo ls.inv.lim.)");
    puntas.add(hoja_categoriaA);

    ids_arbol = solicitarids(puntas_SOLO_red);
    hoja_categoriaA = d.armarcarpetaconpiezas(ids_arbol, "Puntas de mano (solo red.unif.bordes.retalla)");
    puntas.add(hoja_categoriaA);

    ids_arbol = solicitarids(puntas_red_lsinv);
    hoja_categoriaA = d.armarcarpetaconpiezas(ids_arbol, "Puntas de mano (red.unif.bordes.retalla & ls.inv.lim.)");
    puntas.add(hoja_categoriaA);
    
    

    root.add(filos);
    root.add(puntas);
    root.setUserObject(txt_muestra.getText()+"/ "+txt_mp_selec.getText()+"/ Filos y puntas de mano");
    ar.arbol_analisis_FORM.setModel(model);
    model.reload();
    
    
    
    
 

}

private ArrayList<Integer> solicitarids(String condicion){
  ArrayList<Integer> forms = new ArrayList<>();  
       ResultSet rs = null;
    String consulta = "SELECT  DISTINCT(f.ID_FORMATIZADOS)  FROM FORMATIZADOS f   \n"  +
        "INNER JOIN \n" +
"SEGMENTAL_ESTANDAR2 s \n" +
"ON f.ID_FORMATIZADOS = s.ID_FORMATIZADOS " 
        +txt_sentencia.getText() + " AND (f.MP='"+txt_mp_selec.getText()+"')  " + condicion;
             try {
            conexion c = new conexion();
            c.getConexion();
            
             rs = c.consulta(consulta);
         
             
               while(rs.next()){
                int utiles_aux=rs.getInt("ID_FORMATIZADOS");
                forms.add(utiles_aux);
               
           }       
        
        c.closeconnection();
 } catch (SQLException ex) {
            Logger.getLogger(InteraccionesBD.class.getName()).log(Level.SEVERE, null, ex);
        }
             return forms;
}
    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
                if(WHERE.equals("")){
                        JOptionPane.showMessageDialog(null, "Debe seleccionar una muestra previamente");
                    }else{
                        CalculosBD calc = new CalculosBD();
                        calc.cargarmpformdistinct(cbx_mp, WHERE);
                    }
    }//GEN-LAST:event_jButton3ActionPerformed

    private void btn_infoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_infoActionPerformed
               String analisis = "PROCEDIMIENTOS ALTERNATIVOS DE FORMATIZACIÓN SOBRE PUNTAS DE MANO Y FILOS \n" +
"\n" +
"Se distribuyen de acuerdo a:\n" +
"\n" +
"-Reducción unifacial de bordes por retalla\n" +
"-Lascados inversos limitantes\n" +
"\n" +
"\n" +
"El análisis debe entenderse como \n" +
"-'Cantidad de <puntas de mano> que presentan reducción unifacial de bordes y/o lascados inversos limitantes'\n" +
"\n" +
"-'Cantidad de <filos> que presentan reducción unifacial de bordes y/o lascados inversos limitantes'\n" +
"\n" +
"El análisis se efectúa en base a la muestra y la materia prima seleccionada, contabilizando la totalidad de fichas segmentales estándar que correspondan a filos o a puntas de mano.";
                info_frame info = new info_frame();
                info.setVisible(true);
                info.info_procedencia.setText("MUESTRA---->" + txt_muestra.getText() +"\n SENTENCIA---->" +txt_sentencia.getText() );
                info.info_mp.setText(txt_mp_selec.getText());
                info.info_analisis.setText(analisis);
    }//GEN-LAST:event_btn_infoActionPerformed

    private void btn_arbolActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_arbolActionPerformed
      arboltbl2();
    }//GEN-LAST:event_btn_arbolActionPerformed

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

    Copiartabla copy = new Copiartabla();
    copy.copiartabla(tbl2, txt_muestra.getText(), txt_sentencia.getText(), "Prodecimientos alternativos de formatización sobre puntas de mano y filos", "Materia prima: "+txt_mp_selec.getText());
    }//GEN-LAST:event_btn_copiarActionPerformed

    private void formInternalFrameOpened(javax.swing.event.InternalFrameEvent evt) {//GEN-FIRST:event_formInternalFrameOpened
  CalculosBD c = new CalculosBD();
c.cargarmp(cbx_mp);  
    }//GEN-LAST:event_formInternalFrameOpened


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.ButtonGroup botones1;
    private javax.swing.ButtonGroup botones2;
    private javax.swing.JButton btn_arbol;
    private javax.swing.JButton btn_calcular;
    private javax.swing.JButton btn_copiar;
    private javax.swing.JButton btn_info;
    private javax.swing.JComboBox<String> cbx_mp;
    private javax.swing.JRadioButton columna;
    private javax.swing.JRadioButton fila;
    private javax.swing.JButton jButton3;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel27;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane5;
    private javax.swing.JPanel jpanel;
    private javax.swing.JTable tbl2;
    private javax.swing.JTextField txt_mp_selec;
    private javax.swing.JTextField txt_muestra;
    private javax.swing.JTextField txt_sentencia;
    // End of variables declaration//GEN-END:variables
}
