hermes.postoffice
Class PostOffice

java.lang.Object
  extended by hermes.postoffice.PostOffice
All Implemented Interfaces:
com.illposed.osc.OSCListener, java.awt.event.KeyListener, java.awt.event.MouseListener, java.awt.event.MouseMotionListener, java.awt.event.MouseWheelListener, java.util.EventListener

public class PostOffice
extends java.lang.Object
implements java.awt.event.KeyListener, java.awt.event.MouseListener, java.awt.event.MouseMotionListener, java.awt.event.MouseWheelListener, com.illposed.osc.OSCListener

Listens for OSC, mouse, and keyboard messages; can also send OSC messages.

Objects can register "subscriptions" with the P.O. for a particular type of message. When that type of message is received, P.O. tells subscribers and passes along the information stored in the message.


Constructor Summary
PostOffice()
          Constructor with no OSC.
PostOffice(int portIn, int portOut)
          Constructor with OSC running locally.
PostOffice(int portIn, int portOut, java.lang.String netAddress)
          Constructor for PostOffice that sends messages to non-local address (ie over the internet).
 
Method Summary
 void acceptMessage(java.util.Date time, com.illposed.osc.OSCMessage message)
          Accepts and handles messages recieved by osc server.
 void checkMail()
          Command that sends all messages queued by the PostOffice to subscribers.
static POCodes.Button getMouseButton(java.awt.event.MouseEvent e)
          Finds the proper mouse button code from a Swing mouse event.
 PVector getMouseLocation()
          Utility for obtaining current mouse location
 PVector getPMouseLocation()
          Utility for obtaining previous mouse location
 boolean isKeyPressed(int keyCode)
          Utility for checking if key is pressed
 boolean isMouseInRegion(HShape region)
          Utility for checking if mouse is in a region
 void keyPressed(java.awt.event.KeyEvent e)
          On a key press, make a new KeyMessage and add it to the queue.
 void keyReleased(java.awt.event.KeyEvent e)
          On a key release, make a new KeyMessage and add it to the queue.
 void keyTyped(java.awt.event.KeyEvent e)
          Ignore keyTyped events.
 void mouseClicked(java.awt.event.MouseEvent e)
          Ignore mouseClicked events.
 void mouseDragged(java.awt.event.MouseEvent e)
          When the mouse is dragged, create a MouseMessage and add it to the group.
 void mouseEntered(java.awt.event.MouseEvent e)
          Ignore mouseEntered events.
 void mouseExited(java.awt.event.MouseEvent e)
          Ignore mouseExited events.
 void mouseMoved(java.awt.event.MouseEvent e)
          When the mouse is moved, create a MouseMessage and add it to the queue.
 void mousePressed(java.awt.event.MouseEvent e)
          On a mouse press, make a new MouseMessage and add it to the queue.
 void mouseReleased(java.awt.event.MouseEvent e)
          On a mouse button release, make a new MouseMessage and add it to the queue.
 void mouseWheelMoved(java.awt.event.MouseWheelEvent e)
          When the mouse wheel is moved, create a MouseWheelMessage and add it to the queue.
 boolean removeAllSubscriptions(HObject sub)
          Helper method to remove all subscriptions for given HObject
 boolean removeKeySubscriptions(KeySubscriber sub)
          Removes a key subscription
 boolean removeMouseSubscriptions(MouseSubscriber sub)
          Removes a mouse subscription
 boolean removeMouseWheelSubscriptions(KeySubscriber sub)
          Removes a mouse wheel subscription
 boolean removeOSCSubscriptions(KeySubscriber sub)
          Removes an OSC subscription
 void resetSubscriptions()
          Resets all subscriptions Use if passing subscriptions between Worlds
 void sendBoolean(java.lang.String address, boolean send)
          Sends an OscMessage on the given address containing only the given boolean.
 void sendFloat(java.lang.String address, float send)
          Sends an OscMessage on the given address containing only the given float.
 void sendInt(java.lang.String address, int send)
          Sends an OscMessage on the given address containing only the given int.
 void sendList(java.lang.String address, java.util.ArrayList<java.lang.Object> send)
          Sends an OscMessage on the given address containing the contents of the given list.
 void subscribe(KeySubscriber sub, char key)
          Registers a subscription to messages sent by a specific keyboard key.
 void subscribe(KeySubscriber sub, int key)
          Registers a subscription to messages sent by a specific keyboard key.
 void subscribe(MouseSubscriber sub, POCodes.Button button)
          Registers a subscription to messages sent by a specific mouse button.
 void subscribe(MouseSubscriber sub, POCodes.Button button, HShape region)
          A version of registerMouseSubscription that subscribes only to the requested button events that occur in the given region.
 void subscribe(MouseWheelSubscriber sub)
          Registers a subscription to the mouse wheel (one subscription gets you everything).
 void subscribe(OscSubscriber sub, java.lang.String address)
          Registers a subscription to messages received on a specific OSC address.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PostOffice

