/**
 * $Revision: $
 * $Date: $
 *
 * Copyright (C) 2006 Jive Software. All rights reserved.
 *
 * This software is published under the terms of the GNU Lesser Public License (LGPL),
 * a copy of which is included in this distribution.
 */

package org.jivesoftware.spark.component.browser;

import org.jdesktop.jdic.browser.BrowserEngineManager;
import org.jdesktop.jdic.browser.WebBrowser;
import org.jdesktop.jdic.browser.WebBrowserEvent;
import org.jdesktop.jdic.browser.WebBrowserListener;
import org.jivesoftware.spark.util.log.Log;

import java.awt.BorderLayout;
import java.net.MalformedURLException;
import java.net.URL;

/**
 * Implementation of BrowserViewer using Native Browsers (IE / Mozilla)
 *
 * @author Derek DeMoro
 */
class NativeBrowserViewer extends BrowserViewer implements WebBrowserListener {
    private WebBrowser browser;

    public void initializeBrowser() {
        browser = new WebBrowser();


        this.setLayout(new BorderLayout());

        this.add(browser, BorderLayout.CENTER);

        browser.addWebBrowserListener(this);
    }

    public void loadURL(String url) {
        try {
            browser.setURL(new URL(url));
        }
        catch (MalformedURLException e) {
            Log.error(e);
        }
    }

    public void goBack() {
        browser.back();
    }

    public void downloadStarted(WebBrowserEvent event) {
    }

    public void downloadCompleted(WebBrowserEvent event) {
        if (browser == null || browser.getURL() == null) {
            return;
        }

        String url = browser.getURL().toExternalForm();
        documentLoaded(url);
    }

    public void downloadProgress(WebBrowserEvent event) {

    }

    public void downloadError(WebBrowserEvent event) {

    }

    public void documentCompleted(WebBrowserEvent event) {

    }

    public void titleChange(WebBrowserEvent event) {

    }

    public void statusTextChange(WebBrowserEvent event) {

    }


    public void initializationCompleted(WebBrowserEvent webBrowserEvent) {
    }
}

@@ -500,24 +500,56 @@
 rListener;%0D%0A
+import org.jivesoftware.Spark;%0D%0A
 import org.j
@@ -941,24 +941,288 @@
 rowser() %7B%0D%0A
+        BrowserEngineManager bem = BrowserEngineManager.instance();%0D%0A        if (Spark.isWindows()) %7B%0D%0A            bem.setActiveEngine(BrowserEngineManager.IE);%0D%0A        %7D%0D%0A        else %7B%0D%0A            bem.setActiveEngine(BrowserEngineManager.MOZILLA);%0D%0A        %7D%0D%0A
         brow

Fix native browser.