forked from Coded/SIPRP
				
			
			You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
				
					
					
						
							174 lines
						
					
					
						
							4.6 KiB
						
					
					
				
			
		
		
	
	
							174 lines
						
					
					
						
							4.6 KiB
						
					
					
				| /*
 | |
|  * EscolherMotivoDialog.java
 | |
|  *
 | |
|  * Created on 13 de Maio de 2007, 22:16
 | |
|  *
 | |
|  * To change this template, choose Tools | Template Manager
 | |
|  * and open the template in the editor.
 | |
|  */
 | |
| 
 | |
| package siprp.medicina.processo;
 | |
| 
 | |
| import com.evolute.utils.data.IDObject;
 | |
| import com.evolute.utils.data.MappableObject;
 | |
| import com.evolute.utils.ui.CustomJDialog;
 | |
| import java.awt.Dimension;
 | |
| import java.awt.FlowLayout;
 | |
| 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.JPanel;
 | |
| import javax.swing.SwingUtilities;
 | |
| 
 | |
| /**
 | |
|  *
 | |
|  * @author Frederico
 | |
|  */
 | |
| public class EscolherMotivoDialog extends CustomJDialog
 | |
| 	implements ActionListener
 | |
| {
 | |
| 	protected IDObject MOTIVOS[] = 
 | |
| 		new IDObject[]{
 | |
| 			new MappableObject( new Integer( 1 ), "Admiss\u00e3o" ), 
 | |
| 			new MappableObject( new Integer( 2 ), "Peri\u00f3dico" ),
 | |
| 			new MappableObject( new Integer( 5 ), "Peri\u00f3dico inicial" ),
 | |
| 			new MappableObject( new Integer( 3 ), "Ocasional" )
 | |
| 	};
 | |
| 
 | |
| 	protected IDObject SUB_MOTIVOS[][] = 
 | |
| 		new IDObject[][]{
 | |
| 			{},
 | |
| 			{},
 | |
| 			{},
 | |
| 			{ new MappableObject( new Integer( 1 ), "Ap\u00f3s doen\u00e7a" ), 
 | |
| 				new MappableObject( new Integer( 2 ), "Ap\u00f3s acidente" ),
 | |
| 				new MappableObject( new Integer( 3 ), "A pedido do trabalhador" ), 
 | |
| 				new MappableObject( new Integer( 4 ), "A pedido do servi\u00e7o" ),
 | |
| 				new MappableObject( new Integer( 5 ), "Por mudan\u00e7a de fun\u00e7\u00e3o" ),
 | |
| 				new MappableObject( new Integer( 6 ), "Por altera\u00e7\u00e3o das condi\u00e7\u00f5es de trabalho" ),
 | |
| 				new MappableObject( new Integer( 10 ), "Outro" )
 | |
| 			}
 | |
| 	};
 | |
| 	
 | |
| 	protected JButton motivoButtons[];
 | |
| 	protected HashMap<JButton,JButton[]> subMotivoButtons;
 | |
| 	protected HashMap<JButton,Integer> motivoButtonIDs;
 | |
| 	protected HashMap<JButton,Integer> subMotivoButtonIDs;
 | |
| 	protected JPanel motivoPanel;
 | |
| 	protected JPanel subMotivoPanel;
 | |
| 	
 | |
| 	protected Integer motivo;
 | |
| 	protected Integer subMotivo;
 | |
| 	
 | |
| 	/** Creates a new instance of EscolherMotivoDialog */
 | |
| 	public EscolherMotivoDialog( JFrame owner )
 | |
| 	{
 | |
| 		super( owner, true );
 | |
| 		setupComponents();
 | |
| 		
 | |
| 		if( owner != null )
 | |
| 		{
 | |
| 			centerSuper();
 | |
| 		}
 | |
| 		else
 | |
| 		{
 | |
| 			center();
 | |
| 		}
 | |
| 	}
 | |
| 	
 | |
| 	private void setupComponents()
 | |
| 	{
 | |
| 		setTitle( "Escolher Motivo" );
 | |
| 		setLayout( new FlowLayout( FlowLayout.LEFT ) );
 | |
| 		motivoButtons = new JButton[ MOTIVOS.length ];
 | |
| 		subMotivoButtons = new HashMap<JButton,JButton[]>();
 | |
| 		motivoButtonIDs = new HashMap<JButton,Integer>();
 | |
| 		subMotivoButtonIDs = new HashMap<JButton,Integer>();
 | |
| 		for( int m = 0; m < MOTIVOS.length; m++ )
 | |
| 		{
 | |
| 			JButton motivoButton = new JButton( MOTIVOS[ m ].toString() );
 | |
| 			motivoButton.addActionListener( this );
 | |
| 			motivoButtonIDs.put( motivoButton, MOTIVOS[ m ].getID() );
 | |
| 			motivoButton.setPreferredSize( new Dimension( 250, 20 ) );
 | |
| 			motivoButtons[ m ] = motivoButton;
 | |
| 			if( SUB_MOTIVOS[ m ].length > 0 )
 | |
| 			{
 | |
| 				JButton subButtons[] = new JButton[ SUB_MOTIVOS[ m ].length ];
 | |
| 				for( int sm = 0; sm < SUB_MOTIVOS[ m ].length; sm++ )
 | |
| 				{
 | |
| 					JButton subButton = new JButton( SUB_MOTIVOS[ m ][ sm ].toString() );
 | |
| 					subMotivoButtonIDs.put( subButton, SUB_MOTIVOS[ m ][ sm ].getID() );
 | |
| 					subButtons[ sm ] = subButton;
 | |
| 					subButton.setPreferredSize( new Dimension( 300, 20 ) );
 | |
| 					subButton.addActionListener( this );
 | |
| 				}
 | |
| 				subMotivoButtons.put( motivoButton, subButtons );
 | |
| 			}
 | |
| 			else
 | |
| 			{
 | |
| 				subMotivoButtons.put( motivoButton, null );
 | |
| 			}
 | |
| 		}
 | |
| 		motivoPanel = new JPanel();
 | |
| 		subMotivoPanel = new JPanel();
 | |
| 		
 | |
| 		motivoPanel.setLayout( new GridLayout( motivoButtons.length + 1, 1 ) );
 | |
| 		for( int n = 0; n < motivoButtons.length; n++ )
 | |
| 		{
 | |
| 			motivoPanel.add( motivoButtons[ n ] );
 | |
| 		}
 | |
| 		
 | |
| 		add( motivoPanel );
 | |
| 		add( subMotivoPanel );
 | |
| 		
 | |
| 		pack();
 | |
| 	}
 | |
| 
 | |
| 	public void actionPerformed(ActionEvent e)
 | |
| 	{
 | |
| 		JButton source = ( JButton ) e.getSource();
 | |
| 		if( motivoButtonIDs.containsKey( source ) )
 | |
| 		{
 | |
| 			motivo = motivoButtonIDs.get( source );
 | |
| 		}
 | |
| 		else if( subMotivoButtonIDs.containsKey( source ) )
 | |
| 		{
 | |
| 			subMotivo = subMotivoButtonIDs.get( source );
 | |
| 			close();
 | |
| 		}
 | |
| 		if( subMotivoButtons.containsKey( source ) )
 | |
| 		{
 | |
| 			JButton subButtons[] = subMotivoButtons.get( source );
 | |
| 			if( subButtons == null || subButtons.length == 0 )
 | |
| 			{
 | |
| 				close();
 | |
| 			}
 | |
| 			else
 | |
| 			{
 | |
| 				subMotivoPanel.removeAll();
 | |
| 				subMotivoPanel.setLayout( new GridLayout( 0, 1 ) );
 | |
| 				for( int n = 0; n < subButtons.length; n++ )
 | |
| 				{
 | |
| 					subMotivoPanel.add( subButtons[ n ] );
 | |
| 				}
 | |
| 				pack();
 | |
| 			}
 | |
| 		}
 | |
| 	}
 | |
| 	
 | |
| 	protected void close()
 | |
| 	{
 | |
| 		SwingUtilities.invokeLater( new Runnable(){
 | |
| 			public void run()
 | |
| 			{
 | |
| 				setVisible( false );
 | |
| 				dispose();
 | |
| 			}
 | |
| 		} );
 | |
| 	}
 | |
| 	
 | |
| }
 |