/*
 * 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 Filtros;

//import arql2020.DT_sintalon;
import arql2020.Procesar_informacion;
import arql2020.presentacion;
import clases.Filtros;
import clases.conexion;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.stream.Collectors;
import javax.swing.DefaultListModel;
import javax.swing.ListModel;
import javax.swing.RowFilter;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableModel;
import javax.swing.table.TableRowSorter;

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


List<String> filtrosusados;
ArrayList<String> seleccion = new ArrayList<String>();
String apellido="";
DefaultTableModel modelotabla ;
DefaultTableModel modeloausar ;
DefaultTableModel modelooriginal;
int contadorfiltros = 0;
int [] listafiltrosusados = new int[3];


///stm para filtros
String nombre = "";

    public Filtros_frame() {
        initComponents();
        modelooriginal = (DefaultTableModel) tbl.getModel();
        this.setExtendedState(MAXIMIZED_BOTH);


    }

    /**
     * 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();
        jTabbedPane1 = new javax.swing.JTabbedPane();
        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jScrollPane4 = new javax.swing.JScrollPane();
        list1 = new javax.swing.JList<>();
        jScrollPane5 = new javax.swing.JScrollPane();
        list2 = new javax.swing.JList<>();
        jLabel2 = new javax.swing.JLabel();
        jScrollPane6 = new javax.swing.JScrollPane();
        list3 = new javax.swing.JList<>();
        jLabel3 = new javax.swing.JLabel();
        jButton4 = new javax.swing.JButton();
        jPanel2 = new javax.swing.JPanel();
        jScrollPane2 = new javax.swing.JScrollPane();
        jPanel3 = new javax.swing.JPanel();
        jScrollPane3 = new javax.swing.JScrollPane();
        tbl = new javax.swing.JTable();
        jButton2 = new javax.swing.JButton();
        jButton1 = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();
        jMenuBar1 = new javax.swing.JMenuBar();
        jMenu1 = new javax.swing.JMenu();
        jMenuItem1 = new javax.swing.JMenuItem();
        jMenuItem2 = new javax.swing.JMenuItem();
        jMenu2 = new javax.swing.JMenu();
        jMenuItem3 = new javax.swing.JMenuItem();
        jMenu3 = new javax.swing.JMenu();
        jMenuItem4 = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowOpened(java.awt.event.WindowEvent evt) {
                formWindowOpened(evt);
            }
        });

        jLabel1.setText("Nombre");

        list1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                list1MouseClicked(evt);
            }
        });
        list1.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
            public void valueChanged(javax.swing.event.ListSelectionEvent evt) {
                list1ValueChanged(evt);
            }
        });
        jScrollPane4.setViewportView(list1);

        list2.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                list2MouseClicked(evt);
            }
        });
        list2.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
            public void valueChanged(javax.swing.event.ListSelectionEvent evt) {
                list2ValueChanged(evt);
            }
        });
        jScrollPane5.setViewportView(list2);

        jLabel2.setText("Apellido");

        list3.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                list3MouseClicked(evt);
            }
        });
        list3.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
            public void valueChanged(javax.swing.event.ListSelectionEvent evt) {
                list3ValueChanged(evt);
            }
        });
        jScrollPane6.setViewportView(list3);

        jLabel3.setText("Edad");

        jButton4.setText("Ver nomb");
        jButton4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton4ActionPerformed(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()
                .addContainerGap()
                .addComponent(jLabel1)
                .addGap(18, 18, 18)
                .addComponent(jScrollPane4, javax.swing.GroupLayout.PREFERRED_SIZE, 158, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(61, 61, 61)
                        .addComponent(jLabel2))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton4)))
                .addGap(18, 18, 18)
                .addComponent(jScrollPane5, javax.swing.GroupLayout.PREFERRED_SIZE, 158, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(91, 91, 91)
                .addComponent(jLabel3)
                .addGap(18, 18, 18)
                .addComponent(jScrollPane6, javax.swing.GroupLayout.PREFERRED_SIZE, 158, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(192, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(21, 21, 21)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane5, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel1)
                    .addComponent(jScrollPane6, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel3)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                        .addGroup(jPanel1Layout.createSequentialGroup()
                            .addComponent(jLabel2)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jButton4))
                        .addComponent(jScrollPane4, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(150, Short.MAX_VALUE))
        );

        jTabbedPane1.addTab("tab1", jPanel1);

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 980, Short.MAX_VALUE)
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 271, Short.MAX_VALUE)
        );

        jTabbedPane1.addTab("tab2", jPanel2);

        jScrollPane1.setViewportView(jTabbedPane1);

        tbl.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Title 1", "Title 2", "Title 3"
            }
        ));
        tbl.setRowHeight(25);
        jScrollPane3.setViewportView(tbl);

        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(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 962, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 261, Short.MAX_VALUE)
                .addContainerGap())
        );

        jScrollPane2.setViewportView(jPanel3);

        jButton2.setText("Limpiar filtros");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        jButton1.setText("Filtrar");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jButton3.setText("Limpiar");
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });

        jMenu1.setText("Ir...");

        jMenuItem1.setText("Inicio");
        jMenuItem1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem1ActionPerformed(evt);
            }
        });
        jMenu1.add(jMenuItem1);

        jMenuItem2.setText("Opciones de procesamiento de información");
        jMenuItem2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem2ActionPerformed(evt);
            }
        });
        jMenu1.add(jMenuItem2);

        jMenuBar1.add(jMenu1);

        jMenu2.setText("Muestra");

        jMenuItem3.setText("Seleccionar la muestra");
        jMenu2.add(jMenuItem3);

        jMenuBar1.add(jMenu2);

        jMenu3.setText("Personalizar tabla");

        jMenuItem4.setText("Seleccionar columnas");
        jMenuItem4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem4ActionPerformed(evt);
            }
        });
        jMenu3.add(jMenuItem4);

        jMenuBar1.add(jMenu3);

        setJMenuBar(jMenuBar1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane2)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jButton2)
                .addGap(257, 257, 257)
                .addComponent(jButton3)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jButton1)
                .addContainerGap())
            .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 183, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton2)
                    .addComponent(jButton1)
                    .addComponent(jButton3))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jScrollPane2))
        );

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

    private void list1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_list1MouseClicked
        // TODO add your handling code here:
    }//GEN-LAST:event_list1MouseClicked

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



        
       tablainicial();        
        cargarlistas();
 
       
        
        
    
    }//GEN-LAST:event_formWindowOpened


private void tablainicial(){
    
        
///////////CARGA TABLA
try {
            String[]fila = new String[3];
            conexion c = new conexion();
            c.getConexion();
            
            
            
            ResultSet rs = c.consulta("SELECT * FROM TESTING");
            
            while(rs.next()){
               fila[0]=rs.getString("NOMBRE");
               fila[1]=rs.getString("APELLIDO");
               fila[2]=rs.getString("LOCALIDAD");
               modelooriginal.addRow(fila);
            }       
        
        c.closeconnection();
        } catch (SQLException ex) {
            Logger.getLogger(Filtros_frame.class.getName()).log(Level.SEVERE, null, ex);
        }
}

    
    
private void cargarlistas(){
ArrayList<String> columna = new ArrayList<>();


//cargar lista 1        
columna.clear();
        for (int i = 0; i < modelooriginal.getRowCount(); i++) {
               columna.add(String.valueOf(modelooriginal.getValueAt(i, 0)));
           }
        
Collection<String> listadisctint = columna.stream().collect(Collectors.toSet());
ArrayList<String> lista_final = new ArrayList<>(listadisctint);

//Crear un objeto DefaultListModel
DefaultListModel listModel;
listModel = new DefaultListModel();   
//Recorrer el contenido del ArrayList
for(int i=0; i<lista_final.size(); i++) {
    //Añadir cada elemento del ArrayList en el modelo de la lista
    listModel.add(i, lista_final.get(i));
}
//Asociar el modelo de lista al JList
list1.setModel(listModel);
//

//cargar lista 2        
columna.clear();    
        for (int i = 0; i < modelooriginal.getRowCount(); i++) {
               columna.add(String.valueOf(modelooriginal.getValueAt(i, 1)));
           }
        
Collection<String> listadisctint2 = columna.stream().collect(Collectors.toSet());
ArrayList<String> lista_final2 = new ArrayList<>(listadisctint2);

//Crear un objeto DefaultListModel
DefaultListModel listModel2;
listModel2 = new DefaultListModel();   
//Recorrer el contenido del ArrayList
for(int i=0; i<lista_final2.size(); i++) {
    //Añadir cada elemento del ArrayList en el modelo de la lista
    listModel2.add(i, lista_final2.get(i));
}
//Asociar el modelo de lista al JList
list2.setModel(listModel2);
//
//cargar lista 3        
columna.clear();    
        for (int i = 0; i < modelooriginal.getRowCount(); i++) {
               columna.add(String.valueOf(modelooriginal.getValueAt(i, 2)));
           }
        
Collection<String> listadisctint3 = columna.stream().collect(Collectors.toSet());
ArrayList<String> lista_final3 = new ArrayList<>(listadisctint3);

//Crear un objeto DefaultListModel
DefaultListModel listModel3;
listModel3 = new DefaultListModel();   
//Recorrer el contenido del ArrayList
for(int i=0; i<lista_final3.size(); i++) {
    //Añadir cada elemento del ArrayList en el modelo de la lista
    listModel3.add(i, lista_final3.get(i));
}
//Asociar el modelo de lista al JList
list3.setModel(listModel3);
//

}
    private void list2MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_list2MouseClicked
        // TODO add your handling code here:
    }//GEN-LAST:event_list2MouseClicked

    private void list1ValueChanged(javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event_list1ValueChanged
////aqui se ve si hay otros filtros usados. esto permitirá saber con qué modelo de tabla trabajar
//boolean verificarotrosfiltrosusados2 = false;
//int aux=0;
//        for (int i = 0; i < listafiltrosusados.length; i++) {
//            if(i==1){
//                
//            }else{
//                if(listafiltrosusados[i]==1){
//                   aux++;
//
//                }
//            }
//        }
//        
//if(aux>0){
//    verificarotrosfiltrosusados2=true;
//}else{
//   verificarotrosfiltrosusados2=false; 
//}
//        if ((list1.getSelectedValuesList().size()) == 0) {
//            restaurartabla();
//            listafiltrosusados[0]=0;
//        } else {
//
//            int index = list1.getSelectedIndex();
//            if (list1.getSelectedValue().equals("TODOS")) {
//                seleccion.clear();
//                ListModel model = list1.getModel();
//                for (int i = 0; i < model.getSize(); i++) {
//                    seleccion.add(String.valueOf(model.getElementAt(i)));
//
//                }
//                if (verificarotrosfiltrosusados2 == false) {
//                    Filtros f = new Filtros();
//                    tbl.setModel(f.filtrar(modelooriginal, seleccion, 0));
//                    listafiltrosusados[0]=1;
//                } else {
//                    Filtros f = new Filtros();
//                    tbl.setModel(f.filtrar((DefaultTableModel) tbl.getModel(), seleccion, 0));
//                    listafiltrosusados[0]=1;
//                }
//
//            } else {
//
//                seleccion = (ArrayList<String>) list1.getSelectedValuesList();
//
//                if (verificarotrosfiltrosusados2 == false) {
//                    Filtros f = new Filtros();
//                    tbl.setModel(f.filtrar(modelooriginal, seleccion, 0));
//                    listafiltrosusados[0]=1;
//                } else {
//                    Filtros f = new Filtros();
//                    tbl.setModel(f.filtrar((DefaultTableModel) tbl.getModel(), seleccion, 0));
//                    listafiltrosusados[0]=1;
//                }
//            }
//        }
    }//GEN-LAST:event_list1ValueChanged

    private void list2ValueChanged(javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event_list2ValueChanged
//boolean verificarotrosfiltrosusados2 = false;
//int aux=0;
//        for (int i = 0; i < listafiltrosusados.length; i++) {
//            if(i==1){
//                
//            }else{
//                if(listafiltrosusados[i]==1){
//                   aux++;
//
//                }
//            }
//        }
//        
//if(aux>0){
//    verificarotrosfiltrosusados2=true;
//}else{
//   verificarotrosfiltrosusados2=false; 
//}
//
//
//        if ((list2.getSelectedValuesList().size()) == 0) {
//            restaurartabla();
//            listafiltrosusados[1]=0;
//        } else {
//
//            int index = list2.getSelectedIndex();
//            if (list2.getSelectedValue().equals("TODOS")) {
//                seleccion.clear();
//                ListModel model = list2.getModel();
//                for (int i = 0; i < model.getSize(); i++) {
//                    seleccion.add(String.valueOf(model.getElementAt(i)));
//
//                }
//                if (verificarotrosfiltrosusados2 == false) {
//                    Filtros f = new Filtros();
//                    tbl.setModel(f.filtrar(modelooriginal, seleccion, 1));
//                    listafiltrosusados[1]=1;
//                } else {
//                    Filtros f = new Filtros();
//                    tbl.setModel(f.filtrar((DefaultTableModel) tbl.getModel(), seleccion, 1));
//                    listafiltrosusados[1]=1;
//                }
//
//            } else {
//
//                seleccion = (ArrayList<String>) list2.getSelectedValuesList();
//
//                if (verificarotrosfiltrosusados2 == false) {
//                    Filtros f = new Filtros();
//                    tbl.setModel(f.filtrar(modelooriginal, seleccion, 1));
//                    listafiltrosusados[1]=1;
//                } else {
//                    Filtros f = new Filtros();
//                    tbl.setModel(f.filtrar((DefaultTableModel) tbl.getModel(), seleccion, 1));
//                    listafiltrosusados[1]=1;
//                }
//            }
//        }

    }//GEN-LAST:event_list2ValueChanged
private void limpiartabla(){

int rows = modelooriginal.getRowCount();
for(int i = rows - 1; i >=0; i--)
{
   modelooriginal.removeRow(i); 
}
    
}
    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed

limpiartabla();
String nom = nombres();
try {


    
            String[]fila = new String[3];
            conexion c = new conexion();
            c.getConexion();
            
            
            
            ResultSet rs = c.consulta("SELECT * FROM TESTING "+nom+" ");
            while(rs.next()){
               fila[0]=rs.getString("NOMBRE");
               fila[1]=rs.getString("APELLIDO");
               fila[2]=rs.getString("LOCALIDAD");
               modelooriginal.addRow(fila);
            }       
        
        c.closeconnection();
        } catch (SQLException ex) {
            Logger.getLogger(Filtros_frame.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_jButton1ActionPerformed

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
limpiartabla();
tablainicial();       
    }//GEN-LAST:event_jButton2ActionPerformed

    private void list3MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_list3MouseClicked
        // TODO add your handling code here:
    }//GEN-LAST:event_list3MouseClicked

    private void list3ValueChanged(javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event_list3ValueChanged
        // TODO add your handling code here:
    }//GEN-LAST:event_list3ValueChanged

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
limpiartabla();
    }//GEN-LAST:event_jButton3ActionPerformed

    private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed
nombres();
    }//GEN-LAST:event_jButton4ActionPerformed

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

    private void jMenuItem2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem2ActionPerformed
Procesar_informacion procesar = new Procesar_informacion();
procesar.setVisible(true);
this.dispose();
    }//GEN-LAST:event_jMenuItem2ActionPerformed

    private void jMenuItem4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem4ActionPerformed
seleccionar_columnas selecolumns = new seleccionar_columnas();
selecolumns.setVisible(true);
this.dispose();
    }//GEN-LAST:event_jMenuItem4ActionPerformed
private String nombres(){
   int cantidad = list1.getSelectedValuesList().size();

   
   
   if (cantidad == 0){
       nombre="";
   }

   if(cantidad>0){
       seleccion = (ArrayList<String>) list1.getSelectedValuesList();
       if(cantidad==1){
           nombre = "WHERE (NOMBRE='"+list1.getSelectedValue()+"')";
           
       }else{
           for (int i = 0; i < seleccion.size(); i++) {
               if(i==0){
                   nombre = "WHERE (NOMBRE='"+seleccion.get(i)+"' ";
               }if(i>0){
                   if(i==seleccion.size()-1){
                      nombre = nombre + "OR NOMBRE='"+seleccion.get(i)+"')";
                   }else{
                       nombre = nombre + "OR NOMBRE='"+seleccion.get(i)+"' ";
                   }

               }
           }
       }
   }
return nombre;
}
    /**
     * @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(Filtros_frame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(Filtros_frame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(Filtros_frame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(Filtros_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 Filtros_frame().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenu jMenu2;
    private javax.swing.JMenu jMenu3;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JMenuItem jMenuItem1;
    private javax.swing.JMenuItem jMenuItem2;
    private javax.swing.JMenuItem jMenuItem3;
    private javax.swing.JMenuItem jMenuItem4;
    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.JScrollPane jScrollPane4;
    private javax.swing.JScrollPane jScrollPane5;
    private javax.swing.JScrollPane jScrollPane6;
    private javax.swing.JTabbedPane jTabbedPane1;
    private javax.swing.JList<String> list1;
    private javax.swing.JList<String> list2;
    private javax.swing.JList<String> list3;
    private javax.swing.JTable tbl;
    // End of variables declaration//GEN-END:variables
}
