// (c) MIT 2003.  All rights reserved.

// -*-Mode: Java-*- 
// HelloWorld.java -- 
// Author: Christine Alvarado <calvarad@ai.mit.edu> 
// Maintainer: Christine Alvarado <calvarad@ai.mit.edu> 
// Version: 
// Created: <Sat Mar 11 14:21:32 2000> 
// Time-stamp: <2000-03-12 17:10:28 calvarad> 
// Keywords: 
package rec.util;


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

/* for now there is no list event listener.  This could be helpful to
   add later */
public class ListDialog extends Dialog
{
  protected Vector m_Labels;
  protected java.awt.List m_List;
  protected Panel m_LabelPanel;
  
  public ListDialog( Frame parent, String name )
  {
    super( parent, name, true );

    Button ok = new Button( "OK" );
    ActionListener al_ok = new ActionListener() {
      public void actionPerformed( ActionEvent e )
      {
	okCommand();
      }
    };
    ok.addActionListener( al_ok );

    Button cancel = new Button( "Cancel" );
    ActionListener al_cancel = new ActionListener() {
      public void actionPerformed( ActionEvent e )
      {
	cancelCommand();
      }
    };
    cancel.addActionListener( al_cancel );

    m_Labels = new Vector();
    m_List = new java.awt.List();

    Panel p = new Panel();

    m_LabelPanel = new Panel();

    p.add( ok );
    p.add( cancel );
    
    add( p, BorderLayout.SOUTH );
    add( m_List, BorderLayout.CENTER );

    pack();
  }

  protected void okCommand()
  {
    dispose();
  }
  
  protected void cancelCommand()
  {
    dispose();
  }

  /* formats the text well(?) */
  public void addLabels( java.util.List labels )
  {
    m_Labels = new Vector( labels );
    m_LabelPanel = new Panel( new GridLayout(m_Labels.size(), 1) );
    Iterator it = m_Labels.iterator();
    while( it.hasNext() ) {
      Label l = (Label)it.next();
      m_LabelPanel.add( l );
    }
    add( m_LabelPanel, BorderLayout.NORTH );
    pack();
  }

  public void addListElement( String listElem )
  {
    m_List.add( listElem );
  }

}
