     /****************************************************************
      * Copyright (C) 1996 - 2001 Micro Focus International Ltd.     *
      * All Rights Reserved.                                         *
      ****************************************************************/

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

/**
 * Class declaration
 *
 *
 * @author
 * @version
 */
public class RecordDemoFrame extends Frame
{

  // Construct the frame
  BorderLayout borderLayout1 = new BorderLayout();
  MenuBar      ApplicationMenu = new MenuBar();
  Menu	       menu1 = new Menu();
  Menu	       menu2 = new Menu();
  MenuItem     menuItem2 = new MenuItem();
  MenuItem     menuItem1 = new MenuItem();
  Label	       customer_name_label = new Label();
  TextField    customer_name_field = new TextField();
  Label	       customer_address_label = new Label();
  GridLayout   gridLayout1 = new GridLayout();
  TextField    customer_address_field = new TextField();
  Label	       customer_ref_label = new Label();
  TextField    customer_ref_field = new TextField();
  Menu	       menu3 = new Menu();
  MenuItem     menuItem3 = new MenuItem();
  RecordDemo   rd;
  RecordData   customerDetails;

  /**
   * Constructor declaration
   *
   *
   * @see
   */
  public RecordDemoFrame()
  {
    try
    {
      jbInit();
    }
    catch (Exception e)
    {
      e.printStackTrace();
    }
  }

  // Component initialization

  /**
   * Method declaration
   *
   *
   * @throws Exception
   *
   * @see
   */
  private void jbInit() throws Exception
  {
    this.setLayout(borderLayout1);
    this.setSize(new Dimension(400, 300));
    this.setTitle("Record Demo (DataType)");
    menu1.setLabel("File");
    menu2.setLabel("Help");
    menuItem2.setLabel("About");
    menuItem2.addActionListener(new java.awt.event.ActionListener()
    {

      /**
       * Method declaration
       *
       *
       * @param e
       *
       * @see
       */
      public void actionPerformed(ActionEvent e)
      {
	menuItem2_actionPerformed(e);
      }

    });
    menuItem1.setLabel("Exit");
    customer_name_label.setText("Customer Name");
    customer_address_label.setText("Customer Address");
    customer_address_field.setColumns(30);
    customer_address_field.setEditable(false);
    customer_ref_label.setText("Customer Reference");
    customer_ref_field.setColumns(6);
    customer_ref_field.setEditable(false);
    menu3.setLabel("Run");
    menuItem3.setLabel("update Record");
    gridLayout1.setRows(3);
    menuItem1.addActionListener(new java.awt.event.ActionListener()
    {

      /**
       * Method declaration
       *
       *
       * @param e
       */
      public void actionPerformed(ActionEvent e)
      {
	menuItem1_actionPerformed(e);
      }

    });
    this.setLayout(gridLayout1);
    customer_name_field.setColumns(30);
    customer_name_field.setEditable(false);
    ApplicationMenu.add(menu1);
    ApplicationMenu.add(menu3);
    ApplicationMenu.add(menu2);
    menu2.add(menuItem2);
    this.setMenuBar(ApplicationMenu);
    menu1.add(menuItem1);
    this.add(customer_name_label, null);
    this.add(customer_name_field, null);
    this.add(customer_address_label, null);
    this.add(customer_address_field, null);
    this.add(customer_ref_label, null);
    this.add(customer_ref_field, null);
    menu3.add(menuItem3);

    /* Create RecordDemo and CustomerDetails record */
    this.rd = new RecordDemo();
    this.customerDetails = new RecordData("Micro Focus", "Newbury", 123456);

    menuItem3.addActionListener(new java.awt.event.ActionListener()
    {

      /**
       * Method declaration
       *
       *
       * @param e
       */
      public void actionPerformed(ActionEvent e)
      {
	menuItem3_actionPerformed(e);
      }

    });
    this.addWindowListener(new java.awt.event.WindowAdapter()
    {

      /**
       * Method declaration
       *
       *
       * @param e
       */
      public void windowOpened(WindowEvent e)
      {
	this_windowOpened(e);
      }

    });

    WindowListener listener = new WindowListener();

    ApplicationMenu.setHelpMenu(menu2);
    addWindowListener(listener);
  }

  /**
   * Class declaration
   *
   *
   * @author
   * @version
   */
  class WindowListener extends WindowAdapter
  {

    /**
     * Constructor declaration
     */
    WindowListener()
    {
      super();
    }

    /**
     * Method declaration
     *
     *
     * @param e
     *
     * @see
     */
    public void windowClosing(WindowEvent e)
    {
      System.exit(0);
    }

  }

  /**
   * Method declaration
   *
   *
   */
  void updateValues()
  {
    this.customer_name_field.setText(this.customerDetails.getCustomerName());
    this.customer_address_field.setText(this.customerDetails.getCustomerAddress());
    this.customer_ref_field.setText(Integer.toString(this.customerDetails.getCustomerRef()));
  }

  /**
   * Method declaration
   *
   *
   * @param e
   *
   * @see
   */
  void menuItem1_actionPerformed(ActionEvent e)
  {
    System.exit(1);
  }

  /**
   * Method declaration
   *
   *
   * @param e
   *
   */
  void menuItem2_actionPerformed(ActionEvent e)
  {
    AboutBox  aboutBox = new AboutBox(this, "User Defined Record Demo", true);

    // Center the window
    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    Dimension frameSize = aboutBox.getSize();

    if (frameSize.height > screenSize.height)
    {
      frameSize.height = screenSize.height;
    }

    if (frameSize.width > screenSize.width)
    {
      frameSize.width = screenSize.width;
    }

    aboutBox.setLocation((screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2);
    aboutBox.setVisible(true);
  }

  /**
   * Method declaration
   *
   *
   * @param e
   *
   */
  void this_windowOpened(WindowEvent e)
  {
    updateValues();
  }

  /**
   * Method declaration
   *
   *
   * @param e
   */
  void menuItem3_actionPerformed(ActionEvent e)
  {
    try
    {
      this.rd.setDetails(customerDetails);
    }
    catch (Exception theE) {}

    updateValues();
  }

}

