private MainFrame() {
        // Set frame options.
        setTitle("Wombat - Build " + Wombat.VERSION);
        setSize(Options.DisplayWidth, Options.DisplayHeight);
        setLocation(Options.DisplayLeft, Options.DisplayTop);
        setLayout(new BorderLayout(5, 5));
        setDefaultCloseOperation(EXIT_ON_CLOSE);
        try {
        	setIconImage(IconManager.icon("Wombat.png").getImage());
        } catch(NullPointerException ex) {
        	
        }
                
        // Wait for the program to end.
        final MainFrame me = this;
        addWindowListener(new WindowAdapter() {
            public void windowClosing(WindowEvent e) {
        		Options.DisplayTop = Math.max(0, e.getWindow().getLocation().y);
            	Options.DisplayLeft = Math.max(0, e.getWindow().getLocation().x);
            	Options.DisplayWidth = Math.max(400, e.getWindow().getWidth());
            	Options.DisplayHeight = Math.max(400, e.getWindow().getHeight());
            	Options.save();
            	
            	DocumentManager.CloseAll();
            	stopAllThreads(true, false);
            	
            	me.dispose();
            }
        });

        // Set up the menus using the above definitions.
        MenuManager.Singleton(this);
        setJMenuBar(MenuManager.getMenu());
        
        // Create a display for any open documents.
        Root = DockingUtil.createRootWindow(new ViewMap(), true);
        TabWindow documents = new TabWindow();
        ViewMap = new StringViewMap();
        DocumentManager.init(this, Root, ViewMap, documents);
        DocumentManager.New();
         
        // Create displays for a split REPL.
        History = new NonEditableTextArea();
        REPL = new REPLTextArea();
        ViewMap.addView("REPL - Execute", new View("REPL - Execute", null, REPL));
        ViewMap.addView("REPL - History", new View("REPL - History", null, History));
        SplitWindow replSplit = new SplitWindow(true, 0.5f, ViewMap.getView("REPL - Execute"), ViewMap.getView("REPL - History"));
        
        ViewMap.getView("REPL - Execute").getWindowProperties().setCloseEnabled(false);
        ViewMap.getView("REPL - History").getWindowProperties().setCloseEnabled(false);
        
        ViewMap.getView("REPL - Execute").getWindowProperties().setUndockEnabled(false);
        ViewMap.getView("REPL - History").getWindowProperties().setUndockEnabled(false);
        
        // Create the error/debug/display views.
        JPanel debugPanel = new JPanel();
        debugPanel.setLayout(new GridLayout(2, 1));
        Debug = new NonEditableTextArea();
        debugPanel.add(Debug);
        DebugLogs = new NonEditableTextArea();
        debugPanel.add(DebugLogs);
        ViewMap.addView("Debug", new View("Debug", null, debugPanel));
        
        // Listen and report new error messages.
        ErrorManager.addErrorListener(new ErrorListener() {
			@Override
			public void logError(String msg) {
				Debug.append(msg + "\n");
			}
        });
        
        // Put everything together into the actual dockable display.
        SplitWindow fullSplit = new SplitWindow(false, 0.6f, documents, replSplit);
        Root.setWindow(fullSplit);
        add(Root);
        
        // Add a toolbar.
        ToolBar = new JToolBar();
        ToolBarRun = new JButton(MenuManager.itemForName("Run").getAction());
        ToolBarStop = new JButton(MenuManager.itemForName("Stop").getAction());
        
        ToolBar.setFloatable(false);
        for (Action a : new Action[]{
        		MenuManager.itemForName("New").getAction(),
        		MenuManager.itemForName("Open").getAction(),
        		MenuManager.itemForName("Save").getAction(),
        		MenuManager.itemForName("Close").getAction(),
        		})
        	ToolBar.add(new JButton(a));
        
        ToolBar.addSeparator();
        for (Action a : new Action[]{
        		MenuManager.itemForName("Connect").getAction(),
        		MenuManager.itemForName("Upload").getAction(),
        		})
        	ToolBar.add(new JButton(a));
        
        ToolBar.addSeparator();
        for (Action a : new Action[]{
        		MenuManager.itemForName("Cut").getAction(),
        		MenuManager.itemForName("Copy").getAction(),
        		MenuManager.itemForName("Paste").getAction(),
        		MenuManager.itemForName("Undo").getAction(),
        		MenuManager.itemForName("Redo").getAction(),
        		MenuManager.itemForName("Find/Replace").getAction(),
        		})
        	ToolBar.add(new JButton(a));
        	
        ToolBar.addSeparator();
        ToolBar.add(ToolBarRun);
        ToolBar.add(ToolBarStop);
        for (Action a : new Action[]{
        		MenuManager.itemForName("Format").getAction(),
        		MenuManager.itemForName("Reset").getAction(),
        		})
        	ToolBar.add(new JButton(a));
        
        add(ToolBar, BorderLayout.PAGE_START);
        ToolBar.setVisible(Options.DisplayToolbar);
        
        // Disable items by default.
        setRunning(false);
		
		// Remove text on toolbar buttons.
		for (Component c : ToolBar.getComponents())
			if (c instanceof JButton)
				((JButton) c).setText("");
				
		// Add a tool to show the current row and column.
		RowColumn = new JLabel("row:column");
		ToolBar.addSeparator();
        ToolBar.add(RowColumn);
        
        
        // Set up options specifically for OS X.
        if (OS.IsOSX) {
        	try {
        		com.apple.eawt.Application app = com.apple.eawt.Application.getApplication();
        		app.setDockIconImage(IconManager.icon("Wombat.png").getImage());
            } catch (Exception e) {
                System.err.println("Error setting up OSX specific features:");
                e.printStackTrace();
            }
        }
        
	// Finally, intialize petite.
        initPetite();
    }