ch.aplu.jgamegrid
Class GGMouse

java.lang.Object
  extended by ch.aplu.jgamegrid.GGMouse

public class GGMouse
extends java.lang.Object

Singleton class used to report mouse events. For rButton events are triggered by mouse button 2 or 3. Be aware that for some mouse events the reported mouse coordinates are not strictly restricted to the display area. Therefore GameGrid.toLocation() may report cell indices outside the visible grid. Use GameGrid.isInGrid() to test if they are valid grid locations or use GameGrid.toLocationsInGrid() in order to get only valid grid locations.


Field Summary
static int enter
          Mouse cursor enters the window.
static int idle
          No mouse event occured.
static int lClick
          Left mouse button down and up in a quick sequence.
static int lDClick
          Left mouse button down, up, down, up in a quick sequence.
static int lDrag
          Left mouse button down and move.
static int leave
          Mouse cursor leaves the window.
static int lPress
          Left mouse button down.
static int lRelease
          Left mouse button up.
static int move
          Mouse cursor is moved inside the window.
static int rClick
          Right mouse button down and up in a quick sequence.
static int rDClick
          Right mouse button down, up, down, up in a quick sequence.
static int rDrag
          Right mouse button down and move.
static int rPress
          Right mouse button down.
static int rRelease
          Right mouse button up.
 
Method Summary
static GGMouse create()
          Creates a GGMouse instance with default values for the instance variables.
static GGMouse create(GGMouseListener listener, int evt, int x, int y)
          Creates a GGMouse instance with given values for the instance variables.
 int getEvent()
          Retrieves the current event type as integer.
 java.lang.String getEventType()
          Returns the event type as string.
 GGMouseListener getSource()
          Retrieves the GGMouseListener reference that created the event.
 int getX()
          Retrieves the current x-coordinate of the mouse cursor with respect to the upper left corner of the visible area in pixels.
 int getY()
          Retrieves the current y-coordinate of the mouse cursor with respect to the upper left corner of the visible area in pixels.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

idle

public static final int idle
No mouse event occured.

See Also:
Constant Field Values

lPress

public static final int lPress
Left mouse button down.

See Also:
Constant Field Values

lRelease

public static final int lRelease
Left mouse button up.

See Also:
Constant Field Values

lClick

public static final int lClick
Left mouse button down and up in a quick sequence.
Press, release, click are also generated in this order.

See Also:
Constant Field Values

lDClick

public static final int lDClick
Left mouse button down, up, down, up in a quick sequence.
Press, release, press, release, double-click is generated in this order.

See Also:
Constant Field Values

lDrag

public static final int lDrag
Left mouse button down and move. Because many events are generated, use it with precaution. getX(), getY() may report points outside the display area. No move events generated.

See Also:
Constant Field Values

rPress

public static final int rPress
Right mouse button down.

See Also:
Constant Field Values

rRelease

public static final int rRelease
Right mouse button up.

See Also:
Constant Field Values

rClick

public static final int rClick
Right mouse button down and up in a quick sequence.
Press, release, click are also generated in this order.

See Also:
Constant Field Values

rDClick

public static final int rDClick
Right mouse button down, up, down, up in a quick sequence.
Press, release, press, release, double-click is generated in this order.

See Also:
Constant Field Values

rDrag

public static final int rDrag
Right mouse button down and move. Because many events are generated, use it with precaution. getX(), getY() may report points outside the display area. No move events generated.

See Also:
Constant Field Values

enter

public static final int enter
Mouse cursor enters the window. getX(), getY() reports a point inside the display area but not necessarily at the border.

See Also:
Constant Field Values

leave

public static final int leave
Mouse cursor leaves the window. getX(), getY() may report a point outside the display area.

See Also:
Constant Field Values

move

public static final int move
Mouse cursor is moved inside the window. Because many events are generated, use it with precaution. getX(), getY() may report points outside the display area.

See Also:
Constant Field Values
Method Detail

create

public static GGMouse create()
Creates a GGMouse instance with default values for the instance variables.


create

public static GGMouse create(GGMouseListener listener,
                             int evt,
                             int x,
                             int y)
Creates a GGMouse instance with given values for the instance variables.

Parameters:
listener - the listener instances that created the event
evt - the event type (one of the predefined constants)
x - the x-coordinate where the event occurred
y - the y-coordinate where the event occurred
Returns:
a GGMouse instance reference

getSource

public GGMouseListener getSource()
Retrieves the GGMouseListener reference that created the event.

Returns:
a reference to the GGMouseListener that created the event

getEvent

public int getEvent()
Retrieves the current event type as integer.

Returns:
one of the predefined constants

getX

public int getX()
Retrieves the current x-coordinate of the mouse cursor with respect to the upper left corner of the visible area in pixels. Be aware that for some events the value corresponds to a point outside the visible area.

Returns:
x-coordinate (pixel index) where the event occured

getEventType

public java.lang.String getEventType()
Returns the event type as string.

Returns:
the event type

getY

public int getY()
Retrieves the current y-coordinate of the mouse cursor with respect to the upper left corner of the visible area in pixels. Be aware that for some events the value corresponds to a point outside the visible area.

Returns:
y-coordinate (pixel index) where the event occured