Commonly Used Clipboard Objects in Testing

Clipboard Objects in Testing

ClipBoard class is used for a Transferable object and can be used for Cut,Copy,Paste operation.

This is used to get or transfer/send information via Clipboard Mostly Java has two types of clipboards. Local and system.

Local clipboards are only available inside the virtual machine that  your applet or application is running. However, unlike some
operating systems that limit you to only one clipboard, Java allows  you to have as many local clipboards as you desire. Accessing a particular local clipboard is as easy as referring to it by name.System clipboards are directly linked with the peer operating system, allowing your application to transfer information among

any applications running under that operating system. One  disadvantage of using the system clipboard is that you can only
transfer text data. Other types of objects are not supported  by the system clipboard. With any luck, this issue will be addressed in  the next release of the JDK.


ClipboardClassDeals with everything that is a transferable
ClipboardOwnerInterfaceEvery class that deals with the clipboard must implement this interface. This interface is used to notify when the data originally placed in the clipboard has been overwritten
DataflavorClassRepresents all the data types that transferable support
StringSelectionClassOne type of transferable that is supplied with Java
TransferableInterfaceWrapper to objects passed to the clipboard
ExceptionClassException thrown by transferable for an unsupported data flavor
The clipboard Class:
String getName ()Get the name of the clipboard
void setContents (Transferable, ClipboardOwner)Set the content of the clipboard along with owner object
Transferable getContent (Object)Get the content of the clipboard in the form of a Transferable object. The object passed as a parameter is the owner
See also  What is User Acceptance Testing(UAT)?


To access the system clipboard:
Clipboard clip=getToolkit().getSystemClipboard();
The ClipBoard Owner Interface:
Its sole function is to inform the owner of the clipboard when his or her data is being overwritten by someone else. It can also signal an application when to release a resource associated with the data. In a real application, the lostOwnership method could be used to set a flag that informs your application about the availability of the data in the clipboard. Microsoft Word, while not written in Java, is a good example of this mechanism at work in an application. Whenever you put something in the clipboard within Word and then quit, a dialog box appears informing you that data is in the clipboard. You will then be asked if you want to leave the data in the clipboard.


The DataFlavor class
The DataFlavor class is used to represent the type of an object. You’re not limited to one data flavor (or type) per object. And, like us, your objects can have multiple personalities! For example, an image class can be represented as a Java class or as an array of bits (GIF, JPEG, and so on). In reality, a DataFlavor class is a wrapper to a MIME type. The MIME standard is extensive, hence there are virtually no limits to the data that can be transferred to the clipboard.


boolean equals (DataFlavor)Test if the DataFlavor supplied is equal to the DataFlavor represented by this class
String getHumanPresentableName ()Return the human representable name for the format that this DataFlavor represents
void setHumanPresentableName (String)Set the human representation name for this DataFlavor
String getMimeType ()Get the MIME type string represented by this DataFlavor
Class getRepresentationClass ()Return the Class that represents this class
See also  How To Start And Stop Selenium Server From Eclipse


The Transferable interface
The Transferable interface must be implemented by all classes that you want to send to the clipboard, hence the Clipboard class will only understand classes that have been wrapped by the Transferable interface. The Transferable interface is comprised of three methods:
Transferable interface

DataFlavor getTransferDataFlavor ()Return an array of DataFlavor that represents the object
boolean isDataFlavorSupported (DataFlavor)Test if the DataFlavor supplied is supported
Object getTransferData (DataFlavor)Return the object represented by the supplied DataFlavor


Share and Enjoy !

One thought on “Commonly Used Clipboard Objects in Testing

  1. Very great post. I simply stumbled upon your blog and wanted to say that I have really enjoyed browsing your weblog posts. After all I’ll be subscribing on your feed and I am hoping you write again very soon!

Leave a Reply

Your email address will not be published. Required fields are marked *