Class HapticListener

  • java.lang.Object
    • uk.ac.qmul.eecs.depic.jhapticgui.HapticListener


  • public abstract class HapticListener
    extends java.lang.Object
    A general purpose haptic device listener.

    A new instance of this class is to be passed as argument to HapticDeviceFactory.getHapticDevice(java.io.InputStream, HapticListener, java.awt.Dimension). The haptic listener runs in a separate thread and accepts messages from the thread running the haptic device (native) code. When a message arrives, messageReceived is called.

    Note that messageReceived is called in the haptic listener thread, therefore any code that modifies the GUI must be queued for execution in the Event Dispatching Thread (if using the Swing library).

    See Also:
    SwingUtilities.invokeLater(Runnable)
    • Field Summary

      Fields 
      Modifier and Type Field and Description
      static java.lang.String STOP_MSG
      This is the string: "stop".
      static java.lang.String WINDOW_MSG
      This is the string: "window".
    • Constructor Summary

      Constructors 
      Modifier Constructor and Description
      protected HapticListener()
      Constructor
    • Method Summary

      All Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method and Description
      protected void fireMessageReceived(java.lang.String command, java.lang.String args, int ID)
      Calls messageReceived passing on the message data.
      abstract void messageReceived(java.lang.String command, java.lang.String args, int ID)
      Called by the native haptic device handling thread, to notify this thread that a new message has been received.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • STOP_MSG

        public static final java.lang.String STOP_MSG
        This is the string: "stop".

        It is the message command sent from the native code to the listener to stop the execution of the latter. It's the only reserved word for message commands together with WINDOW_MSG

        See Also:
        Constant Field Values
      • WINDOW_MSG

        public static final java.lang.String WINDOW_MSG
        This is the string: "window".

        It is the message command sent from native code to the listener to notify that the window graphical user interface is showing. It's the only reserved word for message commands together with STOP_MSG

        See Also:
        Constant Field Values
    • Constructor Detail

      • HapticListener

        protected HapticListener()
        Constructor
    • Method Detail

      • fireMessageReceived

        protected void fireMessageReceived(java.lang.String command,
                                           java.lang.String args,
                                           int ID)
        Calls messageReceived passing on the message data. Called in the haptic listener thread.
        Parameters:
        command - the command to execute. Examples could be "display shape" or "render force"
        args - arguments to the command. Often position coordinates referring to haptic forces being put in place
        ID - an (optional) unique identifier for the haptic object this message refers to
      • messageReceived

        public abstract void messageReceived(java.lang.String command,
                                             java.lang.String args,
                                             int ID)
        Called by the native haptic device handling thread, to notify this thread that a new message has been received. Subclasses should put here the code that handles messages from the haptic thread. If such code affects the GUI, then it should be queued for execution in the Event Dispatching Thread (if using the Swing library).
        Parameters:
        command - the command to execute. Examples could be "display shape" or "render force"
        args - arguments to the command. Often position coordinates referring to haptic forces being put in place
        ID - an (optional) unique identifier for the haptic object this message refers to
        See Also:
        SwingUtilities.invokeLater(Runnable)