juan.salida.java Source code

Java tutorial

Introduction

Here is the source code for juan.salida.java

Source

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

import com.mongodb.BasicDBList;
import com.mongodb.BasicDBObject;
import com.mongodb.DBCollection;
import com.mongodb.DBCursor;
import com.mongodb.DBObject;
import java.awt.List;
import java.util.ArrayList;
import java.util.Arrays;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author inftel10
 */
public class salida extends javax.swing.JFrame {

    DefaultTableModel tableModel;
    DBCursor cursor = null;
    String[] columnamf = new String[4];
    String[] columnamt = new String[4];
    String[] columnamr = new String[5];
    String[] columnatf = new String[4];
    DBObject documento = null;

    /**
     * Creates new form salida
     *
     * @param cursor
     */
    public salida(DBCursor cursor) {

        tableModel = new DefaultTableModel();
        initComponents();

        this.cursor = cursor;

    }

    /**
     * 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();
        jTable1 = new javax.swing.JTable();
        jButton1 = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("RESULTADOS MONGO");
        setResizable(false);
        getContentPane().setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        jTable1.setModel(tableModel);
        jTable1.setOpaque(false);
        jScrollPane1.setViewportView(jTable1);

        getContentPane().add(jScrollPane1, new org.netbeans.lib.awtextra.AbsoluteConstraints(6, 52, 770, 188));

        jButton1.setText("CARGAR");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });
        getContentPane().add(jButton1, new org.netbeans.lib.awtextra.AbsoluteConstraints(321, 269, 111, 54));

        jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Javi/eos7dmaking12.jpg"))); // NOI18N
        getContentPane().add(jLabel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 0, 780, 370));

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

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

        columnamf[0] = "Nombre";
        columnamf[1] = "ruta";
        columnamf[2] = "fecha";
        columnamf[3] = "marca";
        columnamt[0] = "Nombre";
        columnamt[1] = "ruta";
        columnamt[2] = "marca";
        columnamt[3] = "tamao";
        columnamr[0] = "Nombre";
        columnamr[1] = "ruta";
        columnamr[2] = "marca";
        columnamr[3] = "ancho";
        columnamr[4] = "alto";
        columnatf[0] = "Nombre";
        columnatf[1] = "ruta";
        columnatf[2] = "tamao";
        columnatf[3] = "fecha";

        DBCollection col = cursor.getCollection();
        String collection = col.getFullName();

        if (collection.equals("mydb.modelo-fecha")) {
            tableModel.addColumn(columnamf[0]);
            tableModel.addColumn(columnamf[1]);
            tableModel.addColumn(columnamf[2]);
            tableModel.addColumn(columnamf[3]);

            while (cursor.hasNext()) {
                documento = cursor.next();
                tableModel.addRow(new Object[] { documento.get("nombre"), documento.get("ruta"),
                        documento.get("fecha"), documento.get("marca") });

            }

        } else if (collection.equals("mydb.modelo-tamano")) {
            tableModel.addColumn(columnamt[0]);
            tableModel.addColumn(columnamt[1]);
            tableModel.addColumn(columnamt[2]);
            tableModel.addColumn(columnamt[3]);

            while (cursor.hasNext()) {
                documento = cursor.next();
                tableModel.addRow(new Object[] { documento.get("nombre"), documento.get("ruta"),
                        documento.get("marca"), documento.get("tamano") });

            }

        } else if (collection.equals("mydb.modelo-resolucion")) {
            tableModel.addColumn(columnamr[0]);
            tableModel.addColumn(columnamr[1]);
            tableModel.addColumn(columnamr[2]);
            tableModel.addColumn(columnamr[3]);
            tableModel.addColumn(columnamr[4]);
            while (cursor.hasNext()) {
                documento = cursor.next();
                tableModel.addRow(new Object[] { documento.get("nombre"), documento.get("ruta"),
                        documento.get("marca"), documento.get("width"), documento.get("height") });

            }

        } else {
            tableModel.addColumn(columnatf[0]);
            tableModel.addColumn(columnatf[1]);
            tableModel.addColumn(columnatf[2]);
            tableModel.addColumn(columnatf[3]);

            while (cursor.hasNext()) {
                documento = cursor.next();

                tableModel.addRow(new Object[] { documento.get("nombre"), documento.get("ruta"),
                        documento.get("tamano"), documento.get("fecha") });

            }

        }

        jButton1.setVisible(false);

    }//GEN-LAST:event_jButton1ActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable jTable1;
    // End of variables declaration//GEN-END:variables
}