import java.awt.*;
import java.awt.event.*; 
import javax.swing.*; 
import javax.swing.event.*;

/**
 * Clase que genera y administra los componentes gráficos visibles
 * como botones, area de texto y labels
 */
public class Contenedor extends JPanel
{
/**
 * Layout para los componentes principales
 */
private SpringLayout layout;
/**
 * Administrador de este JPI
 */
private Administrator admin;
/**
 * Area de texto para redactar las notas
 */
private JTextArea papel;
/**
 * Boton para enviar Correo
 */
private JButton correo;
/**
 * Boton para grabacion de Voz
 */
private JButton voz;
/**
 * Boton para esconder la nota
 */
private JButton ok;
/**
 * Contiene informacion de la temporizacion actual
 */
private JLabel status;
/**
 * Panel para contener los botones de Correo y Voz
 */
private JPanel accion;
/**
 * Panel para contener el boton de Esconder y la informacion
 * de temporizacion
 */
private JPanel infoconf;

/**
 * Crea los paneles y componentes graficos, los ordena con Layouts y
 * asigna los Listeners
 * @param a El Administrador del JPI
 */
public Contenedor(Administrator a)
{
admin = a;
accion = new JPanel();
infoconf = new JPanel(new FlowLayout());
layout = new SpringLayout();

papel = new JTextArea();
papel.setFont(new Font("SansSerif", Font.BOLD, 14));
papel.setLineWrap(true);
papel.setWrapStyleWord(true);
papel.setBackground(new Color(247, 249, 145));
papel.setBorder(BorderFactory.createLineBorder(Color.black));
papel.setPreferredSize(new Dimension(195,115));
papel.setMinimumSize(papel.getPreferredSize());
papel.setMaximumSize(papel.getPreferredSize());

correo = new JButton("Correo", new ImageIcon("env6.gif"));
correo.addActionListener(admin);
correo.setPreferredSize(new Dimension(75, 50));
correo.setMinimumSize(correo.getPreferredSize());
correo.setMaximumSize(correo.getPreferredSize());
correo.setVerticalTextPosition(AbstractButton.BOTTOM); 
correo.setHorizontalTextPosition(AbstractButton.CENTER);
voz = new JButton("Voz", new ImageIcon("micro.gif"));
voz.addActionListener(admin);
voz.setPreferredSize(correo.getPreferredSize());
voz.setMinimumSize(voz.getPreferredSize());
voz.setMaximumSize(voz.getPreferredSize());
voz.setVerticalTextPosition(AbstractButton.BOTTOM); 
voz.setHorizontalTextPosition(AbstractButton.CENTER);
accion.setBorder(BorderFactory.createLineBorder(Color.black));
accion.add(correo);
accion.add(voz);
accion.setPreferredSize(new Dimension(85, 115));
accion.setMinimumSize(accion.getPreferredSize());
accion.setMaximumSize(accion.getPreferredSize());


ok = new JButton("Esconder");
ok.addActionListener(admin);
status = new JLabel("Informacion", JLabel.LEFT);
status.setForeground(new Color(0x11ee22));
status.setBorder(BorderFactory.createLineBorder(Color.black));
infoconf.add(status);
infoconf.add(ok);
infoconf.setBackground(new Color(0x111111));
infoconf.setBorder(BorderFactory.createLineBorder(Color.black));
infoconf.setPreferredSize(new Dimension(285,40));
infoconf.setMinimumSize(infoconf.getPreferredSize());
infoconf.setMaximumSize(infoconf.getPreferredSize());
SpringLayout statusLayout = new SpringLayout();
statusLayout.putConstraint(SpringLayout.WEST, status, 15, SpringLayout.WEST, infoconf);
statusLayout.putConstraint(SpringLayout.NORTH, status, 10, SpringLayout.NORTH, infoconf);
statusLayout.putConstraint(SpringLayout.WEST, ok, 190, SpringLayout.WEST, infoconf);
statusLayout.putConstraint(SpringLayout.NORTH, ok, 6, SpringLayout.NORTH, infoconf);
infoconf.setLayout(statusLayout);

setLayout(layout);
ordenar(layout);
	  
add(accion);
add(infoconf);
add(papel);
setOpaque(true);
}

/**
 * Recibe el objeto SpringLayout y ejecuta métodos asociados a esta clase
 * sobre los objetos graficos para ordenarlos
 */
public void ordenar (SpringLayout layout)
{
layout.putConstraint(SpringLayout.WEST, papel, 5, SpringLayout.WEST, this); 
layout.putConstraint(SpringLayout.NORTH, papel, 5, SpringLayout.NORTH, this);
  
layout.putConstraint(SpringLayout.WEST, accion, 205, SpringLayout.WEST, this);
layout.putConstraint(SpringLayout.NORTH, accion, 5, SpringLayout.NORTH, this);
 
layout.putConstraint(SpringLayout.NORTH, infoconf, 5, SpringLayout.SOUTH, papel); 

layout.putConstraint(SpringLayout.WEST, infoconf, 5, SpringLayout.WEST, this);
}

/**
 * Asigna texto al Label. Sera utilizado por el actionPeroformed de JPostItFrame
 * @param s El string para escribir en el label.
 */
public void setStatus(String s)
{ status.setText(s); }

/**
 * Retorna el texto del label. Sera usado por el Timer
 * @return El texto del label
 */
public String getStatus()
{ return status.getText(); }

/**
 * Retorna el area de texto. Lo usara el envio de correo
 * @return papel El JTextField de este Contenedor
 */
public JTextArea getPapel()
{ return papel; }

}