Class 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 from FormEvent and thus provides access to the ComponentHandler 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, the handler and name 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 a FormMouseEvent.
    • 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.
    • Field Detail

      • BUTTON1

        public static final int BUTTON1
        Constant for the mouse button 1. This is the left button. The return value of getButton() 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 of getButton() 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 of getButton() 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 by getButton() 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 of FormMouseEvent 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 - the ComponentHandler of the input component that caused this event
        name - the name of the input component that caused this event
        t - the type of this event (must not be null)
        xp - the x position of the mouse cursor
        yp - the y position of the mouse cursor
        btn - the index of the affected button
        mods - 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 the BUTTONx constants. It indicates which button was pressed or released. If the event is not related to a mouse button, result is NO_BUTTON.
        Returns:
        the index of the mouse button affected by this event
      • getModifiers

        public Set<Modifiers> getModifiers()
        Returns a set with Modifiers 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 class EventObject
        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.
        Overrides:
        hashCode in class FormEvent
        Returns:
        a hash code
        Since:
        1.3
      • 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.
        Overrides:
        equals in class FormEvent
        Since:
        1.3