package com.tarisan.chipcard.tpvvs.webservicetrayicon; import javax.swing.JDialog; import com.tarisan.chipcard.gui.*; import javax.swing.*; import java.util.*; import java.awt.*; import java.awt.event.*; /** * @author jjrider * * To change the template for this generated type comment go to * Window>Preferences>Java>Code Generation>Code and Comments */ public class AutomaticCloseDialog extends JDialog implements ActionListener,Runnable { private int intNumeroSegundos=5; private Thread objThread=null; private Window objWindow=this; private ActionListener externActionListener=null; private int intTypeOfMessage=-1; JPanel pnl=new JPanel(); public AutomaticCloseDialog(String strTitle,String strMensaje,int intNumeroSegundos){ this(strTitle,strMensaje,intNumeroSegundos,null); } public AutomaticCloseDialog(String strTitle,String strMensaje,int intNumeroSegundos,JFrame parentFrame){ this(strTitle,strMensaje,intNumeroSegundos,parentFrame,JOptionPane.INFORMATION_MESSAGE); } public AutomaticCloseDialog(String strTitle,String strMensaje,int intNumeroSegundos,JFrame parentFrame, int intTypeOfMessage){ this(strTitle,strMensaje,intNumeroSegundos,parentFrame,intTypeOfMessage,true); } public AutomaticCloseDialog(String strTitle,String strMensaje,int intNumeroSegundos,JFrame parentFrame, int intTypeOfMessage,ActionListener listener){ this(strTitle,strMensaje,intNumeroSegundos,parentFrame,intTypeOfMessage,true,listener); } public AutomaticCloseDialog(String strTitle,String strMensaje,int intNumeroSegundos,JFrame parentFrame, int intTypeOfMessage, boolean blnModal){ this(strTitle, strMensaje, intNumeroSegundos, parentFrame, intTypeOfMessage, blnModal,null); } public AutomaticCloseDialog(String strTitle,String strMensaje,int intNumeroSegundos,JFrame parentFrame, int intTypeOfMessage, boolean blnModal,ActionListener listener){ super(parentFrame); setUndecorated(false); this.setModal(true); this.intNumeroSegundos=intNumeroSegundos; this.intTypeOfMessage=intTypeOfMessage; setTitle(strTitle); setContentPane(pnl); getContentPane().setLayout(new GridBagLayout()); int columna=0; int fila=0; externActionListener=listener; //getContentPane().setLayout(new BorderLayout()); JPanel panel=new JPanel(); panel.setLayout(new BorderLayout()); //Un tamaņo por defecto... setSize(300,200); JLabel label=null; Icon icon=getIconForType(intTypeOfMessage); if(icon!=null){ label=new JLabel(icon); label.setBounds(10,40,20,20); getContentPane().add(label, new java.awt.GridBagConstraints(columna,fila,1,1,1.0,1.0,java.awt.GridBagConstraints.WEST,java.awt.GridBagConstraints.NONE,new Insets(10,10,10,10),0,0)); columna++; } JPanel panelLabels=new JPanel(); panelLabels.setLayout(new GridBagLayout()); StringTokenizer st=new StringTokenizer(strMensaje,"\n"); int intNumLabels=0; while(st.hasMoreTokens()) { intNumLabels++; label=new JLabel(st.nextToken()); panelLabels.add(label, new java.awt.GridBagConstraints(0,intNumLabels,1,1,1.0,1.0,java.awt.GridBagConstraints.WEST,java.awt.GridBagConstraints.NONE,new Insets(00,00,00,00),0,0)); } //label.setBounds(40,40,300,20); //panel.add(label,BorderLayout.CENTER); getContentPane().add(panelLabels, new java.awt.GridBagConstraints(columna,fila,1,1,1.0,1.0,java.awt.GridBagConstraints.WEST,java.awt.GridBagConstraints.HORIZONTAL,new Insets(10,10,10,10),0,0)); columna=0; fila++; /*panelTemp=new JPanel(); getContentPane().add(panelTemp, new java.awt.GridBagConstraints(columna,fila,1,1,1.0,1.0,java.awt.GridBagConstraints.WEST,java.awt.GridBagConstraints.BOTH,new Insets(0,0,0,0),0,0)); fila++;*/ String strOKText="Aceptar"; if(intTypeOfMessage==JOptionPane.QUESTION_MESSAGE) strOKText="Si"; JButton btnAceptar=new JButton(strOKText); btnAceptar.setActionCommand("Aceptar"); btnAceptar.addActionListener(this); btnAceptar.setPreferredSize(new Dimension(90,20)); btnAceptar.setMaximumSize(new Dimension(90,20)); if(externActionListener==null){ getContentPane().add(btnAceptar, new java.awt.GridBagConstraints(columna,fila,2,1,1.0,1.0,java.awt.GridBagConstraints.CENTER,java.awt.GridBagConstraints.NONE,new Insets(10,0,10,0),0,0)); }else{ JPanel panelButtons=new JPanel(); panelButtons.setLayout(new FlowLayout()); panelButtons.add(btnAceptar); String strCancelText="Cancelar"; if(intTypeOfMessage==JOptionPane.QUESTION_MESSAGE) strCancelText="No"; JButton btnCancelar=new JButton(strCancelText); btnCancelar.setActionCommand("Cancelar"); btnCancelar.addActionListener(this); btnCancelar.setPreferredSize(new Dimension(90,20)); btnCancelar.setMaximumSize(new Dimension(90,20)); panelButtons.add(btnCancelar); getContentPane().add(panelButtons, new java.awt.GridBagConstraints(columna,fila,2,1,1.0,1.0,java.awt.GridBagConstraints.CENTER,java.awt.GridBagConstraints.NONE,new Insets(10,0,10,0),0,0)); if(this.intNumeroSegundos<30) this.intNumeroSegundos=30; } validate(); pack(); centerOn(objWindow,parentFrame); if(this.intNumeroSegundos>0){ objThread=new Thread(this); objThread.start(); } objWindow.show(); objWindow.requestFocus(); objWindow.toFront(); } public void actionPerformed(ActionEvent e){ objWindow.hide(); try{objThread.stop();}catch(Exception err){} if(externActionListener!=null){ externActionListener.actionPerformed(e); } } public static void centerOn(Window dialog,JFrame frame){ if(dialog==null) return; Dimension dimFrame=null; if(frame==null) UtilGUI.centerOnScreen(dialog); else UtilGUI.centerOnWindow(dialog,frame); } public void run(){ if(intNumeroSegundos>0){ try{ while(!objWindow.isShowing()){ objThread.sleep(100); } for(int i=0;i