com.ibm.tspaces.examples.whiteboard
Class WhiteboardPanel

java.lang.Object
  |
  +--java.awt.Component
        |
        +--java.awt.Container
              |
              +--java.awt.Panel
                    |
                    +--com.ibm.tspaces.examples.whiteboard.WhiteboardPanel

public class WhiteboardPanel
extends java.awt.Panel
implements java.awt.event.MouseListener, java.awt.event.MouseMotionListener, Callback

The panel of the whiteboard. This handles the panel where the lines and points are drawn. All of the TSpaces handling is done inside this object. It implements the Tuplespace Callback interface which gets control everytime a matching request is issued to TupleSpace.

Author:
Matthias Eichstaedt, John Thomas
See Also:
Serialized Form

Field Summary
protected static java.awt.Color BACKGROUND_COLOR
           
protected  boolean EraseFlag
           
protected  boolean Failed
           
protected  java.lang.String Host
          This is the Host where the TupleSpace Server is running
static int LINES
           
protected  boolean NotActive
           
static int POINTS
           
protected  int Port
          This is the port number for the TupleSpace server.
protected  TupleSpace TSServer
          This holds a reference to the current TupleSpace.
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Constructor Summary
WhiteboardPanel()
          The constructor
 
Method Summary
 boolean call(java.lang.String eventName_, java.lang.String tsName_, int sequenceNumber_, SuperTuple tuple_, boolean isException_)
          Process the callback from the server that notifies us when anyone (including ourselfes) writes to the Whiteboard TupleSpace.
 void erase()
          Erase the lines that the User has drawn since last Publish.
 void eraseAll()
          Global Erase of the whiteboard.
 void exitcmd()
           
 void init(Whiteboard caller)
          TupleSpace Initiallization routine.
 void mouseClicked(java.awt.event.MouseEvent e)
          The mouse button was clicked.
 void mouseDragged(java.awt.event.MouseEvent e)
          The mouse was dragged.
 void mouseEntered(java.awt.event.MouseEvent e)
          The mouse entered this panel.
 void mouseExited(java.awt.event.MouseEvent e)
          The mouse left this panel.
 void mouseMoved(java.awt.event.MouseEvent e)
          The mouse was moved.
 void mousePressed(java.awt.event.MouseEvent e)
          The mouse button was pressed.
 void mouseReleased(java.awt.event.MouseEvent e)
          The mouse button was released.
 void paint(java.awt.Graphics g)
          Paints the panel.
 void paint(java.awt.Graphics g, java.util.Vector lines, java.util.Vector colors)
          Paints the panel based on the vectos of lines and colors.
 void publish()
          Publish the current content to tuplespace.
 void removeAll()
          This is called our parent (Whiteboard) gets a applet destroy() event.
 void setDrawMode(int mode)
          Set the draw mode.
 void term()
          This is called when the windowClosing event arrives.
 
Methods inherited from class java.awt.Panel
addNotify
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getAlignmentX, getAlignmentY, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getInsets, getLayout, getMaximumSize, getMinimumSize, getPreferredSize, insets, invalidate, isAncestorOf, layout, list, list, locate, minimumSize, paintComponents, paramString, preferredSize, print, printComponents, processContainerEvent, processEvent, remove, remove, removeContainerListener, removeNotify, setCursor, setFont, setLayout, update, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addPropertyChangeListener, addPropertyChangeListener, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, disable, disableEvents, dispatchEvent, enable, enable, enableEvents, enableInputMethods, firePropertyChange, getBackground, getBounds, getBounds, getColorModel, getComponentOrientation, getCursor, getDropTarget, getFont, getFontMetrics, getForeground, getGraphics, getHeight, getInputContext, getInputMethodRequests, getLocale, getLocation, getLocation, getLocationOnScreen, getName, getParent, getPeer, getSize, getSize, getToolkit, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isDisplayable, isDoubleBuffered, isEnabled, isFocusTraversable, isLightweight, isOpaque, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, printAll, processComponentEvent, processFocusEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, remove, removeComponentListener, removeFocusListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, reshape, resize, resize, setBackground, setBounds, setBounds, setComponentOrientation, setDropTarget, setEnabled, setForeground, setLocale, setLocation, setLocation, setName, setSize, setSize, setVisible, show, show, size, toString, transferFocus
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

LINES

public static final int LINES

POINTS

public static final int POINTS

BACKGROUND_COLOR

protected static java.awt.Color BACKGROUND_COLOR

TSServer

protected TupleSpace TSServer
This holds a reference to the current TupleSpace.

Host

protected java.lang.String Host
This is the Host where the TupleSpace Server is running

Port

protected int Port
This is the port number for the TupleSpace server. The TupleSpace HTTP Server is at this port +1

EraseFlag

protected boolean EraseFlag

NotActive

protected boolean NotActive

Failed

protected boolean Failed
Constructor Detail

