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

public class DlgTicketVisual extends javax.swing.JDialog {

   public javax.swing.Timer timerCierraAviso;

   public DlgTicketVisual(java.awt.Frame padre) {
      super(padre, true);
      initComponents();
      setSize(576, 424);
      setLocationRelativeTo(padre);
      jLabel1.setText(gestor.utiles.Global.trad.valor("recojaSuTicket"));
      preparaTimerAviso();
      if (!Configuracion.instanciaUnica().cursorVisible) {
         setCursor(gestor.utiles.Global.mainForm.cursorTransparente);
      }
   }

   public void setTextoEtiqueta(String texto) {
      lbTicket.setText(texto);
   }

   public void setTextoSala(String texto) {
      lbSala.setText(texto);
   }

   void cerrarCon(boolean valor) {
      timerCierraAviso.stop();
      setVisible(false);
   }

   void preparaTimerAviso() {
      Configuracion conf = Configuracion.instanciaUnica();
      int tiempo;
      if(conf.segundosTicketVisual > 0) {
         tiempo = conf.segundosTicketVisual * 1000;
      } else {
         tiempo = Configuracion.instanciaUnica().segundosCierreVentanas  * 500;  // milisegs partido por dos
         if(tiempo < 5000) tiempo = 5000;
      }
      timerCierraAviso = new javax.swing.Timer(tiempo, 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 javax.swing.JPanel();
        jLabel1 = new gestor.utiles.SmoothLabel();
        lbSala = new gestor.utiles.SmoothLabel();
        lbTicket = new gestor.utiles.SmoothLabel();
        jButton1 = new gestor.utiles.MiBoton();

        setTitle("Impresora");
        setBackground(java.awt.Color.white);
        setModal(true);
        setResizable(false);
        setUndecorated(true);
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowActivated(java.awt.event.WindowEvent evt) {
                formWindowActivated(evt);
            }
        });

        jPanel1.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(204, 204, 204), 6));

        jLabel1.setFont(new java.awt.Font("Arial", 1, 50));
        jLabel1.setForeground(new java.awt.Color(255, 0, 0));
        jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel1.setText(Global.trad.valor("Recojasuticket"));
        jLabel1.setDebugGraphicsOptions(javax.swing.DebugGraphics.NONE_OPTION);

        lbSala.setBackground(new java.awt.Color(255, 255, 204));
        lbSala.setFont(new java.awt.Font("Arial", 1, 58));
        lbSala.setForeground(new java.awt.Color(204, 0, 0));
        lbSala.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        lbSala.setText("jLabel2");
        lbSala.setDebugGraphicsOptions(javax.swing.DebugGraphics.NONE_OPTION);

        lbTicket.setFont(new java.awt.Font("Arial", 1, 80));
        lbTicket.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        lbTicket.setText("M-MMM");
        lbTicket.setDebugGraphicsOptions(javax.swing.DebugGraphics.NONE_OPTION);
        lbTicket.setOpaque(true);

        jButton1.setFont(new java.awt.Font("Arial", 3, 35));
        jButton1.setText(Global.trad.valor("Aceptar"));
        jButton1.setDebugGraphicsOptions(javax.swing.DebugGraphics.NONE_OPTION);
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        org.jdesktop.layout.GroupLayout jPanel1Layout = new org.jdesktop.layout.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel1Layout.createSequentialGroup()
                .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING, false)
                    .add(org.jdesktop.layout.GroupLayout.LEADING, lbSala, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .add(org.jdesktop.layout.GroupLayout.LEADING, jPanel1Layout.createSequentialGroup()
                        .add(2, 2, 2)
                        .add(jLabel1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 560, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                    .add(org.jdesktop.layout.GroupLayout.LEADING, jPanel1Layout.createSequentialGroup()
                        .add(84, 84, 84)
                        .add(jButton1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 390, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                    .add(org.jdesktop.layout.GroupLayout.LEADING, jPanel1Layout.createSequentialGroup()
                        .add(4, 4, 4)
                        .add(lbTicket, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 560, Short.MAX_VALUE)))
                .add(2, 2, 2))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel1Layout.createSequentialGroup()
                .add(18, 18, 18)
                .add(jLabel1)
                .add(17, 17, 17)
                .add(lbTicket, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 99, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .add(1, 1, 1)
                .add(lbSala, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 90, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .add(30, 30, 30)
                .add(jButton1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 60, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
        );

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

        pack();
    }// </editor-fold>//GEN-END:initComponents
    private void formWindowActivated(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowActivated
       timerCierraAviso.start();
    }//GEN-LAST:event_formWindowActivated

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
       cerrarCon(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.JPanel jPanel1;
    private javax.swing.JLabel lbSala;
    private javax.swing.JLabel lbTicket;
    // End of variables declaration//GEN-END:variables
}
