/* * EstadoChooser.java * * Created on 13 de Maio de 2007, 11:54 * * To change this template, choose Tools | Template Manager * and open the template in the editor. */ package siprp.medicina.processo.detalhes; import com.evolute.utils.ui.CustomJDialog; import java.awt.Color; import java.awt.GridLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.util.HashMap; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.SwingUtilities; import siprp.medicina.MedicinaConstants; /** * * @author Frederico */ public class EstadoChooser extends CustomJDialog implements MedicinaConstants, ActionListener { protected int tipo; protected int estado; protected HashMap buttonMap = new HashMap(); /** Creates a new instance of EstadoChooser */ public EstadoChooser( JFrame owner, int tipo, int estadoActual ) { super( owner, true ); this.tipo = tipo; estado = estadoActual; setupComponents(); if( owner != null ) { centerSuper(); } else { center(); } } private void setupComponents() { setTitle( "Escolha o novo estado" ); setLayout( new GridLayout( ESTADOS_STR[ tipo ].length, 1 ) ); for( int n = 0; n < ESTADOS_STR[ tipo ].length; n++ ) { if( ESTADOS_STR[ tipo ][ n ] == null ) { continue; } JButton button = new JButton( ESTADOS_STR[ tipo ][ n ] ); if( n == estado ) { button.setForeground( Color.green ); } buttonMap.put( button, new Integer( n ) ); add( button ); button.addActionListener( this ); } pack(); } public void actionPerformed( ActionEvent e ) { JButton source = ( JButton ) e.getSource(); estado = buttonMap.get( source ).intValue(); close(); } public void close() { SwingUtilities.invokeLater( new Runnable(){ public void run() { setVisible( false ); dispose(); } } ); } public int getEstado() { return estado; } }