|
What this is
Other links
The source code/*
* Sun Public License Notice
*
* The contents of this file are subject to the Sun Public License
* Version 1.0 (the "License"). You may not use this file except in
* compliance with the License. A copy of the License is available at
* http://www.sun.com/
*
* The Original Code is NetBeans. The Initial Developer of the Original
* Code is Sun Microsystems, Inc. Portions Copyright 1997-2003 Sun
* Microsystems, Inc. All Rights Reserved.
*/
package org.netbeans.modules.webclient;
import java.awt.*;
import java.awt.event.*;
import java.beans.*;
import java.net.*;
import java.util.*;
import javax.swing.SwingUtilities;
import org.openide.*;
import org.openide.awt.*;
import org.mozilla.util.*;
import org.mozilla.webclient.*;
import org.openide.util.NbBundle;
import org.openide.util.RequestProcessor;
/**
* Real implementation of Mozilla browser functionality needed by IDE.
*
* @author Radim.Kubacki@sun.com
*/
class WebclientBrowserImpl extends HtmlBrowser.Impl {
private static boolean debug = true;
// variables .................................................................
/** browser factory */
private WebclientBrowser factory;
/** browser controller */
private BrowserControl browserControl;
/** browser visual component */
private WebclientBrowserComponent browser;
/** WindowControl for embedding */
private WindowControl winCtrl;
/** browser navigation interface */
private Navigation navigation;
/** browser history interface */
private History browserHistory;
/** browser event interface */
private EventRegistration eventRegistration;
/** current URL */
private URL url;
/** standart helper variable */
private PropertyChangeSupport pcs;
/** Current status message. */
private String statusMessage = ""; // NOI18N
/** Current value of title property. */
private String title = ""; // NOI18N
// init ......................................................................
/**
* Creates instance of browser.
*/
public WebclientBrowserImpl (WebclientBrowser fact) {
pcs = new PropertyChangeSupport (this);
this.factory = fact;
// Create the browser
try {
// This is a workaround - webclient requires jawt but it is not loaded yet (IDE is Swing app)
System.loadLibrary("jawt"); // NOI18N
if (factory.getAppData () != null)
BrowserControlFactory.setAppData (factory.getAppData ().getAbsolutePath ());
else
throw new IllegalStateException (NbBundle.getMessage(WebclientBrowserImpl.class,"ERR_appData_path_is_not_set"));
browserControl = BrowserControlFactory.newBrowserControl();
winCtrl = (WindowControl)
browserControl.queryInterface(BrowserControl.WINDOW_CONTROL_NAME);
if (debug) System.out.println("NativeWebShell="+winCtrl.getNativeWebShell()); // NOI18N
browser = new WebclientBrowserComponent (this);
}
catch(Exception e) {
ErrorManager.getDefault().annotate(e, NbBundle.getMessage(WebclientBrowserImpl.class,"ERR_Cannot_init_impl"));
ErrorManager.getDefault().notify(ErrorManager.EXCEPTION, e);
}
}
public void initialize () {
browser.setVisible(true);
if (navigation == null ) {
try {
// PENDING: Need to wait until it gets inited
for (int i=0; i<20; i++) {
if (debug) System.out.println("Checking ("+i+") NativeWebShell="+winCtrl.getNativeWebShell()); // NOI18N
if (winCtrl.getNativeWebShell() != -1)
break;
try {
Thread.currentThread().sleep(1000);
}
catch (InterruptedException e) { // do nothing
}
}
if (winCtrl.getNativeWebShell() == -1)
throw new IllegalStateException ("Cannot get native web shell"); // NOI18N
navigation = (Navigation)
browserControl.queryInterface(BrowserControl.NAVIGATION_NAME);
CurrentPage currentPage = (CurrentPage)
browserControl.queryInterface(BrowserControl.CURRENT_PAGE_NAME);
browserHistory = (History)
browserControl.queryInterface(BrowserControl.HISTORY_NAME);
eventRegistration = (EventRegistration)
browserControl.queryInterface(BrowserControl.EVENT_REGISTRATION_NAME);
eventRegistration.addDocumentLoadListener (new DocumentLoadListener () {
public void eventDispatched(WebclientEvent event)
{
String old = statusMessage;
int eventType = (int)event.getType();
if (eventType == (int)DocumentLoadEvent.START_DOCUMENT_LOAD_EVENT_MASK) {
setStatusMessage (NbBundle.getMessage(WebclientBrowserImpl.class,"MSG_Loading"));
Object o = event.getEventData();
if (debug) System.out.println("start evt data: "+o+" class "+((o!=null)?o.getClass().getName():"null"));
if (o != null) {
if (o instanceof String) {
try {
url = new URL ((String)o);
pcs.firePropertyChange (PROP_URL, null, null);
}
catch (MalformedURLException ex) {
// do nothing - URL won't be updated
}
}
else if (o instanceof URL) {
url = (URL)o;
pcs.firePropertyChange (PROP_URL, null, null);
}
}
}
else if (eventType == (int)DocumentLoadEvent.END_DOCUMENT_LOAD_EVENT_MASK) {
setStatusMessage (NbBundle.getMessage(WebclientBrowserImpl.class,"MSG_Done"));
pcs.firePropertyChange (null, null, null);
if (debug) System.out.println("end evt data: "+event.getEventData());
}
else if (eventType == (int)DocumentLoadEvent.START_URL_LOAD_EVENT_MASK
|| eventType == (int)DocumentLoadEvent.END_URL_LOAD_EVENT_MASK
|| eventType == (int)DocumentLoadEvent.FETCH_INTERRUPT_EVENT_MASK
|| eventType == (int)DocumentLoadEvent.PROGRESS_URL_LOAD_EVENT_MASK
|| eventType == (int)DocumentLoadEvent.STATUS_URL_LOAD_EVENT_MASK
|| eventType == (int)DocumentLoadEvent.UNKNOWN_CONTENT_EVENT_MASK) {
if (event.getEventData () instanceof String)
setStatusMessage ((String)event.getEventData ());
}
}
});
}
catch(Exception e) {
ErrorManager.getDefault().annotate(e, NbBundle.getMessage(WebclientBrowserImpl.class,"ERR_Cannot_init_impl"));
ErrorManager.getDefault().notify(ErrorManager.EXCEPTION, e);
}
}
}
/**
* Closes BrowserControl resources
*/
public void destroy () {
/*
System.out.println("destroy");
BrowserControlFactory.deleteBrowserControl(browserControl);
browserControl = null;
// if it is last
try {
BrowserControlFactory.appTerminate();
}
catch (Exception ex) {
ex.printStackTrace();
}
*/
}
// HtmpBrowser.Impl implementation ...........................................
/**
* Returns visual component of html browser.
* Actually returns null to allow custom window handling.
*
* @return
|
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.