// file: FilterApplet.java
//

// include the necessary system files
//
import java.applet.*;
import javax.swing.*;
import java.awt.*;
import java.util.*;
import java.net.*;
import java.io.*; 

// include the necessary local files
//
//import Designer;
//import ControlPanel;
//import Constants;

// class: FilterApplet
//
// this class implements the interface to a threaded applet which allows the
// user to interactively design analog and digital filters
//
public class FilterApplet extends JApplet implements Constants{
    
    // set class constants
    //
    
    // declare components to read the help files
    //
    URL url;
    Vector<URL> urlvec = new Vector<URL>(5, 1);
    
    private final static Color BGCOLOR = Color.lightGray;
    private final static int FRAME_SEPARATION = 2;
    
    // declare class variables
    //
    private JPanel main_panel = new JPanel();
    private Designer designer;
    private MainMenu control;
    private Thread applet_thread;
    
    
    //****************************************************************
    //
    // public methods
    //
    //****************************************************************
    
    // method init
    //
    // parameters: none
    //
    // this method initializes this applet
    // 
    // returns: none
    //
    public void init() {
	
	// initialize the super-class
	//
	super.init();
	
	// declare components to read the help files
	//
	try {
	    url = new URL(getCodeBase() + "doc/help_release.txt");
	    urlvec.addElement(url);
	    url = new URL(getCodeBase() + "doc/help_info_support.txt");
	    urlvec.addElement(url);
	    url = new URL(getCodeBase() + "doc/help_overview.txt");
	    urlvec.addElement(url);
	    url = new URL(getCodeBase() + "doc/tutorial.html");
	    urlvec.addElement(url);
	    url = new URL(getCodeBase() + "doc/help_plugins.txt");
	    urlvec.addElement(url);
	}
	catch(MalformedURLException me) { }

	// get the applet context
	//
	AppletContext context = getAppletContext();
	
	// give this applet color
	//
	this.setBackground(Color.white);
	
	// instantiate the windowed tool frame 
	//
	designer = new Designer(Constants.DEFAULT_DESIGN);
	control = new MainMenu(designer, Constants.DEFAULT_DESIGN, urlvec,
			       context);
	
	// create a new layout manager
	GridBagLayout gridbag= new GridBagLayout();
	
	// reset the layout
	//
	getContentPane().setLayout(null);
	addNotify();
	
	// add main panel to applet
	//
	
	main_panel.setLayout(gridbag);
	Dimension dimen = new Dimension();
	dimen = this.getSize();
	main_panel.setBounds(0,0,dimen.width,dimen.height);
	main_panel.setBackground(BGCOLOR);
	getContentPane().add(main_panel);
	
	control.constrain(main_panel, control, 0, 0, 1, 1, 
			  GridBagConstraints.BOTH, GridBagConstraints.NORTH, 
			  1.0, 0.0, FRAME_SEPARATION,  FRAME_SEPARATION,  
			  FRAME_SEPARATION,  FRAME_SEPARATION);
	
	designer.constrain(main_panel, designer, 0, 1, 1, 1, 
			   GridBagConstraints.BOTH, GridBagConstraints.NORTHWEST, 
			   1.0, 1.0, FRAME_SEPARATION,  FRAME_SEPARATION,  
			   FRAME_SEPARATION,  FRAME_SEPARATION);	
	
	control.add_components();
    }
    
    
    // method start
    //
    // parameters: none
    //
    // this method starts or restarts the threaded applet
    //
    // returns: none
    //
    public void start () {
	
	designer.start();
	
    }
    
    
    // method stop
    //
    // parameters: none
    //
    // this method stops the threaded applet
    //
    // returns: none
    //
    public void stop () {
	designer.stop();
    }
    
    
} // end class FilterApplet
