edu.umd.cs.piccolo.event
Class PInputEvent

java.lang.Object
  extended by edu.umd.cs.piccolo.event.PInputEvent

public class PInputEvent
extends Object

PInputEvent is used to notify PInputEventListeners of keyboard and mouse input. It has methods for normal event properties such as event modifier keys and event canvas location.

In addition is has methods to get the mouse position and delta in a variety of coordinate systems.

Last of all it provides access to the dispatch manager that can be queried to find the current mouse over, mouse focus, and keyboard focus.

Version:
1.0
Author:
Jesse Grosjean

Constructor Summary
PInputEvent(PInputManager inputManager, InputEvent event)
          Create an event with the given inputManager and based on the given swing event.
 
Method Summary
 int getButton()
          Returns the mouse button value of the underlying mouse event.
 PCamera getCamera()
          Return the bottom most camera that is currently painting.
 PDimension getCanvasDelta()
          Return the delta between the last and current mouse position in PCanvas coordinates.
 Point2D getCanvasPosition()
          Return the mouse position in PCanvas coordinates.
 int getClickCount()
          Returns the click count of the mouse event.
 PComponent getComponent()
          Get the canvas associated with the top camera.
 PDimension getDelta()
          Return the delta between the last and current mouse positions transformed through the view transform of the bottom camera.
 PDimension getDeltaRelativeTo(PNode nodeOnPath)
          Return the delta between the last and current mouse positions relative to a given node on the pick path.
 PInputManager getInputManager()
          Return the input manager that dispatched this event.
 char getKeyChar()
          Returns the character associated with a key event.
 int getKeyCode()
          Returns the key code associated with a key event.
 int getKeyLocation()
          Returns the location on the keyboard from which the key stroke originated.
 int getModifiers()
          Returns the modifiers provided for the input event by swing.
 int getModifiersEx()
          Returns the extended modifiers provided for the input event by swing.
 PPickPath getPath()
          Return the PPickPath associated with this input event.
 PNode getPickedNode()
          Return the bottom node on the current pickpath, that is the picked node furthest from the root node.
 Point2D getPosition()
          Return the mouse position transformed through the view transform of the bottom camera.
 Point2D getPositionRelativeTo(PNode nodeOnPath)
          Return the mouse position relative to a given node on the pick path.
 InputEvent getSourceSwingEvent()
          Returns the underlying swing event that this PInputEvent is wrapping.
 PCamera getTopCamera()
          Return the topmost camera this is painting.
 int getWheelRotation()
          Returns the current value of the wheel rotation on Mouse Wheel Rotation events.
 long getWhen()
          Returns the time at which the event was emitted.
 boolean isActionKey()
          Returns whether the key event involves the action key.
 boolean isAltDown()
          Returns whether the alt key is currently down.
 boolean isControlDown()
          Returns whether the control key is currently down.
 boolean isFocusEvent()
          Returns whether the underlying event is a Focus Event.
 boolean isHandled()
          Return true if another event handler has already handled this event.
 boolean isKeyEvent()
          Returns whether the underlying event is a KeyEvent.
 boolean isLeftMouseButton()
          Returns whether the mouse event involves the left mouse button.
 boolean isMetaDown()
          Returns whether the meta key is currently down.
 boolean isMiddleMouseButton()
          Returns whether the mouse event involves the middle mouse button.
 boolean isMouseEnteredOrMouseExited()
          Returns whether the underlying event is a mouse entered or exited event.
 boolean isMouseEvent()
          Returns whether the underlying event is a MouseEvent.
 boolean isMouseWheelEvent()
          Returns whether the underlying event is a Mouse Wheel Event.
 boolean isPopupTrigger()
          Returns whether or not this event is a popup menu trigger event for the platform.
 boolean isRightMouseButton()
          Returns whether the mouse event involves the right mouse button.
 boolean isShiftDown()
          Returns whether the shift key is currently down.
 void popCursor()
          Removes the top most cursor from the cursor stack and sets it as the current cursor.
 void pushCursor(Cursor cursor)
          Changes the cursor to the one provided and stores it on the cursor stack for later retrieval.
 void setHandled(boolean handled)
          Set that this event has been handled by an event handler.
 void setPath(PPickPath path)
          Sets the PIckPath associated with this mouse event.
 String toString()
          Returns a string representation of this object for debugging purposes.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

PInputEvent

public PInputEvent(PInputManager inputManager,
                   InputEvent event)
Create an event with the given inputManager and based on the given swing event.

Parameters:
inputManager - source of PInputEvent
event - underlying swing event
Method Detail

pushCursor

public void pushCursor(Cursor cursor)
Changes the cursor to the one provided and stores it on the cursor stack for later retrieval.

Parameters:
cursor - cursor to push on cursor stack

popCursor

public void popCursor()
Removes the top most cursor from the cursor stack and sets it as the current cursor.


getCamera

public PCamera getCamera()
Return the bottom most camera that is currently painting. If you are using internal cameras this may be different then what is returned by getTopCamera.

Returns:
the current PickPath's bottom camera.

getTopCamera

public PCamera getTopCamera()
Return the topmost camera this is painting. This is the camera associated with the PCanvas that requested the current repaint.

Returns:
topmost camera on the pick path

getComponent

public PComponent getComponent()
Get the canvas associated with the top camera. This is the canvas where the originating swing event came from.

Returns:
component attached to the top camera of the current pick path

getInputManager

public PInputManager getInputManager()
Return the input manager that dispatched this event. You can use this input manager to find the current mouse focus, mouse over, and key focus nodes. You can also set a new key focus node.

Returns:
input manager that dispatched this event

getPath

public PPickPath getPath()
Return the PPickPath associated with this input event.

Returns:
pick path associated with this event (may be null)

