junit.extensions.jfcunit.eventdata
Class JFCEventManager

java.lang.Object
  extended byjunit.extensions.jfcunit.eventdata.JFCEventManager
All Implemented Interfaces:
java.awt.event.AWTEventListener, EventDataConstants, java.util.EventListener

public final class JFCEventManager
extends java.lang.Object
implements java.awt.event.AWTEventListener, EventDataConstants

This class provides a recording capabilities for AWTEvents. AWTEvents are translated into their coresponding Event Data types. An application may register a listener against this class, to receive the event data. This class temporarily holds events until either a different event type is received or a timer expires on the event.

Author:
Kevin Wilson

Field Summary
static int DEBUG_ALL
          All debugging types.
static int DEBUG_CREATE
          EventData creations.
static int DEBUG_INPUT
          AWTEvent inputs.
static int DEBUG_OUTPUT
          EventData outputs.
static java.lang.String EVENT_DEBUG
          Used to turn on debug info.
static java.lang.String EVENT_MAPPING_PROPERTY
          Event Mapping Property.
private  long m_holdTime
          Hold time for the timer thread before firing the pending event.
private  long m_lastEventTime
          Time when the last event was recorded.
private  javax.swing.event.EventListenerList m_listenerList
          Listener list.
private  AbstractEventData m_pendingEvent
          Pending event held for consolidation.
private  boolean m_recording
          Recording state.
private  java.lang.Thread m_timerThread
          Timer Thread used to send the pending event.
private static boolean s_debug
          Debug flag set by UIManager property JFCEventManager.debug="true".
private static int s_debugType
          Debugging type to be used.
private static JFCEventManager s_singleton
          This is a singleton class.
 
Fields inherited from interface junit.extensions.jfcunit.eventdata.EventDataConstants
CENTER, CUSTOM, DEFAULT_HOLDTIME, DEFAULT_ISPOPUPTRIGGER, DEFAULT_KEY_MODIFIERS, DEFAULT_MOUSE_MODIFIERS, DEFAULT_NUMBEROFCLICKS, DEFAULT_POPUP_MODIFIERS, DEFAULT_POSITION, DEFAULT_SCROLL_AMOUNT, DEFAULT_SLEEPTIME, DEFAULT_WHEEL_ROTATION, DOWN_ARROW_SUBCOMPONENT, EAST, EDITOR_SUBCOMPONENT, INVALID_SUBCOMPONENT, INVALID_TEXT_OFFSET, NORTH, NORTH_EAST, NORTH_WEST, OFFSET, PERCENT, POSITIONSTRINGS, SOUTH, SOUTH_EAST, SOUTH_WEST, UP_ARROW_SUBCOMPONENT, WEST
 
Constructor Summary
private JFCEventManager(long holdTime)
          Private constructor.
 
Method Summary
 void addJFCEventDataListener(JFCEventDataListener jl)
          Add a listener.
 boolean convertDrag(java.awt.AWTEvent ae)
          Converts the event to a drag event if necessary.
 AbstractEventData createEvent(java.awt.AWTEvent ae)
          Create a event for the data given.
 void eventDispatched(java.awt.AWTEvent ae)
          This method implements the AWTEventListener interface.
protected  void fireEventData()
          Fire event data to the listeners.
static boolean getDebug()
          Get the state of debugging.
static int getDebugType()
          Get the debugging type.
static JFCEventManager getEventManager()
          Returns a singleton instance of this class.
static JFCEventManager getEventManager(long holdTime)
          Returns a singleton instance of this class.
 long getHoldTime()
          Get the maximum hold time for a event.
 boolean getRecording()
          Get the current recording state.
protected  void processEventData(java.awt.AWTEvent ae)
          This method converts the AWTEvent to the corresponding AbstractEventData.
 void removeAllJFCEventDataListeners()
          Remove all listeners.
 void removeJFCEventDataListener(JFCEventDataListener jl)
          Remove a listener.
static void setDebug(boolean aValue)
          Enable/Disable debug tracing of events.
static void setDebugType(int type)
          Set the debugging type.
 void setHoldTime(long holdTime)
          Set the maximum hold time for a event.
static void setRecording(boolean recording)
          Set the recording state.
private  void setRecordingImpl(boolean recording)
          Set the recording state.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

EVENT_MAPPING_PROPERTY

public static final java.lang.String EVENT_MAPPING_PROPERTY
Event Mapping Property.

See Also:
Constant Field Values

EVENT_DEBUG

public static final java.lang.String EVENT_DEBUG
Used to turn on debug info.

See Also:
Constant Field Values

s_singleton

private static JFCEventManager s_singleton
This is a singleton class. There should never be more than one recording session.


