net.xoetrope.swt
Class XSwtEventHandler

java.lang.Object
  extended by net.xoetrope.swt.XSwtEventHandler
All Implemented Interfaces:
java.util.EventListener, XuiEventHandler, org.eclipse.swt.events.FocusListener, org.eclipse.swt.events.KeyListener, org.eclipse.swt.events.MouseListener, org.eclipse.swt.events.MouseMoveListener, org.eclipse.swt.events.MouseTrackListener, org.eclipse.swt.events.SelectionListener, org.eclipse.swt.internal.SWTEventListener

public class XSwtEventHandler
extends java.lang.Object
implements XuiEventHandler, org.eclipse.swt.events.SelectionListener, org.eclipse.swt.events.FocusListener, org.eclipse.swt.events.KeyListener, org.eclipse.swt.events.MouseListener, org.eclipse.swt.events.MouseMoveListener, org.eclipse.swt.events.MouseTrackListener

Implements an event handler for XUI. Most of the common events are handled. The class is intended as a mixin for a panel class such as XPage and should not be used directly

Copyright (c) Xoetrope Ltd., 2002-2003

License: see license.txt

$Revision: 1.8 $


Field Summary
protected  java.util.Hashtable classInstances
           
protected  java.lang.Object container
           
protected static java.util.EventObject currentEvt
           
protected  XProject currentProject
           
protected  java.util.Hashtable handlers
           
protected static java.lang.Object mouseDownComponent
           
protected static boolean mouseEventInvoked
           
protected static int suppressFocusEvents
           
protected  XValidationHandler xValidationHandler
           
 
Constructor Summary
XSwtEventHandler(XProject project, java.lang.Object c, XValidationHandler vh)
          Create a new XSwtEventHandler
 
Method Summary
 void addActionHandler(java.lang.Object comp, java.lang.String methodName)
          Adds a handler for action events
 void addFocusHandler(java.lang.Object comp, java.lang.String methodName)
          Adds a handler for focus events
 XMethodReference addHandler(java.lang.Object comp, long eventType, java.lang.String methodStr)
          Adds an event handler.
 XMethodReference addHandler(java.lang.Object srcObj, java.lang.String methodName, java.lang.String adderMethod, java.lang.String listenerInterface, long eventMask, java.lang.Object listener)
          Adds a handler for action events
 void addHandler(PageSupport xpage, java.lang.Object targetComp, java.lang.String typeStr, java.lang.String methodName)
          Adds an event handler.
 void addItemHandler(java.lang.Object comp, java.lang.String methodName)
          Adds a handler for item events
 void addKeyHandler(java.lang.Object comp, java.lang.String methodName)
          Adds a handler for key events
 void addListener(java.lang.Object comp, java.lang.String listenerName, java.lang.String argType, java.lang.Object listener)
          Adds a listener for an event type.
 void addMenuHandler(java.lang.Object menuItem, java.lang.String methodName)
          Adds a handler for action events
 void addMouseHandler(java.lang.Object comp, java.lang.String methodName)
          Adds a handler for mouse events
 void addMouseMotionHandler(java.lang.Object comp, java.lang.String methodName)
          Adds a handler for mouse motion events
 void addTextHandler(java.lang.Object comp, java.lang.String methodName)
          Adds a handler for text events
 java.lang.reflect.Method findEvent(java.lang.Object src, long eventType)
          Lookup an event for a component.
 void focusGained(org.eclipse.swt.events.FocusEvent e)
           
 void focusLost(org.eclipse.swt.events.FocusEvent e)
           
 java.util.EventObject getCurrentEvent()
          Get the current event
 XValidationHandler getValidationHandler()
          Get the validation handler reference.
 void invoke(long eventType, java.util.EventObject evt)
          Invokes an event.
 boolean isFocusChangeSuppressed()
          Check the focus change status
 void keyPressed(org.eclipse.swt.events.KeyEvent e)
           
 void keyReleased(org.eclipse.swt.events.KeyEvent e)
           
 void keyTyped(org.eclipse.swt.events.KeyEvent e)
           
 void mouseClick(org.eclipse.swt.events.MouseEvent e)
           
 void mouseDoubleClick(org.eclipse.swt.events.MouseEvent e)
           
 void mouseDown(org.eclipse.swt.events.MouseEvent e)
           
 void mouseDragged(org.eclipse.swt.events.MouseEvent e)
           
 void mouseEnter(org.eclipse.swt.events.MouseEvent e)
           
 void mouseExit(org.eclipse.swt.events.MouseEvent e)
           
 void mouseHover(org.eclipse.swt.events.MouseEvent e)
           
 void mouseMove(org.eclipse.swt.events.MouseEvent e)
           
 void mouseUp(org.eclipse.swt.events.MouseEvent e)
           
 void removeHandlers(java.lang.Object comp)
          Remove all the event handlers for a particular object
 void suppressFocusEvents(boolean suppress)
          Used by messageboxes and other dialogs to prevent the display of the dialog causing extra focus events from being fired.
 boolean wasMouseClicked()
          A utility method used to determine if the last event corrseponds to a mouse click.
 boolean wasMouseDoubleClicked()
          A utility method used to determine if the last event corrseponds to a mouse double click.
 boolean wasMouseRightClicked()
          A utility method used to determine if the last event corrseponds to a mouse right click.
 void widgetDefaultSelected(org.eclipse.swt.events.SelectionEvent e)
           
 void widgetSelected(org.eclipse.swt.events.SelectionEvent e)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

