/*****************************************
* MainInterface.java
* From http://home.att.net/~gobruen
*
* 	Main class for the program
*		Opens a small window with button options
*		for the sub-programs/classes
*
*
*	Sub-Programs:
*		HTMLGen.java
*		Hlib.java
*		WebEdit.java
*
******************************************/



import javax.swing.*;
import java.awt.*;
import java.awt.event.*;


public class MainInterface extends JFrame implements ActionListener
{
	public static final int WIDTH = 600;
	public static final int HEIGHT = 100;

	public static void main(String[] args)
	{
		MainInterface mi = new MainInterface();
		mi.setVisible(true);
	}

	public MainInterface()
	{
		setTitle("MainInterface");
		addWindowListener(new WindowDestroyer());
		setSize(WIDTH, HEIGHT);
		Container contentPane = getContentPane();
		contentPane.setLayout(new BorderLayout());


		JPanel instructPanel = new JPanel();
		instructPanel.setBackground(Color.gray);
		instructPanel.setLayout(new FlowLayout());
		JLabel iLabel = new JLabel("Welcome to the Web Page Generator");
		instructPanel.add(iLabel);
		contentPane.add(instructPanel, BorderLayout.NORTH);

		JPanel buttPanel = new JPanel();
		buttPanel.setBackground(Color.gray);
		buttPanel.setLayout(new FlowLayout());

		JButton nButton = new JButton("New Web");
		nButton.addActionListener(this);
		buttPanel.add(nButton);

		JButton gButton = new JButton("Generator");
		gButton.addActionListener(this);
		buttPanel.add(gButton);

		JButton eButton = new JButton("Editor");
		eButton.addActionListener(this);
		buttPanel.add(eButton);

		JButton helpBut = new JButton("Help");
		helpBut.addActionListener(this);
		buttPanel.add(helpBut);

		contentPane.add(buttPanel, BorderLayout.CENTER);

	}

/****************************************
*
*actionPerformed()
*
*Editor		Opens Interface for editing current files
*Generator	Opens Interface for creating HTML files
*New Web	Creates a directory by calling system commands
*Help		Opens Instructions for this program
*
*
*****************************************/




	public void actionPerformed(ActionEvent e)
	{
		if(e.getActionCommand().equals("Editor"))
		{
			WebEdit we = new WebEdit();
	
			we.setSize(500, 500);
			we.setVisible(true);
		}//Call the editor interface


		if(e.getActionCommand().equals("Generator"))
		{
			HTMLGen hg = new HTMLGen();
			hg.setSize(500, 500);
			hg.setVisible(true);
		}//Call the generator interface


/*******************************
*New Web 
*
* Calls an external DOS batch file for creating a
*	directory for the files. 
* Runtime.getRuntime().exec calls the external DOS batch
*
*Contents are listed below:
****************************************************************
***
***@ECHO OFF
***if exist c:\windows\desktop\myWeb\myweb.txt GOTO QUIT
***
***MKDIR c:\windows\desktop\myWeb
***MKDIR c:\windows\desktop\myWeb\images
***VER>>c:\windows\desktop\myWeb\myweb.txt
***SET>>c:\windows\desktop\myWeb\myweb.txt
***GOTO EX
***
***:QUIT
***ECHO DIRECTORY ALREADY EXISTS
***PAUSE
***GOTO EX
***
***:EX
***CLS
***EXIT
***
*****************************************************************
*********************************/

		if(e.getActionCommand().equals("New Web"))
		{
			String cmd = "mkWeb.bat";
			try{
				Runtime.getRuntime().exec
			    	(cmd);
				JOptionPane.showMessageDialog(null, "Directory created : c:\\windows\\desktop\\MyWeb, all files will go here.");
			}
			catch(Exception ce){
				ce.printStackTrace();
				JOptionPane.showMessageDialog(null, "Problem creating directory: "+ce.toString());
			}

		}//end New Web



		if(e.getActionCommand().equals("Help")){
     			try{
				Runtime.getRuntime().exec
			    	("rundll32 url.dll,FileProtocolHandler " + "helpfiles.html");
       			}
     			catch (Exception er) {
       				er.printStackTrace();
       			}
		}//end Help
		//else
			//outputField.setText("Error in code.");
		

	}

}//end class
