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/HistoricoEstabelecimentoPan...

273 lines
7.9 KiB

/*
* HistoricoEstabelecimentoPanel.java
*
* Created on 7 de Dezembro de 2004, 15:17
*/
package siprp.clientes;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import java.util.*;
import com.evolute.utils.*;
import com.evolute.utils.dataui.*;
import com.evolute.utils.toolbar.*;
import com.evolute.utils.tables.*;
import com.evolute.utils.ui.*;
import com.evolute.utils.ui.text.*;
import siprp.data.*;
/**
*
* @author fpalma
*/
public class HistoricoEstabelecimentoPanel extends JPanel
implements ControllableComponent, DocumentListener, ActionListener
{
protected static final String LIST_PANEL = "LIST_PANEL";
protected static final String FULL_LIST_PANEL = "FULL_LIST_PANEL";
protected static final String EDIT_PANEL = "EDIT_PANEL";
private ComponentsHashtable components;
private EstabelecimentoPanel owner;
private JCalendarPanel calendarPanel;
private JTextArea text;
private JButton saveButton;
private JButton cancelButton;
private EstabelecimentoData estabelecimento;
private boolean changed = false;
private boolean filling = false;
private HistoricoEstabelecimentoData historico;
public HistoricoEstabelecimentoPanel( EstabelecimentoPanel owner )
{
this.owner = owner;
setupComponents();
setupComponentsHashtable();
}
private void setupComponents()
{
calendarPanel = new JCalendarPanel( null );
// calendarPanel.addDocumentListener( this );
text = new JTextArea();
new CopyPasteHandler( text );
// text.getDocument().addDocumentListener( this );
text.setLineWrap( true );
text.setWrapStyleWord( true );
JScrollPane textScp = new JScrollPane( text, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
JScrollPane.HORIZONTAL_SCROLLBAR_NEVER );
saveButton = new JButton( "Guardar" );
saveButton.addActionListener( this );
cancelButton = new JButton( "Voltar" );
cancelButton.addActionListener( this );
GridBagLayout gridbag = new GridBagLayout();
setLayout( gridbag );
GridBagConstraints constraints = new GridBagConstraints();
constraints.insets = new Insets( 1, 1, 1, 1 );
constraints.fill = GridBagConstraints.HORIZONTAL;
constraints.weightx = 0;
constraints.gridwidth = 1;
constraints.weighty = 0;
constraints.gridheight = 1;
calendarPanel.setPreferredSize( new Dimension( 130, 30 ) );
gridbag.setConstraints( calendarPanel, constraints );
add( calendarPanel );
constraints.weightx = 1;
constraints.gridwidth = GridBagConstraints.REMAINDER;
JPanel buttonPanel = new JPanel();
gridbag.setConstraints( buttonPanel, constraints );
add( buttonPanel );
constraints.fill = GridBagConstraints.BOTH;
constraints.weighty = 1;
constraints.gridheight = GridBagConstraints.REMAINDER;
constraints.gridwidth = GridBagConstraints.REMAINDER;
constraints.weightx = 1;
gridbag.setConstraints( textScp, constraints );
add( textScp );
buttonPanel.setLayout( new FlowLayout( FlowLayout.RIGHT ) );
initButtons();
buttonPanel.add( cancelButton );
buttonPanel.add( saveButton );
}
private void setupComponentsHashtable()
{
components = new ComponentsHashtable();
components.putComponent( HistoricoEstabelecimentoData.DATA, calendarPanel );
components.putComponent( HistoricoEstabelecimentoData.TEXTO, text );
components.putDummy( HistoricoEstabelecimentoData.ESTABELECIMENTO );
}
public void clear()
{
String names[] = (String[])components.keySet().toArray( new String[0] );
ComponentController.clear( names, components );
historico = null;
}
public void fill(Object value)
{
filling = true;
clear();
initButtons();
historico = (HistoricoEstabelecimentoData)value;
if( historico == null )
{
filling = false;
return;
}
String names[] = historico.getFieldNames();
ComponentController.fill( names, historico.getHashData(), components );
filling = false;
}
public Object save()
{
if( historico == null )
{
historico = new HistoricoEstabelecimentoData();
}
String names[] = historico.getFieldNames();
Hashtable hash = new Hashtable();
ComponentController.save( names, hash, components );
hash.put( HistoricoEstabelecimentoData.ESTABELECIMENTO, estabelecimento );
historico.setHashData( hash );
return historico;
}
public void setEnabled(boolean enable)
{
super.setEnabled( enable );
String names[] = (String[])components.keySet().toArray( new String[0] );
ComponentController.setEnabled( names, enable, components );
}
public void changedUpdate(javax.swing.event.DocumentEvent documentEvent)
{
startEditedState();
}
public void insertUpdate(javax.swing.event.DocumentEvent documentEvent)
{
startEditedState();
}
public void removeUpdate(javax.swing.event.DocumentEvent documentEvent)
{
startEditedState();
}
private void startEditedState()
{
if( !filling )
{
calendarPanel.removeDocumentListener( this );
text.getDocument().removeDocumentListener( this );
changed = true;
saveButton.setEnabled( true );
changeButton();
}
}
private void initButtons()
{
saveButton.setEnabled( false );
calendarPanel.addDocumentListener( this );
text.getDocument().addDocumentListener( this );
ClassLoader cl = new EVUtilsImageLib().getClass().getClassLoader();
Icon normal = new ImageIcon( cl.getResource( "buttons/save_normal.gif" ) );
Icon rollover = new ImageIcon( cl.getResource( "buttons/save_rollover.gif" ) );
Icon pressed = new ImageIcon( cl.getResource( "buttons/save_pressed.gif" ) );
Icon disabled = new ImageIcon( cl.getResource( "buttons/save_disabled.gif" ) );
saveButton.setIcon( normal );
saveButton.setRolloverIcon( rollover );
saveButton.setPressedIcon( pressed );
saveButton.setDisabledIcon( disabled );
saveButton.setText( null );
saveButton.setBorderPainted( false );
saveButton.setRequestFocusEnabled( false );
saveButton.setMargin( new Insets( 0, 0, 0, 0 ) );
saveButton.setToolTipText( "Gravar" );
normal = new ImageIcon( cl.getResource( "buttons/shiftl_normal.gif" ) );
rollover = new ImageIcon( cl.getResource( "buttons/shiftl_rollover.gif" ) );
pressed = new ImageIcon( cl.getResource( "buttons/shiftl_pressed.gif" ) );
disabled = new ImageIcon( cl.getResource( "buttons/shiftl_disabled.gif" ) );
cancelButton.setIcon( normal );
cancelButton.setRolloverIcon( rollover );
cancelButton.setPressedIcon( pressed );
cancelButton.setDisabledIcon( disabled );
cancelButton.setText( null );
cancelButton.setBorderPainted( false );
cancelButton.setRequestFocusEnabled( false );
cancelButton.setMargin( new Insets( 0, 0, 0, 0 ) );
cancelButton.setToolTipText( "Voltar \u00e0 lista" );
}
private void changeButton()
{
ClassLoader cl = new EVUtilsImageLib().getClass().getClassLoader();
Icon normal = new ImageIcon( cl.getResource( "buttons/cancel_normal.gif" ) );
Icon rollover = new ImageIcon( cl.getResource( "buttons/cancel_rollover.gif" ) );
Icon pressed = new ImageIcon( cl.getResource( "buttons/cancel_pressed.gif" ) );
Icon disabled = new ImageIcon( cl.getResource( "buttons/cancel_disabled.gif" ) );
cancelButton.setIcon( normal );
cancelButton.setRolloverIcon( rollover );
cancelButton.setPressedIcon( pressed );
cancelButton.setDisabledIcon( disabled );
cancelButton.setToolTipText( "Cancelar" );
}
public void actionPerformed( ActionEvent e )
{
Object source = e.getSource();
if( source.equals( saveButton ) )
{
if( calendarPanel.getDate() == null )
{
JOptionPane.showMessageDialog( this, "Tem de escolher uma data", "Erro...", JOptionPane.ERROR_MESSAGE );
return;
}
HistoricoEstabelecimentoData hist = ( HistoricoEstabelecimentoData ) save();
try
{
hist.save();
}
catch( Exception ex )
{
DialogException.showExceptionMessage( ex, "Erro a gravar", true );
return;
}
owner.reloadHistorico();
}
else if( source.equals( cancelButton ) )
{
owner.showHistorico();
}
}
public void setEstabelecimento( EstabelecimentoData estabelecimento )
{
this.estabelecimento = estabelecimento;
}
}