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

// -*-Mode: JDE-*- 
// $Id: AnnotationBrowser.java,v 1.3 2003/03/06 00:40:49 moltmans Exp $
// AnnotationBrowser.java -- 
// Author: Michael Oltmans <moltmans@ai.mit.edu> 
// Created: <Mon Jun 12 14:14:25 2000> 
// Time-stamp: <2000-06-18 17:26:03 moltmans> 
package rec.annotate.gui;

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

import rec.util.*;
import rec.annotate.rules.*;

public class AnnotationBrowser
{
  private Notebook m_notebook;
  private JFrame m_frame;
  private Tabs m_tabs;

  public AnnotationBrowser( Notebook book ) 
  {
    m_notebook = book;
  }
  
  public void startBrowser()
  {
    m_frame = new JFrame("Annotation Browser");

    m_frame.addWindowListener(new WindowAdapter() {
	public void windowClosing(WindowEvent e) {
	  m_frame.setVisible( false );
	}
      });

    m_tabs = new Tabs( m_notebook );
   
    JButton update = new JButton( "Update" );
    update.addActionListener( new ActionListener() {
	public void actionPerformed( ActionEvent e ) {
	  updateNotes();
	}} );

    m_frame.getContentPane().add( m_tabs, BorderLayout.CENTER );
    m_frame.getContentPane().add( update, BorderLayout.SOUTH );

    m_frame.setSize( 400, 350 );
    m_frame.setVisible(true);
  }

  public void updateNotes() 
  {
    // swing methods are not generally thread safe so make sure we are
    // always called in the event dispatch thread...
    if( SwingUtilities.isEventDispatchThread() ) {
      m_tabs.updateNotes();
      return;
    }

    Runnable runner = new Runnable() {
	public void run() {
	  m_tabs.updateNotes();
	}
    };

    SwingUtilities.invokeLater( runner );
  }
}

