/**
 * FILE: WomanFrame.java
 * AUTHOR: Ivan J Leichtling
 * INERNET: ivan@columbia.edu
 * 
 * This file defines a a pop-up frame with info about a woman.
 */
import java.awt.*;
import java.util.*;

public class WomanFrame extends Frame
{
  Woman w;
  Button bClose;
  
  public WomanFrame( Woman w )
  {
    this.w = w;
    
    setBackground( Color.pink );
    setForeground( Color.black );

    GridBagLayout gbl = new GridBagLayout();
    GridBagConstraints gbc = new GridBagConstraints();
    
    setLayout( gbl );

    Font f = new Font( "Helvetica", Font.BOLD, 16 );
    Label name = new Label( w.getName(), Label.CENTER );
    name.setFont( f );
    gbc.gridwidth = GridBagConstraints.REMAINDER;
    gbl.setConstraints( name, gbc );
    add( name );

    Label spacer1 = new Label( "" );
    gbc.gridwidth = GridBagConstraints.REMAINDER;
    gbl.setConstraints( spacer1, gbc );
    add( spacer1 );
    
    if( w.getEngaged() ) {
      Label fiancee = new Label( "Fiancee: ", Label.CENTER );
      gbc.gridwidth = 1;
      gbl.setConstraints( fiancee, gbc );
      add( fiancee );
      
      PersonButton pb = new PersonButton( w.getFiancee(), true );
      gbc.gridwidth = GridBagConstraints.REMAINDER;
      gbl.setConstraints( pb, gbc );
      add( pb );
    }
    else {
      Label none = new Label( "No fiancee.", Label.CENTER );
      gbl.setConstraints( none, gbc );
      add( none );
    }
    
    Label spacer2 = new Label( "" );
    gbc.gridwidth = GridBagConstraints.REMAINDER;
    gbl.setConstraints( spacer2, gbc );
    add( spacer2 );

    Label preferences = new Label( "Preferences:", Label.LEFT );
    gbl.setConstraints( preferences, gbc );
    add( preferences );

    List list = new List();
    Enumeration e = w.getPreferences();
    
    while( e.hasMoreElements() ) {
      list.addItem( ((Person)e.nextElement()).getName() );
    }
    gbc.weighty = 15;
    gbc.gridheight = 15;
    gbc.fill = GridBagConstraints.VERTICAL;
    gbl.setConstraints( list, gbc );
    add( list );
    
    Label spacer3 = new Label( "" );
    gbc.gridwidth = GridBagConstraints.REMAINDER;
    gbc.fill = GridBagConstraints.NONE;
    gbl.setConstraints( spacer3, gbc );
    add( spacer3 );

    Label proposals = new Label( "Proposals:", Label.LEFT );
    gbl.setConstraints( proposals, gbc );
    add( proposals );

    List listProps = new List();
    e = w.getProposals();
    
    while( e.hasMoreElements() ) {
      listProps.addItem( ((Person)e.nextElement()).getName() );
    }
    gbc.weighty = 5;
    gbc.gridheight = 5;
    gbc.fill = GridBagConstraints.VERTICAL;
    gbl.setConstraints( listProps, gbc );
    add( listProps );

    Label spacer4 = new Label( "" );
    gbc.gridwidth = GridBagConstraints.REMAINDER;
    gbc.weighty = 1;
    gbc.gridheight = 1;
    gbc.fill = GridBagConstraints.NONE;
    gbl.setConstraints( spacer4, gbc );
    add( spacer4 );

    bClose = new Button( "Close" );
    gbl.setConstraints( bClose, gbc );
    add( bClose );
    
    pack();
    resize( 200, 450 );
    show();
  }

  public boolean handleEvent( Event evt )
  {
    if( evt.id == Event.WINDOW_DESTROY ||
	( evt.id == Event.ACTION_EVENT && evt.target == bClose ) ) {
      dispose();
      return( true );
    }

    return( super.handleEvent( evt ) );
  }
}
