com.ibm.tspaces.examples.copypaste
Class TClipboard

java.lang.Object
  |
  +--java.awt.Component
        |
        +--java.awt.Container
              |
              +--java.awt.Window
                    |
                    +--java.awt.Frame
                          |
                          +--com.ibm.tspaces.examples.copypaste.TClipboard

public class TClipboard
extends java.awt.Frame
implements java.awt.datatransfer.ClipboardOwner, Callback

This is a sample application to show the usefulness of TupleSpace. It is a cut and paste buffer that works across programs, systems, platforms, and the universe. This version is a rewrite of the simple prototype written by Matthias. The simple version used just the java cut and paste buffer that could hold only a single entry in the buffer -- not all that useful. There was no way to query the contents of the clipboard database to choose amoung multiple entries -- only one entry was permitted. Part of the problem is that the Java cut and paste buffer itself is somewhat brain-damaged. It is a limitation of the buffer that it can handle only a single entry. Thus, we must add our own selection window to talk to tuplespace and query its contents. Then, when we find what we want in the tuplespace, then we can place that in the cut and paste buffer for use by the local system. The global cut-n-paste buffer concept is appealing and potentially very useful, but if done wrong it can be painful to use. As a result, we'll probably have to experiment with several things before we get it right. So, the starting idea is this. We have a Tuplespace communication frame that shows what's in the tuplespace. We should be able to fill up the communication frame with entries from the tuplespace. Users can interact with the frame to pick the TS entry that they want, then they can have that entry be pasted into the local system cut and paste buffer. From there, the entry can be dropped into any application. Version 1.1 We're going to automatically number the individual entries in the communication frame. The user will use the mouse to select one of the numbers to be used in the query back to TS to get the actual entry, which will then be placed in the cut and paste buffer. Version 1.2 (The first GCSClipboard2) THIS IS FOR DEMO PURPOSES ONLY! Don't distribute it too widely until we know that the ReTaker class is not causing serious damage to anybody. The UI has changed quite a bit: The top TextArea displays the current contents of the local clipboard. The other TextAreas display the contents of the user's buffers in TupleSpace. The user can select the active buffer, and either Read the buffer into the local clipboard or Publish the local clipboard into the buffer. (swm) Version 1.2.1 has had a couple of enhancements. (jthomas) It is now called TClipboard to match the BlueSpaces component The current retake method causes a problem if you you try to start 2 instances on the same system because they fight over ownership of the system clipboard. This hacks it a bit more to recogonise this and one of the instance will give up. It now uses eventRegister so it will be informed when other TClipboard instances update on of the buffers. It now updates the local clipboard display consistantly It now has Copy/Paste buttons instead of read/Publish because these are more familiar clipboard actions. AutoCopy and AutoPaste options added to automate the copy/paste between systems Version 1.3 should probably implement the multi-user version, so you can look at other user's buffers (but probably not publish into them). A rudimentary multi-user version has been implemented. It allows one user to look at (view) another user's buffers, but does not allow him to modify them. In the earlier version, a bug was detected. If another user wrote a tuple into the same tuplespace as the present user, it appeared on the present user's clipboard. This has been fixed. Version 1.4 should probably implement non-text transfers.

Author:
Matthias Eichstaedt, June 97, Toby Lehman, Sept 97, Steve McLaughry, Sept 97, John Thomas, Dec 97, Thomas Baby, Jun 98
See Also:
Serialized Form

Field Summary
static java.lang.String _AUTO_COPY_LABEL
           
static java.lang.String _AUTO_PASTE_LABEL
           
static java.lang.String _DEFAULTSERVERNAME
           
static java.lang.String _DEFAULTSPACENAME
           
static java.lang.String _DEFAULTUSERNAME
           
static java.lang.String _EXIT_BUTTON
           
static int _NUMBER_OF_BUFFERS
           
static java.lang.String _OK_BUTTON
           
static java.lang.String _PUBLISH_BUTTON
           
static java.lang.String _READ_BUTTON
           
static java.lang.String _VIEW_BUTTON
           
static java.lang.String _VIEW_DIALOG_TITLE
           
 
Fields inherited from class java.awt.Frame
CROSSHAIR_CURSOR, DEFAULT_CURSOR, E_RESIZE_CURSOR, HAND_CURSOR, ICONIFIED, MOVE_CURSOR, N_RESIZE_CURSOR, NE_RESIZE_CURSOR, NORMAL, NW_RESIZE_CURSOR, S_RESIZE_CURSOR, SE_RESIZE_CURSOR, SW_RESIZE_CURSOR, TEXT_CURSOR, W_RESIZE_CURSOR, WAIT_CURSOR
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Constructor Summary
TClipboard(java.lang.String serverName_, java.lang.String userName_)
          Layout the frame and the buttons for the TClipboard Frame.
 
Method Summary
protected  void actionBufferChange(java.awt.event.ItemEvent e)
          Change the currently active buffer
protected  void actionPublish()
          Paste an object from the local buffer and put it into TS.
protected  void actionRead()
          Read an object from the TS and Copy it into the local buffer.
