edu.wpi.cs.cs509.clipboard
Class Clipboard

java.lang.Object
  |
  +--edu.wpi.cs.cs509.clipboard.Clipboard
All Implemented Interfaces:
IClipboard, IClipboardGUI

public class Clipboard
extends java.lang.Object
implements IClipboardGUI

Maintains primitive Clipboard for block components.

This clipboard component supports both the original IClipboard interface (a programmatic API interface) and the graphical IClipboardGUI interface (a Microsoft-office-like Clipboard frame for maintaining multiple items on the clipboard).

As such, its provided and required are suitably configured. Note that you do not have to satisfy the required interface of the graphical component if you are only going to use the standard API.

Provided: IClipboard, IClipboardGUI (since V1.1)

Required: IClipboardAccessor (but only if connected via IClipboardGUI)

VERSIONS:

1.1.1 Fixed problems with DataType in some of its interfaces. 1.1 Added GUI Functionality 1.0 Original

Author:
George T. Heineman (heineman@cs.wpi.edu)

Field Summary
protected  java.util.Stack contents
          Stack to hold the entries.
protected  ClipboardGUI guiInstance
          Each clipboard can have a single GUI instance.
protected  java.util.Vector providedV
          Internal storage of provided interfaces.
protected  java.util.Vector requiredV
          Internal storage of required interfaces.
protected  boolean useGraphicalInterface
          Determines whether to use the graphical interface of clipboard.
 
Constructor Summary
Clipboard()
          Clipboard constructor comment.
 
Method Summary
 boolean activate()
          Used to activate the component
protected  void activateGUI(boolean enabled)
          Activates GUI in its own thread.
 void clear()
          Clear the contents of the clipboard
 boolean connect(IBlock obj, java.lang.String interfaceName)
          Gives the components an IBlock object to connect to and the interface at which to connect
 void deactivate()
          Used to deactivate the component
 java.util.Enumeration getProvided()
          This method returns an Enumeration of Strings, specifying all the interfaces that this component provides
 java.util.Enumeration getRequired()
          This method returns an Enumeration of Strings, specifying all the interfaces that this component requires
 boolean insert(IItem i)
          Inserts the given object conforming to the IItem interface into the clipboard.
 IDataType newDataTypeInstance(java.lang.String s)
          Constructs an object conforming to the IDataType interface given a String object.
 IItem newItemInstance(IDataType type, java.lang.Object o)
          Constructs an object conforming to the IItem interface given an IDataType and object
 IItem retrieve()
          Retrieves the last IItem inserted into the clipboard.
 IItem retrieve(IDataType type)
          Retrieves most recent IItem inserted into clipboard of given type.
 IItem retrieveNth(int n)
          Returns the nth last IItem inserted into the Clipboard counting from 1.
 IItem retrieveNth(int n, IDataType type)
          Returns the nth IItem in the clipboard that is a sub-type of given IDataType.
 void setAccessor(IClipboardAccessor ica)
          Tell GUI Clipboard to whom its commands should be sent.
 void showClipboard(boolean flag)
          Make the Clipboard GUI visible or invisible.
 java.util.Enumeration types()
          Return Enumeration of IDataType objects representing the clipboard contents
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

providedV

protected java.util.Vector providedV
Internal storage of provided interfaces.


requiredV

protected java.util.Vector requiredV
Internal storage of required interfaces.


contents

protected java.util.Stack contents
Stack to hold the entries.


guiInstance

protected ClipboardGUI guiInstance
Each clipboard can have a single GUI instance.

Since:
V1.1 of clipboard

useGraphicalInterface

protected boolean useGraphicalInterface
Determines whether to use the graphical interface of clipboard.

Since:
V1.1 of clipboard
Constructor Detail

Clipboard

public Clipboard()
Clipboard constructor comment.

Needs to be here for CMI.

Method Detail

activate

public boolean activate()
Used to activate the component

Returns:
boolean Indicates if the component activated successfully or not

activateGUI

protected void activateGUI(boolean enabled)
Activates GUI in its own thread.

Also responsible for telling GUI of external agent to whom requests should be redirected. If GUI does not already exist, it will become visible even if the enabled parameter is false.


clear

public void clear()
Clear the contents of the clipboard

PRE: none
POST: clipboard is empty

Modified V1.1 to work with GUI

Specified by:
clear in interface IClipboard

connect

public boolean connect(IBlock obj,
                       java.lang.String interfaceName)
Gives the components an IBlock object to connect to and the interface at which to connect

