home *** CD-ROM | disk | FTP | other *** search
Java Source | 1998-10-25 | 3.4 KB | 96 lines |
- /*
- * Copyright 1998 Symantec Corporation, All Rights Reserved.
- */
-
- package com.symantec.itools.vcafe.openapi.datatransfer;
-
- import java.awt.datatransfer.*;
- import java.io.IOException;
-
- /**
- * Adds <code>StringSelection</code> functionality to any <code>Transferable</code> object.
- * <p>The system clipboard essentially ignores non <code>StringSelection</code> transferables,
- * so we wrap them in order to force the system clipboard to freshen/clear Visual Cafe's clipboard.
- * @see VisualCafeClipboard
- * @see com.symantec.itools.vcafe.openapi.VisualCafe#getClipboard
- *
- * @author Symantec Internet Tools Division
- * @version 1.0
- * @since VCafe 3.0
- */
- public class TransferableProxy extends StringSelection
- {
- /**
- * Constructs a <code>TransferableProxy</code>, wrapping the given <code>Transferable</code> in
- * one with string flavors as well.
- * @param t the <code>Transferable</code> object to wrap.
- */
- public TransferableProxy(Transferable t)
- {
- super("");
- proxiedTransferable = t;
- }
-
- /**
- * Gets the original <code>Transferable</code> object that this <code>TransferableProxy</code> wraps.
- * @return the user's <code>Transferable</code> object.
- */
- public Transferable getProxiedTransferable()
- {
- return proxiedTransferable;
- }
-
- /**
- * Gets an array of <code>DataFlavor</code> objects indicating the formats the data
- * can be provided in. The array should be ordered according to preference
- * for providing the data (from most richly descriptive to least descriptive).
- * <p>The <code>StringSelection</code> flavors are at the end of the array.
- * @return an array of data flavors in which this data can be transferred
- */
- public synchronized DataFlavor[] getTransferDataFlavors()
- {
- DataFlavor[] tFlavors = proxiedTransferable.getTransferDataFlavors();
- DataFlavor[] sFlavors = super.getTransferDataFlavors();
-
- DataFlavor[] flavors = new DataFlavor[tFlavors.length + sFlavors.length];
- int f = 0;
- for (int i = 0; i < tFlavors.length; i++, f++)
- flavors[f] = tFlavors[i];
- for (int i = 0; i < sFlavors.length; i++, f++)
- flavors[f] = sFlavors[i];
-
- return flavors;
- }
-
- /**
- * Determines whether the specified data flavor is supported for this object.
- * @param flavor the requested flavor for the data.
- * @return <code>true</code> if the <code>DataFlavor</code> is supported, <code>false</code> otherwise.
- */
- public boolean isDataFlavorSupported(DataFlavor flavor)
- {
- return proxiedTransferable.isDataFlavorSupported(flavor) ||
- super.isDataFlavorSupported(flavor);
- }
-
- /**
- * Gets an object which represents the data to be transferred. The class of the object returned
- * is defined by the representation class (<code>DataFlavor.getRepresentationClass()</code>)
- * of the flavor.
- * @param flavor the requested flavor for the data.
- * @return The data to be transferred.
- * @see DataFlavor#getRepresentationClass
- * @exception IOException if the data is no longer available
- * in the requested flavor.
- * @exception UnsupportedFlavorException if the requested data flavor is
- * not supported.
- */
- public synchronized Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException, IOException
- {
- if (proxiedTransferable.isDataFlavorSupported(flavor))
- return proxiedTransferable.getTransferData(flavor);
- return super.getTransferData(flavor);
- }
-
- private Transferable proxiedTransferable;
- }