currentEvt

protected static java.util.EventObject currentEvt

container

protected java.lang.Object container

currentProject

protected XProject currentProject

handlers

protected java.util.Hashtable handlers

classInstances

protected java.util.Hashtable classInstances

mouseDownComponent

protected static java.lang.Object mouseDownComponent

mouseEventInvoked

protected static boolean mouseEventInvoked

suppressFocusEvents

protected static int suppressFocusEvents

xValidationHandler

protected XValidationHandler xValidationHandler
Constructor Detail

XSwtEventHandler

public XSwtEventHandler(XProject project,
                        java.lang.Object c,
                        XValidationHandler vh)
Create a new XSwtEventHandler

Parameters:
project - project concerned
c - container object
vh - validation handler
Method Detail

removeHandlers

public void removeHandlers(java.lang.Object comp)
Remove all the event handlers for a particular object

Specified by:
removeHandlers in interface XuiEventHandler
Parameters:
comp - the object whose events are being removed

getValidationHandler

public XValidationHandler getValidationHandler()
Get the validation handler reference. Note that you should not hold a reference to this value as it will probably cause a memory leak.

Specified by:
getValidationHandler in interface XuiEventHandler
Returns:
the current validation handler

invoke

public void invoke(long eventType,
                   java.util.EventObject evt)
Invokes an event. Called in response to an event. If a handler has been added for the event it will be invoked.

Specified by:
invoke in interface XuiEventHandler
Parameters:
eventType - type of event
evt - the event object

findEvent

public java.lang.reflect.Method findEvent(java.lang.Object src,
                                          long eventType)
Lookup an event for a component.

Specified by:
findEvent in interface XuiEventHandler
Parameters:
src - the event source object
eventType - The id of the event required
Returns:
The Method object

isFocusChangeSuppressed

public boolean isFocusChangeSuppressed()
Check the focus change status

Specified by:
isFocusChangeSuppressed in interface XuiEventHandler
Returns:
true if the focus change events are being suppressed.

getCurrentEvent

public java.util.EventObject getCurrentEvent()
Get the current event

Specified by:
getCurrentEvent in interface XuiEventHandler
Returns:
the AWTEvent that was last triggered

addHandler

public XMethodReference addHandler(java.lang.Object comp,
                                   long eventType,
                                   java.lang.String methodStr)
                            throws java.lang.ClassNotFoundException,
                                   java.lang.NoSuchMethodException
Adds an event handler. A specific handler such as the addActionHandler should be used instead of calling this method

Specified by:
addHandler in interface XuiEventHandler
Parameters:
comp - the component that fires the event
methodStr - the method to be invoked in response to the object
eventType - long value indicating the mask of the event to be handled
Throws:
java.lang.ClassNotFoundException - throw if the class cannot be located
java.lang.NoSuchMethodException - throw if the named method cannot be located