public PostOffice()
Constructor with no OSC.


PostOffice

public PostOffice(int portIn,
                  int portOut)
Constructor with OSC running locally. Messages can be sent to and received from other programs running on the same computer.

Parameters:
portIn - port to receive messages on
portOut - port to send messages on

PostOffice

public PostOffice(int portIn,
                  int portOut,
                  java.lang.String netAddress)
Constructor for PostOffice that sends messages to non-local address (ie over the internet).

Parameters:
portIn - port to receive messages on
portOut - port to send messages on
netAddress - url of location to send messages to
Method Detail

subscribe

public void subscribe(KeySubscriber sub,
                      int key)
Registers a subscription to messages sent by a specific keyboard key.

Parameters:
sub - the KeySubscriber signing up
key - the code of the keyboard key whose messages the subscriber wants (use value from POConstants)

subscribe

public void subscribe(KeySubscriber sub,
                      char key)
Registers a subscription to messages sent by a specific keyboard key.

Parameters:
sub - the KeySubscriber signing up
key - the char of the keyboard key whose messages the subscriber wants

subscribe

public void subscribe(MouseSubscriber sub,
                      POCodes.Button button)
Registers a subscription to messages sent by a specific mouse button.

Buttons are defined by constants in the POConstants class; subscribe with "NO_BUTTON" to receive information about mouse movements when no button is pressed.

Parameters:
sub - the MouseSubscriber signing up
button - the code of the button whose messages the subscriber wants (use value from POContants)

subscribe

public void subscribe(MouseSubscriber sub,
                      POCodes.Button button,
                      HShape region)
A version of registerMouseSubscription that subscribes only to the requested button events that occur in the given region.

Parameters:
sub - the MouseSubscriber signing up
button - the code of the button whose messages the subscriber wants (use value from POContants)
region - the region on screen the subscriber wants to limit its subscription to

subscribe

public void subscribe(MouseWheelSubscriber sub)
Registers a subscription to the mouse wheel (one subscription gets you everything).

Parameters:
sub - the MouseWheelSubscriber signing up

subscribe

public void subscribe(OscSubscriber sub,
                      java.lang.String address)
Registers a subscription to messages received on a specific OSC address.

Parameters:
sub - the OscSubscriber signing up
address - the address whose messages the subscriber wants

removeMouseSubscriptions

public boolean removeMouseSubscriptions(MouseSubscriber sub)
Removes a mouse subscription

Parameters:
sub - the subscriber to be removed
Returns:
true if subscriber was present and removed, false otherwise

removeKeySubscriptions

public boolean removeKeySubscriptions(KeySubscriber sub)
Removes a key subscription

Parameters:
sub - the subscriber to be removed
Returns:
true if subscriber was present and removed, false otherwise

removeMouseWheelSubscriptions

public boolean removeMouseWheelSubscriptions(KeySubscriber sub)
Removes a mouse wheel subscription

Parameters:
sub - the subscriber to be removed
Returns:
true if subscriber was present and removed, false otherwise

removeOSCSubscriptions

public boolean removeOSCSubscriptions(KeySubscriber sub)
Removes an OSC subscription

Parameters:
sub - the subscriber to be removed
Returns:
true if subscriber was present and removed, false otherwise

removeAllSubscriptions

public boolean removeAllSubscriptions(HObject sub)
Helper method to remove all subscriptions for given HObject

Parameters:
sub - HObject to remove from PostOffice
Returns:
true if HObject had subscriptions that were removed, false otherwise

resetSubscriptions

public void resetSubscriptions()
Resets all subscriptions Use if passing subscriptions between Worlds


isKeyPressed

public boolean isKeyPressed(int keyCode)
Utility for checking if key is pressed

