///////////////////////////////////////////////////////////////////////
//
// Editor.java : A Simple Java applet LaTeX editor.  
//
///////////////////////////////////////////////////////////////////////
//
// Copyright (c) 1997-98 by the IBM Corporation. All Rights Reserved.
//
// Author:          Angel L. Diaz     aldiaz@us.ibm.com
//                  Robert S. Sutor   sutor@us.ibm.com
//
// IBM MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF
// THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
// TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
// PARTICULAR PURPOSE, OR NON-INFRINGEMENT. IBM SHALL NOT BE LIABLE FOR
// ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING OR MODIFYING
// THIS SOFTWARE OR ITS DERIVATIVES.
//
///////////////////////////////////////////////////////////////////////

import java.awt.*;
import java.applet.Applet;

import ibm.techexplorer.techexplorer;
import ibm.techexplorer.control.techexplorerControl;
import ibm.techexplorer.axtchexp.AxTchExpRaw;
import ibm.techexplorer.util.DhObject;

public class Editor extends Applet {
   
   TextArea sourceLaTeXArea;
   Button   sendDocumentBtn,getDocumentBtn,aboutBtn;

   private techexplorer techexplorer = null;
   private DhObject dHTML = null;

   public void setPlugin( techexplorer obj )
   {
       if ( obj instanceof techexplorer )
           techexplorer = obj;
	   dHTML = new DhObject((Applet) this);
   }

   public void setControl( AxTchExpRaw obj, Object dhtmlobj )
   {
       if ( obj instanceof AxTchExpRaw )
           techexplorer = new techexplorerControl( obj );
	   dHTML = new DhObject(dhtmlobj);
   }
   
   public void init(){
      GridBagLayout gridbag = new GridBagLayout();
      GridBagConstraints c = new GridBagConstraints();
      setLayout(gridbag);

      sourceLaTeXArea = new TextArea(  );
      c.gridwidth = 2; c.fill = GridBagConstraints.BOTH; 
      gridbag.setConstraints(sourceLaTeXArea,c); 
      add(sourceLaTeXArea);

      sendDocumentBtn = new Button();
      sendDocumentBtn.setLabel("Click to send document");
      c.gridwidth = 1; c.weightx = 1; c.gridy = 1; c.gridx = 0;
      gridbag.setConstraints(sendDocumentBtn,c);
      add( sendDocumentBtn );

      getDocumentBtn = new Button();
      getDocumentBtn.setLabel("Click to get document");
      c.gridy = 1; c.gridx = 1;
      gridbag.setConstraints(getDocumentBtn,c);
      add( getDocumentBtn );

      aboutBtn = new Button();
      aboutBtn.setLabel("About ...");
      c.gridwidth = 2; c.weightx = 1; c.gridy = 2; c.gridx = 0;
      gridbag.setConstraints(aboutBtn,c);
      add( aboutBtn );
   }

  public void start() {      
  }

  public boolean action(Event e, Object arg){
     if (e.target == sendDocumentBtn) 
        techexplorer.reloadFromTeXString( sourceLaTeXArea.getText() );
     if (e.target == getDocumentBtn) 
        sourceLaTeXArea.setText( (String) techexplorer.getTeXString() );
     if (e.target == aboutBtn)
	 {
         Object args[] = new Object[1];
         args[0] = new String( "Java LaTeX Text Editor 1.0" );
         dHTML.call("alert", args);
	 }
     return true;
  }
}


