/**
 * Scott's XML Editor - Swing and JDOM XML Editor
 * @author Scott Hurring - scott at hurring dot com
 * @version beta1
 * @license GPL
 * For most recent version, go to this url:
 * http://hurring.com/code/java/xmleditor/
 */

import java.awt.BorderLayout;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import javax.swing.JFrame;
import javax.swing.JMenuBar;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;

/**
 * The main frame of the application.
 */
public class MainFrame extends JFrame 
{
	private ScottEditor parent;
	// Debug output text box
	public JTextArea text = new JTextArea();
	// Where the XML Editor lives
	private JPanel xmleditorpanel;

	public MainFrame(ScottEditor parent) {
		super();
		this.parent = parent;
		createFrame();
	}

	public void setTitle(String string) {	
		super.setTitle("Scott's XML Editor : "+ string);
	}
	
	private JMenuBar createMenuBar() {
		return new MainFrameMenuBar(parent).create();
	}

	private JPanel createStatusBar() {
		return new MainFrameStatusBar(parent).create();
	}
	
	private void createFrame() {	
		setBounds(100, 100, 750, 600);
		setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
		addWindowListener(new WindowAdapter() {
			public void windowClosing(WindowEvent e) {
				parent.performExitAction();
			}
		});
		
		setJMenuBar(createMenuBar());
		
		JPanel jp = new JPanel(new BorderLayout());
		
		// This is where the XML Editor will go
		xmleditorpanel = new JPanel(new BorderLayout());
		jp.add(xmleditorpanel, BorderLayout.CENTER);
		
		JPanel south = new JPanel(new BorderLayout());
		south.add(new JScrollPane(createDebugText()), BorderLayout.NORTH);
		//south.add(createStatusBar(), BorderLayout.SOUTH);
		jp.add(south, BorderLayout.SOUTH);
		
		getContentPane().add(jp);
		
		setVisible(true);
	}
	
	public void setXMLEditor(JPanel c) {
		xmleditorpanel.removeAll();
		xmleditorpanel.add(c, BorderLayout.CENTER);
	}
	
	private JTextArea createDebugText() {
		text = new JTextArea();
		text.setRows(5);
		return text;
	}
	
}
