/*---------------------------------------------------------------------------
File:         			SourceWindow.java
Package:                        JFLAP Version 3.1
Author:			        Eric Gramond
Modified:			Ted Hung V3.1 7/10/99
                                
Description of Contents:	Contains class SourceWindow.
				
--------------------------------------------------------------------------*/

/* 
 * Susan H. Rodger, Magda Procopiuc, Octavian Procopiuc, Eric Gramond, Ted Hung
 * Computer Science Department
 * Duke University
 * August 1999
 * Supported by National Science Foundation DUE-9596002, DUE-9555084,
 *  and DUE-9752583
 *
 * Copyright (c) 1999
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms are permitted
 * provided that the above copyright notice and this paragraph are
 * duplicated in all such forms and that any documentation,
 * advertising materials, and other materials related to such
 * distribution and use acknowledge that the software was developed
 * by the author.  The name of the author may not be used to
 * endorse or promote products derived from this software without
 * specific prior written permission.
 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 */


package flap;

import java.util.*;
import java.awt.*;
import java.io.*;
import java.awt.image.*;
import java.awt.event.*;



public abstract class SourceWindow extends Frame {
  
  
    /**
     * standard close name through the whole application 
     */
  public static String STR_CLOSE = "Close";
  
    /**
     * standard quit name through the whole application
     */
  public final static String	STR_QUIT = "Quit JFLAP";
  
    /**
     * standard empty file name
     */
  public final static String	NO_FILE_NAME		= "(no name)";
  
    /**
     * The Container which opened this Environment.
     * Can be either MainMenu or FLAPApplet.
     */
  protected MainMenu	mainmenu;    
  
    /**
     * When isApplet is set, some items in the menu bar are disabled.
     */
  protected boolean	isApplet = false;
  
    /**
     * The name of the file containing the current machine.
     */
  public String		fileName = NO_FILE_NAME;
    /**
     * The current directory for opening/saving.
     */
    public String		currentDir = null;

  
  public SourceWindow(MainMenu mainMenu, boolean isApplet) {
    this.mainmenu = mainMenu;
    this.isApplet = isApplet;
    setBackground(Params._e_backcolor);
  }
  
    /**
     * sourcewindows handle their own quiting. 
     * assuming auto-saving was already doen
     */
  public boolean quit() {
    ((MainMenu) mainmenu).actionPerformed(new ActionEvent(this, 
              ActionEvent.ACTION_PERFORMED, SourceWindow.STR_CLOSE));
    setVisible(false);
    return true;
  }
  
    /**
     * Shows the about dialog.
     */
  public void about() {
    OKDialog dg = new OKDialog(
       "\nJFLAP v. 3.1, July 15th, 1999 (c) 1999 Susan Rodger and\n Ted Hung.\n ---------------------------- \n" +
       "JFLAP v. 3.0, August 16th, 1998 (c) 1998 Susan Rodger and\n Eric Gramond.\n ---------------------------- \n" + 
       "JFLAP v. 2.0, July 31, 1997\n (c) 1997 Susan H. Rodger and\n Eric Gramond.\n ---------------------------- \n" +
       "JFlap v. 1.0 July 15 1996\n (c) 1996 Susan H. Rodger,\nMagda Procopiuc&\nOctavian Procopiuc.", this, "About jflap");
    //dg.setDim(380, 300);
    dg.show();
  }
  
    /**
     * Shows the help dialog HTML
     */
  public void helpHTML()
  {
    if(mainmenu.myHelpWindow == null || !mainmenu.myHelpWindow.getType().equals("HTML"))
    {
       try
       {
          mainmenu.myHelpWindow = new HelpWindowHTML("JFLAP", Params._e_backcolor, mainmenu.isApplet);
       }
       catch(Exception e)
       {
          OKDialog dg = new OKDialog(e.getMessage(), this, "Error");
          dg.show();
          return;
       }
    }
    mainmenu.myHelpWindow.setLocation(
       (Toolkit.getDefaultToolkit().getScreenSize().width - mainmenu.myHelpWindow.getSize().width) / 2,
       (Toolkit.getDefaultToolkit().getScreenSize().height - mainmenu.myHelpWindow.getSize().height) / 2);
    mainmenu.myHelpWindow.setVisible(true);
    mainmenu.myHelpWindow.toFront();
  }

    /**
     * Shows the help dialog.TEXT
     */
  public void helpText()
  {
    if(mainmenu.myHelpWindow == null || !mainmenu.myHelpWindow.getType().equals("Text"))
      mainmenu.myHelpWindow = new HelpWindowText("JFLAP", Params._e_backcolor, isApplet);
    mainmenu.myHelpWindow.setLocation(
       (Toolkit.getDefaultToolkit().getScreenSize().width - mainmenu.myHelpWindow.getSize().width) / 2,
       (Toolkit.getDefaultToolkit().getScreenSize().height - mainmenu.myHelpWindow.getSize().height) / 2);
    mainmenu.myHelpWindow.setVisible(true);
    mainmenu.myHelpWindow.toFront();
  }
    
}