s_debug

private static boolean s_debug
Debug flag set by UIManager property JFCEventManager.debug="true".


DEBUG_INPUT

public static final int DEBUG_INPUT
AWTEvent inputs.

See Also:
Constant Field Values

DEBUG_OUTPUT

public static final int DEBUG_OUTPUT
EventData outputs.

See Also:
Constant Field Values

DEBUG_CREATE

public static final int DEBUG_CREATE
EventData creations.

See Also:
Constant Field Values

DEBUG_ALL

public static final int DEBUG_ALL
All debugging types.

See Also:
Constant Field Values

s_debugType

private static int s_debugType
Debugging type to be used.


m_pendingEvent

private AbstractEventData m_pendingEvent
Pending event held for consolidation.


m_listenerList

private javax.swing.event.EventListenerList m_listenerList
Listener list.


m_timerThread

private java.lang.Thread m_timerThread
Timer Thread used to send the pending event.


m_recording

private boolean m_recording
Recording state.


m_holdTime

private long m_holdTime
Hold time for the timer thread before firing the pending event.


m_lastEventTime

private volatile long m_lastEventTime
Time when the last event was recorded.

Constructor Detail

JFCEventManager

private JFCEventManager(long holdTime)
Private constructor. The method getEventManager() should be used instead.

Parameters:
holdTime - duration to hold a pending event.
Method Detail

setDebug

public static void setDebug(boolean aValue)
Enable/Disable debug tracing of events.

Parameters:
aValue - true if debugging is to be turned on.

getDebug

public static boolean getDebug()
Get the state of debugging.

Returns:
true if debugging is enabled.

setDebugType

public static void setDebugType(int type)
Set the debugging type.

Parameters:
type - DEBUG_INPUT, DEBUG_OUTPUT and/or DEBUG_CREATE

getDebugType

public static int getDebugType()
Get the debugging type.

Returns:
sum of current debugging types.

getEventManager

public static JFCEventManager getEventManager()
Returns a singleton instance of this class. This method should be used instead of the constructor. to attempt to consolidate events.

Returns:
JFCEventManager singleton instance.

getEventManager

public static JFCEventManager getEventManager(long holdTime)
Returns a singleton instance of this class. This method should be used instead of the constructor.

Parameters:
holdTime - druration a event should be held to attempt to consolidate events.
Returns:
JFCEventManager singleton instance.

setRecording

public static void setRecording(boolean recording)
Set the recording state.

Parameters:
recording - true if enabled. Otherwise false.

setHoldTime

public void setHoldTime(long holdTime)
Set the maximum hold time for a event.

Parameters:
holdTime - maximum duration in millis to hold a event.

getHoldTime

public long getHoldTime()
Get the maximum hold time for a event.

Returns:
long maximum hold time.

getRecording

public boolean getRecording()
Get the current recording state.

Returns:
boolean recording state. True if recording is enabled. Otherwise, false.

addJFCEventDataListener

public void addJFCEventDataListener(JFCEventDataListener jl)
Add a listener.

Parameters:
jl - Listener to be added.

convertDrag

public boolean convertDrag(java.awt.AWTEvent ae)
Converts the event to a drag event if necessary.

Parameters:
ae - Event to be processed.
Returns:
true if converted to drag event.

createEvent

public AbstractEventData createEvent(java.awt.AWTEvent ae)
Create a event for the data given.

Parameters:
ae - Event to be processed.
Returns:
true if the event is created.

eventDispatched

public void eventDispatched(java.awt.AWTEvent ae)
This method implements the AWTEventListener interface. This method will be accessed for every AWTEvent which is of the type: MOUSE_MOTION_EVENT, MOUSE_EVENT, KEY_EVENT, or TEXT_EVENT.

Specified by:
eventDispatched in interface java.awt.event.AWTEventListener
Parameters:
ae - Event to be processed.

removeAllJFCEventDataListeners

public void removeAllJFCEventDataListeners()
Remove all listeners.


removeJFCEventDataListener

public void removeJFCEventDataListener(JFCEventDataListener jl)
Remove a listener.

Parameters:
jl - Listener to be removed.

fireEventData

protected void fireEventData()
Fire event data to the listeners.


processEventData

protected void processEventData(java.awt.AWTEvent ae)
This method converts the AWTEvent to the corresponding AbstractEventData.

Parameters:
ae - AWTEvent to be processed.

setRecordingImpl

private void setRecordingImpl(boolean recording)
Set the recording state.

Parameters:
recording - true if recording is to be enabled. otherwise false.


Licensed under: GNU Lesser General Public License, Ver 2.1, February 1999