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.
Name | Type | Description |
Clipboard | Class | Deals with everything that is a transferable |
ClipboardOwner | Interface | Every 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 |
Dataflavor | Class | Represents all the data types that transferable support |
StringSelection | Class | One type of transferable that is supplied with Java |
Transferable | Interface | Wrapper to objects passed to the clipboard |
Exception | Class | Exception thrown by transferable for an unsupported data flavor |
The clipboard Class:
Method | Description |
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 |
READ How To Solve Synchronization Failures In Selenium or QTP?
Powered by Inline Related Posts
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 classThe Transferable interface |
Methods | Description |
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 |