DirectX Media for Animation Java Reference Previous
Previous
Classes
Classes
Index
Index
Next
Next

DXMEvent Class

Constructor , Methods , Fields

public class DXMEvent extends Behavior{
    // Fields
    public static DXMEvent always;
    public static DXMEvent leftButtonDown;
    public static DXMEvent leftButtonUp;
    public static DXMEvent never;
    public static DXMEvent rightButtonDown;
    public static DXMEvent rightButtonUp;

    // Constructor
    public DXMEvent();

    // Methods
    public DXMEvent attachData(Object object);
    public DXMEvent notifyEvent(UntilNotifier notifier);
    public Object registerCallback(EventCallbackObject object, double eventTime, BehaviorCtx ctx, boolean bool);
    public DXMEvent snapshotEvent(Behavior a);
    
    public static DXMEvent andEvent(DXMEvent first, DXMEvent second);
    public static DXMEvent newUninitBvr();
    public static DXMEvent notEvent(DXMEvent ev);
    public static DXMEvent orEvent(DXMEvent first, DXMEvent second);
    public static DXMEvent predicate(BooleanBvr bool);
    public static DXMEvent thenEvent(DXMEvent e1, DXMEvent e2);
    public static DXMEvent timer(NumberBvr timeout);
    public static void unregisterCallback(Object object);
}

Creates an object that represents an event. Events identify specific times, states or user actions and are used to specify when given actions should occur. Typically, you use events with the until and untilNotify methods to create behaviors that change as a result of the event. For example, you can change the color of an object when the user presses a mouse button by specifying the mouse button event in a call to the until method of the ColorBvr class. Every event, when it occurs, returns some event data. This data may or may not be meaningful. The data returned, for example, by leftButtonDown has no meaning.

You can combine existing events to create new, more complex events. For example, the andEvent method lets you combine two events so that the resulting event occurs only if both of the original events occur simultaneously.


Constructor


DXMEvent

public DXMEvent();

Constructs an DXMEvent object.


Methods


attachData

public DXMEvent attachData(Object object);

Takes an arbitrary object and produces a new event. The new event occurs at the same time as the original event, but its data is now the data that was specified in the call to attachData. This allows an application to associate arbitrary client data with an event and know that it will be delivered to the notifier when the event occurs. In the following example, the behavior is red until the left mouse button is pressed. It then passes either green or yellow, depending on what is returned by the notifier.

DXMEvent greenLeft = leftButtonDown.attachData(green);
DXMEvent yellowright = rightButtonDown.attachData(yellow);
ColorBvr myBvr = (ColorBvr)untilNotify(red, orEvent(greenLeft, yellowRight), notifier);

Return Value:

Returns a DXMEvent object. The event data is the event data of the new event.

ParameterDescription
object An arbitrary object.


notifyEvent

public DXMEvent notifyEvent(UntilNotifier notifier);

Creates a new event. This occurs when the original event occurs. It then calls the notifier and uses the result as its event data.

Return Value:

Returns the DXMEvent object. The event data is the time the event fired and the new behavior.

ParameterDescription
notifier Returns the new behavior.


registerCallback

public Object registerCallback(EventCallbackObject object, double startTime, BehaviorCtx ctx, boolean bool);

Causes an external action when an event occurs in Direct Animation for Java and is used in conjunction with the EventCallbackObject. Whenever that event occurs, the invoke method of the callback is called with the event data produced by the event. An example of where this method is used is displaying a GUI window when the mouse moves to a particular area.

Return Value:

Returns an object of type java.lang.Object. This object can be used to unregister the callback.

ParameterDescription
object An object that implements the EventCallback interface.
startTime The start time of the event.
ctx Contains state information (such as the view).
bool If true, the first occurrence of the event will trigger invoke. If false, every occurrence of the event will trigger invoke.

See Also: unregisterCallback


andEvent

public static DXMEvent andEvent(DXMEvent first, DXMEvent second);

Creates an event that occurs only when the two given events happen simultaneously. The event time for the new event is when both of the given events occur.

