/*
 * Burton Rosenberg
 * June 2004
 */

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

public class VisualTree
extends JApplet {

   private static final String FRAME_TITLE = "Tree Visualizer" ;
   private static final int WIDTH = 400 ;
   private static final int HEIGHT = 400 ;

   // invoked as application
   public static void main(String [] args) {
      JFrame jf = new JFrame(FRAME_TITLE) ;
      JMenuBar jmb = makeGui(jf.getContentPane(), args) ;
      jf.setJMenuBar(jmb) ;
      jf.setSize( WIDTH, HEIGHT ) ;
      jf.setVisible(true) ;
  }

  // invoked as applet
  public void init() {
      JMenuBar jmb = makeGui( this.getContentPane(), null ) ;
      this.setJMenuBar(jmb) ;
  }

  private static JMenuBar  makeGui(Container c, String [] args) {

      TreeModel tm = new TreeModel() ;
      TreeController tc = new TreeController(tm) ;
      TreeViewer tv = new TreeViewer(tm) ;
      tm.setTreeViewer(tv) ;
      tv.addMouseListener(tc) ;
      c.add( tc, BorderLayout.NORTH ) ;
      c.add( tv, BorderLayout.CENTER ) ;
      JMenuBar jmb = tc.makeMenuBar() ;
      
      if ( args!=null && args.length > 0 ) 
         tm.loadFromFile(new File(args[0])) ;

      //jf.setJMenuBar(jmb) ;
      return jmb ;
  }
  
}