Parameters:
obj - The IBlock object to connect
interfaceName - The name of the interface as a string
Returns:
boolean Indicates if the connection was successful or not

deactivate

public void deactivate()
Used to deactivate the component


getProvided

public java.util.Enumeration getProvided()
This method returns an Enumeration of Strings, specifying all the interfaces that this component provides

Returns:
Enumeration The interfaces provided by this component

getRequired

public java.util.Enumeration getRequired()
This method returns an Enumeration of Strings, specifying all the interfaces that this component requires

Returns:
Enumeration The interfaces required by this component

insert

public boolean insert(IItem i)
Inserts the given object conforming to the IItem interface into the clipboard.

PRE: none
POST: contents.size() = contents'.size() + 1. i is the next item to be retrieved.

Modified in V1.1 to pop up GUI if one is being used.

Specified by:
insert in interface IClipboard
Parameters:
i - edu.wpi.cs.cs509.graph.clipboard.Item
Returns:
true if Item successfully added.

newDataTypeInstance

public IDataType newDataTypeInstance(java.lang.String s)
                              throws ClipboardException
Constructs an object conforming to the IDataType interface given a String object.

Specified by:
newDataTypeInstance in interface IClipboard
Returns:
edu.wpi.cs.cs509.graph.clipboard.IDataType
Throws:
ClipboardException - If String refers to non-valid Java type.

newItemInstance

public IItem newItemInstance(IDataType type,
                             java.lang.Object o)
                      throws ClipboardException
Constructs an object conforming to the IItem interface given an IDataType and object

Specified by:
newItemInstance in interface IClipboard
Parameters:
type - edu.wpi.cs.cs509.graph.clipboard.IDataType
o - java.lang.Object
Returns:
edu.wpi.cs.cs509.graph.clipboard.Item
Throws:
ClipboardException - If type was not previously constructed by clipboard.

retrieve

public IItem retrieve()
               throws ClipboardException
Retrieves the last IItem inserted into the clipboard.

PRE: clipboard.size() > 1
POST: stack unchanged.

Specified by:
retrieve in interface IClipboard
Returns:
edu.wpi.cs.cs509.graph.clipboard.IItem
Throws:
ClipboardException - If clipboard is empty.

retrieve

public IItem retrieve(IDataType type)
               throws ClipboardException
Retrieves most recent IItem inserted into clipboard of given type.

PRE: clipboard.size() > 1
POST: clipboard unchanged.

Specified by:
retrieve in interface IClipboard
Parameters:
type - edu.wpi.cs.cs509.graph.clipboard.IDataType
Returns:
edu.wpi.cs.cs509.graph.clipboard.IItem
Throws:
ClipboardException - No such type exists in the clipboard.

retrieveNth

public IItem retrieveNth(int n)
                  throws ClipboardException
Returns the nth last IItem inserted into the Clipboard counting from 1.

PRE: clipboard.size() > n
POST: clipboard unchanged.

Specified by:
retrieveNth in interface IClipboard
Parameters:
n - int
Returns:
edu.wpi.cs.cs509.graph.clipboard.IItem
Throws:
ClipboardException - If n is invalid given state of clipboard.

retrieveNth

public IItem retrieveNth(int n,
                         IDataType type)
                  throws ClipboardException
Returns the nth IItem in the clipboard that is a sub-type of given IDataType.

Note: This method is not yet implemented in Version 1.1

PRE: clipboard.size() > n
POST: clipboard unchanged.

Specified by:
retrieveNth in interface IClipboard
Parameters:
n - int
type - edu.wpi.cs.cs509.graph.clipboard.IDataType
Returns:
edu.wpi.cs.cs509.graph.clipboard.IItem
Throws:
ClipboardException - the nth object of type does not exist in clipboard.

setAccessor

public void setAccessor(IClipboardAccessor ica)
Tell GUI Clipboard to whom its commands should be sent.

Specified by:
setAccessor in interface IClipboardGUI
Parameters:
ica - edu.wpi.cs.cs509.graph.clipboard.IClipboardAccessor
Since:
V1.1 of Clipboard

showClipboard

public void showClipboard(boolean flag)
Make the Clipboard GUI visible or invisible.

If the clipboard is NOT operating in graphical mode, nothing happens.

Specified by:
showClipboard in interface IClipboardGUI
Since:
V1.1 of Clipboard.

types

public java.util.Enumeration types()
Return Enumeration of IDataType objects representing the clipboard contents

PRE: none
POST: clipboard unchanged.

Specified by:
types in interface IClipboard
Returns:
java.util.Enumeration