addHandler

public XMethodReference addHandler(java.lang.Object srcObj,
                                   java.lang.String methodName,
                                   java.lang.String adderMethod,
                                   java.lang.String listenerInterface,
                                   long eventMask,
                                   java.lang.Object listener)
Adds a handler for action events

Specified by:
addHandler in interface XuiEventHandler
Parameters:
srcObj - the menu item that fires the events
methodName - the method to be invoked in response to the action event
adderMethod - the adder method name e.g. addActionListener
listenerInterface - the listener interface e.g. org.eclipse.swt.events.ActionListener
eventMask - the event mask e.g. AWTEvent.ACTION_EVENT_MASK
listener - the listener implementation, usually the page's this pointer
See Also:
org.eclipse.swt.events.ActionListener, org.eclipse.swt.events.ActionEvent

addListener

public void addListener(java.lang.Object comp,
                        java.lang.String listenerName,
                        java.lang.String argType,
                        java.lang.Object listener)
Adds a listener for an event type. This method should not normally be called by an application

Specified by:
addListener in interface XuiEventHandler
Parameters:
comp - the component that fires events
listenerName - the name of the listener interface
argType - the listener arguments
listener - the listener implementation

addMenuHandler

public void addMenuHandler(java.lang.Object menuItem,
                           java.lang.String methodName)
Adds a handler for action events

Parameters:
menuItem - the menu item that fires the events
methodName - the method to be invoked in response to the action event
See Also:
org.eclipse.swt.events.ActionListener, org.eclipse.swt.events.ActionEvent

addActionHandler

public void addActionHandler(java.lang.Object comp,
                             java.lang.String methodName)
Adds a handler for action events

Parameters:
comp - the component that fires the events
methodName - the method to be invoked in response to the action event
See Also:
org.eclipse.swt.events.ActionListener, org.eclipse.swt.events.ActionEvent

addFocusHandler

public void addFocusHandler(java.lang.Object comp,
                            java.lang.String methodName)
Adds a handler for focus events

Parameters:
comp - the component that fires the events
methodName - the method to be invoked in response to the focus event
See Also:
FocusListener, FocusEvent

addTextHandler

public void addTextHandler(java.lang.Object comp,
                           java.lang.String methodName)
Adds a handler for text events

Parameters:
comp - the component that fires the events
methodName - the method to be invoked in response to the text event
See Also:
org.eclipse.swt.events.TextListener, org.eclipse.swt.events.TextEvent

addItemHandler

public void addItemHandler(java.lang.Object comp,
                           java.lang.String methodName)
Adds a handler for item events

Parameters:
comp - the component that fires the events
methodName - the method to be invoked in response to the item event
See Also:
org.eclipse.swt.events.ItemListener, org.eclipse.swt.events.ItemEvent

addKeyHandler

public void addKeyHandler(java.lang.Object comp,
                          java.lang.String methodName)
Adds a handler for key events

Parameters:
comp - the component that fires the events
methodName - the method to be invoked in response to the key event
See Also:
KeyListener, KeyEvent

addMouseHandler

public void addMouseHandler(java.lang.Object comp,
                            java.lang.String methodName)
Adds a handler for mouse events

Parameters:
comp - the component that fires the events
methodName - the method to be invoked in response to the mouse event
See Also:
org.eclipse.swt.events.MouseMotionListener, MouseEvent

addMouseMotionHandler

public void addMouseMotionHandler(java.lang.Object comp,
                                  java.lang.String methodName)
Adds a handler for mouse motion events

Parameters:
comp - the component that fires the events
methodName - the method to be invoked in response to the mouse event
See Also:
org.eclipse.swt.events.MouseMotionListener, MouseEvent

wasMouseClicked

public boolean wasMouseClicked()
A utility method used to determine if the last event corrseponds to a mouse click. The notion of a click is extended by assuming the a mouse press and release within a single component constitutes a click even if not at the same coordinate. A MouseEvent.MOUSE_CLICKED is only triggered when the press and release are at the same location and this is often inadequate for end-user interaction.

Specified by:
wasMouseClicked in interface XuiEventHandler
Returns:
true if the mouse was clicked

wasMouseDoubleClicked

