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.

102 lines
2.7 KiB

/*
* DiaPanel.java
*
* Created on February 1, 2006, 6:42 PM
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
package siprp.higiene.mapa;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import com.evolute.utils.dataui.*;
/**
*
* @author fpalma
*/
public class DiaPanel extends JPanel
implements ControllableComponent, ActionListener
{
protected Object data[][];
protected JButton buttons[];
/** Creates a new instance of DiaPanel */
public DiaPanel()
{
}
private void setupComponents()
{
}
public void setEnabled( boolean enable )
{
}
public void fill( Object value )
{
removeAll();
Object arr[][] = ( Object[][] ) value;
data = arr;
buttons = new JButton[ arr.length ];
if( arr.length > 0 )
{
GridBagLayout gridbag = new GridBagLayout();
setLayout( gridbag );
GridBagConstraints constraints = new GridBagConstraints();
constraints.insets = new Insets( 0, 0, 0, 0 );
constraints.fill = GridBagConstraints.BOTH;
constraints.weightx = 1;
constraints.gridwidth = GridBagConstraints.REMAINDER;
constraints.weighty = 0;
constraints.gridheight = 1;
Integer dia = ( Integer ) arr[ 0 ][ 0 ];
JLabel diaLabel = new JLabel( dia.toString(), JLabel.LEFT );
gridbag.setConstraints( diaLabel, constraints );
add( diaLabel );
for( int n = 1; n < arr.length; n++ )
{
String empresa = ( String ) arr[ n ][ 0 ];
String estabelecimento = ( String ) arr[ n ][ 1 ];
String tecnico = ( String ) arr[ n ][ 2 ];
Color cor = ( Color ) arr[ n ][ 3 ];
String empresaR = empresa.length() > 10 ? empresa.substring( 0, 10 ) : empresa;
String estabelecimentoR = estabelecimento.length() > 10 ? estabelecimento.substring( 0, 10 ) : estabelecimento;
buttons[ n ] = new JButton( "<html><FONT SIZE=\"-2\">" + empresaR + "<br>" + estabelecimentoR + "</FONT></html>" );
buttons[ n ].setMargin( new Insets( 2, 1, 2, 1 ) );
buttons[ n ].setBackground( cor );
buttons[ n ].setToolTipText( "T\u00e9cnico: " + ( tecnico != null ? tecnico : "n.d." )
+ " \nEmpresa: " + empresa + " \nEstabelecimento: " + estabelecimento );
gridbag.setConstraints( buttons[ n ], constraints );
add( buttons[ n ] );
buttons[ n ].addActionListener( this );
}
JPanel pad = new JPanel();
constraints.weighty = 1;
constraints.gridheight = GridBagConstraints.REMAINDER;
gridbag.setConstraints( pad, constraints );
add( pad );
}
}
public Object save()
{
return data;
}
public void clear()
{
}
public void actionPerformed( ActionEvent e )
{
JButton source = ( JButton ) e.getSource();
JOptionPane.showMessageDialog( source, source.getToolTipText(), "", JOptionPane.PLAIN_MESSAGE );
}
}