/*
 * JVirus is a PacMan clone, written in Java.
 *
 * Please read "http://jvirus.sourceforge.net/jvirus_licence.txt" for copyrights.
 * 
 * The sourcecode is designed and created with
 * Sun J2SDK 1.3 and Microsoft Visual J++ 6.0
 *
 * JVirus homepage: http://jvirus.sourceforge.net
 *
 * autor: Slawa Weis
 * email: slawaweis@animatronik.net
 *
 */

package org.game.JVirus;

import java.awt.*;
import java.awt.event.*;

import javax.swing.*;
import javax.swing.border.*;

/**
 * this panel contains the Display panel and the panel for messages
 *
 * @see     org.game.JVirus.Display
 */
public class DisplayBackPanel extends JPanel
{
 /**
  * display panel
  *
  * @see     org.game.JVirus.Display
  */
 protected JPanel center = null;
 /**
  * message panel
  */
 protected JPanel dialogPanel = null;

 /**
  * creates the panel.
  *
  * @param center the panel for the display panel
  */
 public DisplayBackPanel(JPanel center)
  {
  super(null);

  dialogPanel = new JPanel(new GridLayout(1, 1));
  dialogPanel.setSize(600, 400);
  dialogPanel.setBackground(new Color(0, 0, 0, 128));
  dialogPanel.setBorder(new LineBorder(SwingTheme.black, 1));
  dialogPanel.setVisible(false);
  add(dialogPanel);

  this.center = center;
  center.setLocation(0, 0);
  add(center);

  setPreferredSize(center.getSize());

  addComponentListener(new Resizer());
  }

 /**
  * show the message panel
  *
  * @param component the component with the message
  */
 public void showDialogPanel(Component component)
  {
  dialogPanel.removeAll();
  dialogPanel.add(component);
  dialogPanel.doLayout();
  dialogPanel.setVisible(true);
  }

 /**
  * hide the message panel
  */
 public void hideDialogPanel()
  {
  dialogPanel.setVisible(false);
  }

 /**
  * help class. If the DisplayBackPanel is resized, the center panel movin in the center of DisplayBackPanel
  */
 protected class Resizer extends ComponentAdapter
 {
  public void componentResized(ComponentEvent e)
   {
   Dimension size = getSize();
   Dimension center_size = center.getSize();
   center.setLocation((size.width - center_size.width)/2, (size.height - center_size.height)/2);
   setPreferredSize(center_size);

   Dimension dialogPanel_size = dialogPanel.getSize();
   dialogPanel.setLocation((size.width - dialogPanel_size.width)/2, (size.height - dialogPanel_size.height)/2);
   }
 }
}