|
|
All WebRenderer events are processed through the com.webrenderer.event
package classes. Events available in this
package include:
Browser
Events:
onBeforeNavigate description
The WebRenderer BrowserListener
and BrowserAdapter
makes available URLs loading, HTTP Header
information, HTTP POST information, page
titles, width and height etc.
browser.addBrowserListener(new
BrowserListener() { //
Fired as a document is navigating to a new
URL public
void onBeforeNavigate(BrowserEvent e) {
System.out.println("URL:"+e.getURL()); }
// Fired before
a document has started loading - Use this
to cancel document loads public
void onLoadIntercept(BrowserEvent e) {
System.out.println("onLoadIntercept
:"+e.getURL()); //
If the loading URL contains "www.google.com" if(e.getURL().indexOf("www.google.com")
!= -1) { //
Stopping the document from loading e.blockLoad(); } } //
Fired when links in the browser status bar
change - such as moving the mouse over URLs public void onLinkChange(BrowserEvent
e) { System.out.println("onLinkChange"); }
// Fired when
page loading is cancelled public void onNavigationCancelled(BrowserEvent
e) { System.out.println("onNavigationCancelled:
" + e.getURL()); }
// Fired when
the document title changes public void onTitleChange(BrowserEvent
e) { //
The document title is available System.out.println("onTitleChange:
" + e.getTitle()); }
// Fired when
the URL changes public void onURLChange(BrowserEvent
e) { System.out.println("onURLChange:
"); } });
Network Events:
The NetworkListener and NetworkAdapter classes provde
WebRenderer with useful information regarding
the document loading process.
IBrowserCanvas
browser = BrowserFactory.spawnMozilla();
browser.addNetworkListener(new com.webrenderer.event.NetworkListener()
{ // Fired when a document completes downloading public void onDocumentComplete(com.webrenderer.event.NetworkEvent e)
{ System.out.println("onDocumentComplete
- Document completed downloading"); }
// Fired when
a document begins loading public void
onDocumentLoad(com.webrenderer.event.NetworkEvent e)
{ System.out.println("onDocumentLoad"); }
// Fired
when an HTTP response is received (only
fired for IMozillaBrowserCanvas) public
void onHTTPResponse(com.webrenderer.event.NetworkEvent e)
{ System.out.println("onHTTPResponse
- (e.getStatusText()): "+ e.getStatusText()); System.out.println("onHTTPResponse
- (e.getStatus()): "+ e.getStatus()); System.out.println("onHTTPResponse
- (e.getHeaders()): "+ e.getHeaders()); }
// Fired
if there is a network error public
void onNetworkError(com.webrenderer.event.NetworkEvent e)
{ System.out.println("onNetworkError
- (e.getFailure()): "+ e.getFailure()); }
// Fired
when the network status changes - Status
is the paged download progress public
void onNetworkStatus(com.webrenderer.event.NetworkEvent e)
{ System.out.println("onNetworkStatus
- (e.getStatus()): "+e.getStatus()); }
// Fired
to update the progress of the document load
- useful for status and progress bars public
void onProgressChange(com.webrenderer.event.NetworkEvent e)
{ System.out.println("onProgressChange
- (e.getCurrentProgress): "+ e.getCurrentProgress()); System.out.println("onProgressChange
- (e.getMaximumProgress): "+ e.getMaximumProgress()); } });
Capturing Key Events within WebRenderer
Capturing Key Events witin the WebRenderer component follow
standard Java convention. A key listener is added to the component, and the
events are implemented and results are returned.
IBrowserCanvas browser =
BrowserFactory.spawnMozilla();
browser.addKeyListener(new com.webrenderer.event.KeyListener()
{ // Fired when a key is pressed - combination
of key down and key up public void onKeyPress(com.webrenderer.event.KeyEvent e)
{ System.out.println("Key
pressed:"+e); } //
Fired when a key is held down public void
onKeyDown(com.webrenderer.event.KeyEvent e)
{ System.out.println("Key down"); }
// Fired
when a key is released public
void onKeyUp(com.webrenderer.event.KeyEvent e)
{ System.out.println("Key up"); } });
Capturing Mouse Events
within WebRenderer
Capturing
Mouse Events within the WebRenderer component follows convention in standard
java. A Mouse listener is added, interfaces are implemented and events are
returned to the browsers functions.
browser =
BrowserFactory.spawnMozilla();
browser.addMouseListener(new
com.webrenderer.event.MouseListener() { public void
onClick(com.webrenderer.event.MouseEvent
e){ System.out.println("Mouse
pressed:"+e); //
Finding out what button has been pressed if ((e.getModifiers() & 4)>0) System.out.println("Right Button
Pressed"); else System.out.println("Left Button Pressed"); } public void
onMouseDown(com.webrenderer.event.MouseEvent
e) { System.out.println("Mouse
down"); } public void
onMouseUp(com.webrenderer.event.MouseEvent
e) { System.out.println("Mouse
up"); } public void
onDoubleClick(com.webrenderer.event.MouseEvent
e) { System.out.println("Double
Click"); } });
Print Events:
The WebRenderer print listener tracks the status of print
jobs firing on status changes.
browser.addPrintListener(new PrintListener() { //
Fires when the printer status changes after
calling IBrowserCanvas print method
public void onStatusChange(PrintEvent e) { //
Gets the status of the print job - which
is either start, cancelled or undefined
System.out.println("Print
status changed to: " + e.getStatus()); } });
DOM
Events:
The
DOM Event listener class is useful for listening
for changes within HTML pages namely on
input and selection elements such as checkboxes,
radio buttons, buttons and textfields.
browser.addDOMListener(new DOMListener() { //
Fires when the printer status changes after
calling IBrowserCanvas print method
public void onButtonClicked(DOMEvent e) { //
Fired when any HTML Button is clicked
System.out.println("HTML
Button clicked"); //
Getting the selected element IElement
element = e.getTargetElement(); } public void onCheckboxChecked(DOMEvent e) { //
Fired when any HTML Checkbox is selected
System.out.println("HTML
Checkbox selected"); //
Getting the selected element IElement
element = e.getTargetElement(); } public void onCheckboxUnchecked(DOMEvent e) { //
Fired when any HTML Checkbox is un-checked/selected
System.out.println("HTML
Checkbox unselected"); //
Getting the selected element IElement
element = e.getTargetElement(); } public void onInputTextChanged(DOMEvent e) { //
Fired when any HTML Text input field changes
System.out.println("HTML
Text input changed"); //
Getting the selected element IElement
element = e.getTargetElement(); } public void onRadioSelected(DOMEvent e) { //
Fired when any HTML Radio Button is selected
System.out.println("HTML
Radio Button selected"); //
Getting the selected element IElement
element = e.getTargetElement(); } });
Javascript Events:
The
onJavaDialog event is fired when a Javascript
error dialog is shown. The purpose of this
event is to know when a Javascript error
dialog is to be shown and handle it in a
graceful manner. The blockDialog method
in JavascriptEvent prevents the dialog from
showing.
browser.addJavascriptListener(new JavascriptListener(){ public void
onJavascriptDialog(JavascriptEvent e) { e.blockDialog(); //Stops the
dialog from being shown } });
Prompt Events:
Prompt
Events are fired when a Javascript alert
dialog is shown (Internet Explorer) or
any dialog is shown (Mozilla).
Using the blockDialog method in PromptEvent
one can prevent dialogs from showing and
therefore not require user interaction.
browser.addPromptListener(new PromptListener(){ public void
onPromptDialog(PromptEvent e) { System.out.println("Blocking a dialog
with type: "+e.getDialogType()); e.blockPromptDialog(); //Stops the
dialog from being shown } });
Window
Events:
The
Window Events class allows for the captuing
of popup window events and gives handles
to the popup window browser objects. The
Window Event class also has methods for
capturing popup window resize and destroy
events.
browser.addWindowListener(new
WindowListener() { // Fired when a popup window
is to be displayed public void
onNewWindow(WindowtEvent e) { //
If this event is captured you must handle
the display of the popup window IBrowserCanvas
browser = e.getPopupBrowser(); //
The browser can then be placed into a JFrame
and displayed. This is useful for customizing
popups. } //
Fired when the Window receives a resize
event public void
onWindowResize(WindowtEvent e) { System.out.println("Browser
resize event: - Width: " + e.getWidth()
+ " and Height: " + e.getHeight() ); } //
Fired when the browser window is destroyed public void
onWindowDestroy(WindowtEvent e) { System.out.println("Browser
Window destroyed"); } });
|