Package gui.event

Class MouseBinding

java.lang.Object
gui.event.MouseBinding

public class MouseBinding extends Object
A simple class that represents a mouse button and any modifiers needed to bind an action to a mouse input event.

The modifiers used by this class will include the button down mask for the given button. This is done to match how MouseEvent uses its modifiers.

  • Constructor Details

    • MouseBinding

      public MouseBinding(int button)
      Construct a binding with the given button number of the desired mouse button (e.g., 1, 2,...)
      Parameters:
      button - the button number
    • MouseBinding

      public MouseBinding(int button, int modifiers)
      Construct a binding with the given button number of the desired mouse button (e.g., 1, 2,...) as well as any desired modifiers (e.g., InputEvent.SHIFT_DOWN_MASK).
      Parameters:
      button - the button number
      modifiers - the event modifiers
  • Method Details

    • getButton

      public int getButton()
      The button used by this class
      Returns:
      the button used by this class
    • getModifiers

      public int getModifiers()
      The modifiers used by this class
      Returns:
      the modifiers used by this class
    • getDisplayText

      public String getDisplayText()
      A user-friendly display string for this class
      Returns:
      a user-friendly display string for this class
    • getMouseBinding

      public static MouseBinding getMouseBinding(MouseEvent e)
      Create a mouse binding for the given event
      Parameters:
      e - the event
      Returns:
      the mouse binding
    • getMouseBinding

      public static MouseBinding getMouseBinding(String mouseString)
      Creates a mouse binding from the given string. The string is expected to be of the form: Ctrl+Button1, which is the form of the text generated by getDisplayText().
      Parameters:
      mouseString - the mouse string
      Returns:
      the mouse binding or null if an invalid string was given
    • isMatchingRelease

      public boolean isMatchingRelease(MouseEvent e)
      Returns true if the given mouse event is the mouse released event for the mouse button used by this class. This method will ignore modifier text, since modifiers can be pressed and released independent of the mouse button's release.
      Parameters:
      e - the event
      Returns:
      true if the given mouse event is the mouse released event for the mouse button used by this class
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object