Class FormMouseEvent
- java.lang.Object
-
- java.util.EventObject
-
- net.sf.jguiraffe.gui.builder.event.BuilderEvent
-
- net.sf.jguiraffe.gui.builder.event.FormEvent
-
- net.sf.jguiraffe.gui.builder.event.FormMouseEvent
-
- All Implemented Interfaces:
Serializable
public class FormMouseEvent extends FormEvent
A specialized event class for reporting events related to mouse actions.
Events of this type are passed to components that have registered themselves as mouse listeners at input components. This way listeners get notified, for instance, if the mouse is clicked, released, or moved within an input components. The
type
property can be queried to find out which mouse action was performed. The coordinates of the mouse cursor (relative to the origin of the source component) are also available. Further, the affected mouse button and the status of special modifier keys (like SHIFT or ALT) are available.Mouse events are more low-level. In typical controller classes for input forms it is rarely necessary to react on specific mouse actions. In most cases action or change events are more appropriate. An exception can be double-click events, which are only available through a mouse listener.
FormMouseEvent
is derived fromFormEvent
and thus provides access to theComponentHandler
and the name of the component that triggered this event. Nevertheless, it is possible to register a mouse listener at non-input components, e.g. windows. In this case, thehandler
andname
properties are undefined.- Version:
- $Id: FormMouseEvent.java 205 2012-01-29 18:29:57Z oheger $
- Author:
- Oliver Heger
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
FormMouseEvent.Type
An enumeration class defining constants for the possible mouse actions that can trigger aFormMouseEvent
.
-
Field Summary
Fields Modifier and Type Field Description static int
BUTTON1
Constant for the mouse button 1.static int
BUTTON2
Constant for the mouse button 2.static int
BUTTON3
Constant for the mouse button 3.static int
NO_BUTTON
Constant for an undefined mouse button.-
Fields inherited from class java.util.EventObject
source
-
-
Constructor Summary
Constructors Constructor Description FormMouseEvent(Object source, ComponentHandler<?> handler, String name, FormMouseEvent.Type t, int xp, int yp, int btn, Collection<Modifiers> mods)
Creates a new instance ofFormMouseEvent
and initializes all its properties.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
equals(Object obj)
This base implementation tests the handler and name properties.int
getButton()
Returns the index of the mouse button affected by this event.Set<Modifiers>
getModifiers()
Returns a set withModifiers
representing the special modifier keys that were pressed when the mouse event occurred.FormMouseEvent.Type
getType()
Returns the type of this event.int
getX()
Returns the X position of the mouse relative to the origin of the component that caused this event.int
getY()
Returns the Y position of the mouse relative to the origin of the component that caused this event.int
hashCode()
Returns a hash code for this object.String
toString()
Returns a string representation of this object.-
Methods inherited from class net.sf.jguiraffe.gui.builder.event.FormEvent
getHandler, getName
-
Methods inherited from class java.util.EventObject
getSource
-
-
-
-
Field Detail
-
BUTTON1
public static final int BUTTON1
Constant for the mouse button 1. This is the left button. The return value ofgetButton()
can be checked with this constant.- See Also:
- Constant Field Values
-
BUTTON2
public static final int BUTTON2
Constant for the mouse button 2. This is the middle mouse button. The return value ofgetButton()
can be checked with this constant.- See Also:
- Constant Field Values
-
BUTTON3
public static final int BUTTON3
Constant for the mouse button 3. This is the right mouse button. The return value ofgetButton()
can be checked with this constant.- See Also:
- Constant Field Values
-
NO_BUTTON
public static final int NO_BUTTON
Constant for an undefined mouse button. This value is returned bygetButton()
if the event is not related to a button.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
FormMouseEvent
public FormMouseEvent(Object source, ComponentHandler<?> handler, String name, FormMouseEvent.Type t, int xp, int yp, int btn, Collection<Modifiers> mods)
Creates a new instance ofFormMouseEvent
and initializes all its properties.- Parameters:
source
- the source of this event (this is typically the original, platform-specific event this object was created from)handler
- theComponentHandler
of the input component that caused this eventname
- the name of the input component that caused this eventt
- the type of this event (must not be null)xp
- the x position of the mouse cursoryp
- the y position of the mouse cursorbtn
- the index of the affected buttonmods
- a set with modifier keys (may be empty or null)- Throws:
IllegalArgumentException
- if a required parameter is missing
-
-
Method Detail
-
getType
public FormMouseEvent.Type getType()
Returns the type of this event. The type provides information about which mouse action has actually happened.- Returns:
- the type of this event
-
getX
public int getX()
Returns the X position of the mouse relative to the origin of the component that caused this event.- Returns:
- the X position of the mouse cursor
-
getY
public int getY()
Returns the Y position of the mouse relative to the origin of the component that caused this event.- Returns:
- the Y position of the mouse cursor
-
getButton
public int getButton()
Returns the index of the mouse button affected by this event. The return value is one of theBUTTONx
constants. It indicates which button was pressed or released. If the event is not related to a mouse button, result isNO_BUTTON
.- Returns:
- the index of the mouse button affected by this event
-
getModifiers
public Set<Modifiers> getModifiers()
Returns a set withModifiers
representing the special modifier keys that were pressed when the mouse event occurred. This information can be used to distinguish enhanced mouse gestures, e.g. SHIFT+CLICK for text selection. The set returned by this method cannot be modified.- Returns:
- a set with the active modifier keys
-
toString
public String toString()
Returns a string representation of this object. This string contains the most important properties that have a meaningful string representation.- Overrides:
toString
in classEventObject
- Returns:
- a string for this object
-
hashCode
public int hashCode()
Returns a hash code for this object. This implementation takes the additional fields into account declared by this class.
-
equals
public boolean equals(Object obj)
This base implementation tests the handler and name properties. It is implemented in a way that subclasses can override it to add checks for additional properties. This implementation checks the additional fields declared by this class.
-
-