/* 
* 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 final class DlgMensajeGenerico extends javax.swing.JDialog implements ISmartCardAvisable {

   public javax.swing.Timer timerCierraAviso;

   public DlgMensajeGenerico(javax.swing.JFrame parent) {
      super(parent, true);
      initComponents();
      setLocationRelativeTo(parent);
      BotonSi.setText(Global.trad.valor("Aceptar"));
      setLineas("","","");
      getRootPane().setDefaultButton(BotonSi);
      preparaTimerAviso();
      timerCierraAviso.start();
   }
  
   public void setLinea1(String texto) {
      jLinea0.setText(texto);
   }

   public void setLinea2(String texto) {
      jLinea1.setText(texto);
   }

   public void setLinea3(String texto) {
      jLinea2.setText(texto);
   }

   public void centrarLineas(boolean l1, boolean l2, boolean l3) {
      if(l1) jLinea1.setHorizontalAlignment(javax.swing.JLabel.CENTER);
      if(l2) jLinea2.setHorizontalAlignment(javax.swing.JLabel.CENTER);
      if(l3) jLinea2.setHorizontalAlignment(javax.swing.JLabel.CENTER);      
   }
   
   public void setLineas(String s1, String s2, String s3) {
      jLinea0.setText(s1);
      jLinea1.setText(s2);
      jLinea2.setText(s3);
   }

   @Override
   public void avisoSmartCardInsertada(String nif, String nombre) {
   }

   @Override
   public void avisoSmartCardExtraida() {
      cerrar();
   }
   
   void cerrar() {
      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) {
            cerrar();
         }
      });
   }

   void mostrar() {
      if(jLinea2.getText().equals("")) {
         this.setSize(this.getWidth(), this.getHeight() - 40);
      }
   }
   /** 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();
        jLinea0 = new gestor.utiles.SmoothLabel();
        jLinea1 = new gestor.utiles.SmoothLabel();
        jLinea2 = new gestor.utiles.SmoothLabel();
        BotonSi = new gestor.utiles.MiBoton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setBackground(java.awt.Color.white);
        setModal(true);
        setResizable(false);
        setUndecorated(true);
        addComponentListener(new java.awt.event.ComponentAdapter() {
            public void componentShown(java.awt.event.ComponentEvent evt) {
                formComponentShown(evt);
            }
        });

        jPanel1.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(180, 180, 180), 4));

        jLinea0.setFont(new java.awt.Font("MS Sans Serif", 1, 30));
        jLinea0.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLinea0.setText("l1");

        jLinea1.setFont(new java.awt.Font("MS Sans Serif", 0, 25));
        jLinea1.setText("l2");

        jLinea2.setFont(new java.awt.Font("MS Sans Serif", 0, 25));
        jLinea2.setText("l3");

        BotonSi.setFont(new java.awt.Font("MS Sans Serif", 0, 25));
        BotonSi.setText("Aceptar");
        BotonSi.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BotonSiActionPerformed(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.LEADING)
                    .add(jPanel1Layout.createSequentialGroup()
                        .addContainerGap()
                        .add(jLinea0, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 679, Short.MAX_VALUE))
                    .add(jPanel1Layout.createSequentialGroup()
                        .add(175, 175, 175)
                        .add(BotonSi, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 276, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                    .add(jPanel1Layout.createSequentialGroup()
                        .addContainerGap()
                        .add(jLinea1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 679, Short.MAX_VALUE))
                    .add(jPanel1Layout.createSequentialGroup()
                        .addContainerGap()
                        .add(jLinea2, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 679, Short.MAX_VALUE)))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .add(jLinea0)
                .add(33, 33, 33)
                .add(jLinea1)
                .add(21, 21, 21)
                .add(jLinea2)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 62, Short.MAX_VALUE)
                .add(BotonSi, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 61, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .add(25, 25, 25))
        );

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

        pack();
    }// </editor-fold>//GEN-END:initComponents
    private void BotonSiActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BotonSiActionPerformed
       cerrar();
    }//GEN-LAST:event_BotonSiActionPerformed

    private void formComponentShown(java.awt.event.ComponentEvent evt) {//GEN-FIRST:event_formComponentShown
      mostrar();
    }//GEN-LAST:event_formComponentShown

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton BotonSi;
    private javax.swing.JLabel jLinea0;
    private javax.swing.JLabel jLinea1;
    private javax.swing.JLabel jLinea2;
    private javax.swing.JPanel jPanel1;
    // End of variables declaration//GEN-END:variables

}
