vrml.eai.event
Class VrmlEvent

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

public class VrmlEvent
extends java.lang.Object

Contains information about a VRML event. When you implement a VrmlEventListener, you'll get a VrmlEvent object as a parameter that contains a reference to the EventOut object that fired the event as well as a timestamp and the user-provided data object attached to the EventOut object.

The following example shows the skeleton of a vrml event listener, and how the VrmlEvent object is used inside the listener:

 class MyVrmlEventListener implements vrml.eai.event.VrmlEventListener
 {
     private vrml.eai.field.EventOutSFColor diffuseColor_changed;
     ...
     public void eventOutChanged(VrmlEvent evt)
     {
         vrml.eai.field.BaseField field = evt.getSource();
         double time = evt.getTime();
         Object data = evt.getData();
         if (field == diffuseColor_changed)
         {
             // diffuseColor_changed event-out slot fired an event
             ...
         }
     }
     ...
 }
 


Constructor Summary
VrmlEvent(BaseField src, double ts, java.lang.Object data)
          Initializes a VrmlEvent with a given EventOut object, timestamp and user-provided data object.
 
Method Summary
 java.lang.Object getData()
          The user-provided data object attached to the event-out slot that fired the event.
 BaseField getSource()
          Returns the event-out slot that fired the event.
 double getTime()
          Returns the time when the event happened.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

VrmlEvent

public VrmlEvent(BaseField src,
                 double ts,
                 java.lang.Object data)
Initializes a VrmlEvent with a given EventOut object, timestamp and user-provided data object. Usually, you do not create your own VRML events - they get generated by the EventOut object when it fires an event, and you get them as a parameter to your VrmlEventListener. But nevertheless this constructor is public which allows you to create your own events and send them to your listener.

Parameters:
src - The event-out slot whose value changed.
ts - The time when the event happened, measured in seconds since January the 1st, 1970, 00:00:00 GMT.
data - A user-provided data object.
Method Detail

getSource

public BaseField getSource()
Returns the event-out slot that fired the event. This slot gets set via the VrmlEvent(vrml.eai.field.BaseField, double, java.lang.Object) constructor when creating new VrmlEvent objects.

The following example shows how to get the EventOut object from the event:

 vrml.eai.event.VrmlEvent evt = ...;
 vrml.eai.field.BaseField field = evt.getSource();
 

Returns:
The event-out slot that fired the event.

getTime

public double getTime()
Returns the time when the event happened. The time is specified as the number of seconds since January the 1st, 1970, 00:00:00 GMT. This time gets set via the VrmlEvent(vrml.eai.field.BaseField, double, java.lang.Object) constructor when creating new VrmlEvent objects.

The following example gets the timestamp from the event, converts it to a Date object, and prints it to the console:

 vrml.eai.event.VrmlEvent evt = ...;
 Date date = new Date((long)(evt.getTime() * 1000.0));
 System.out.println("Date = " + date);
 

Returns:
The time when the event happened.

getData

public java.lang.Object getData()
The user-provided data object attached to the event-out slot that fired the event. You can attach data objects to event-out slot by calling their EventOut.setUserData(java.lang.Object) method. This object gets set via the VrmlEvent(vrml.eai.field.BaseField, double, java.lang.Object) constructor when creating new VrmlEvent objects.

The following example shows how to get the user-provided data object from the event:

 vrml.eai.event.VrmlEvent evt = ...;
 Object data = evt.getData();
 

Returns:
The user-provided data object.