/*	this class extends frame, and is a window that contains the original code
 *	it also contains a button that will "Beautify" the code, and switch
 *	to the output window.
 */

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

public class Original extends Frame {
	
	// Standard AWT initializers
	Button Update = new Button("Beautify");
	TextArea originalarea = new TextArea(25,90);
	MenuBar menubar = new MenuBar();
	Menu window_menu = new Menu("Windows");
	
	public Original(String title) {
		
		super(title);
		
		setMenuBar(menubar);
		window_menu.add(new MenuItem("Control Window"));
		menubar.add(window_menu);
		
		originalarea.setFont(new Font("Courier", Font.PLAIN, 12));
		originalarea.setEditable(true);
		setLayout(new BorderLayout());
		add("Center", originalarea);
		add("South", Update);
		pack();
	}
	
	public void setText(String input) {
		originalarea.setText(input);
	}
	
	public String getText() {
		return originalarea.getText();
	}
	
	public boolean action(Event evt, Object arg) {
		if (evt.target instanceof MenuItem) {
			if (arg == "Control Window") {
				// had to do a hide, then show, since MSDev does not handle

				// to front properly.

				Beautify.UI_Frame.hide();
				Beautify.UI_Frame.show();
				return true;
			}
		}
		else if (evt.target instanceof Button) {
			if (arg == "Beautify") {
				Beautify.UI_Frame.updateCode();
				// had to do a hide, then show, since MSDev does not handle

				// to front properly.

				Beautify.UI_Frame.hide();
				Beautify.UI_Frame.show();
				return true;
			}
		}
		return false;
	}
	
	public boolean handleEvent(Event evt) {
		if (evt.id == Event.WINDOW_DESTROY) {
			hide();
			return true;
		}
		return super.handleEvent(evt);
	}
	
}