/*
* SearchDialog.java
*
* Created on 7 de agosto de 2007, 01:49 PM
*/
package gafetes;
import gafetes.util.VariablesAmbiente;
import gafetes.beans.Empleado;
import gafetes.model.EmpleadosModel;
import java.awt.event.KeyEvent;
import javax.swing.InputMap;
import javax.swing.ActionMap;
import javax.swing.KeyStroke;
import javax.swing.JComponent;
import javax.swing.AbstractAction;
import java.awt.event.KeyEvent;
import java.awt.event.ActionEvent;
import java.awt.event.*;
//import java.awt.*;
import javax.swing.event.*;
import javax.swing.InputMap;
import javax.swing.ActionMap;
import javax.swing.KeyStroke;
import javax.swing.JComponent;
import javax.swing.Action;
import javax.swing.AbstractAction;
import java.awt.event.KeyEvent;
import java.sql.*;
import javax.swing.*;
import java.io.File;
import java.awt.*;
import java.awt.event.*;
import java.awt.image.BufferedImage;
import java.beans.*;
import java.io.*;
import javax.imageio.ImageIO;
import javax.swing.*;
/**
*
* @author maritza
*/
public class SearchDialog extends javax.swing.JFrame {
/** Creates new form SearchDialog */
public SearchDialog(java.awt.Frame parent, boolean modal) {
// super(parent, modal);
gafetes.util.Misc.windowsItemActionPerformed(this);
initComponents();
initComponentsWithoutNetbeans();
}
public SearchDialog(java.awt.Frame parent, boolean modal, Empleado integrante) {
// super(parent, modal);
initComponents();
this.integrante = integrante;
initComponentsWithoutNetbeans();
}
private void initComponentsWithoutNetbeans(){
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
//Especificamos un modelo de tipo Empleado para posteriormente llenarlo mediante una consulta
table.setModel(new EmpleadosModel());
table.getSelectionModel().setSelectionMode( table.getSelectionModel().SINGLE_SELECTION);
//Al dar ENTER en la caja de busqueda, ejecutar la busqueda
InputMap im = searchTextField.getInputMap(JComponent.WHEN_FOCUSED);
im.put(KeyStroke.getKeyStroke( KeyEvent.VK_ENTER, 0 ), "enterAction");
ActionMap am = searchTextField.getActionMap();
am.put("enterAction",
new AbstractAction("enterAction") {
public void actionPerformed(ActionEvent evt) {
findButtonActionPerformed(evt);
}
});
//Al dar ESC en la caja de texto, salir. Lo desahbilitare hoy 25-abril-2010
/*InputMap im2 = searchTextField.getInputMap(JComponent.WHEN_FOCUSED);
im2.put(KeyStroke.getKeyStroke( KeyEvent.VK_ESCAPE, 0 ), "cancelAction");
ActionMap am2 = searchTextField.getActionMap();
am2.put("cancelAction",
new AbstractAction("cancelAction") {
public void actionPerformed(ActionEvent evt) {
dispose();
}
});
*/
// findAction();
searchTextField.requestFocus();
SplashDialog sp = new SplashDialog( null, false);
sp.setVisible(true);
if (sp!=null)
sp.updateLoadingStatus(40,"Inicializando componentes");
if (sp!=null)
sp.updateLoadingStatus(80,"Conectando...");
if (sp!=null)
sp.updateLoadingStatus(95,"Validando usuario...");
LoginDialogAdqal d = new LoginDialogAdqal( Application.getparentFrame(), true );
gafetes.util.Misc.centerFrame( d );
d.setModal(true);
d.setVisible(true);
if (sp!=null)
sp.updateLoadingStatus(100,"Listo");
if (sp!=null)
sp.setVisible(false);
createUserButton.setVisible(Application.getUsuario().EsAdministrador());
configButton.setVisible(Application.getUsuario().EsAdministrador());
generatePasswordButton.setVisible(Application.getUsuario().EsAdministrador());
findButton1.setVisible(Application.getUsuario().EsAdministrador());
jButton3.setVisible(Application.getUsuario().EsAdministrador());
jButton4.setVisible(Application.getUsuario().EsAdministrador());
//printOneButton.setVisible(false);
}
/** 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() {
buttonGroup1 = new javax.swing.ButtonGroup();
jFrame1 = new javax.swing.JFrame();
jPanel1 = new javax.swing.JPanel();
jButton4 = new javax.swing.JButton();
configButton = new javax.swing.JButton();
createUserButton = new javax.swing.JButton();
templatesButton = new javax.swing.JButton();
generatePasswordButton = new javax.swing.JButton();
cancelButton = new javax.swing.JButton();
jPanel2 = new javax.swing.JPanel();
jPanel3 = new javax.swing.JPanel();
jPanel4 = new javax.swing.JPanel();
jPanel5 = new javax.swing.JPanel();
jLabel1 = new javax.swing.JLabel();
searchTextField = new javax.swing.JTextField();
jScrollPane1 = new javax.swing.JScrollPane();
table = new javax.swing.JTable();
findButton = new javax.swing.JButton();
searchComboBox = new javax.swing.JComboBox();
jLabel2 = new javax.swing.JLabel();
jButton1 = new javax.swing.JButton();
printButton = new javax.swing.JButton();
printButton1 = new javax.swing.JButton();
findButton1 = new javax.swing.JButton();
jButton3 = new javax.swing.JButton();
printOneButton = new javax.swing.JButton();
printButton2 = new javax.swing.JButton();
org.jdesktop.layout.GroupLayout jFrame1Layout = new org.jdesktop.layout.GroupLayout(jFrame1.getContentPane());
jFrame1.getContentPane().setLayout(jFrame1Layout);
jFrame1Layout.setHorizontalGroup(
jFrame1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(0, 400, Short.MAX_VALUE)
);
jFrame1Layout.setVerticalGroup(
jFrame1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(0, 300, Short.MAX_VALUE)
);
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
setTitle("Busqueda de Empleados");
jPanel1.setBackground(new java.awt.Color(205, 199, 182));
jPanel1.setPreferredSize(new java.awt.Dimension(100, 50));
jButton4.setBackground(new java.awt.Color(205, 199, 182));
jButton4.setIcon(new javax.swing.ImageIcon(getClass().getResource("/gafetes/images/nuevo.gif")));
jButton4.setText("Nuevo Empleado");
jButton4.setToolTipText("Nuevo Empleado");
jButton4.setBorder(null);
jButton4.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton4ActionPerformed(evt);
}
});
jPanel1.add(jButton4);
configButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/gafetes/images/Edit24.gif")));
configButton.setText("Configuraci\u00f3n");
configButton.setPreferredSize(new java.awt.Dimension(135, 31));
configButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
configButtonActionPerformed(evt);
}
});
jPanel1.add(configButton);
createUserButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/gafetes/images/nuevo.gif")));
createUserButton.setText("Crear Usuario");
createUserButton.setPreferredSize(new java.awt.Dimension(145, 31));
createUserButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
createUserButtonActionPerformed(evt);
}
});
jPanel1.add(createUserButton);
templatesButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/gafetes/images/nuevo.gif")));
templatesButton.setText("Plantillas");
templatesButton.setPreferredSize(new java.awt.Dimension(145, 31));
templatesButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
templatesButtonActionPerformed(evt);
}
});
jPanel1.add(templatesButton);
generatePasswordButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/gafetes/images/modulo_activo.gif")));
generatePasswordButton.setLabel("Encriptar cadenas");
generatePasswordButton.setPreferredSize(new java.awt.Dimension(160, 31));
generatePasswordButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
generatePasswordButtonActionPerformed(evt);
createUserButton1ActionPerformed(evt);
}
});
jPanel1.add(generatePasswordButton);
cancelButton.setBackground(new java.awt.Color(205, 199, 182));
cancelButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/gafetes/images/salir.gif")));
cancelButton.setText("Cerrar");
cancelButton.setToolTipText("Cerrar");
cancelButton.setBorder(null);
cancelButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
cancelButtonActionPerformed(evt);
}
});
jPanel1.add(cancelButton);
getContentPane().add(jPanel1, java.awt.BorderLayout.NORTH);
jPanel2.setBackground(new java.awt.Color(236, 227, 211));
jPanel2.setPreferredSize(new java.awt.Dimension(10, 100));
org.jdesktop.layout.GroupLayout jPanel2Layout = new org.jdesktop.layout.GroupLayout(jPanel2);
jPanel2.setLayout(jPanel2Layout);
jPanel2Layout.setHorizontalGroup(
jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(0, 10, Short.MAX_VALUE)
);
jPanel2Layout.setVerticalGroup(
jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(0, 472, Short.MAX_VALUE)
);
getContentPane().add(jPanel2, java.awt.BorderLayout.EAST);
jPanel3.setBackground(new java.awt.Color(205, 199, 182));
jPanel3.setPreferredSize(new java.awt.Dimension(100, 10));
getContentPane().add(jPanel3, java.awt.BorderLayout.SOUTH);
jPanel4.setBackground(new java.awt.Color(236, 227, 211));
jPanel4.setPreferredSize(new java.awt.Dimension(10, 100));
org.jdesktop.layout.GroupLayout jPanel4Layout = new org.jdesktop.layout.GroupLayout(jPanel4);
jPanel4.setLayout(jPanel4Layout);
jPanel4Layout.setHorizontalGroup(
jPanel4Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(0, 10, Short.MAX_VALUE)
);
jPanel4Layout.setVerticalGroup(
jPanel4Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(0, 472, Short.MAX_VALUE)
);
getContentPane().add(jPanel4, java.awt.BorderLayout.WEST);
jPanel5.setBackground(new java.awt.Color(236, 227, 211));
jPanel5.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
jLabel1.setText("Palabra a buscar");
searchTextField.addKeyListener(new java.awt.event.KeyAdapter() {
public void keyPressed(java.awt.event.KeyEvent evt) {
searchTextFieldKeyPressed(evt);
}
});
jScrollPane1.setBackground(new java.awt.Color(244, 244, 240));
table.setModel(new javax.swing.table.DefaultTableModel(
new Object [][] {
{null, null, null, null},
{null, null, null, null},
{null, null, null, null},
{null, null, null, null}
},
new String [] {
"Title 1", "Title 2", "Title 3", "Title 4"
}
));
table.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
tableMouseClicked(evt);
}
});
table.addKeyListener(new java.awt.event.KeyAdapter() {
public void keyPressed(java.awt.event.KeyEvent evt) {
tableKeyPressed(evt);
}
public void keyTyped(java.awt.event.KeyEvent evt) {
tableKeyTyped(evt);
}
});
jScrollPane1.setViewportView(table);
findButton.setBackground(new java.awt.Color(236, 227, 211));
findButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/gafetes/images/busqueda.gif")));
findButton.setBorder(null);
findButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
findButtonActionPerformed(evt);
}
});
searchComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "CLAVE", "NOMBRE", "APELLIDOS", "AREA", "IMSS", "EMPRESA" }));
searchComboBox.addKeyListener(new java.awt.event.KeyAdapter() {
public void keyPressed(java.awt.event.KeyEvent evt) {
searchComboBoxKeyPressed(evt);
}
});
jLabel2.setText("Buscar por:");
jButton1.setBackground(new java.awt.Color(244, 244, 240));
jButton1.setIcon(new javax.swing.ImageIcon(""));
jButton1.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
printButton.setBackground(new java.awt.Color(236, 227, 211));
printButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/gafetes/images/imprimir.gif")));
printButton.setText("Impresion carta");
printButton.setToolTipText("Imprimir Frente");
printButton.setBorder(null);
printButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
printButtonActionPerformed(evt);
}
});
printButton1.setBackground(new java.awt.Color(236, 227, 211));
printButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/gafetes/images/imprimir.gif")));
printButton1.setText("Imprimir Firmas");
printButton1.setToolTipText("Imprimir Firmas");
printButton1.setBorder(null);
printButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
printButton1ActionPerformed(evt);
}
});
findButton1.setBackground(new java.awt.Color(236, 227, 211));
findButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/gafetes/images/Edit24.gif")));
findButton1.setText("Modificar");
findButton1.setToolTipText("Modificar Datos");
findButton1.setBorder(null);
findButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
findButton1ActionPerformed(evt);
}
});
jButton3.setBackground(new java.awt.Color(236, 227, 211));
jButton3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/gafetes/images/basura.gif")));
jButton3.setText("Eliminar");
jButton3.setBorder(null);
jButton3.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton3ActionPerformed(evt);
}
});
printOneButton.setBackground(new java.awt.Color(236, 227, 211));
printOneButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/gafetes/images/imprimir.gif")));
printOneButton.setText("Imprimir Frente");
printOneButton.setToolTipText("Imprimir Frente");
printOneButton.setBorder(null);
printOneButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
printOneButtonActionPerformed(evt);
}
});
printOneButton.addAncestorListener(new javax.swing.event.AncestorListener() {
public void ancestorMoved(javax.swing.event.AncestorEvent evt) {
}
public void ancestorAdded(javax.swing.event.AncestorEvent evt) {
printOneButtonAncestorAdded(evt);
}
public void ancestorRemoved(javax.swing.event.AncestorEvent evt) {
}
});
printButton2.setBackground(new java.awt.Color(236, 227, 211));
printButton2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/gafetes/images/imprimir.gif")));
printButton2.setText("Frente");
printButton2.setToolTipText("Imprimir Firmas");
printButton2.setBorder(null);
printButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
printButton2ActionPerformed(evt);
}
});
org.jdesktop.layout.GroupLayout jPanel5Layout = new org.jdesktop.layout.GroupLayout(jPanel5);
jPanel5.setLayout(jPanel5Layout);
jPanel5Layout.setHorizontalGroup(
jPanel5Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(jPanel5Layout.createSequentialGroup()
.addContainerGap()
.add(jPanel5Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(jPanel5Layout.createSequentialGroup()
.add(jPanel5Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
.add(jLabel1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 123, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(jLabel2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 123, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(jPanel5Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(jPanel5Layout.createSequentialGroup()
.add(searchComboBox, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 232, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(findButton, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 31, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.add(searchTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 480, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.add(92, 92, 92))
.add(jPanel5Layout.createSequentialGroup()
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(jPanel5Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(jPanel5Layout.createSequentialGroup()
.add(findButton1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 85, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 26, Short.MAX_VALUE)
.add(jButton3, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 85, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(20, 20, 20)
.add(printOneButton, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 130, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(printButton, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 130, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(26, 26, 26)
.add(printButton1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 134, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.add(jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 642, Short.MAX_VALUE))
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(jPanel5Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(printButton2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 96, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(jButton1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 200, Short.MAX_VALUE))))
.addContainerGap())
);
jPanel5Layout.setVerticalGroup(
jPanel5Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(org.jdesktop.layout.GroupLayout.TRAILING, jPanel5Layout.createSequentialGroup()
.add(64, 64, 64)
.add(jPanel5Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
.add(jLabel1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 17, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(searchTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.add(14, 14, 14)
.add(jPanel5Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
.add(jPanel5Layout.createSequentialGroup()
.add(jPanel5Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
.add(searchComboBox, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(jLabel2)
.add(findButton))
.add(35, 35, 35)
.add(findButton1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 28, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.add(jPanel5Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
.add(printButton1)
.add(printButton)
.add(printOneButton)
.add(jButton3, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 31, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(printButton2)))
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(jPanel5Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
.add(org.jdesktop.layout.GroupLayout.LEADING, jButton1, 0, 0, Short.MAX_VALUE)
.add(jScrollPane1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 269, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.addContainerGap())
);
getContentPane().add(jPanel5, java.awt.BorderLayout.CENTER);
pack();
}// </editor-fold>//GEN-END:initComponents
private void printButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_printButton2ActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_printButton2ActionPerformed
private void templatesButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_templatesButtonActionPerformed
// TODO add your handling code here:
gafetes.TemplatesDialog ef = new TemplatesDialog(Application.getparentFrame(),false);
gafetes.util.Misc.centerFrame(ef);
ef.setTitle("Administracion de plantillas disponibles");
ef.setModal(true);
ef.setVisible(true);
}//GEN-LAST:event_templatesButtonActionPerformed
private void printOneButtonAncestorAdded(javax.swing.event.AncestorEvent evt) {//GEN-FIRST:event_printOneButtonAncestorAdded
// TODO add your handling code here:
}//GEN-LAST:event_printOneButtonAncestorAdded
private void printOneButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_printOneButtonActionPerformed
// TODO add your handling code here:
printGafete(true);
}//GEN-LAST:event_printOneButtonActionPerformed
private void createUserButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_createUserButton1ActionPerformed
// TODO add your handling code here:
gafetes.GeneratePasswordDialog ef = new GeneratePasswordDialog(Application.getparentFrame(),false);
gafetes.util.Misc.centerFrame(ef);
ef.setTitle("Generar cadenas encriptadas");
ef.setModal(true);
ef.setVisible(true);
}//GEN-LAST:event_createUserButton1ActionPerformed
private void generatePasswordButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_generatePasswordButtonActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_generatePasswordButtonActionPerformed
private void createUserButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_createUserButtonActionPerformed
// TODO add your handling code here:
gafetes.UsuariosDialog ef = new UsuariosDialog(Application.getparentFrame(),false);
gafetes.util.Misc.centerFrame(ef);
ef.setTitle("Alta de usuario");
ef.setModal(true);
ef.setVisible(true);
}//GEN-LAST:event_createUserButtonActionPerformed
private void configButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_configButtonActionPerformed
// TODO add your handling code here:
gafetes.ConfigDialog cf = new ConfigDialog(Application.getparentFrame(),false);
gafetes.util.Misc.centerFrame(cf);
cf.setTitle("Configuraci�n de la aplicaci�n");
cf.setModal(true);
cf.setVisible(true);
}//GEN-LAST:event_configButtonActionPerformed
private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
// TODO add your handling code here:
//Eliminacion de registro
int confirm = javax.swing.JOptionPane.showOptionDialog( Application.getparentFrame(),
"�Desea eliminar el registro?", "Confirmaci�n",
javax.swing.JOptionPane.YES_NO_OPTION, javax.swing.JOptionPane.QUESTION_MESSAGE,
null,null,null);
if ( confirm == 0 ) {
gafetes.beans.Empleado e = new gafetes.beans.Empleado();
int row = table.getSelectedRow();
if(row<0){
javax.swing.JOptionPane.showMessageDialog(new JFrame(),"Selecccione un registro");
table.requestFocus();
}
e = ( (Empleado) table.getModel().getValueAt(row,1) );
gafetes.business.SqlHelper.deleteEmpleado(e);
}
findAction();
}//GEN-LAST:event_jButton3ActionPerformed
private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed
// TODO add your handling code here:
newAction();
}//GEN-LAST:event_jButton4ActionPerformed
public void newAction(){
gafetes.EmpleadoDialog ef = new EmpleadoDialog(Application.getparentFrame(),false);
ef.newMode();
gafetes.beans.Empleado e = new gafetes.beans.Empleado();
gafetes.util.Misc.centerFrame(ef);
ef.setTitle("Alta de Empleado");
ef.setModal(true);
ef.setVisible(true);
findAction();
}
private void findButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_findButton1ActionPerformed
// TODO add your handling code here:
gafetes.beans.Empleado e = new gafetes.beans.Empleado();
int row = table.getSelectedRow();
if(row<0){
javax.swing.JOptionPane.showMessageDialog(new JFrame(),"Selecccione un registro");
table.requestFocus();
}
e = ( (Empleado) table.getModel().getValueAt(row,1) );
gafetes.EmpleadoDialog ef = new EmpleadoDialog(Application.getparentFrame(),false);
ef.setTitle("Modificaci�n de datos del empleado");
ef.setEditMode(e);
ef.setModal(true);
gafetes.util.Misc.centerFrame(ef);
ef.setVisible(true);
findAction();
}//GEN-LAST:event_findButton1ActionPerformed
private void searchComboBoxKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_searchComboBoxKeyPressed
// TODO add your handling code here:
if(evt.getKeyCode() == java.awt.event.KeyEvent.VK_ENTER )
findAction();
}//GEN-LAST:event_searchComboBoxKeyPressed
private void printButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_printButton1ActionPerformed
// TODO add your handling code here:
//printGafete(false);
printLetterSize(false);
}//GEN-LAST:event_printButton1ActionPerformed
private void tableKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_tableKeyTyped
// TODO add your handling code here:
}//GEN-LAST:event_tableKeyTyped
private void tableKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_tableKeyPressed
// TODO add your handling code here:
if(evt.getKeyCode() == java.awt.event.KeyEvent.VK_DOWN )
changePhoto(1);
if(evt.getKeyCode() == java.awt.event.KeyEvent.VK_UP )
changePhoto(-1);
if(evt.getKeyCode() == java.awt.event.KeyEvent.VK_LEFT )
changePhoto(0);
if(evt.getKeyCode() == java.awt.event.KeyEvent.VK_RIGHT )
changePhoto(0);
}//GEN-LAST:event_tableKeyPressed
private void printButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_printButtonActionPerformed
// TODO add your handling code here:
//Imprimir el frente
printLetterSize(true);
}//GEN-LAST:event_printButtonActionPerformed
public void actualizarFoto(){
findAction();
}
private void printGafete(boolean imprimirFrente){
int row = table.getSelectedRow();
if( row < 0 ){
javax.swing.JOptionPane.showMessageDialog(new JFrame(),"Selecccione un registro");
table.requestFocus();
}
//Obtenemos el empleado de la lista
gafetes.beans.Empleado e = new gafetes.beans.Empleado();
e = ( (Empleado) table.getModel().getValueAt(row,1) );
e = gafetes.business.SqlHelper.getEmpleadoById(e);
gafetes.print.PrintGafete pr = new gafetes.print.PrintGafete();
pr.print(e,imprimirFrente);
}
private void printLetterSize(boolean imprimirFrente){
int impresiones = 1 ;
String sqlString1="", sqlString2="", sqlString3 = "";
gafetes.beans.Empleado e = new gafetes.beans.Empleado();
for(int row=0; row < table.getRowCount(); row++){
Object valor = (Object)(table.getModel().getValueAt(row, 5));
Boolean imprimir = (Boolean)valor;
//El registro est� seleccionado para imprimir
if(imprimir){
//Obtenemos el empleado de la lista
e = ( (Empleado) table.getModel().getValueAt(row,1) );
e = gafetes.business.SqlHelper.getEmpleadoById(e);
//Obtenemos la ruta a la plantilla
java.io.FileInputStream file = null;
String rutaReporte = gafetes.business.SqlHelper.getRutaTemplate(e.getTemplate(),imprimirFrente);
try {
rutaReporte = "reports" + java.io.File.separator + rutaReporte;
file = new FileInputStream(rutaReporte);
}catch(Exception exs){
System.out.println("La plantilla para el empleado " + e.getNombre() + " " + e.getApellidos() + " no existe en la ruta: " + rutaReporte );
javax.swing.JOptionPane.showMessageDialog(Application.getparentFrame() ,
"La plantilla para el empleado " + e.getNombre() + " " + e.getApellidos() + " no existe en la ruta: " + rutaReporte , "Mensaje desde el Servidor",
javax.swing.JOptionPane.INFORMATION_MESSAGE);
return;
}
if(imprimirFrente){
if( (impresiones % 3)==0){
if(impresiones == 3){
sqlString3 = "SELECT E.CLAVE, E.NOMBRE, E.APELLIDOS, E.PUESTO, E.RFC, E.IMSS, E.PHOTOFILE, T.LOGOTIPO, T.FONDO1, T.FONDO2 FROM " + gafetes.db.GlobalSettings.GetPrefix() + "EMPLEADOS E INNER JOIN " + gafetes.db.GlobalSettings.GetPrefix() + "TEMPLATES T ON E.TEMPLATE = T.ID "
+ "WHERE CLAVE = '" + e.getClave() + "' " ;
}else{
sqlString3 += " OR CLAVE = '" + e.getClave() + "' " ;
}
}else if( (impresiones % 3)==2){
if(impresiones == 2){
sqlString2 = "SELECT E.CLAVE, E.NOMBRE, E.APELLIDOS, E.PUESTO, E.RFC, E.IMSS, E.PHOTOFILE, T.LOGOTIPO, T.FONDO1, T.FONDO2 FROM " + gafetes.db.GlobalSettings.GetPrefix() + "EMPLEADOS E INNER JOIN " + gafetes.db.GlobalSettings.GetPrefix() + "TEMPLATES T ON E.TEMPLATE = T.ID "
+ " WHERE CLAVE = '" + e.getClave() + "' " ;
}else{
sqlString2 += " OR CLAVE = '" + e.getClave() + "' " ;
}
}else if( (impresiones % 3)==1){
if(impresiones == 1){
sqlString1 = "SELECT E.CLAVE, E.NOMBRE, E.APELLIDOS, E.PUESTO, E.RFC, E.IMSS, E.PHOTOFILE, T.LOGOTIPO, T.FONDO1, T.FONDO2 FROM " + gafetes.db.GlobalSettings.GetPrefix() + "EMPLEADOS E INNER JOIN " + gafetes.db.GlobalSettings.GetPrefix() + "TEMPLATES T ON E.TEMPLATE = T.ID "
+ " WHERE CLAVE = '" + e.getClave() + "' " ;
}else{
sqlString1 += " OR CLAVE = '" + e.getClave() + "' " ;
}
}
}else{
if( impresiones == 1 ){
sqlString1 = "SELECT * FROM " + gafetes.db.GlobalSettings.GetPrefix() + "EMPLEADOS E INNER JOIN " + gafetes.db.GlobalSettings.GetPrefix() + "TEMPLATES T ON E.TEMPLATE = T.ID "
+ " WHERE CLAVE = '" + e.getClave() + "' " ;
}else
sqlString1 += " OR CLAVE = '" + e.getClave() + "' " ;
}
impresiones++;
}
}
if(impresiones > 1){
//No importa lo que tenga el empleado porque ahora se imprimen varios
gafetes.print.PrintGafete pr = new gafetes.print.PrintGafete();
pr.printLetterSize(e,imprimirFrente, sqlString1, sqlString2, sqlString3);
}
/*Modo de impresion de varias tarjetas en varias impresiones
//El registro est� seleccionado para imprimir
if(imprimir){
gafetes.beans.Empleado e = new gafetes.beans.Empleado();
e = ( (Empleado) table.getModel().getValueAt(row,1) );
e = gafetes.business.SqlHelper.getEmpleadoById(e);
if(impresiones==0){
sqlString = "SELECT * FROM " + gafetes.db.GlobalSettings.GetPrefix()
+ "EMPLEADOS WHERE CLAVE = '" + e.getClave() + "' " ;
}else
sqlString = " OR ID_INTEGRANTE = '" + e.getClave() + "' " ;
if( gafetes.business.SqlHelper.existeTemplate(e.getTemplate()) ){
integrante = e;
gafetes.print.PrintGafete pr = new gafetes.print.PrintGafete();
pr.print(e,imprimirFrente, sqlString);
}else{
javax.swing.JOptionPane.showMessageDialog(
new JFrame(),"El empleado no tiene asignado una plantilla, Seleccione una plantilla dando Click a Cambiar Plantilla");
}
impresiones++;
}
}
*/
if( impresiones == 0 ){
javax.swing.JOptionPane.showMessageDialog(new JFrame(),"Selecccione al menos un registro para imprimir.");
table.requestFocus();
}
}
private void changePhoto(int value){
gafetes.beans.Empleado e = new gafetes.beans.Empleado();
int row =0;
row= table.getSelectedRow()+value;
if(value<0){
return;
}
e = (Empleado) table.getModel().getValueAt(row,1);
java.io.File file = new java.io.File(e.getRutaFoto());
Icon icon = null;
int maxImgWidth = 195;
try {
// BufferedImage img = ImageIO.read(new java.net.URL(VariablesAmbiente.getRutaCarpetaFotos()+e.getRutaFoto().substring(11)));
System.out.println(e.getRutaFoto().substring(11));
BufferedImage img = ImageIO.read(file);
float width = img.getWidth();
float height = img.getHeight();
float scale = height / width;
width = maxImgWidth;
height = (width * scale); // height should be scaled from new width
icon = new ImageIcon(img.getScaledInstance(Math.max(1, (int)width), Math.max(1, (int)height), Image.SCALE_SMOOTH));
//jButton1.setIcon(new javax.swing.ImageIcon(e.getRutaFoto()));
jButton1.setIcon( icon );
}
catch(IOException exa) {
try {
// File files = new java.io.File("c:\\Gafetes\\fotos\\unavailable.jpg");
//String rutaCompletaArchivo = VariablesAmbiente.getRutaCarpetaFotos()+e.getRutaFoto().substring(11);
//System.out.println(rutaCompletaArchivo);
String rutaArchivo = VariablesAmbiente.getRutaFotoNoExiste();
File files = new java.io.File(rutaArchivo);
BufferedImage img = ImageIO.read(files);
// BufferedImage img = ImageIO.read(files);
float width = img.getWidth();
float height = img.getHeight();
float scale = height / width;
width = maxImgWidth;
height = (width * scale); // height should be scaled from new width
icon = new ImageIcon(img.getScaledInstance(Math.max(1, (int)width), Math.max(1, (int)height), Image.SCALE_SMOOTH));
jButton1.setIcon( icon );
}catch(IOException exas){
System.out.println("No existe imagen por Default.");
}
}
}
private void tableMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tableMouseClicked
// TODO add your handling code here:
changePhoto(0);
}//GEN-LAST:event_tableMouseClicked
private void searchTextFieldKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_searchTextFieldKeyPressed
// TODO add your handling code here:
if(evt.getKeyCode()== java.awt.event.KeyEvent.VK_DOWN){
table.requestFocus();
table.getSelectionModel().setLeadSelectionIndex(1);
}
}//GEN-LAST:event_searchTextFieldKeyPressed
private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelButtonActionPerformed
// TODO add your handling code here:
System.exit(0);
}//GEN-LAST:event_cancelButtonActionPerformed
private void selectAndClose(){
int row = table.getSelectedRow();
if( row == -1 ) {
javax.swing.JOptionPane.showMessageDialog( Application.getparentFrame(),
"Seleccione un registro", "Mensaje de la Aplicacion",
javax.swing.JOptionPane.INFORMATION_MESSAGE);
searchTextField.requestFocus();
return ;
}
java.util.Vector newRow = new java.util.Vector();
for ( int col = 0; col < table.getColumnCount() ; col++ ) {
newRow.addElement( table.getValueAt( row, col) );
}
integrante.setId( (( Integer ) newRow.elementAt(0)).intValue() );
integrante.setNombre( ( String ) newRow.elementAt(1));
integrante.setApellidos(( String ) newRow.elementAt(2));
integrante.setPuesto(( String ) newRow.elementAt(3));
integrante.setArea(( String ) newRow.elementAt(6));
this.dispose();
}
public void doSearch(String value,boolean byId){
searchTextField.setText(value);
System.out.println(value);
findAction();
}
private void findAction()
{
/*if(searchTextField.getText().trim().equals("")){
javax.swing.JOptionPane.showMessageDialog( Application.getparentFrame(),
"Especifique la palabra a buscar", "Mensaje de la Aplicacion",
javax.swing.JOptionPane.INFORMATION_MESSAGE);
searchTextField.requestFocus();
return;
}*/
gafetes.model.EmpleadosModel im=null;
try{
boolean showTemplate = false;
//Realizamos la busqueda del empleado por medio del campo especificado
im = gafetes.business.SqlHelper.getEmpleadosByField(searchTextField.getText().trim(),(String) searchComboBox.getSelectedItem());
}catch(java.lang.NumberFormatException nfe ){
javax.swing.JOptionPane.showMessageDialog( Application.getparentFrame(),
"El identificador debe ser num�rico", "Aviso",
javax.swing.JOptionPane.INFORMATION_MESSAGE);
}
if( im != null ){
table.setModel(im);
if(im.getRowCount() > 0){
table.getColumnModel().getColumn( 0 ).setPreferredWidth( 70 );
table.getColumnModel().getColumn( 1 ).setPreferredWidth( 150);
table.getColumnModel().getColumn( 2 ).setPreferredWidth( 150);
table.changeSelection(0, table.getModel().getColumnCount()-1, false, false);
table.changeSelection(0, 0, false, false);
//table.requestFocus();
changePhoto(0);
table.getInputMap(JComponent.WHEN_FOCUSED).put(
KeyStroke.getKeyStroke( KeyEvent.VK_ESCAPE,
0 ), "disposeDialog");
table.getInputMap(JComponent.WHEN_FOCUSED).put(
KeyStroke.getKeyStroke( KeyEvent.VK_ENTER,
0 ), "returnIntegrante");
Action disposeDialog = new AbstractAction("disposeDialog") {
public void actionPerformed(ActionEvent evt) {
System.exit(0);
//dialog = null;
}
};
Action returnIntegrante = new AbstractAction("returnIntegrante") {
public void actionPerformed(ActionEvent evt) {
selectAndClose();
}
};
table.getActionMap().put("disposeDialog", disposeDialog);
table.getActionMap().put("returnIntegrante", returnIntegrante);
table.requestFocus();
table.getSelectionModel().setLeadSelectionIndex(0);
}else{
javax.swing.JOptionPane.showMessageDialog( Application.getparentFrame(),
"La busqueda no devolvi� resultados con los par�metros especificados", "Mensaje de la Aplicaci�n",
javax.swing.JOptionPane.INFORMATION_MESSAGE);
searchTextField.requestFocus();
}
}
}
private void findButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_findButtonActionPerformed
// TODO add your handling code here:
findAction();
}//GEN-LAST:event_findButtonActionPerformed
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new SearchDialog(Application.getparentFrame(), true).setVisible(true);
}
});
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.ButtonGroup buttonGroup1;
private javax.swing.JButton cancelButton;
private javax.swing.JButton configButton;
private javax.swing.JButton createUserButton;
private javax.swing.JButton findButton;
private javax.swing.JButton findButton1;
private javax.swing.JButton generatePasswordButton;
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton3;
private javax.swing.JButton jButton4;
private javax.swing.JFrame jFrame1;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JPanel jPanel1;
private javax.swing.JPanel jPanel2;
private javax.swing.JPanel jPanel3;
private javax.swing.JPanel jPanel4;
private javax.swing.JPanel jPanel5;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JButton printButton;
private javax.swing.JButton printButton1;
private javax.swing.JButton printButton2;
private javax.swing.JButton printOneButton;
private javax.swing.JComboBox searchComboBox;
private javax.swing.JTextField searchTextField;
private javax.swing.JTable table;
private javax.swing.JButton templatesButton;
// End of variables declaration//GEN-END:variables
private gafetes.beans.Empleado integrante = new gafetes.beans.Empleado();
private gafetes.beans.Usuario usuario = new gafetes.beans.Usuario();
}