/*
* EditTemplateDialog.java
*
* Created on 10 de mayo de 2010, 08:01 PM
*/
package gafetes;
import gafetes.beans.Template;
/**
*
* @author gateway
*/
public class EditTemplateDialog extends javax.swing.JDialog {
/**
* Creates new form EditTemplateDialog
*/
public EditTemplateDialog(java.awt.Frame parent, boolean modal) {
super(parent, modal);
initComponents();
txtName.requestFocus();
}
/** 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() {
jPanel1 = new javax.swing.JPanel();
jPanel2 = new javax.swing.JPanel();
jPanel3 = new javax.swing.JPanel();
okButton = new javax.swing.JButton();
cancelButton = new javax.swing.JButton();
jPanel4 = new javax.swing.JPanel();
jPanel5 = new javax.swing.JPanel();
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
txtId = new javax.swing.JTextField();
txtName = new javax.swing.JTextField();
jLabel3 = new javax.swing.JLabel();
jLabel4 = new javax.swing.JLabel();
txtFrontName = new javax.swing.JTextField();
txtLogoName = new javax.swing.JTextField();
jLabel5 = new javax.swing.JLabel();
txtRearName = new javax.swing.JTextField();
jLabel6 = new javax.swing.JLabel();
txtBack1 = new javax.swing.JTextField();
jLabel7 = new javax.swing.JLabel();
txtBack2 = new javax.swing.JTextField();
jButton1 = new javax.swing.JButton();
jButton2 = new javax.swing.JButton();
jButton3 = new javax.swing.JButton();
jLabel8 = new javax.swing.JLabel();
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
getContentPane().add(jPanel1, java.awt.BorderLayout.NORTH);
getContentPane().add(jPanel2, java.awt.BorderLayout.EAST);
okButton.setText("Aceptar");
okButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
okButtonActionPerformed(evt);
}
});
jPanel3.add(okButton);
cancelButton.setText("Cancelar");
cancelButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
cancelButtonActionPerformed(evt);
}
});
jPanel3.add(cancelButton);
getContentPane().add(jPanel3, java.awt.BorderLayout.SOUTH);
getContentPane().add(jPanel4, java.awt.BorderLayout.WEST);
jPanel5.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED));
jLabel1.setText("ID");
jLabel2.setText("Nombre Plantilla");
txtId.setEditable(false);
jLabel3.setText("Nombre del archivo frontal");
jLabel4.setText("Nombre del archivo reverso");
jLabel5.setText("Ruta al logotipo");
jLabel6.setText("Fondo 1(para el puesto)");
jLabel7.setText("Fondo 2(para la fotografia)");
jButton1.setText("Examinar");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
jButton2.setText("Examinar");
jButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton2ActionPerformed(evt);
}
});
jButton3.setText("Examinar");
jButton3.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton3ActionPerformed(evt);
}
});
jLabel8.setText("especifique el nombre + la extension .jasper");
javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
jPanel5.setLayout(jPanel5Layout);
jPanel5Layout.setHorizontalGroup(
jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel5Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel5Layout.createSequentialGroup()
.addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel3)
.addComponent(jLabel2)
.addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 86, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel4)
.addComponent(jLabel5)
.addComponent(jLabel6)
.addComponent(jLabel7))
.addGap(18, 18, 18)
.addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(txtBack2, javax.swing.GroupLayout.DEFAULT_SIZE, 336, Short.MAX_VALUE)
.addComponent(txtBack1, javax.swing.GroupLayout.DEFAULT_SIZE, 336, Short.MAX_VALUE)
.addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(txtLogoName)
.addComponent(txtRearName)
.addComponent(txtFrontName, javax.swing.GroupLayout.DEFAULT_SIZE, 336, Short.MAX_VALUE))
.addComponent(txtName, javax.swing.GroupLayout.DEFAULT_SIZE, 336, Short.MAX_VALUE)
.addComponent(txtId, javax.swing.GroupLayout.PREFERRED_SIZE, 85, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(jButton1)
.addComponent(jButton2))
.addComponent(jButton3))
.addContainerGap())
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel5Layout.createSequentialGroup()
.addComponent(jLabel8)
.addGap(140, 140, 140))))
);
jPanel5Layout.setVerticalGroup(
jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel5Layout.createSequentialGroup()
.addGap(20, 20, 20)
.addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(txtId, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel1))
.addGap(19, 19, 19)
.addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(txtName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel2))
.addGap(23, 23, 23)
.addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel3)
.addComponent(txtFrontName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jLabel8)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(txtRearName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel4))
.addGap(19, 19, 19)
.addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(txtLogoName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel5)
.addComponent(jButton1))
.addGap(19, 19, 19)
.addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(txtBack1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel6)
.addComponent(jButton2))
.addGap(25, 25, 25)
.addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel7)
.addComponent(txtBack2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jButton3))
.addContainerGap(20, Short.MAX_VALUE))
);
getContentPane().add(jPanel5, java.awt.BorderLayout.CENTER);
pack();
}// </editor-fold>//GEN-END:initComponents
private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
// TODO add your handling code here:
obtenerRuta(txtBack2);
}//GEN-LAST:event_jButton3ActionPerformed
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
// TODO add your handling code here:
obtenerRuta(txtBack1);
}//GEN-LAST:event_jButton2ActionPerformed
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
// TODO add your handling code here:
obtenerRuta(txtLogoName);
}//GEN-LAST:event_jButton1ActionPerformed
private void obtenerRuta(javax.swing.JTextField caja)
{
//String rutaFotos = gafetes.util.VariablesAmbiente.getRutaFondos();
javax.swing.JFileChooser fc = new javax.swing.JFileChooser();
//File f = new File(new File(rutaFotos).getAbsolutePath());
java.io.File f = new java.io.File("");
fc.setCurrentDirectory(f);
PreviewPane previewPane = new PreviewPane();
fc.setAccessory(previewPane);
fc.addPropertyChangeListener(previewPane);
int returnVal = fc.showDialog(this, "OK");
//Process the results.
if (returnVal == javax.swing.JFileChooser.APPROVE_OPTION)
{
java.io.File file = fc.getSelectedFile();
String ruta = file.getAbsolutePath();
caja.setText(ruta);
}
}
private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelButtonActionPerformed
// TODO add your handling code here:
dispose();
}//GEN-LAST:event_cancelButtonActionPerformed
private void okButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_okButtonActionPerformed
// TODO add your handling code here:
saveTemplate();
}//GEN-LAST:event_okButtonActionPerformed
public void setEditMode(Template template)
{
gafetes.beans.Template t = null;
t = gafetes.business.SqlHelper.getTemplateById(template.getId());
editmode = true;
if ( t != null ){
txtId.setText("" + t.getId());
txtName.setText(t.getNombre());
txtFrontName.setText(t.getRuta());
txtRearName.setText(t.getRutaReverso());
txtLogoName.setText(t.getLogotipo());
txtBack1.setText(t.getFondo1());
txtBack2.setText(t.getFondo2());
}else{
javax.swing.JOptionPane.showMessageDialog( Application.getparentFrame(), "La plantilla no existe en la Base de Datos con el ID especificado.");
dispose();
}
}
private Template toTemplate()
{
Template template = new Template();
if(editmode)
template.setId( Integer.parseInt(txtId.getText().trim() ));
template.setFondo1(txtBack1.getText().trim());
template.setFondo2(txtBack2.getText().trim());
template.setLogotipo(txtLogoName.getText().trim());
template.setNombre(txtName.getText().trim());
template.setRuta(txtFrontName.getText().trim());
template.setRutaReverso(txtRearName.getText().trim());
return template;
}
//Save te template in DB, we use Helpers to save in SQL Server
private void saveTemplate()
{
Template template = toTemplate();
if(editmode){
if( gafetes.business.SqlHelper.updateTemplate(template) == 1 ){
javax.swing.JOptionPane.showMessageDialog( Application.getparentFrame(), "La plantilla se actualiz� correctamente.");
dispose();
}
else
javax.swing.JOptionPane.showMessageDialog( Application.getparentFrame(), "Ocurri� un error al actualizar la plantilla.");
}else{
//-1 means that all ok
if( gafetes.business.SqlHelper.saveTemplate(template) == 1 ){
javax.swing.JOptionPane.showMessageDialog( Application.getparentFrame(), "La plantilla se guard� correctamente.");
dispose();
}
else
javax.swing.JOptionPane.showMessageDialog( Application.getparentFrame(), "Ocurri� un error al guardar la plantilla.");
}
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new EditTemplateDialog(new javax.swing.JFrame(), true).setVisible(true);
}
});
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton cancelButton;
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton2;
private javax.swing.JButton jButton3;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
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.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.JButton okButton;
private javax.swing.JTextField txtBack1;
private javax.swing.JTextField txtBack2;
private javax.swing.JTextField txtFrontName;
private javax.swing.JTextField txtId;
private javax.swing.JTextField txtLogoName;
private javax.swing.JTextField txtName;
private javax.swing.JTextField txtRearName;
// End of variables declaration//GEN-END:variables
private boolean editmode = false;
}