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

// $Id: CanonicalEventPane.java,v 1.3 2003/03/06 00:40:49 moltmans Exp $
// CanonicalEventPane.java -- 
// Author: Michael Oltmans <moltmans@ai.mit.edu> 
// Created: <Wed Jul 12 18:56:01 2000> 
// Time-stamp: <2000-07-17 18:14:50 moltmans> 
package rec.annotate.gui;

import java.awt.Component;
import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.tree.*;
import java.util.*;

import rec.util.*;
import rec.annotate.*;
import rec.annotate.rules.*;
import rec.annotate.facts.*;
import rec.tms.gui.*;

public class CanonicalEventPane extends JPanel
{
  JLabel m_description;
  StringGeneratedJList m_causes;
  StringGeneratedJList m_effects;
  StringGeneratedJList m_events;
  StringGeneratedJList m_subEvents;

  public CanonicalEventPane() 
  {
    m_description = new JLabel();

    StringGenerator gen = new StringGenerator() {
	public String makeString( Object o )
	{
	  if( o instanceof CanonicalEvent ) {
	    return ((CanonicalEvent)o).toEnglish();
	  }
	  else {
	    return o.toString();
	  }
	}
      };
	
    m_causes = new StringGeneratedJList( gen );
    m_effects = new StringGeneratedJList( gen );
    m_events = new StringGeneratedJList( gen );
    m_subEvents = new StringGeneratedJList( gen );

    m_causes.setVisibleRowCount( 3 );
    m_effects.setVisibleRowCount( 3 );
    m_events.setVisibleRowCount( 5 );
    m_subEvents.setVisibleRowCount( 3 );

    m_description.setHorizontalAlignment( SwingConstants.CENTER );
    
    JScrollPane eventPane = new JScrollPane( m_events );
    JScrollPane causePane = new JScrollPane( m_causes );
    JScrollPane effectPane = new JScrollPane( m_effects );
    JScrollPane subEvtPane = new JScrollPane( m_subEvents );

    JPanel panel = new JPanel();
    panel.setLayout( new GridLayout( 0, 1 ) );
    panel.add( makeLabeledPanel( eventPane, "Canonical events:" ) );
    panel.add( makeLabeledPanel( causePane, "Caused by:" ) );
    panel.add( makeLabeledPanel( effectPane, "Causes:" ) );
    panel.add( makeLabeledPanel( subEvtPane, "Sub Events:" ) );

    setLayout( new BorderLayout() );
    add( m_description, BorderLayout.NORTH );
    add( panel, BorderLayout.CENTER );
  }

  private JPanel makeLabeledPanel( Component comp, String title )
  {
    JPanel p = new JPanel();
    p.setLayout( new BorderLayout() );
    p.add( new JLabel( title ), BorderLayout.NORTH );
    p.add( comp, BorderLayout.CENTER );
    return p;
  }

  public void setEvent( CanonicalEvent event ) 
  {
    m_description.setText( event.toEnglish() );
    m_causes.setListData( event.getCauses().toArray() );
    m_effects.setListData( event.getEffects().toArray() );
    m_events.setListData( event.getEvents().toArray() );
    m_subEvents.setListData( event.getSubEvents().toArray() );
  }
  
}