setPath

public void setPath(PPickPath path)
Sets the PIckPath associated with this mouse event.

Parameters:
path - path to associate with this mouse event

getPickedNode

public PNode getPickedNode()
Return the bottom node on the current pickpath, that is the picked node furthest from the root node.

Returns:
the currently picked node of this mouse event

getKeyCode

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

Returns:
key code associated with a key event

getKeyChar

public char getKeyChar()
Returns the character associated with a key event.

Returns:
char associated with a key event

getKeyLocation

public int getKeyLocation()
Returns the location on the keyboard from which the key stroke originated.

Returns:
location on keyboard from which stroke originated.

isActionKey

public boolean isActionKey()
Returns whether the key event involves the action key.

Returns:
true if key involved is the action key

getModifiers

public int getModifiers()
Returns the modifiers provided for the input event by swing.

Returns:
modifier flags for the input event

getModifiersEx

public int getModifiersEx()
Returns the extended modifiers provided for the input event by swing.

Returns:
extended modifies of input event

getClickCount

public int getClickCount()
Returns the click count of the mouse event.

Returns:
click count of mouse event

getWhen

public long getWhen()
Returns the time at which the event was emitted.

Returns:
time at which the vent was emitted

isAltDown

public boolean isAltDown()
Returns whether the alt key is currently down.

Returns:
true if alt key is down

isControlDown

public boolean isControlDown()
Returns whether the control key is currently down.

Returns:
true if control key is down

isMetaDown

public boolean isMetaDown()
Returns whether the meta key is currently down.

Returns:
true if meta key is down

isShiftDown

public boolean isShiftDown()
Returns whether the shift key is currently down.

Returns:
true if shift key is down

isLeftMouseButton

public boolean isLeftMouseButton()
Returns whether the mouse event involves the left mouse button.

Returns:
true if left mouse button is involved the mouse event

isMiddleMouseButton

public boolean isMiddleMouseButton()
Returns whether the mouse event involves the middle mouse button.

Returns:
true if middle mouse button is involved the mouse event

isRightMouseButton

public boolean isRightMouseButton()
Returns whether the mouse event involves the right mouse button.

Returns:
true if right mouse button is involved the mouse event

isHandled

public boolean isHandled()
Return true if another event handler has already handled this event. Event handlers should use this as a hint before handling the event themselves and possibly reject events that have already been handled.

Returns:
true if event has been marked as handled

setHandled

public void setHandled(boolean handled)
Set that this event has been handled by an event handler. This is a relaxed for of consuming events. The event will continue to get dispatched to event handlers even after it is marked as handled, but other event handlers that might conflict are expected to ignore events that have already been handled.

Parameters:
handled - whether the event is marked

getButton

public int getButton()
Returns the mouse button value of the underlying mouse event.

Returns:
button value of underlying mouse event

getWheelRotation

public int getWheelRotation()
Returns the current value of the wheel rotation on Mouse Wheel Rotation events.

Returns:
wheel rotation value

getSourceSwingEvent

public InputEvent getSourceSwingEvent()
Returns the underlying swing event that this PInputEvent is wrapping.

Returns:
underlying swing event

isKeyEvent

public boolean isKeyEvent()
Returns whether the underlying event is a KeyEvent.

Returns:
true if is key event

isMouseEvent

public boolean isMouseEvent()
Returns whether the underlying event is a MouseEvent.

Returns:
true if is mouse event

isMouseWheelEvent

public boolean isMouseWheelEvent()
Returns whether the underlying event is a Mouse Wheel Event.

Returns:
true if is a mouse wheel event

isFocusEvent

public boolean isFocusEvent()
Returns whether the underlying event is a Focus Event.

Returns:
true if is focus event

isMouseEnteredOrMouseExited

public boolean isMouseEnteredOrMouseExited()
Returns whether the underlying event is a mouse entered or exited event.

Returns:
true if is a mouse entered or exited event

isPopupTrigger

public boolean isPopupTrigger()
Returns whether or not this event is a popup menu trigger event for the platform. Must not be called if this event isn't a mouse event.

Note: Popup menus are triggered differently on different systems. Therefore, isPopupTrigger should be checked in both mousePressed and mouseReleased for proper cross-platform functionality.

Returns:
boolean, true if this event triggers a popup menu for this platform

getCanvasPosition

public Point2D getCanvasPosition()
Return the mouse position in PCanvas coordinates.

Returns:
mouse position in PCanvas coordinates

getCanvasDelta

public PDimension getCanvasDelta()
Return the delta between the last and current mouse position in PCanvas coordinates.

Returns:
delta between last and current mouse position as measured by the PCanvas

getPositionRelativeTo

public Point2D getPositionRelativeTo(PNode nodeOnPath)
Return the mouse position relative to a given node on the pick path.

Parameters:
nodeOnPath - node on the current PPickPath
Returns:
mouse position relative to the provided node on pick path

getDeltaRelativeTo

public PDimension getDeltaRelativeTo(PNode nodeOnPath)
Return the delta between the last and current mouse positions relative to a given node on the pick path.

Parameters:
nodeOnPath - node from which to measure
Returns:
delta between current mouse position and a given node on the pick path

getPosition

public Point2D getPosition()
Return the mouse position transformed through the view transform of the bottom camera.

Returns:
mouse position as measured by the bottom camera

getDelta

public PDimension getDelta()
Return the delta between the last and current mouse positions transformed through the view transform of the bottom camera.

Returns:
delta between last and current mouse position as measured by the bottom camera

toString

public String toString()
Returns a string representation of this object for debugging purposes.

Overrides:
toString in class Object
Returns:
string representation of this object


Copyright © 1995-2011 Piccolo2D. All Rights Reserved.