Parameters:
keyCode - the key being checked
Returns:
true if pressed, false otherwise

isMouseInRegion

public boolean isMouseInRegion(HShape region)
Utility for checking if mouse is in a region

Parameters:
region - region to check
Returns:
true if mouse is in region

getMouseLocation

public PVector getMouseLocation()
Utility for obtaining current mouse location

Returns:
mouse location

getPMouseLocation

public PVector getPMouseLocation()
Utility for obtaining previous mouse location

Returns:
mouse location on last update

sendInt

public void sendInt(java.lang.String address,
                    int send)
Sends an OscMessage on the given address containing only the given int.

Parameters:
address - address message is to be sent on
send - integer to be sent

sendFloat

public void sendFloat(java.lang.String address,
                      float send)
Sends an OscMessage on the given address containing only the given float.

Parameters:
address - address message is to be sent on
send - float to be sent

sendBoolean

public void sendBoolean(java.lang.String address,
                        boolean send)
Sends an OscMessage on the given address containing only the given boolean.

Parameters:
address - address message is to be sent on
send - boolean to be sent

sendList

public void sendList(java.lang.String address,
                     java.util.ArrayList<java.lang.Object> send)
Sends an OscMessage on the given address containing the contents of the given list.

Parameters:
address - address message is to be sent on
send - List to be sent

checkMail

public void checkMail()
Command that sends all messages queued by the PostOffice to subscribers.

Called at end of update loop (for thread safety).


keyTyped

public void keyTyped(java.awt.event.KeyEvent e)
Ignore keyTyped events.

Specified by:
keyTyped in interface java.awt.event.KeyListener

keyPressed

public void keyPressed(java.awt.event.KeyEvent e)
On a key press, make a new KeyMessage and add it to the queue. Note: keyPressed events will repeat at rate set by OS if key is held down; users should control this with keyReleased events.

Specified by:
keyPressed in interface java.awt.event.KeyListener

keyReleased

public void keyReleased(java.awt.event.KeyEvent e)
On a key release, make a new KeyMessage and add it to the queue.

Specified by:
keyReleased in interface java.awt.event.KeyListener

mouseClicked

public void mouseClicked(java.awt.event.MouseEvent e)
Ignore mouseClicked events.

Specified by:
mouseClicked in interface java.awt.event.MouseListener

mousePressed

public void mousePressed(java.awt.event.MouseEvent e)
On a mouse press, make a new MouseMessage and add it to the queue.

Specified by:
mousePressed in interface java.awt.event.MouseListener

mouseReleased

public void mouseReleased(java.awt.event.MouseEvent e)
On a mouse button release, make a new MouseMessage and add it to the queue.

Specified by:
mouseReleased in interface java.awt.event.MouseListener

mouseEntered

public void mouseEntered(java.awt.event.MouseEvent e)
Ignore mouseEntered events.

Specified by:
mouseEntered in interface java.awt.event.MouseListener

mouseExited

public void mouseExited(java.awt.event.MouseEvent e)
Ignore mouseExited events.

Specified by:
mouseExited in interface java.awt.event.MouseListener

mouseDragged

public void mouseDragged(java.awt.event.MouseEvent e)
When the mouse is dragged, create a MouseMessage and add it to the group.

Specified by:
mouseDragged in interface java.awt.event.MouseMotionListener

mouseMoved

public void mouseMoved(java.awt.event.MouseEvent e)
When the mouse is moved, create a MouseMessage and add it to the queue.

Specified by:
mouseMoved in interface java.awt.event.MouseMotionListener

mouseWheelMoved

public void mouseWheelMoved(java.awt.event.MouseWheelEvent e)
When the mouse wheel is moved, create a MouseWheelMessage and add it to the queue.

Specified by:
mouseWheelMoved in interface java.awt.event.MouseWheelListener

acceptMessage

public void acceptMessage(java.util.Date time,
                          com.illposed.osc.OSCMessage message)
Accepts and handles messages recieved by osc server. Called from within illposed library.

Specified by:
acceptMessage in interface com.illposed.osc.OSCListener

getMouseButton

public static POCodes.Button getMouseButton(java.awt.event.MouseEvent e)
Finds the proper mouse button code from a Swing mouse event. Use instead of e.getButton() because it may not work for some events on some systems.

Parameters:
e - the MouseEvent
Returns:
the mouse button code