package com.tarisan.chipcard.tpvvs.webservicetrayicon; import java.awt.*; import java.awt.event.*; import javax.swing.*; import com.tarisan.chipcard.gui.*; import com.tarisan.chipcard.tpvvs.webservicetrayicon.accesodatos.*; /** * @author jjrider */ public class DialogoTarjetaSanitaria extends JDialog { /** * */ private static final long serialVersionUID = -6280299266737876697L; private JFrame objParent=null; private JPasswordField txtLecturaPistaTarjeta=new JPasswordField(); private boolean LecturaManual=false; private JLabel lblNumeroTarjeta=new JLabel("Tarjeta:"); private JTextField txtNumeroTarjeta=new JTextField(); private JLabel lblCaducidadTarjeta=new JLabel("F.Cad.:"); private JTextField txtCaducidadTarjeta=new JTextField(); private JLabel lblAltaTarjeta=new JLabel("F.Alta:"); private JTextField txtAltaTarjeta=new JTextField(); private JLabel lblCoberturaTarjeta=new JLabel("Cobertura:"); private JTextField txtCoberturaTarjeta=new JTextField(); private JLabel lblVersionTarjeta=new JLabel("Version:"); private JTextField txtVersionTarjeta=new JTextField(); private JCheckBox NoCapturaTarjeta=new JCheckBox("No Capturar Tarjeta"); private JButton jbtnAceptar=new JButton(); private Paciente paciente=new Paciente(); public DialogoTarjetaSanitaria(JFrame objParent){ super(objParent,true); this.setUndecorated(true); this.objParent=objParent; setTitle("Lectura de Tarjeta"); init(); } private void init(){ getContentPane().setLayout(new BorderLayout()); JPanel pn=new JPanel(); getContentPane().add(pn,BorderLayout.CENTER); JLabel lblFondo=new JLabel(); ImageIcon iconFondo= new ImageIcon(WebServiceTrayIcon.loadImage("paseTarjetaConTeclado.jpg")); lblFondo.setIcon(iconFondo); lblFondo.setBounds(0,0,iconFondo.getIconWidth(),iconFondo.getIconHeight()); pn.setLayout(null); NoCapturaTarjeta.setBounds(5,135,180,20); pn.add(NoCapturaTarjeta); NoCapturaTarjeta.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent evt){ setVisible(false); dispose(); } } ); txtLecturaPistaTarjeta.setBounds(5,160,180,20); pn.add(txtLecturaPistaTarjeta); txtLecturaPistaTarjeta.requestFocus(); //txtLecturaPistaTarjeta.requestDefaultFocus(); lblNumeroTarjeta.setBounds(2,50,45,20); pn.add(lblNumeroTarjeta); txtNumeroTarjeta.setBounds(lblNumeroTarjeta.getX()+lblNumeroTarjeta.getWidth()+3,lblNumeroTarjeta.getY(),140,20); pn.add(txtNumeroTarjeta); lblCaducidadTarjeta.setBounds(2,75,40,20); pn.add(lblCaducidadTarjeta); txtCaducidadTarjeta.setBounds(lblCaducidadTarjeta.getX()+lblCaducidadTarjeta.getWidth()+3,lblCaducidadTarjeta.getY(),50,20); pn.add(txtCaducidadTarjeta); lblAltaTarjeta.setBounds(txtCaducidadTarjeta.getX()+txtCaducidadTarjeta.getWidth()+15,lblCaducidadTarjeta.getY(),40,20); pn.add(lblAltaTarjeta); txtAltaTarjeta.setBounds(lblAltaTarjeta.getX()+lblAltaTarjeta.getWidth()+3,lblCaducidadTarjeta.getY(),50,20); pn.add(txtAltaTarjeta); lblCoberturaTarjeta.setBounds(2,100,80,20); pn.add(lblCoberturaTarjeta); txtCoberturaTarjeta.setBounds(lblCoberturaTarjeta.getX()+lblCoberturaTarjeta.getWidth()+3,lblCoberturaTarjeta.getY(),40,20); pn.add(txtCoberturaTarjeta); lblVersionTarjeta.setBounds(txtCoberturaTarjeta.getX()+txtCoberturaTarjeta.getWidth()+15,txtCoberturaTarjeta.getY(),60,20); pn.add(lblVersionTarjeta); txtVersionTarjeta.setBounds(lblVersionTarjeta.getX()+lblVersionTarjeta.getWidth()+5,lblVersionTarjeta.getY(),35,20); pn.add(txtVersionTarjeta); ImageIcon iconAceptar= new ImageIcon(WebServiceTrayIcon.loadImage("aceptaro1.gif")); jbtnAceptar.setIcon(iconAceptar); jbtnAceptar.setBounds(40,140,iconAceptar.getIconWidth(),iconAceptar.getIconHeight()); jbtnAceptar.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent evt){ String sTarjeta=txtNumeroTarjeta.getText().trim(); if(sTarjeta.length()>0) paciente.setTarjeta(sTarjeta); String sAlta=txtAltaTarjeta.getText().trim(); if(sAlta.length()>0) paciente.setFAlta(sAlta); String sBaja=txtCaducidadTarjeta.getText().trim(); if(sBaja.length()>0) paciente.setFBaja(sBaja); String sCobertura=txtCoberturaTarjeta.getText().trim(); if(sCobertura.length()>0) paciente.setCobertura(sCobertura); String sVersion=txtVersionTarjeta.getText().trim(); if(sVersion.length()>0) paciente.setVersion(sVersion); setVisible(false); dispose(); } }); pn.add(jbtnAceptar); pn.add(lblFondo); setSize(209,191); UtilGUI.centerOnWindow(this,objParent ); showLecturaBanda(); txtLecturaPistaTarjeta.requestFocus(); lblFondo.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent evt) { //System.out.println("Mouse clicked"); setTipoLectura(!LecturaManual); } }); LecturaPistaThread th=new LecturaPistaThread(this); th.start(); show(); } private void showLecturaBanda(){ setTipoLectura(false); } private void showLecturaManual(){ setTipoLectura(true); } private void setTipoLectura(boolean LectManual){ LecturaManual=LectManual; txtNumeroTarjeta.setVisible(LecturaManual); txtCaducidadTarjeta.setVisible(LecturaManual); txtAltaTarjeta.setVisible(LecturaManual); txtCoberturaTarjeta.setVisible(LecturaManual); txtVersionTarjeta.setVisible(LecturaManual); lblNumeroTarjeta.setVisible(LecturaManual); lblCaducidadTarjeta.setVisible(LecturaManual); lblAltaTarjeta.setVisible(LecturaManual); lblCoberturaTarjeta.setVisible(LecturaManual); lblVersionTarjeta.setVisible(LecturaManual); jbtnAceptar.setVisible(LecturaManual); txtLecturaPistaTarjeta.setVisible(!LecturaManual); if(!LecturaManual){ txtLecturaPistaTarjeta.requestFocus(); txtNumeroTarjeta.setText(""); txtCaducidadTarjeta.setText(""); txtAltaTarjeta.setText(""); txtCoberturaTarjeta.setText(""); txtVersionTarjeta.setText(""); }else{ txtLecturaPistaTarjeta.setText(""); txtNumeroTarjeta.requestFocus(); } } public boolean esLecturaManual(){ return LecturaManual; } public Paciente getPaciente(){ return paciente; } public class LecturaPistaThread extends Thread{ private JDialog dialog=null; protected LecturaPistaThread(JDialog dialog){ this.dialog=dialog; } public void run(){ txtLecturaPistaTarjeta.requestFocus(); try{ Thread.sleep(2000); }catch(Exception err){} while(dialog.isVisible()){ if(!esLecturaManual()){ txtLecturaPistaTarjeta.requestFocus(); } try{ try{ Thread.sleep(200); }catch(Exception err){} String sPista=new String(txtLecturaPistaTarjeta.getPassword()); sPista=sPista.trim(); if(sPista.endsWith("?")){ try{ Thread.sleep(200); }catch(Exception err){} String sPistaConfirmation=new String(txtLecturaPistaTarjeta.getPassword()); sPistaConfirmation=sPistaConfirmation.trim(); if(sPistaConfirmation.equals(sPista)){ paciente.setPista(sPista); setVisible(false); } } }catch(Exception err){ } } System.out.println("Fin del hilo"); } } }