Return Value:

Returns a DXMEvent object. When the event occurs, it produces a PairObject. The first member is the event data returned by the first event. The second member is the event data returned by the second event.

ParameterDescription
first and second The DXMEvent objects.


newUninitBvr

public static newUninitBvr();

This method allows you to refer to an DXMEvent behavior before that behavior has been defined. With this method you can create the behavior and use it in the definition of other behaviors, but not actually define its contents until some later point. (This is accomplished with the init method, which is available on all behaviors.) The system generates a run-time error if you initialize a non-uninitialized behavior, initialize an uninitialized behavior that has already been initialized, or run an initialized behavior that has not yet been initialized.

Return Value:

Returns the DXMEvent object.


notEvent

public static DXMEvent notEvent(DXMEvent ev);

Creates an event that occurs when the given event does not occur. This is useful for creating combined events that occur only if the given event is not also occurring, for example, an event that occurs when the left mouse button is down and the right button is not down.

Return Value:

Returns the DXMEvent object. This event produces no data.

ParameterDescription
ev The DXMEvent object.


orEvent

public static DXMEvent orEvent(DXMEvent first, DXMEvent second);

Creates an event that occurs when either one of the given events occur. The event time for the new event is when either the first or second given event has occurred.

Return Value:

Returns a DXMEvent object. Its data is the event data of either the first or second event.

ParameterDescription
first and second The DXMEvent objects.


predicate

public static DXMEvent predicate(BooleanBvr bool);

Creates an event that occurs when the value of the given Boolean behavior changes from false to true. Note that, because of implementation dependencies and the potential for aliasing, the system cannot always detect when a Boolean behavior becomes true. For example, the expression: predicate(eq(sin(localTime), toBvr(0))) may never occur unless the system happens to sample it when sin(localTime)is exactly zero. Therefore, it is advisable to use inequality comparisons (for example, gte) rather than equality comparisons (for example, eq). Alternatively, the timer constructor may be a better choice for these situations.

Return Value:

Returns the DXMEvent. This event produces no data.

ParameterDescription
bool The BooleanBvr object.


snapshotEvent

public DXMEvent snapshotEvent(Behavior a);

When called on an instance of a behavior, samples the given behavior and returns it as a constant behavior with the value as data. The event time of the new event is when the original event occurs. In the following example, the value of n is localTime until the left mouse button is pressed. It then becomes whatever the value of localTime was when the event occurred:


n=until(localTime, leftButtonDown.snapshotEvent(localTime));

Return Value:

Returns the DXMEvent object. The event data is the value of the behavior at the time it was sampled, returned as a constant behavior.

ParameterDescription
a The Behavior object which will be sampled when the method is invoked.


thenEvent

public static DXMEvent thenEvent(DXMEvent e1, DXMEvent e2);

Creates an event if e2 occurs after e1. The event time of the new event is the time of the second event.

Return Value:

Returns the DXMEvent object. Its event data is the time the second event fired and a PairObject containing the event data for both events.

ParameterDescription
e1 The first event, that, when it occurs, triggers the second event.
e2 The second event, caused by the occurrence of the first event.


timer

public static DXMEvent timer(NumberBvr timeout);

Creates an event that occurs when the specified time has elapsed.

Return Value:

Returns the DXMEvent object. This event produces no data.

ParameterDescription
timeout The NumberBvr object.


unregisterCallback

public static void unregisterCallback(Object object);

Used to unregister the callback.

ParameterDescription
object The object used to unregister the callback.

See Also: registerCallback


Fields

always
An event (DXMEvent object) that occurs at all times. It produces no data.
leftButtonDown
An event that occurs when the left mouse button is down.
leftButtonUp
An event that occurs when the left mouse button is up.
never
An event (DXMEvent object) that never occurs. It produces no data.
rightButtonDown
An event that occurs when the right mouse button is down.
rightButtonUp
An event that occurs when the right mouse button is up.


Top© 1997 Microsoft Corporation. All rights reserved. Legal Notices.