Package ManejoVentanas

Source Code of ManejoVentanas.VentanaPrincipal

package ManejoVentanas;

import GeneracionHorarios.EstructuraGeneral;
import GeneracionHorarios.EstructuraProfesor;
import GeneracionHorarios.Generador;
import ManejoBD.AccesoBD;
import java.sql.SQLException;
import javax.swing.*;

public class VentanaPrincipal extends JFrame {

    private EstructuraGeneral estGeneral;
    private EstructuraProfesor estProfesor;
    private Generador gen;
    private float puntajeGRASP = 0;
    private float puntajeTABU = 0;

    public VentanaPrincipal() {
        initComponents();
        estGeneral = new EstructuraGeneral();
        estProfesor = new EstructuraProfesor();
        gen = new Generador(0.25, 50);

        setVisible(true);


    }

    /** 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.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jtbBarraPrincipal = new javax.swing.JToolBar();
        btnCargarSalones = new javax.swing.JButton();
        btnCargarProfesores = new javax.swing.JButton();
        btnCargarDispProfesores = new javax.swing.JButton();
        btnCargarCursos = new javax.swing.JButton();
        btnGenerarHorario = new javax.swing.JButton();
        btnOptimizarHorario = new javax.swing.JButton();
        btnMostrarHorario = new javax.swing.JButton();
        btnLimpiar = new javax.swing.JButton();
        btnSalir = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        jmbMenu = new javax.swing.JMenuBar();
        jmMenuPrincipal = new javax.swing.JMenu();
        mtmCargarSalones = new javax.swing.JMenuItem();
        mtmCargarCursos = new javax.swing.JMenuItem();
        mtmGenerarHorario = new javax.swing.JMenuItem();
        mtmSalir = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Generación de Horarios");

        jtbBarraPrincipal.setFocusable(false);

        btnCargarSalones.setText("Salones");
        btnCargarSalones.setToolTipText("Cargar Salones");
        btnCargarSalones.setFocusable(false);
        btnCargarSalones.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCargarSalonesActionPerformed(evt);
            }
        });
        jtbBarraPrincipal.add(btnCargarSalones);

        btnCargarProfesores.setText("Profesores");
        btnCargarProfesores.setFocusable(false);
        btnCargarProfesores.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCargarProfesoresActionPerformed(evt);
            }
        });
        jtbBarraPrincipal.add(btnCargarProfesores);

        btnCargarDispProfesores.setText("Disponibilidad");
        btnCargarDispProfesores.setFocusable(false);
        btnCargarDispProfesores.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCargarDispProfesoresActionPerformed(evt);
            }
        });
        jtbBarraPrincipal.add(btnCargarDispProfesores);

        btnCargarCursos.setText("Cursos");
        btnCargarCursos.setToolTipText("Cargar Cursos");
        btnCargarCursos.setFocusable(false);
        btnCargarCursos.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCargarCursosActionPerformed(evt);
            }
        });
        jtbBarraPrincipal.add(btnCargarCursos);

        btnGenerarHorario.setText("Generar Horario (GRASP)");
        btnGenerarHorario.setToolTipText("Generar Horario (GRASP)");
        btnGenerarHorario.setFocusable(false);
        btnGenerarHorario.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnGenerarHorarioActionPerformed(evt);
            }
        });
        jtbBarraPrincipal.add(btnGenerarHorario);

        btnOptimizarHorario.setToolTipText("Optimizar Horario (Tabu)");
        btnOptimizarHorario.setFocusable(false);
        btnOptimizarHorario.setLabel("Optimizar Horario (Tabu)");
        btnOptimizarHorario.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnTabuActionPerformed(evt);
            }
        });
        jtbBarraPrincipal.add(btnOptimizarHorario);

        btnMostrarHorario.setText("Mostrar Horario");
        btnMostrarHorario.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnMostrarHorarioActionPerformed(evt);
            }
        });
        jtbBarraPrincipal.add(btnMostrarHorario);

        btnLimpiar.setText("Limpiar");
        btnLimpiar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnLimpiarActionPerformed(evt);
            }
        });
        jtbBarraPrincipal.add(btnLimpiar);

        btnSalir.setText("Salir");
        btnSalir.setToolTipText("Salir");
        btnSalir.setFocusable(false);
        btnSalir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSalirActionPerformed(evt);
            }
        });
        jtbBarraPrincipal.add(btnSalir);

        jLabel1.setEnabled(false);

        jmMenuPrincipal.setText("Principal");

        mtmCargarSalones.setText("Cargar Salones");
        mtmCargarSalones.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mtmCargarSalonesActionPerformed(evt);
            }
        });
        jmMenuPrincipal.add(mtmCargarSalones);

        mtmCargarCursos.setText("Cargar Cursos");
        mtmCargarCursos.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mtmCargarCursosActionPerformed(evt);
            }
        });
        jmMenuPrincipal.add(mtmCargarCursos);

        mtmGenerarHorario.setText("Generar Horario");
        mtmGenerarHorario.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mtmGenerarHorarioActionPerformed(evt);
            }
        });
        jmMenuPrincipal.add(mtmGenerarHorario);

        mtmSalir.setText("Salir");
        mtmSalir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mtmSalirActionPerformed(evt);
            }
        });
        jmMenuPrincipal.add(mtmSalir);

        jmbMenu.add(jmMenuPrincipal);

        setJMenuBar(jmbMenu);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jtbBarraPrincipal, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(61, 61, 61)
                        .addComponent(jLabel1)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jtbBarraPrincipal, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(26, 26, 26)
                .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 438, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(34, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents
    private void btnLimpiarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnLimpiarActionPerformed
// TODO add your handling code here:
        try {
            try {
                AccesoBD.conexionODBC("horariosBD");
            } catch (SQLException ex) {
                ex.printStackTrace();
            } catch (ClassNotFoundException ex) {
                ex.printStackTrace();
            }
            if (AccesoBD.Limpiar()) {
                JOptionPane.showMessageDialog(this, "Se limpió correctamente la BD");
            }




        } catch (SQLException ex) {
            //JOptionPane.showMessageDialog(this,ex);
            ex.printStackTrace();
            JOptionPane.showMessageDialog(this, "No se pudo limpiar correctamente");
        } finally {
            try {
                AccesoBD.desconexion();
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        }
}//GEN-LAST:event_btnLimpiarActionPerformed

    private void btnMostrarHorarioActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnMostrarHorarioActionPerformed
// TODO add your handling code here:
        new VentanaHorario(VentanaPrincipal.this, true, puntajeGRASP, puntajeTABU);
    }//GEN-LAST:event_btnMostrarHorarioActionPerformed

    private void btnTabuActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnTabuActionPerformed
// TODO add your handling code here:
        new VentanaCfg(VentanaPrincipal.this, gen);
        try {
            try {
                AccesoBD.conexionODBC("horariosBD");
            } catch (SQLException ex) {
                ex.printStackTrace();
            } catch (ClassNotFoundException ex) {
                ex.printStackTrace();
            }
            if (gen.TabuSearch(estGeneral, estProfesor, 300)) {
                {
                    JOptionPane.showMessageDialog(this, "El Horario se ha optimizado satisfactoriamente");

                    gen.copiarEstructuraAbD(estGeneral);
                }

                System.out.println("PUNTAJE OPTIMIZADO");
                puntajeTABU = gen.calculaPtj(estGeneral);
                System.out.println(gen.calculaPtj(estGeneral));
            } else {
                JOptionPane.showMessageDialog(this, "No se pudo generar el horario completamente");
            }
        } catch (SQLException ex) {
            //JOptionPane.showMessageDialog(this,ex);
            ex.printStackTrace();
        } finally {
            try {
                AccesoBD.desconexion();
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        }
        
       
       
       
       
    }//GEN-LAST:event_btnTabuActionPerformed

    private void btnCargarDispProfesoresActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCargarDispProfesoresActionPerformed
        new VentanaCargarDispProfesores(VentanaPrincipal.this, this.estProfesor);
    }//GEN-LAST:event_btnCargarDispProfesoresActionPerformed

    private void btnCargarProfesoresActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCargarProfesoresActionPerformed
        new VentanaCargarProfesores(VentanaPrincipal.this, this.estProfesor);
    }//GEN-LAST:event_btnCargarProfesoresActionPerformed

    private void mtmGenerarHorarioActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mtmGenerarHorarioActionPerformed
        generarHorario();
    }//GEN-LAST:event_mtmGenerarHorarioActionPerformed

    private void mtmSalirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mtmSalirActionPerformed
        dispose();
    }//GEN-LAST:event_mtmSalirActionPerformed

    private void btnSalirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSalirActionPerformed
        dispose();
    }//GEN-LAST:event_btnSalirActionPerformed

    private void mtmCargarCursosActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mtmCargarCursosActionPerformed
        cargarCursos();
    }//GEN-LAST:event_mtmCargarCursosActionPerformed

    private void btnCargarCursosActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCargarCursosActionPerformed
        cargarCursos();
    }//GEN-LAST:event_btnCargarCursosActionPerformed

    private void cargarCursos() {
        new VentanaCargarCursos(VentanaPrincipal.this, estGeneral);
    }

    private void btnGenerarHorarioActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnGenerarHorarioActionPerformed
        generarHorario();
    }//GEN-LAST:event_btnGenerarHorarioActionPerformed

    private void generarHorario() {
        try {
            try {
                AccesoBD.conexionODBC("horariosBD");
            } catch (SQLException ex) {
                ex.printStackTrace();
            } catch (ClassNotFoundException ex) {
                ex.printStackTrace();
            }
            if (gen.generarHorario(estGeneral, estProfesor)) {
                System.out.println("PUNTAJE GRASP");
                puntajeGRASP = gen.calculaPtj(estGeneral);
                System.out.println(puntajeGRASP);

                JOptionPane.showMessageDialog(this, "El Horario se elaboro satisfactoriamente");
            } else {
                JOptionPane.showMessageDialog(this, "No se pudo generar el horario completamente");
            }
        } catch (SQLException ex) {
            //JOptionPane.showMessageDialog(this,ex);
            ex.printStackTrace();
        } finally {
            try {
                AccesoBD.desconexion();
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        }
    }

    private void btnCargarSalonesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCargarSalonesActionPerformed
        cargarSalones();
    }//GEN-LAST:event_btnCargarSalonesActionPerformed

    private void mtmCargarSalonesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mtmCargarSalonesActionPerformed
        cargarSalones();
    }//GEN-LAST:event_mtmCargarSalonesActionPerformed

    private void cargarSalones() {
        new VentanaCargarSalones(VentanaPrincipal.this, this.estGeneral);
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnCargarCursos;
    private javax.swing.JButton btnCargarDispProfesores;
    private javax.swing.JButton btnCargarProfesores;
    private javax.swing.JButton btnCargarSalones;
    private javax.swing.JButton btnGenerarHorario;
    private javax.swing.JButton btnLimpiar;
    private javax.swing.JButton btnMostrarHorario;
    private javax.swing.JButton btnOptimizarHorario;
    private javax.swing.JButton btnSalir;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JMenu jmMenuPrincipal;
    private javax.swing.JMenuBar jmbMenu;
    private javax.swing.JToolBar jtbBarraPrincipal;
    private javax.swing.JMenuItem mtmCargarCursos;
    private javax.swing.JMenuItem mtmCargarSalones;
    private javax.swing.JMenuItem mtmGenerarHorario;
    private javax.swing.JMenuItem mtmSalir;
    // End of variables declaration//GEN-END:variables
    private String rutaCursos;
    private String rutaSalones[] = new String[5];

    public void setRutaCursos(String rutaCursos) {
        this.rutaCursos = rutaCursos;
    }

    public void setRutaSalones(String rutaSalones[]) {
        this.rutaSalones = rutaSalones;
    }
}
TOP

Related Classes of ManejoVentanas.VentanaPrincipal

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.