/* 
* Copyright 2016 Agencia Estatal de Administración Tibutaria
*
* Licencia con arreglo a la EUPL, Versión 1.1 o –en cuanto
* sean aprobadas por la Comisión Europea– versiones
* posteriores de la EUPL (la «Licencia»);
* Solo podrá usarse esta obra si se respeta la Licencia.
* Puede obtenerse una copia de la Licencia en:
*  
* https://joinup.ec.europa.eu/software/page/eupl
*  
* Salvo cuando lo exija la legislación aplicable o se acuerde
* por escrito, el programa distribuido con arreglo a la
* Licencia se distribuye «TAL CUAL», SIN GARANTÍAS NI CONDICIONES
* DE NINGÚN TIPO, ni expresasni implícitas.
*
* Véase la Licencia en el idioma concreto que rige los permisos y 
* limitaciones que establece la Licencia.
*/ 

package gestor;

import gestor.utiles.*;
import javax.swing.*;

public final class DlgConfirmarTicket extends javax.swing.JDialog {

   boolean emitirTicket = false;
   JFrame padre;
   public javax.swing.Timer timerCierraAviso;

   public DlgConfirmarTicket(JFrame padre) {
      super(padre, true);
      this.padre = padre;
      initComponents();
      botonSi.setText(Global.trad.valor("SI"));
      botonNo.setText(Global.trad.valor("NO"));
      preparaTimerAviso();
      ajustar();
   }

   public void ajustar() {
      int anchoPadre = padre.getContentPane().getWidth();
      int altoPadre = padre.getContentPane().getWidth();
      int ancho = (int) (anchoPadre / 2f);
      int alto = altoPadre / 3;
      setBounds((anchoPadre - ancho) / 2, (altoPadre - alto) / 2, ancho, alto);
      if (!Configuracion.instanciaUnica().cursorVisible) {
         setCursor(Global.mainForm.cursorTransparente);
      }
      setLocationRelativeTo(padre);
      timerCierraAviso.start();
      Global.mainForm.desactivarSalvaPantalla();      
   }

   public void setPregunta(String texto) {
      this.lbPregunta.setText(texto);
   }
   
   public void setRotulo(String texto) {
      this.rotulo.setText(texto);
   }

   public void setRotuloHora(java.sql.Timestamp hora) {
      this.rotuloHora.setText("con cita a las " + Fecha.formatoHoraHM(hora) + " ?");
   }
   
   void cerrarCon(boolean valor) {
      // poner aviso sonoro...
      Global.mainForm.activarSalvaPantalla();     
      emitirTicket = valor;
      timerCierraAviso.stop();
      setVisible(false);
   }

   void preparaTimerAviso() {
      timerCierraAviso = new javax.swing.Timer(Configuracion.instanciaUnica().segundosCierreVentanas * 1000, new java.awt.event.ActionListener() {

         public void actionPerformed(java.awt.event.ActionEvent evt) {
            cerrarCon(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() {

      jPanel1 = new MiPanel();
      botonSi = new gestor.utiles.MiBoton();
      botonNo = new gestor.utiles.MiBoton();
      lbPregunta = new gestor.utiles.SmoothLabel();
      rotulo = new gestor.utiles.SmoothLabel();
      rotuloHora = new gestor.utiles.SmoothLabel();

      setUndecorated(true);

      jPanel1.setBorder(javax.swing.BorderFactory.createCompoundBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED), javax.swing.BorderFactory.createMatteBorder(4, 4, 4, 4, new java.awt.Color(153, 153, 153))));

      botonSi.setFont(new java.awt.Font("Arial", 3, 36));
      botonSi.setForeground(new java.awt.Color(255, 0, 0));
      botonSi.setText("SI");
      botonSi.setFocusable(false);
      botonSi.addActionListener(new java.awt.event.ActionListener() {
         public void actionPerformed(java.awt.event.ActionEvent evt) {
            botonSiActionPerformed(evt);
         }
      });

      botonNo.setFont(new java.awt.Font("Arial", 3, 36));
      botonNo.setForeground(new java.awt.Color(255, 0, 0));
      botonNo.setText("NO");
      botonNo.setFocusable(false);
      botonNo.addActionListener(new java.awt.event.ActionListener() {
         public void actionPerformed(java.awt.event.ActionEvent evt) {
            botonNoActionPerformed(evt);
         }
      });

      lbPregunta.setFont(new java.awt.Font("Arial", 3, 30));
      lbPregunta.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
      lbPregunta.setText("¿Imprimir ticket para ");
      lbPregunta.setFocusable(false);

      rotulo.setFont(new java.awt.Font("Arial", 3, 30));
      rotulo.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
      rotulo.setText("  ");
      rotulo.setFocusable(false);

      rotuloHora.setFont(new java.awt.Font("Arial", 3, 30));
      rotuloHora.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
      rotuloHora.setText("  ");
      rotuloHora.setFocusable(false);

      org.jdesktop.layout.GroupLayout jPanel1Layout = new org.jdesktop.layout.GroupLayout(jPanel1);
      jPanel1.setLayout(jPanel1Layout);
      jPanel1Layout.setHorizontalGroup(
         jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
         .add(org.jdesktop.layout.GroupLayout.TRAILING, jPanel1Layout.createSequentialGroup()
            .addContainerGap()
            .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
               .add(lbPregunta, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 593, Short.MAX_VALUE)
               .add(jPanel1Layout.createSequentialGroup()
                  .add(botonSi, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 278, Short.MAX_VALUE)
                  .add(18, 18, 18)
                  .add(botonNo, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 297, Short.MAX_VALUE)))
            .addContainerGap())
         .add(jPanel1Layout.createSequentialGroup()
            .addContainerGap()
            .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
               .add(org.jdesktop.layout.GroupLayout.TRAILING, rotuloHora, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 593, Short.MAX_VALUE)
               .add(org.jdesktop.layout.GroupLayout.TRAILING, rotulo, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 593, Short.MAX_VALUE))
            .addContainerGap())
      );
      jPanel1Layout.setVerticalGroup(
         jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
         .add(jPanel1Layout.createSequentialGroup()
            .add(25, 25, 25)
            .add(lbPregunta)
            .add(27, 27, 27)
            .add(rotulo, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
            .add(rotuloHora, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 35, Short.MAX_VALUE)
            .add(20, 20, 20)
            .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
               .add(botonNo, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 103, Short.MAX_VALUE)
               .add(botonSi, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 103, Short.MAX_VALUE))
            .add(19, 19, 19))
      );

      getContentPane().add(jPanel1, java.awt.BorderLayout.CENTER);

      pack();
   }// </editor-fold>//GEN-END:initComponents
   private void botonNoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botonNoActionPerformed
      cerrarCon(false);
   }//GEN-LAST:event_botonNoActionPerformed

   private void botonSiActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botonSiActionPerformed
      cerrarCon(true);
   }//GEN-LAST:event_botonSiActionPerformed

   // Variables declaration - do not modify//GEN-BEGIN:variables
   javax.swing.JButton botonNo;
   javax.swing.JButton botonSi;
   javax.swing.JPanel jPanel1;
   javax.swing.JLabel lbPregunta;
   javax.swing.JLabel rotulo;
   javax.swing.JLabel rotuloHora;
   // End of variables declaration//GEN-END:variables
}