public boolean wasMouseDoubleClicked()
A utility method used to determine if the last event corrseponds to a mouse double click. The notion of a click is extended by assuming the a mouse press and release within a single component constitutes a click even if not at the same coordinate. A MouseEvent.MOUSE_CLICKED is only triggered when the press and release are at the same location and this is often inadequate for end-user interaction.

Specified by:
wasMouseDoubleClicked in interface XuiEventHandler
Returns:
true if the mouse was double clicked

wasMouseRightClicked

public boolean wasMouseRightClicked()
A utility method used to determine if the last event corrseponds to a mouse right click. The notion of a click is extended by assuming the a mouse press and release within a single component constitutes a click even if not at the same coordinate. A MouseEvent.MOUSE_CLICKED is only triggered when the press and release are at the same location and this is often inadequate for end-user interaction.

Specified by:
wasMouseRightClicked in interface XuiEventHandler
Returns:
true if the mouse was right clicked

widgetSelected

public void widgetSelected(org.eclipse.swt.events.SelectionEvent e)
Specified by:
widgetSelected in interface org.eclipse.swt.events.SelectionListener

widgetDefaultSelected

public void widgetDefaultSelected(org.eclipse.swt.events.SelectionEvent e)
Specified by:
widgetDefaultSelected in interface org.eclipse.swt.events.SelectionListener

focusGained

public void focusGained(org.eclipse.swt.events.FocusEvent e)
Specified by:
focusGained in interface org.eclipse.swt.events.FocusListener

focusLost

public void focusLost(org.eclipse.swt.events.FocusEvent e)
Specified by:
focusLost in interface org.eclipse.swt.events.FocusListener

keyPressed

public void keyPressed(org.eclipse.swt.events.KeyEvent e)
Specified by:
keyPressed in interface org.eclipse.swt.events.KeyListener

keyReleased

public void keyReleased(org.eclipse.swt.events.KeyEvent e)
Specified by:
keyReleased in interface org.eclipse.swt.events.KeyListener

keyTyped

public void keyTyped(org.eclipse.swt.events.KeyEvent e)

mouseClick

public void mouseClick(org.eclipse.swt.events.MouseEvent e)

mouseDoubleClick

public void mouseDoubleClick(org.eclipse.swt.events.MouseEvent e)
Specified by:
mouseDoubleClick in interface org.eclipse.swt.events.MouseListener

mouseEnter

public void mouseEnter(org.eclipse.swt.events.MouseEvent e)
Specified by:
mouseEnter in interface org.eclipse.swt.events.MouseTrackListener

mouseExit

public void mouseExit(org.eclipse.swt.events.MouseEvent e)
Specified by:
mouseExit in interface org.eclipse.swt.events.MouseTrackListener

mouseDown

public void mouseDown(org.eclipse.swt.events.MouseEvent e)
Specified by:
mouseDown in interface org.eclipse.swt.events.MouseListener

mouseUp

public void mouseUp(org.eclipse.swt.events.MouseEvent e)
Specified by:
mouseUp in interface org.eclipse.swt.events.MouseListener

mouseMove

public void mouseMove(org.eclipse.swt.events.MouseEvent e)
Specified by:
mouseMove in interface org.eclipse.swt.events.MouseMoveListener

mouseHover

public void mouseHover(org.eclipse.swt.events.MouseEvent e)
Specified by:
mouseHover in interface org.eclipse.swt.events.MouseTrackListener

mouseDragged

public void mouseDragged(org.eclipse.swt.events.MouseEvent e)

suppressFocusEvents

public void suppressFocusEvents(boolean suppress)
Used by messageboxes and other dialogs to prevent the display of the dialog causing extra focus events from being fired.

Specified by:
suppressFocusEvents in interface XuiEventHandler
Parameters:
suppress - true to suppress focus events

addHandler

public void addHandler(PageSupport xpage,
                       java.lang.Object targetComp,
                       java.lang.String typeStr,
                       java.lang.String methodName)
Adds an event handler.

Specified by:
addHandler in interface XuiEventHandler
Parameters:
xpage - The page that contains the response methods
targetComp - the component to which the event handler is added
typeStr - the type of handler
methodName - the name of the response method