Class PInputManager

All Implemented Interfaces:
PInputEventListener, PRoot.InputSource, EventListener

public class PInputManager extends PBasicInputEventHandler implements PRoot.InputSource
PInputManager is responsible for dispatching PInputEvents to node's event listeners. Events are dispatched from PRoot's processInputs method.

Version:
1.0
Author:
Jesse Grosjean
See Also:
  • Constructor Details

    • PInputManager

      public PInputManager()
      Creates a PInputManager and sets positions (last, current) to the origin (0,0).
  • Method Details

    • getKeyboardFocus

      public PInputEventListener getKeyboardFocus()
      Return the node that currently has the keyboard focus. This node receives the key events.
      Returns:
      the current keyboard focus
    • setKeyboardFocus

      public void setKeyboardFocus(PInputEventListener eventHandler)
      Set the node that should receive key events.
      Parameters:
      eventHandler - sets the keyboard event focus, may be null
    • getMouseFocus

      public PPickPath getMouseFocus()
      Return the current Pick Path under the mouse focus. This will return the path that received the current mouse pressed event, or null if the mouse is not pressed. The mouse focus gets mouse dragged events even what the mouse is not over the mouse focus.
      Returns:
      the current Pick Path under the mouse focus
    • setMouseFocus

      public void setMouseFocus(PPickPath path)
      Sets the current Pick Path under the mouse focus. The mouse focus gets mouse dragged events even when the mouse is not over the mouse focus.
      Parameters:
      path - the new mouse focus
    • getMouseOver

      public PPickPath getMouseOver()
      Return the node the the mouse is currently over.
      Returns:
      the path over which the mouse currently is
    • setMouseOver

      public void setMouseOver(PPickPath path)
      Records the path which is directly below the mouse.
      Parameters:
      path - path over which the mouse has been moved
    • getLastCanvasPosition

      public Point2D getLastCanvasPosition()
      Returns the position on the Canvas of the last event.
      Returns:
      position of last canvas event
    • getCurrentCanvasPosition

      public Point2D getCurrentCanvasPosition()
      Returns the position of the current canvas event.
      Returns:
      position of current canvas event
    • keyPressed

      public void keyPressed(PInputEvent event)
      Will get called whenever a key has been pressed down. Subclasses should override this method to implement their own behavior.
      Overrides:
      keyPressed in class PBasicInputEventHandler
      Parameters:
      event - the event representing the keystroke
    • keyReleased

      public void keyReleased(PInputEvent event)
      Will get called whenever a key has been released. Subclasses should override this method to implement their own behavior.
      Overrides:
      keyReleased in class PBasicInputEventHandler
      Parameters:
      event - the event representing the keystroke
    • keyTyped

      public void keyTyped(PInputEvent event)
      Will be called at the end of a full keystroke (down then up). Subclasses should override this method to implement their own behavior.
      Overrides:
      keyTyped in class PBasicInputEventHandler
      Parameters:
      event - object which can be queried for the event's details
    • mouseClicked

      public void mouseClicked(PInputEvent event)
      Will be called at the end of a full click (mouse pressed followed by mouse released). Subclasses should override this method to implement their own behavior.
      Overrides:
      mouseClicked in class PBasicInputEventHandler
      Parameters:
      event - object which can be queried for the event's details
    • mouseWheelRotated

      public void mouseWheelRotated(PInputEvent event)
      This method is invoked when the mouse wheel is rotated. Subclasses should override this method to implement their own behavior.
      Overrides:
      mouseWheelRotated in class PBasicInputEventHandler
      Parameters:
      event - an object that can be queries to discover the event's details
    • mouseWheelRotatedByBlock

      public void mouseWheelRotatedByBlock(PInputEvent event)
      This method is invoked when the mouse wheel is rotated by a block. Subclasses should override this method to implement their own behavior.
      Overrides:
      mouseWheelRotatedByBlock in class PBasicInputEventHandler
      Parameters:
      event - an object that can be queries to discover the event's details
    • mouseDragged

      public void mouseDragged(PInputEvent event)
      Will be called when a drag is occurring. This is system dependent. Subclasses should override this method to implement their own behavior.
      Overrides:
      mouseDragged in class PBasicInputEventHandler
      Parameters:
      event - object which can be queried for the event's details
    • mouseEntered

      public void mouseEntered(PInputEvent event)
      Will be invoked when the mouse enters a specified region. Subclasses should override this method to implement their own behavior.
      Overrides:
      mouseEntered in class PBasicInputEventHandler
      Parameters:
      event - object which can be queried for the event's details
    • mouseExited

      public void mouseExited(PInputEvent event)
      Will be invoked when the mouse leaves a specified region. Subclasses should override this method to implement their own behavior.
      Overrides:
      mouseExited in class PBasicInputEventHandler
      Parameters:
      event - object which can be queried for the event's details
    • mouseMoved

      public void mouseMoved(PInputEvent event)
      Will be called when the mouse is moved. Subclasses should override this method to implement their own behavior.
      Overrides:
      mouseMoved in class PBasicInputEventHandler
      Parameters:
      event - object which can be queried for event details
    • mousePressed

      public void mousePressed(PInputEvent event)
      Will be called when a mouse button is pressed down. Should two buttons be pressed simultaneously, it will dispatch two of these in an unspecified order. Subclasses should override this method to implement their own behavior.
      Overrides:
      mousePressed in class PBasicInputEventHandler
      Parameters:
      event - object which can be queried for the event's details
    • mouseReleased

      public void mouseReleased(PInputEvent event)
      Will be called when any mouse button is released. Should two or more buttons be released simultaneously, this method will be called multiple times. Subclasses should override this method to implement their own behavior.
      Overrides:
      mouseReleased in class PBasicInputEventHandler
      Parameters:
      event - object which can be queried for event details
    • checkForMouseEnteredAndExited

      protected void checkForMouseEnteredAndExited(PInputEvent event)
      Fires events whenever the mouse moves from PNode to PNode.
      Parameters:
      event - to check to see if the top node has changed.
    • processInput

      public void processInput()
      Causes the system to process any pending Input Events.
      Specified by:
      processInput in interface PRoot.InputSource
    • createInputEvent

      protected PInputEvent createInputEvent(InputEvent event)
      Creates a PInputEvent based on the given Swing InputEvent.
      Has been introduced for enabling the "injection" of specialized implementations (subclasses) via overriding this factory method, and, hence, is called instead of calling PInputEvent(PInputManager, InputEvent) directly.
      Parameters:
      event - the Swing InputEvent to wrap
      Returns:
      the desired PInputEvent
    • processEventFromCamera

      public void processEventFromCamera(InputEvent event, int type, PCamera camera)
      Flags the given event as needing to be processed.
      Parameters:
      event - the event to be processed
      type - type of event to be processed
      camera - camera from which the event was dispatched
    • dispatchEventToListener

      protected void dispatchEventToListener(PInputEvent event, int type, PInputEventListener listener)
      Dispatches the given event to the listener, or does nothing if listener is null.
      Parameters:
      event - event to be dispatched
      type - type of event to dispatch
      listener - target of dispatch