vrml.eai.event
Class BrowserEvent

java.lang.Object
  extended by vrml.eai.event.BrowserEvent

public class BrowserEvent
extends java.lang.Object

Contains information about a browser event. When you implement a BrowserListener, you'll get a BrowserEvent object as a parameter that contains a reference to the Browser object whose status changed as well as an event ID that specifies what exactly happened.

The following example shows the skeleton of a browser listener, and how the BrowserEvent object is used inside the listener:

 class MyBrowserListener implements vrml.eai.event.BrowserListener
 {
     public void browserChanged(vrml.eai.event.BrowserEvent evt)
     {
         // Get the Browser object whose status changed
         vrml.eai.Browser browser = evt.getSource();
         switch (evt.getID())
         {
         case vrml.eai.event.BrowserEvent.INITIALIZED:
             // The browser finished to load a new scene
             ...
             break;
         case vrml.eai.event.BrowserEvent.SHUTDOWN:
             // The browser is about to unload a scene
             ...
             break;
         case vrml.eai.event.BrowserEvent.URL_ERROR:
             // Download from an URL failed
             ...
             break;
         case vrml.eai.event.BrowserEvent.CONNECTION_ERROR:
             // An error occurred when communicating with the browser
             ...
             break;
         }
     }
 }
 


Field Summary
static int CONNECTION_ERROR
          Identifier for events that get sent when the communication with the browser failed.
static int INITIALIZED
          Identifier for events that get sent when the browser finished to load a new 3D scene.
static int LAST_IDENTIFIER
          Defines the first event identifier that is not used by EAI standard events.
static int SHUTDOWN
          Identifier for events that get sent when the browser is about to unload a 3D scene.
static int URL_ERROR
          Identifier for events that get sent when the download from an URL failed.
 
Constructor Summary
BrowserEvent(Browser b, int action)
          Initializes a BrowserEvent with a given browser and event ID.
 
Method Summary
 int getID()
          Returns the type of event.
 Browser getSource()
          Returns the Browser object that produced this event.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

INITIALIZED

public static final int INITIALIZED
Identifier for events that get sent when the browser finished to load a new 3D scene. The Browser object issues an INITIALIZED event when the X3D browser finished to load a 3D scene. This happens after calling the Browser.loadURL(java.lang.String[], java.lang.String[]) or Browser.replaceWorld(vrml.eai.Node[]) methods of the Browser object, or when the user loads a new scene via the browser user interface.

You usually use this event as a hint when to start interaction with a new scene after calling Browser.loadURL(java.lang.String[], java.lang.String[]) or Browser.replaceWorld(vrml.eai.Node[]), i.e. after receiving this event it is possible to get references to nodes by calling Browser.getNode(java.lang.String), or to create new routes by calling Browser.addRoute(vrml.eai.Node, java.lang.String, vrml.eai.Node, java.lang.String).

The following example demonstrates how to check if an INITIALIZED event happened:

 vrml.eai.event.BrowserEvent evt = ...;
 if (evt.getID() == vrml.eai.event.BrowserEvent.INITIALIZED)
 {
     // The browser finished to load a new scene
     ...
 }
 

See Also:
Constant Field Values

SHUTDOWN

public static final int SHUTDOWN
Identifier for events that get sent when the browser is about to unload a 3D scene. The Browser object issues a SHUTDOWN event when the X3D browser is about to unload a 3D scene. This happens after calling the Browser.loadURL(java.lang.String[], java.lang.String[]) or Browser.replaceWorld(vrml.eai.Node[]) methods of the Browser object, or when the user loads a new scene via the browser user interface or quits the browser.

Receiving this event means that all existing references to nodes, event-in slots and event-out slots are about to become invalid. Do not call any methods of these objects anymore, instead dispose them.

The following example demonstrates how to check if a SHUTDOWN event happened:

 vrml.eai.event.BrowserEvent evt = ...;
 if (evt.getID() == vrml.eai.event.BrowserEvent.SHUTDOWN)
 {
     // The browser is about to unload a scene
     ...
 }
 

See Also:
Constant Field Values

URL_ERROR