WhiteboardPanel

public WhiteboardPanel()
The constructor
Method Detail

init

public void init(Whiteboard caller)
TupleSpace Initiallization routine. This will setup to access TupleSpace and register to be informed when anyone writes a "Whiteboard" tuple to the "Whiteboard" tuplespace. It will then get all the current Tuples and paint them. TupleSpace contains the all of the whiteboard tuples that have been written up to this time. We want to read in and process all of them. We use the scan method for this and get back a tuple that is a list of the tuples.
See Also:
TupleSpace, Tuple, Field

term

public void term()
This is called when the windowClosing event arrives. We will tell the server that we are going away by issuing the cleanup() command.
See Also:
TupleSpace.cleanup()

removeAll

public void removeAll()
This is called our parent (Whiteboard) gets a applet destroy() event. We will tell the server that we are going away by issuing the term() command.
Overrides:
removeAll in class java.awt.Container

publish

public void publish()
Publish the current content to tuplespace. This will write the vector of lines and colors that the user has created since the last publish. It will then start a new set of lines and colors. Since we will be informed of our own write in the callback, we will let the callback update the set of all lines.

erase

public void erase()
Erase the lines that the User has drawn since last Publish.

eraseAll

public void eraseAll()
Global Erase of the whiteboard. This will write a empty vector of lines and colors to tuplespace. This will be treated as an erase command by other clients that receive the request. We will also delete all of the old lines and points that have been accumulating in the TupleSpace. Since we will be informed of this in the callback, we will let the callback update the set of all lines. We won't worry about problems caused by requests arriving at the the server and clients in different orders.

exitcmd

public void exitcmd()

call

public boolean call(java.lang.String eventName_,
                    java.lang.String tsName_,
                    int sequenceNumber_,
                    SuperTuple tuple_,
                    boolean isException_)
Process the callback from the server that notifies us when anyone (including ourselfes) writes to the Whiteboard TupleSpace. If we get back 2 empty vectors, then this was an erase request from one of our users. Otherwise, the 2 vectors are the lines/points and colors that one of our users is publishing
Specified by:
call in interface Callback
Parameters:
eventName_ - the name of the event command that caused this call, that is the name of the client side command of the thread that registered this call, e.g., in the case of a read, this would be TupleSpace.READ, **not** TupleSpace.WRITE which is the corresponding command that caused the actaul event.
tsName_ - the name of the tuple space this command was executed on.
sequenceNumber_ - the sequenceNumber for this event/command
tuple_ - the returned tuple or a Tuple with an exception inside
isException_ - was the command processed normaly or was there an exception
Returns:
true if this is the last call this sequence # should be getting otherwise false

paint

public void paint(java.awt.Graphics g)
Paints the panel. The real paint method is called first for the objects that this user has generated, and then for a vector of objects that have been recieved form TupleSpace. If an Erase request was received from TupleSpace then the EraseFlag was set and we will erase the window before proceeding.
Overrides:
paint in class java.awt.Container
Parameters:
g - - the graphics context

paint

public void paint(java.awt.Graphics g,
                  java.util.Vector lines,
                  java.util.Vector colors)
Paints the panel based on the vectos of lines and colors.
Parameters:
g - - the graphics context
lines - - A vector of Rectangle objects
colors - - A vector of color objects.

setDrawMode

public void setDrawMode(int mode)
Set the draw mode.
Parameters:
mode - - the draw mode

mouseDragged

public void mouseDragged(java.awt.event.MouseEvent e)
The mouse was dragged.
Specified by:
mouseDragged in interface java.awt.event.MouseMotionListener
Parameters:
e - - the mouse event

mouseMoved

public void mouseMoved(java.awt.event.MouseEvent e)
The mouse was moved.
Specified by:
mouseMoved in interface java.awt.event.MouseMotionListener
Parameters:
e - - the mouse event

mousePressed

public void mousePressed(java.awt.event.MouseEvent e)
The mouse button was pressed.
Specified by:
mousePressed in interface java.awt.event.MouseListener
Parameters:
e - - the mouse event

mouseReleased

public void mouseReleased(java.awt.event.MouseEvent e)
The mouse button was released.
Specified by:
mouseReleased in interface java.awt.event.MouseListener
Parameters:
e - - the mouse event

mouseEntered

public void mouseEntered(java.awt.event.MouseEvent e)
The mouse entered this panel.
Specified by:
mouseEntered in interface java.awt.event.MouseListener
Parameters:
e - - the mouse event

mouseExited

public void mouseExited(java.awt.event.MouseEvent e)
The mouse left this panel.
Specified by:
mouseExited in interface java.awt.event.MouseListener
Parameters:
e - - the mouse event

mouseClicked

public void mouseClicked(java.awt.event.MouseEvent e)
The mouse button was clicked.
Specified by:
mouseClicked in interface java.awt.event.MouseListener
Parameters:
e - - the mouse event