//------------------------------------------------------------------------------
// MDialog.java:
//		Implementation of "control creator" class MDialog
//------------------------------------------------------------------------------
import java.awt.*;
import DialogLayout;

public class MDialog
{
  Container    m_Parent       = null;
  boolean      m_fInitialized = false;
  DialogLayout m_Layout;

  // Control definitions
  //--------------------------------------------------------------------------
  Button        IDOK;
  Label         IDC_STATIC1;


  // Constructor
  //--------------------------------------------------------------------------
  public MDialog (Container parent)
  {
    m_Parent = parent;
  }

  // Initialization.
  //--------------------------------------------------------------------------
  public boolean CreateControls()
  {
    // CreateControls should be called only once
    //----------------------------------------------------------------------
    if (m_fInitialized || m_Parent == null)
      return false;

    // m_Parent must be extended from the Container class
    //----------------------------------------------------------------------
    if (!(m_Parent instanceof Container))
      return false;

    // Since a given font may not be supported across all platforms, it
    // is safe to modify only the size of the font, not the typeface.
    //----------------------------------------------------------------------
    Font OldFnt = m_Parent.getFont();
    if (OldFnt != null)
      {
	Font NewFnt = new Font(OldFnt.getName(), OldFnt.getStyle(), 12);

	m_Parent.setFont(NewFnt);
      }

    // All position and sizes are in dialog logical units, so we use a
    // DialogLayout as our layout manager.
    //----------------------------------------------------------------------
    m_Layout = new DialogLayout(m_Parent, 186, 95);
    m_Parent.setLayout(m_Layout);
    m_Parent.addNotify();

    Dimension size   = m_Layout.getDialogSize();
    Insets    insets = m_Parent.insets();
		
    m_Parent.resize(insets.left + size.width  + insets.right,
		    insets.top  + size.height + insets.bottom);

    // Control creation
    //----------------------------------------------------------------------
    IDOK = new Button ("OK");
    m_Parent.add(IDOK);
    m_Layout.setShape(IDOK, 67, 68, 50, 14);

    IDC_STATIC1 = new Label ("", Label.LEFT);
    m_Parent.add(IDC_STATIC1);
    m_Layout.setShape(IDC_STATIC1, 41, 29, 101, 23);

    m_fInitialized = true;
    return true;
  }
}

class MsgDialog extends Dialog
{
  private MDialog mdlg = null;
  private DLSim theApplet = null;
  
  MsgDialog(DLSim theApplet, String title, String msg)
  {
    super(theApplet.myFrame, title, true);
    this.theApplet = theApplet;
    setFont(new Font("Arial", Font.PLAIN, 12));
    mdlg = new MDialog(this);
    mdlg.CreateControls();
    mdlg.IDC_STATIC1.setText(msg);
  }

  public boolean action(Event evt, Object what)
  {
    Object target = evt.target;
    if (target instanceof Button) {
      hide();
      return true;
    }
    return false;
  }
  
  public boolean handleEvent(Event evt)
  {
    switch (evt.id) {
    case Event.WINDOW_DESTROY:
      dispose();
      return true;
    default:
      return super.handleEvent(evt);
    }			 
  }
}
