com.extjs.gxt.ui.client.event
Class DomEvent

java.lang.Object
  extended by com.extjs.gxt.ui.client.event.BaseEvent
      extended by com.extjs.gxt.ui.client.event.DomEvent
Direct Known Subclasses:
ComponentEvent, DNDEvent, DragEvent, EditorEvent, PreviewEvent

public class DomEvent
extends BaseEvent

A BaseEvent that wraps a browser event and provides a set of DOM related method.

    Button btn = new Button();
    btn.addListener(Event.ONCLICK, new Listener<ButtonEvent>() {
      public void handleEvent(ButtonEvent be) {
        // ButtonEvent is a DomEvent subclass

        // retrieve the event target
        Element target = be.getTarget();

        // get the mouse location
        Point point = be.getXY();

        // is the control key pressed?
        boolean control = be.isControlKey();

        // cancel event bubbling
        be.cancelBubble();
      }
    });
 


Field Summary
protected  com.google.gwt.user.client.Event event
           
 
Constructor Summary
DomEvent(java.lang.Object source)
          Creates a new base event.
DomEvent(java.lang.Object source, com.google.gwt.user.client.Event event)
          Creates a new base event.
 
Method Summary
 void cancelBubble()
          Cancels bubbling for the given event.
 int getClientX()
          Returns the event's x coordinate.
 int getClientY()
          Returns the event's y coordinate.
 com.google.gwt.user.client.Event getEvent()
          Returns the dom event.
 int getEventTypeInt()
          Returns the dom event type int.
 int getKeyCode()
          Returns the key code associated with this event.
 com.google.gwt.user.client.Element getTarget()
          Returns the event's target element.
 El getTarget(java.lang.String selector, int maxDepth)
          Returns the matching parent using the specified selector.
 El getTargetEl()
          Returns the event's target element.
 Point getXY()
          Returns the mouse location.
 boolean hasModifier()
          Returns true if the control, alt, shift, or meta key is pressed.
 boolean isAltKey()
          Returns true if the alt key is pressed.
 boolean isControlKey()
          Returns true if the control key (or meta key) is pressed.
 boolean isNavKeyPress()
          Returns true if the key is a "navigation" key.
 boolean isNavKeyPress(int k)
          Returns true if the key is a "navigation" key.
 boolean isRightClick()
          Returns true if the event is a right click.
 boolean isShiftKey()
          Returns true if the shift key is pressed.
 boolean isSpecialKey()
          Returns true if the key is a "special" key.
 boolean isSpecialKey(int k)
          Returns true if the key is a "special" key.
 void preventDefault()
          Prevents the browser from taking its default action for the given event.
 void setEvent(com.google.gwt.user.client.Event event)
          Sets the dom event.
 void stopEvent()
          Stops the event (preventDefault and cancelBubble).
 boolean within(com.google.gwt.user.client.Element element)
          Returns true if the target of this event equals or is a child of the given element.
 boolean within(com.google.gwt.user.client.Element element, boolean toElement)
          Returns true if the target of this event equals or is a child of the given element.
 
Methods inherited from class com.extjs.gxt.ui.client.event.BaseEvent
getSource, getType, isCancelled, setCancelled, setSource, setType
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

event

protected com.google.gwt.user.client.Event event
Constructor Detail

DomEvent

public DomEvent(java.lang.Object source)
Creates a new base event.

Parameters:
source - the source object

DomEvent

public DomEvent(java.lang.Object source,
                com.google.gwt.user.client.Event event)
Creates a new base event.

Parameters:
source - the source object
Method Detail

cancelBubble

public void cancelBubble()
Cancels bubbling for the given event. This will stop the event from being propagated to parent elements.


getClientX

public int getClientX()
Returns the event's x coordinate.

Returns:
the x coordinate or -1 if no dom event.

getClientY

public int getClientY()
Returns the event's y coordinate.

Returns:
the y coordinate or -1 if no dom event.

getEvent

public com.google.gwt.user.client.Event getEvent()
Returns the dom event.

Returns:
the dom event

getEventTypeInt

public int getEventTypeInt()
Returns the dom event type int.

Returns:
the event type

getKeyCode

public int getKeyCode()
Returns the key code associated with this event.

Returns:
the key code

getTarget

public com.google.gwt.user.client.Element getTarget()
Returns the event's target element.

Returns:
the target element or null if no dom event

getTarget

public El getTarget(java.lang.String selector,
                    int maxDepth)
Returns the matching parent using the specified selector.

Parameters:
selector - the CSS selector
maxDepth - the maximum number of parents to search
Returns:
the matching element or null

getTargetEl

public El getTargetEl()
Returns the event's target element.

Returns:
the target element or null if no dom event

getXY

public Point getXY()
Returns the mouse location.

Returns:
the mouse location

hasModifier

public boolean hasModifier()
Returns true if the control, alt, shift, or meta key is pressed.

Returns:
the modifier state

isAltKey

public boolean isAltKey()
Returns true if the alt key is pressed.

Returns:
the alt key state

isControlKey

public boolean isControlKey()
Returns true if the control key (or meta key) is pressed.

Returns:
the control key state

isNavKeyPress

public boolean isNavKeyPress()
Returns true if the key is a "navigation" key.

Returns:
the nav state

isNavKeyPress

public boolean isNavKeyPress(int k)
Returns true if the key is a "navigation" key.

Parameters:
k - the key code
Returns:
the nav state

isRightClick

public boolean isRightClick()
Returns true if the event is a right click.

Returns:
the right click state

isShiftKey

public boolean isShiftKey()
Returns true if the shift key is pressed.

Returns:
the shift key state

isSpecialKey

public boolean isSpecialKey()
Returns true if the key is a "special" key.

Returns:
the special state

isSpecialKey

public boolean isSpecialKey(int k)
Returns true if the key is a "special" key.

Parameters:
k - the key code
Returns:
the special state

preventDefault

public void preventDefault()
Prevents the browser from taking its default action for the given event.


setEvent

public void setEvent(com.google.gwt.user.client.Event event)
Sets the dom event.

Parameters:
event - the dom event

stopEvent

public void stopEvent()
Stops the event (preventDefault and cancelBubble).


within

public boolean within(com.google.gwt.user.client.Element element)
Returns true if the target of this event equals or is a child of the given element.

Parameters:
element - the element
Returns:
the within state

within

public boolean within(com.google.gwt.user.client.Element element,
                      boolean toElement)
Returns true if the target of this event equals or is a child of the given element.

Parameters:
element - the element
toElement - true to use NativeEvent.getRelatedEventTarget()
Returns:
the within state