protected  void actionRefresh()
          Get the contents of each buffer, display it in the corresponding TextArea.
protected  void actionView()
          Open a GCSClipboardReader looking at another user's buffers.
 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 clipboard TupleSpace.
 void lostOwnership(java.awt.datatransfer.Clipboard clipboard_, java.awt.datatransfer.Transferable oldContents_)
          lostOwnership method is required to implement the ClipboardOwner interface.
static void main(java.lang.String[] argv)
          The main man.
 void takeOwnership()
          Called during initialization to get the current clipboard contents for display and then take Ownership of the system clipboard
 
Methods inherited from class java.awt.Frame
addNotify, finalize, getCursorType, getFrames, getIconImage, getMenuBar, getState, getTitle, isResizable, paramString, remove, removeNotify, setCursor, setIconImage, setMenuBar, setResizable, setState, setTitle
 
Methods inherited from class java.awt.Window
addWindowListener, applyResourceBundle, applyResourceBundle, dispose, getFocusOwner, getInputContext, getLocale, getOwnedWindows, getOwner, getToolkit, getWarningString, hide, isShowing, pack, postEvent, processEvent, processWindowEvent, removeWindowListener, setCursor, show, toBack, toFront
 
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, paint, paintComponents, preferredSize, print, printComponents, processContainerEvent, remove, remove, removeAll, removeContainerListener, 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, getInputMethodRequests, getLocation, getLocation, getLocationOnScreen, getName, getParent, getPeer, getSize, getSize, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, imageUpdate, inside, isDisplayable, isDoubleBuffered, isEnabled, isFocusTraversable, isLightweight, isOpaque, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, prepareImage, prepareImage, printAll, processComponentEvent, processFocusEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, 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, size, toString, transferFocus
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

_NUMBER_OF_BUFFERS

public static int _NUMBER_OF_BUFFERS

_DEFAULTSPACENAME

public static final java.lang.String _DEFAULTSPACENAME

_DEFAULTSERVERNAME

public static final java.lang.String _DEFAULTSERVERNAME

_DEFAULTUSERNAME

public static final java.lang.String _DEFAULTUSERNAME

_PUBLISH_BUTTON

public static final java.lang.String _PUBLISH_BUTTON

_READ_BUTTON

public static final java.lang.String _READ_BUTTON

_VIEW_BUTTON

public static final java.lang.String _VIEW_BUTTON

_EXIT_BUTTON

public static final java.lang.String _EXIT_BUTTON

_OK_BUTTON

public static final java.lang.String _OK_BUTTON

_VIEW_DIALOG_TITLE

public static final java.lang.String _VIEW_DIALOG_TITLE

_AUTO_PASTE_LABEL

public static final java.lang.String _AUTO_PASTE_LABEL

_AUTO_COPY_LABEL

public static final java.lang.String _AUTO_COPY_LABEL
Constructor Detail

TClipboard

public TClipboard(java.lang.String serverName_,
                  java.lang.String userName_)
Layout the frame and the buttons for the TClipboard Frame. Then, attach to the tuplespace (create an instance of the client tuplespace object).
Parameters:
serverName_ - Specify which server we're going to talk to
userName_ - Specify which user we're acting for
Method Detail

actionRead

protected void actionRead()
Read an object from the TS and Copy it into the local buffer.

actionPublish

protected void actionPublish()
Paste an object from the local buffer and put it into TS.

actionRefresh

protected void actionRefresh()
Get the contents of each buffer, display it in the corresponding TextArea.

actionView

protected void actionView()
Open a GCSClipboardReader looking at another user's buffers.

actionBufferChange

protected void actionBufferChange(java.awt.event.ItemEvent e)
Change the currently active buffer

takeOwnership

public void takeOwnership()
Called during initialization to get the current clipboard contents for display and then take Ownership of the system clipboard

lostOwnership

public void lostOwnership(java.awt.datatransfer.Clipboard clipboard_,
                          java.awt.datatransfer.Transferable oldContents_)
lostOwnership method is required to implement the ClipboardOwner interface. Called when another application replaces the string we had in the clipboard. Unfortunately, it seems to be called AFTER our string (which we're also given as oldContents_) has been taken out, but BEFORE the new contents are added. So start another thread to re-take ownership, but return from this call. It is possible that another application may also try to keep ownership of the clipboard this way, perhaps even another instance of TClibboard. so we try to handle this. We will set a time limit of 10 seconds and count all of the lostOwnership events that occur in that time limit. If it is more than some number (say 10), then we will give up ownership.
Specified by:
lostOwnership in interface java.awt.datatransfer.ClipboardOwner
Parameters:
clipboard_ - the clipboard that we lost
oldContents_ - what we had in the clipboard

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 clipboard TupleSpace.
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

main

public static void main(java.lang.String[] argv)
The main man. We process the command line arguments, then creates a clipboard object.
   Usage:   classname options  userName 
        options: 
          -D            - turn on Debug flag
          -h host       - Specify TS Server name
          -userName     - Username field for clipboard Tuples,
 
Parameters:
args_ - Command line arguments