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.
SIPRP/trunk/siprp/clientes/ContactoPanel.java

182 lines
4.8 KiB

/*
* ContactoPanel.java
*
* Created on 14 de Maio de 2004, 15:26
*/
package siprp.clientes;
import java.awt.*;
import javax.swing.*;
import java.util.*;
import com.evolute.utils.dataui.*;
import com.evolute.utils.ui.text.*;
import siprp.data.*;
/**
*
* @author fpalma
*/
public class ContactoPanel extends JPanel
implements ControllableComponent
{
private ContactoData contacto;
private ComponentsHashtable components;
private JTextField nomeText;
private JTextField cargoText;
private JTextField telefoneText;
private JTextField telemovelText;
private JTextField faxText;
private JTextField emailText;
/** Creates a new instance of ContactoPanel */
public ContactoPanel()
{
setupComponents();
setupComponentsHashtable();
}
private void setupComponents()
{
JLabel nomeLabel = new JLabel( "Nome" );
nomeText = new JTextField();
JLabel cargoLabel = new JLabel( "Cargo" );
cargoText = new JTextField();
JLabel telefoneLabel = new JLabel( "Telef." );
telefoneText = new JTextField();
JLabel telemovelLabel = new JLabel( "Tlm." );
telemovelText = new JTextField();
JLabel faxLabel = new JLabel( "Fax" );
faxText = new JTextField();
JLabel emailLabel = new JLabel( "Email" );
emailText = new JTextField();
GridBagLayout gridbag = new GridBagLayout();
setLayout( gridbag );
GridBagConstraints constraints = new GridBagConstraints();
constraints.insets = new Insets( 1, 1, 1, 1 );
constraints.fill = GridBagConstraints.HORIZONTAL;
constraints.gridheight = 1;
constraints.weighty = 0;
constraints.weightx = 0;
constraints.gridwidth = 1;
gridbag.setConstraints( nomeLabel, constraints );
add( nomeLabel );
constraints.weightx = 1;
constraints.gridwidth = GridBagConstraints.REMAINDER;
gridbag.setConstraints( nomeText, constraints );
add( nomeText );
constraints.weightx = 0;
constraints.gridwidth = 1;
gridbag.setConstraints( cargoLabel, constraints );
add( cargoLabel );
constraints.weightx = 1;
constraints.gridwidth = GridBagConstraints.REMAINDER;
gridbag.setConstraints( cargoText, constraints );
add( cargoText );
constraints.weightx = 0;
constraints.gridwidth = 1;
gridbag.setConstraints( telefoneLabel, constraints );
add( telefoneLabel );
constraints.weightx = .5;
constraints.gridwidth = 1;
gridbag.setConstraints( telefoneText, constraints );
add( telefoneText );
constraints.weightx = 0;
constraints.gridwidth = 1;
gridbag.setConstraints( telemovelLabel, constraints );
add( telemovelLabel );
constraints.weightx = .5;
constraints.gridwidth = GridBagConstraints.REMAINDER;
gridbag.setConstraints( telemovelText, constraints );
add( telemovelText );
constraints.weightx = 0;
constraints.gridwidth = 1;
gridbag.setConstraints( faxLabel, constraints );
add( faxLabel );
constraints.weightx = 1;
constraints.gridwidth = GridBagConstraints.REMAINDER;
gridbag.setConstraints( faxText, constraints );
add( faxText );
constraints.weightx = 0;
constraints.gridwidth = 1;
gridbag.setConstraints( emailLabel, constraints );
add( emailLabel );
constraints.weightx = 1;
constraints.gridwidth = GridBagConstraints.REMAINDER;
gridbag.setConstraints( emailText, constraints );
add( emailText );
new CopyPasteHandler( nomeText );
new CopyPasteHandler( cargoText );
new CopyPasteHandler( telefoneText );
new CopyPasteHandler( telemovelText );
new CopyPasteHandler( faxText );
new CopyPasteHandler( emailText );
}
private void setupComponentsHashtable()
{
components = new ComponentsHashtable();
components.putComponent( ContactoData.NOME, nomeText );
components.putComponent( ContactoData.CARGO, cargoText );
components.putComponent( ContactoData.TELEFONE, telefoneText );
components.putComponent( ContactoData.TELEMOVEL, telemovelText );
components.putComponent( ContactoData.FAX, faxText );
components.putComponent( ContactoData.EMAIL, emailText );
}
public void clear()
{
String names[] = (String[])components.keySet().toArray( new String[0] );
ComponentController.clear( names, components );
contacto = null;
}
public void fill(Object value)
{
clear();
contacto = ( ContactoData ) value;
if( contacto == null )
{
return;
}
String names[] = contacto.getFieldNames();
ComponentController.fill( names, contacto.getHashData(), components );
}
public Object save()
{
if( contacto == null )
{
contacto = new ContactoData();
}
String names[] = contacto.getFieldNames();
Hashtable hash = new Hashtable();
ComponentController.save( names, hash, components );
contacto.setHashData( hash );
return contacto;
}
public void setEnabled( boolean enable )
{
String names[] = (String[])components.keySet().toArray( new String[0] );
ComponentController.setEnabled( names, enable, components );
}
}