/*
 * 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.awt.Dimension;
import static java.awt.Frame.MAXIMIZED_BOTH;
import java.beans.PropertyVetoException;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Locale;
import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.DefaultListModel;
import javax.swing.JList;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTable;
import javax.swing.JTextField;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartFrame;
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;

public class B_Composicion_puntasfilossup extends javax.swing.JInternalFrame {


    public B_Composicion_puntasfilossup() {
        initComponents();
        try {
            this.setMaximum(true);
        } catch (PropertyVetoException ex) {
            Logger.getLogger(B_Composicion_puntasfilossup.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

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

        jScrollPane1 = new javax.swing.JScrollPane();
        jPanel1 = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        jScrollPane2 = new javax.swing.JScrollPane();
        lista_filos = new javax.swing.JList<>();
        jLabel3 = new javax.swing.JLabel();
        jScrollPane3 = new javax.swing.JScrollPane();
        lista_puntasdemano = new javax.swing.JList<>();
        jLabel4 = new javax.swing.JLabel();
        jScrollPane4 = new javax.swing.JScrollPane();
        lista_superficies = new javax.swing.JList<>();
        jPanel2 = new javax.swing.JPanel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        total_filos = new javax.swing.JTextField();
        total_puntasdemano = new javax.swing.JTextField();
        total_superficies = new javax.swing.JTextField();
        jLabel8 = new javax.swing.JLabel();
        total_n = new javax.swing.JTextField();
        jSeparator1 = new javax.swing.JSeparator();
        jLabel9 = new javax.swing.JLabel();
        porcentaje_filos = new javax.swing.JTextField();
        jLabel10 = new javax.swing.JLabel();
        porcentaje_puntasdemano = new javax.swing.JTextField();
        jLabel11 = new javax.swing.JLabel();
        porcentaje_superficies = new javax.swing.JTextField();
        jLabel12 = new javax.swing.JLabel();
        porcentaje_simples = new javax.swing.JTextField();
        jLabel13 = new javax.swing.JLabel();
        porcentaje_compuestos = new javax.swing.JTextField();
        jLabel17 = new javax.swing.JLabel();
        total_puntasproy = new javax.swing.JTextField();
        jLabel18 = new javax.swing.JLabel();
        total_nucleos = new javax.swing.JTextField();
        jLabel19 = new javax.swing.JLabel();
        porcentaje_puntasproy = new javax.swing.JTextField();
        jLabel20 = new javax.swing.JLabel();
        porcentaje_nucleos = new javax.swing.JTextField();
        jLabel21 = new javax.swing.JLabel();
        n_artef_simples = new javax.swing.JTextField();
        jLabel22 = new javax.swing.JLabel();
        n_artef_compuestos = new javax.swing.JTextField();
        jpanel = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        cbx_mp = new javax.swing.JComboBox<>();
        btn_calcular = new javax.swing.JButton();
        jLabel14 = new javax.swing.JLabel();
        txt_muestra = new javax.swing.JTextField();
        btn_info = new javax.swing.JButton();
        btn_arbol = new javax.swing.JButton();
        btn_copiar = new javax.swing.JButton();
        jLabel15 = new javax.swing.JLabel();
        txt_mp_selec = new javax.swing.JTextField();
        txt_sentencia = new javax.swing.JTextField();
        jLabel16 = new javax.swing.JLabel();
        jLabel23 = new javax.swing.JLabel();
        jScrollPane5 = new javax.swing.JScrollPane();
        lista_puntas_de_proyectil = new javax.swing.JList<>();
        jLabel24 = new javax.swing.JLabel();
        jScrollPane6 = new javax.swing.JScrollPane();
        lista_nucleos = new javax.swing.JList<>();
        jButton1 = new javax.swing.JButton();

        setClosable(true);
        setResizable(true);
        setTitle("Composición de la muestra según puntas, filos y superficies");
        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);
            }
        });

        jLabel2.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel2.setText("Filos (grupos tipológicos)");

        jScrollPane2.setViewportView(lista_filos);

        jLabel3.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel3.setText("Puntas de mano (grupos tipológicos)");

        jScrollPane3.setViewportView(lista_puntasdemano);

        jLabel4.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel4.setText("Superficies activas (grupos tipológicos)");

        jScrollPane4.setViewportView(lista_superficies);

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Totales", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 14))); // NOI18N

        jLabel5.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabel5.setText("Total filos (n)");

        jLabel6.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabel6.setText("Total puntas de mano (n)");

        jLabel7.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabel7.setText("Total superficies (n)");

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

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

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

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

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

        jLabel9.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabel9.setText("% filos");

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

        jLabel10.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabel10.setText("% puntas de mano");

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

        jLabel11.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabel11.setText("% superficies");

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

        jLabel12.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabel12.setText("% artefactos simples");

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

        jLabel13.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabel13.setText("% artefactos comp.");

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

        jLabel17.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabel17.setText("Puntas de proyectil (n)");

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

        jLabel18.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabel18.setText("Núcleos (n)");

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

        jLabel19.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabel19.setText("% puntas de proyectil");

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

        jLabel20.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabel20.setText("% núcleos");

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

        jLabel21.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabel21.setText("Artefactos simples (n)");

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

        jLabel22.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabel22.setText("Artefactos comp. (n)");

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

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel22, javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel21, javax.swing.GroupLayout.Alignment.TRAILING))
                .addGap(18, 18, 18)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(n_artef_compuestos, javax.swing.GroupLayout.PREFERRED_SIZE, 69, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(n_artef_simples, javax.swing.GroupLayout.PREFERRED_SIZE, 69, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(30, 30, 30)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel13, javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel12, javax.swing.GroupLayout.Alignment.TRAILING))
                .addGap(18, 18, 18)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(porcentaje_simples, javax.swing.GroupLayout.PREFERRED_SIZE, 69, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(porcentaje_compuestos, javax.swing.GroupLayout.PREFERRED_SIZE, 69, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(12, 12, 12))
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGap(14, 14, 14)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel8, javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel18, javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel17, javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel7, javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel6, javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel5, javax.swing.GroupLayout.Alignment.TRAILING))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(total_n, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(total_nucleos, javax.swing.GroupLayout.PREFERRED_SIZE, 69, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(total_puntasproy, javax.swing.GroupLayout.PREFERRED_SIZE, 69, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(total_superficies, javax.swing.GroupLayout.PREFERRED_SIZE, 69, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(total_puntasdemano, javax.swing.GroupLayout.PREFERRED_SIZE, 69, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(total_filos, javax.swing.GroupLayout.PREFERRED_SIZE, 69, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(156, 156, 156)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel20, javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel19, javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel11, javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel10, javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel9, javax.swing.GroupLayout.Alignment.TRAILING))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(porcentaje_nucleos, javax.swing.GroupLayout.PREFERRED_SIZE, 69, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(porcentaje_puntasdemano, javax.swing.GroupLayout.PREFERRED_SIZE, 69, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(porcentaje_puntasproy, javax.swing.GroupLayout.PREFERRED_SIZE, 69, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(porcentaje_superficies, javax.swing.GroupLayout.PREFERRED_SIZE, 69, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(porcentaje_filos, javax.swing.GroupLayout.PREFERRED_SIZE, 69, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 339, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(88, Short.MAX_VALUE))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGap(22, 22, 22)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel9)
                            .addComponent(porcentaje_filos, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel10)
                            .addComponent(porcentaje_puntasdemano, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel11)
                            .addComponent(porcentaje_superficies, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel5)
                            .addComponent(total_filos, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel6)
                            .addComponent(total_puntasdemano, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel7)
                            .addComponent(total_superficies, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel19)
                            .addComponent(porcentaje_puntasproy, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel20)
                            .addComponent(porcentaje_nucleos, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel17)
                            .addComponent(total_puntasproy, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel18)
                            .addComponent(total_nucleos, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addGap(8, 8, 8)
                .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(total_n, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel8))
                .addGap(24, 24, 24)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel12)
                            .addComponent(porcentaje_simples, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel13)
                            .addComponent(porcentaje_compuestos, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel21)
                            .addComponent(n_artef_simples, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel22)
                            .addComponent(n_artef_compuestos, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addContainerGap(20, Short.MAX_VALUE))
        );

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

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

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

        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.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_calcularActionPerformed(evt);
            }
        });

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

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

        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("Abrir árbol de piezas");
        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);
            }
        });

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

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

        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:");

        jLabel23.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel23.setText("Puntas de proyectil (subgrupostipológicos)");

        jScrollPane5.setViewportView(lista_puntas_de_proyectil);

        jLabel24.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel24.setText("Núcleos (subgrupostipológicos)");

        jScrollPane6.setViewportView(lista_nucleos);

        jButton1.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jButton1.setText("MP PRESENTES EN LA MUESTRA");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(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()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(26, 26, 26)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                .addComponent(jLabel3)
                                .addComponent(jLabel4)
                                .addComponent(jScrollPane2)
                                .addComponent(jScrollPane3)
                                .addComponent(jScrollPane4, javax.swing.GroupLayout.PREFERRED_SIZE, 370, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(jLabel23)
                            .addComponent(jScrollPane5, javax.swing.GroupLayout.PREFERRED_SIZE, 370, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel24)
                            .addComponent(jScrollPane6, javax.swing.GroupLayout.PREFERRED_SIZE, 370, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel2))
                        .addGap(60, 60, 60)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jpanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jLabel1)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(cbx_mp, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addGroup(jPanel1Layout.createSequentialGroup()
                                        .addGap(167, 167, 167)
                                        .addComponent(jLabel15)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                        .addComponent(txt_mp_selec))
                                    .addGroup(jPanel1Layout.createSequentialGroup()
                                        .addComponent(btn_calcular, javax.swing.GroupLayout.PREFERRED_SIZE, 39, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGap(18, 18, 18)
                                        .addComponent(jLabel14)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                        .addComponent(txt_muestra)
                                        .addGap(32, 32, 32)
                                        .addComponent(jLabel16)
                                        .addGap(18, 18, 18)
                                        .addComponent(txt_sentencia, javax.swing.GroupLayout.PREFERRED_SIZE, 197, javax.swing.GroupLayout.PREFERRED_SIZE)))
                                .addGap(14, 14, 14)
                                .addComponent(btn_info, javax.swing.GroupLayout.PREFERRED_SIZE, 39, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .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))
                            .addComponent(jButton1))))
                .addGap(32, 32, 32))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(cbx_mp, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButton1))
                .addGap(26, 26, 26)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                        .addComponent(btn_calcular, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .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))
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel14)
                        .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(jLabel15))
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(48, 48, 48)
                        .addComponent(jLabel2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jLabel3)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
                        .addGap(18, 18, 18)
                        .addComponent(jLabel4)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jScrollPane4, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
                        .addGap(18, 18, 18)
                        .addComponent(jLabel23)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jScrollPane5, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
                        .addGap(24, 24, 24)
                        .addComponent(jLabel24)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jScrollPane6, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(62, 62, 62)
                        .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(7, 7, 7)
                        .addComponent(jpanel, javax.swing.GroupLayout.DEFAULT_SIZE, 354, Short.MAX_VALUE)))
                .addGap(40, 40, 40))
        );

        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)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 903, Short.MAX_VALUE)
                .addGap(0, 0, 0))
        );

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

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



    }//GEN-LAST:event_formInternalFrameOpened


    private void btn_calcularActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_calcularActionPerformed
if(WHERE.equals("")){
    JOptionPane.showMessageDialog(null, "Seleccione previamente una muestra");
}else{
        
        if(cbx_mp.getSelectedIndex()==0){
JOptionPane.showMessageDialog(null, "Seleccione previamente una materia prima");
}else{
txt_muestra.setText(ARQL2020.etiqueta_muestra);
txt_sentencia.setText(ARQL2020.WHERE);
txt_mp_selec.setText(cbx_mp.getSelectedItem().toString());

ArrayList<String> lista=innerjoin_filos_puntas_sup(txt_sentencia.getText(), txt_mp_selec.getText(), "Filo" );
cargarlistas(lista_filos, lista);    
lista=innerjoin_filos_puntas_sup(txt_sentencia.getText(), txt_mp_selec.getText(), "Punta de mano" );
cargarlistas(lista_puntasdemano, lista);    
lista=innerjoin_filos_puntas_sup(txt_sentencia.getText(), txt_mp_selec.getText(), "Superficie activa" );
cargarlistas(lista_superficies, lista);    

lista=innerjoin_puntasproy(txt_sentencia.getText(), txt_mp_selec.getText());
cargarlistas(lista_puntas_de_proyectil, lista);    
lista=innerjoin_nu(txt_sentencia.getText(), txt_mp_selec.getText());
Set<String> hashSet = new HashSet<String>(lista);
        lista.clear();
        lista.addAll(hashSet);
cargarlistas(lista_nucleos, lista);    


contarn(lista_filos, total_filos);
contarn(lista_puntas_de_proyectil, total_puntasproy);
contarn(lista_puntasdemano, total_puntasdemano);
contarn(lista_nucleos, total_nucleos);
contarn(lista_superficies, total_superficies);
sumarn();

CalculosBD c = new CalculosBD();
String a = String.valueOf(c.porcentajeCIENPORCIENTO(total_filos.getText(), total_n.getText()));
porcentaje_filos.setText(a);
a = String.valueOf(c.porcentajeCIENPORCIENTO(total_puntasdemano.getText(), total_n.getText()));
porcentaje_puntasdemano.setText(a);
a = String.valueOf(c.porcentajeCIENPORCIENTO(total_puntasproy.getText(), total_n.getText()));
porcentaje_puntasproy.setText(a);
a = String.valueOf(c.porcentajeCIENPORCIENTO(total_superficies.getText(), total_n.getText()));
porcentaje_superficies.setText(a);
a = String.valueOf(c.porcentajeCIENPORCIENTO(total_nucleos.getText(), total_n.getText()));
porcentaje_nucleos.setText(a);

InteraccionesBD inter = new InteraccionesBD();
int simple = inter.getcountf("FORMATIZADOS f", WHERE+" AND (f.SIMPLE_COMPUESTA='1-Simple') AND (f.MP='"+txt_mp_selec.getText()+"')");
n_artef_simples.setText(String.valueOf(simple));
int compuesto = inter.getcountf("FORMATIZADOS f", WHERE+" AND (f.SIMPLE_COMPUESTA='2-Compuesta') AND (f.MP='"+txt_mp_selec.getText()+"')");
n_artef_compuestos.setText(String.valueOf(compuesto));
a = String.valueOf(c.porcentajeCIENPORCIENTO(n_artef_simples.getText(), String.valueOf(simple+compuesto)));
porcentaje_simples.setText(a);
a = String.valueOf(c.porcentajeCIENPORCIENTO(n_artef_compuestos.getText(), String.valueOf(simple+compuesto)));
porcentaje_compuestos.setText(a);

cargargrafico();
btn_arbol.setEnabled(true);

}
}
    }//GEN-LAST:event_btn_calcularActionPerformed
private void cargargrafico(){
    try{

DefaultCategoryDataset ds = new DefaultCategoryDataset();

         int valor = Integer.parseInt(total_filos.getText());
         ds.addValue(valor, "Filos", "");
         valor = Integer.parseInt(total_puntasdemano.getText());
         ds.addValue(valor, "Puntas de mano", "");
         valor = Integer.parseInt(total_puntasproy.getText());
         ds.addValue(valor, "Puntas de proyectil", "");
         valor = Integer.parseInt(total_superficies.getText());
         ds.addValue(valor, "Superficies activas", "");
         valor = Integer.parseInt(total_nucleos.getText());
         ds.addValue(valor, "Núcleos", "");
 

    JFreeChart jf =ChartFactory.createBarChart3D("Composición de la muestra", "Filos,puntas,sup.", "Cantidad", ds, PlotOrientation.HORIZONTAL, true, true, true);

    
    CategoryPlot barchrt = jf.getCategoryPlot();
    barchrt.setRangeGridlinePaint(Color.ORANGE);
    ChartPanel barpanel = new ChartPanel(jf);
    jpanel.removeAll();
    jpanel.add(barpanel, BorderLayout.CENTER);
    jpanel.validate();
    

}catch (Exception ex){
    JOptionPane.showMessageDialog(null, "No se puede generar gráfico");
}
    
}
    
   
    
    private void sumarn(){
    int a = Integer.parseInt(total_filos.getText());
    int b = Integer.parseInt(total_puntasdemano.getText());
    int c = Integer.parseInt(total_puntasproy.getText());
    int d = Integer.parseInt(total_superficies.getText());
    int e = Integer.parseInt(total_nucleos.getText());
    int f = a+b+c+d+e;
    String g = String.valueOf(f);
    total_n.setText(g);
    
}
private void contarn (JList jlist, JTextField txt){
    
  int a = jlist.getModel().getSize();
  txt.setText(String.valueOf(a));
  
}    
    
    
    private void cargarlistas(JList jlist, ArrayList<String> lista){


DefaultListModel modelopuntas = new DefaultListModel();
    for (int j = 0; j < lista.size(); j++) {
        modelopuntas.addElement(lista.get(j));        
    }
jlist.setModel(modelopuntas);

}

private ArrayList<String> innerjoin_filos_puntas_sup (String where, String MP, String filo_punta_sup){
    ArrayList<String> lista = new ArrayList<>();
    
     ResultSet rs = null; 
     String consulta = "SELECT  f.ID_FORMATIZADOS, s.GRUPO \n" +
"FROM FORMATIZADOS f\n" +
"INNER JOIN\n" +
"SEGMENTAL_ESTANDAR2 s\n" +
"ON f.ID_FORMATIZADOS = s.ID_FORMATIZADOS " +where + " AND (f.MP='"+MP+"')  AND (s.FILO_PUNTA_SUP='"+filo_punta_sup+"')";
         try {
            conexion c = new conexion();
            c.getConexion();
            
             rs = c.consulta(consulta);

            while(rs.next()){
                String pieza = String.valueOf(rs.getInt("ID_FORMATIZADOS"));
                lista.add(rs.getString("GRUPO")+"/ PIEZA:"+pieza);
            }       
        
        c.closeconnection();
        
        
        } catch (SQLException ex) {
            Logger.getLogger(InteraccionesBD.class.getName()).log(Level.SEVERE, null, ex);
        }
     
    
    return lista;
}
private ArrayList<String> innerjoin_puntasproy (String where, String MP){
    ArrayList<String> lista = new ArrayList<>();
    
     ResultSet rs = null; 
     String consulta = "SELECT  f.ID_FORMATIZADOS, s.SUBGRUPO \n" +
"FROM FORMATIZADOS f\n" +
"INNER JOIN\n" +
"PUNTAS_DE_PROYECTIL2 s\n" +
"ON f.ID_FORMATIZADOS = s.ID_FORMATIZADOS " +where + " AND (f.MP='"+MP+"')";
         try {
            conexion c = new conexion();
            c.getConexion();
            
             rs = c.consulta(consulta);

            while(rs.next()){
                String pieza = String.valueOf(rs.getInt("ID_FORMATIZADOS"));
                lista.add(rs.getString("SUBGRUPO")+"/ PIEZA:"+pieza);
            }       
        
        c.closeconnection();
        
        
        } catch (SQLException ex) {
            Logger.getLogger(InteraccionesBD.class.getName()).log(Level.SEVERE, null, ex);
        }
     
    
    return lista;
}
private ArrayList<String> innerjoin_nu (String where, String MP){
    ArrayList<String> lista = new ArrayList<>();
    
     ResultSet rs = null; 
     String consulta = "SELECT  f.ID_FORMATIZADOS, s.SUBGRUPO \n" +
"FROM FORMATIZADOS f\n" +
"INNER JOIN\n" +
"NUCLEOS s\n" +
"ON f.ID_FORMATIZADOS = s.ID_FORMATIZADOS " +where + " AND (f.MP='"+MP+"')";
         try {
            conexion c = new conexion();
            c.getConexion();
            
             rs = c.consulta(consulta);

            while(rs.next()){
                String pieza = String.valueOf(rs.getInt("ID_FORMATIZADOS"));
                lista.add(rs.getString("SUBGRUPO")+"/ PIEZA:"+pieza);
            }       
        
        c.closeconnection();
        
        
        } catch (SQLException ex) {
            Logger.getLogger(InteraccionesBD.class.getName()).log(Level.SEVERE, null, ex);
        }
     
    
    return lista;
}
    private void btn_infoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_infoActionPerformed
        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("FILOS, PUNTAS DE PROYECTIL, PUNTAS DE MANO, SUPERFICIES Y NUCLEOS: Se contabilizan las piezas de acuerdo al 100% de fichas: segmental estandar, núcleos, puntas de proyectil, en base a la muestra y la materia prima seleccionada."
                + "\n"
                + "\n - Fichas segmentales estandar: se contabilizan filos, puntas de mano y superficies."
                + "\n - Fichas de puntas de proyectil: se contabilizan puntas de proyectil."
                + "\n - Núcleos: se contabilizan núcleos, independientemente de la cantidad de plataformas ingresadas."
                + "\n "
                + "\n "
                
                + "\n - ARTEFACTOS SIMPLES Y COMPUESTOS: se contabilizan según fichas generales.");
    }//GEN-LAST:event_btn_infoActionPerformed

    private void btn_arbolActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_arbolActionPerformed
        Arbol ar = new Arbol();
        ar.setVisible(true);
        CalculosBD calc = new CalculosBD();
        String mp = txt_mp_selec.getText();
        calc.cargarArbolCriterioFORMATIZADOSf(ar.arbol_analisis_FORM, "FORMATIZADOS f", mp, "f.ID_FORMATIZADOS", "ID_FORMATIZADOS", "f.PIEZA", "PIEZA", "Gen", WHERE+" AND ( f.MP= '"+mp+"')", txt_muestra.getText());
      
        ar.txt_mp.setText("Todas la piezas de la materia prima " + mp);
    }//GEN-LAST:event_btn_arbolActionPerformed

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

        String aux1= concatenarlistas(lista_filos);
        String aux2= concatenarlistas(lista_superficies);
        String aux3= concatenarlistas(lista_puntasdemano);
        String aux4= concatenarlistas(lista_puntas_de_proyectil);
        String aux5= concatenarlistas(lista_nucleos);
        
        
        String texto = "-----------TOTALES-----------"
              
              +"\n Filo,punta o sup. \tN\tPorcentaje"
              +"\n Filos(n): \t" + total_filos.getText() + "\t"+ porcentaje_filos.getText()
              +"\n Puntas de mano(n): \t" + total_puntasdemano.getText() + "\t"+ porcentaje_puntasdemano.getText()
              +"\n Puntas de proyectil(n): \t" + total_puntasproy.getText() + "\t"+ porcentaje_puntasproy.getText()
              +"\n Superficies activas(n): \t" + total_superficies.getText() + "\t"+ porcentaje_superficies.getText()
              +"\n Núcleos(n): \t" + total_nucleos.getText() + "\t"+ porcentaje_nucleos.getText()
              +"\n TOTAL (n): \t" + total_n.getText() + "\t100%"
              +"\n "
              +"\n ARTEF.SIMP.COMP.\tN\tPorcentaje"
              +"\n -Artef.Simples\t"+n_artef_simples.getText()+"\t"+porcentaje_simples.getText()
              +"\n -Artef.Simples\t"+n_artef_compuestos.getText()+"\t"+porcentaje_compuestos.getText()
              +"\n "
              +"\n GRUPOS TIPOLOGICOS PRESENTES SEGÚN FILOS,PUNTAS Y SUPERFICIES:"
              +"\n --FILOS: \n" + aux1
              +"\n --SUPERFICIES ACTIVAS:\n" + aux2
              +"\n --PUNTAS DE MANO:\n" + aux3
              +"\n --PUNTAS DE PROYECTIL:\n" + aux4
              +"\n --NÚCLEOS:" + aux5;
        
        Copiartabla copy = new Copiartabla();
        copy.copiarsolotexto(txt_muestra.getText(), WHERE, "Composición de la muestra según filos, puntas de mano, puntas de proyectil, superficies activas y núcleos", texto);
    }//GEN-LAST:event_btn_copiarActionPerformed
private String concatenarlistas(JList jList1){
 
    int a =jList1.getModel().getSize();
    String[] myArray = new String[a];
    for (int i = 0; i < a; i++) {
             myArray[i] = String.valueOf(jList1.getModel().getElementAt(i));
        }
    
    
    String lista_concat = "";
    for (int i = 0; i < myArray.length; i++) {
            lista_concat= lista_concat+ " " +myArray[i]+ "\n";
            
        }
    return lista_concat;
}
    private void porcentaje_compuestosActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_porcentaje_compuestosActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_porcentaje_compuestosActionPerformed

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

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
if(WHERE.equals("")){
    JOptionPane.showMessageDialog(null, "Debe seleccionar una muestra previamente");
}else{
    cbx_mp.removeAllItems();
cbx_mp.addItem("Materias primas presentes en la muestra");    
    CalculosBD c = new CalculosBD();
    c.cargarmpformdistinct(cbx_mp, WHERE);
}
        
        
    }//GEN-LAST:event_jButton1ActionPerformed

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

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

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


    // Variables declaration - do not modify//GEN-BEGIN:variables
    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.JButton jButton1;
    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 jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel17;
    private javax.swing.JLabel jLabel18;
    private javax.swing.JLabel jLabel19;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel20;
    private javax.swing.JLabel jLabel21;
    private javax.swing.JLabel jLabel22;
    private javax.swing.JLabel jLabel23;
    private javax.swing.JLabel jLabel24;
    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.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JScrollPane jScrollPane4;
    private javax.swing.JScrollPane jScrollPane5;
    private javax.swing.JScrollPane jScrollPane6;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JPanel jpanel;
    private javax.swing.JList<String> lista_filos;
    private javax.swing.JList<String> lista_nucleos;
    private javax.swing.JList<String> lista_puntas_de_proyectil;
    private javax.swing.JList<String> lista_puntasdemano;
    private javax.swing.JList<String> lista_superficies;
    private javax.swing.JTextField n_artef_compuestos;
    private javax.swing.JTextField n_artef_simples;
    private javax.swing.JTextField porcentaje_compuestos;
    private javax.swing.JTextField porcentaje_filos;
    private javax.swing.JTextField porcentaje_nucleos;
    private javax.swing.JTextField porcentaje_puntasdemano;
    private javax.swing.JTextField porcentaje_puntasproy;
    private javax.swing.JTextField porcentaje_simples;
    private javax.swing.JTextField porcentaje_superficies;
    private javax.swing.JTextField total_filos;
    private javax.swing.JTextField total_n;
    private javax.swing.JTextField total_nucleos;
    private javax.swing.JTextField total_puntasdemano;
    private javax.swing.JTextField total_puntasproy;
    private javax.swing.JTextField total_superficies;
    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
}
