source.ucregents.playground.gui
Class UserEvent

java.lang.Object
  extended by source.ucregents.playground.gui.UserEvent

public class UserEvent
extends java.lang.Object

The UserEvent object stores all the components necessary to invoke any number of methods using reflection. This way you can dynamically add player events to an object to make them controllable by mouse and keyboard input.


Field Summary
static int OBJECT_COLLIDED
           
static int OBJECT_DESTROYED
           
 
Constructor Summary
UserEvent()
           
UserEvent(int e, int es, java.lang.reflect.Method meth, java.lang.Object[] p, java.lang.Object obj)
          Constructor that accepts a single method and set of parameters rather than a vector of methods.
UserEvent(int e, int es, java.lang.Object obj)
          Simple constructor that accepts no methods or parameters.
UserEvent(int e, int es, java.util.Vector<java.lang.reflect.Method> meth, java.util.Vector<java.lang.Object[]> p, java.lang.Object obj)
          Main constructor.
 
Method Summary
 void addMethod(java.lang.reflect.Method m)
           
 void addMethodAndParams(java.lang.reflect.Method m, java.lang.Object[] p)
          Add a set of corresponding methods and parameters to the UserEvent vectors
 void addParams(java.lang.reflect.Method m)
           
 UserEvent cloneTo(java.lang.Object obj)
          Create a cloned version of this event to a given object
 void execute()
          Attempt to invoke all methods with the given parameters.
 java.lang.String getActionCommand()
           
 int getEventSubType()
           
 int getEventType()
           
 java.util.Vector<java.lang.reflect.Method> getMethods()
           
 java.lang.Object getObject()
           
 java.util.Vector<java.lang.Object[]> getParameters()
           
 void removeMethod(int index)
           
 void setActionCommand(java.lang.String s)
          The set action command allows you to associate the user event with whatever text you like.
 void setEventSubType(int es)
           
 void setEventType(int e)
           
 void setMethod(java.util.Vector<java.lang.reflect.Method> meth)
           
 void setObject(java.lang.Object obj)
           
 void setParameters(java.util.Vector<java.lang.Object[]> p)
           
 java.lang.String toString()
          Associates this UserEvent with a string.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

OBJECT_COLLIDED

public static final int OBJECT_COLLIDED
See Also:
Constant Field Values

OBJECT_DESTROYED

public static final int OBJECT_DESTROYED
See Also:
Constant Field Values
Constructor Detail

UserEvent

public UserEvent()

UserEvent

public UserEvent(int e,
                 int es,
                 java.lang.reflect.Method meth,
                 java.lang.Object[] p,
                 java.lang.Object obj)
Constructor that accepts a single method and set of parameters rather than a vector of methods. The main constructor is called and the method and parameters are added to the class's appropriate vectors

Parameters:
e - event type which corresponds to the event ids (e.g. MouseEvent.MOUSE_PRESSED)
es - event sub-type which corresponds to the exact event (e.g MouseEvent.BUTTON1)
meth - Method to add to the method container for the object
p - parameters that correspond to the given method
obj - Object on which to invoke the given method

UserEvent

public UserEvent(int e,
                 int es,
                 java.lang.Object obj)
Simple constructor that accepts no methods or parameters. Designed for easy object-association with the event tree nodes in EventManagerFrame: these nodes should represent UserEvent objects, but don't yet have any methods or parameters associated.

Parameters:
e - event type which corresponds to the event ids (e.g. MouseEvent.MOUSE_PRESSED)
es - event sub-type which corresponds to the exact event (e.g MouseEvent.BUTTON1)
obj - Object on which to invoke the specified method

UserEvent

public UserEvent(int e,
                 int es,
                 java.util.Vector<java.lang.reflect.Method> meth,
                 java.util.Vector<java.lang.Object[]> p,
                 java.lang.Object obj)
Main constructor. Defines event type, method to invoke, and parameters

Parameters:
e - event type which corresponds to the event ids (e.g. MouseEvent.MOUSE_PRESSED)
es - event sub-type which corresponds to the exact event (e.g MouseEvent.BUTTON1)
meth - Vector of Methods to invoke on the given object
p - Vector of parameters that correspond on a one-to-one basis with the method vector
obj - Object on which to invoke the given methods
Method Detail

addMethod

public void addMethod(java.lang.reflect.Method m)

addMethodAndParams

public void addMethodAndParams(java.lang.reflect.Method m,
                               java.lang.Object[] p)
Add a set of corresponding methods and parameters to the UserEvent vectors

Parameters:
m - Method to add
p - Parameters to send to the method

addParams

public void addParams(java.lang.reflect.Method m)

cloneTo

public UserEvent cloneTo(java.lang.Object obj)
Create a cloned version of this event to a given object

Parameters:
obj -
Returns:
Returns a copy of this object but with the parameters as needed by the new Object

execute

public void execute()
Attempt to invoke all methods with the given parameters.


getActionCommand

public java.lang.String getActionCommand()

getEventSubType

public int getEventSubType()

getEventType

public int getEventType()

getMethods

public java.util.Vector<java.lang.reflect.Method> getMethods()

getObject

public java.lang.Object getObject()

getParameters

public java.util.Vector<java.lang.Object[]> getParameters()

removeMethod

public void removeMethod(int index)

setActionCommand

public void setActionCommand(java.lang.String s)
The set action command allows you to associate the user event with whatever text you like. For example, you might want to add a User Event to a list and would like the list to display "Up Arrow" rather than the object's default tostring()

Parameters:
s -

setEventSubType

public void setEventSubType(int es)

setEventType

public void setEventType(int e)

setMethod

public void setMethod(java.util.Vector<java.lang.reflect.Method> meth)

setObject

public void setObject(java.lang.Object obj)

setParameters

public void setParameters(java.util.Vector<java.lang.Object[]> p)

toString

public java.lang.String toString()
Associates this UserEvent with a string. This string may be defined by the user through the setActionCommand method, or the class will attempt to determine the appropriate text to display. Using the auto-detect, it will just display the key or button that was pressed.

Overrides:
toString in class java.lang.Object