public static final int URL_ERROR
Identifier for events that get sent when the download from an URL failed. The Browser object issues an URL_ERROR event when the download from an URL failed. This might happen after calling the Browser.loadURL(java.lang.String[], java.lang.String[]) or Browser.replaceWorld(vrml.eai.Node[]) methods of the Browser object.

The following example demonstrates how to check if an URL_ERROR event happened:

 vrml.eai.event.BrowserEvent evt = ...;
 if (evt.getID() == vrml.eai.event.BrowserEvent.URL_ERROR)
 {
     // Download from an URL failed
     ...
 }
 

See Also:
Constant Field Values

CONNECTION_ERROR

public static final int CONNECTION_ERROR
Identifier for events that get sent when the communication with the browser failed. The Browser object issues a CONNECTION_ERROR event when the communication with the browser failed. This can happen anytime and usually means that you have to reinitialize the whole session by creating a new Browser object.

The following example demonstrates how to check if a CONNECTION_ERROR event happened:

 vrml.eai.event.BrowserEvent evt = ...;
 if (evt.getID() == vrml.eai.event.BrowserEvent.CONNECTION_ERROR)
 {
     // An error occurred when communicating with the browser
     ...
 }
 

See Also:
Constant Field Values

LAST_IDENTIFIER

public static final int LAST_IDENTIFIER
Defines the first event identifier that is not used by EAI standard events. All event IDs for EAI standard events are smaller than this identifier. There might be browser-specific events whose ID is greater than or equal to this identifier.

The following example demonstrates how to check if a browser event is a standard EAI event or a browser-specific event:

 vrml.eai.event.BrowserEvent evt = ...;
 if (evt.getID() < vrml.eai.event.BrowserEvent.LAST_IDENTIFIER)
 {
     // A standard EAI event happened
     ...
 }
 else
 {
     // A browser-specific event happened
     ...
 }
 

See Also:
Constant Field Values
Constructor Detail

BrowserEvent

public BrowserEvent(Browser b,
                    int action)
             throws java.lang.IllegalArgumentException
Initializes a BrowserEvent with a given browser and event ID. Usually, you do not create your own browser events - they get generated by the Browser object when its status changes, and you get them as a parameter to your implementation of BrowserListener.browserChanged(vrml.eai.event.BrowserEvent). But nevertheless this constructor is public which allows you to create your own events and send them to your listener.

The following example demonstrates how you can create your own URL_ERROR event and send it to your delegate:

 vrml.eai.Browser browser = ...;
 vrml.eai.event.BrowserEvent evt = new vrml.eai.event.BrowserEvent(browser, vrml.eai.event.BrowserEvent.URL_ERROR);
 listener.browserChanged(evt);
 

Parameters:
b - The Browser object that produced this event.
action - The type of event. This is should be one of the constants INITIALIZED, SHUTDOWN, URL_ERROR or CONNECTION_ERROR defined in this class.
Throws:
java.lang.IllegalArgumentException - when you specify an invalid event type.
Method Detail

getID

public int getID()
Returns the type of event. This is one of the constants INITIALIZED, SHUTDOWN, URL_ERROR or CONNECTION_ERROR defined in this class. This method allows the get information about which specific event actually happened. The type gets set via the BrowserEvent(Browser, int) constructor when creating new BrowserEvent objects.

The following example shows how to find out which type of event actually happened:

 vrml.eai.event.BrowserEvent evt = ...;
 switch (evt.getID())
 {
 case vrml.eai.event.BrowserEvent.INITIALIZED:
     // The browser finished to load a new scene
     ...
     break;
 case vrml.eai.event.BrowserEvent.SHUTDOWN:
     // The browser is about to unload a scene
     ...
     break;
 case vrml.eai.event.BrowserEvent.URL_ERROR:
     // Download from an URL failed
     ...
     break;
 case vrml.eai.event.BrowserEvent.CONNECTION_ERROR:
     // An error occurred when communicating with the browser
     ...
     break;
 }
 

Returns:
The type of event.

getSource

public Browser getSource()
Returns the Browser object that produced this event. This object gets set via the BrowserEvent(Browser, int) constructor when creating new BrowserEvent objects.

The following example shows how to find out which Browser object created the event:

 vrml.eai.event.BrowserEvent evt = ...;
 vrml.eai.Browser browser = evt.getSource();
 

Returns:
The Browser object that produced this event.