home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Programming Languages Suite
/
ProgLangD.iso
/
VCAFE.3.0A
/
Main.bin
/
TransferableVisualObjects.java
< prev
next >
Wrap
Text File
|
1998-10-25
|
6KB
|
154 lines
/*
* Copyright 1998 Symantec Corporation, All Rights Reserved.
*/
package com.symantec.itools.vcafe.openapi.datatransfer;
import com.symantec.itools.vcafe.openapi.VisualObject;
import java.awt.datatransfer.*;
import java.io.IOException;
/**
* Adds <code>StringSelection</code> functionality to transferable <code>VisualObjects</code>.
* <p>The system clipboard essentially ignores non <code>StringSelection</code> transferables,
* so we wrap <code>VisualObjects</code> 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 TransferableVisualObjects extends StringSelection
{
/**
* The <code>DataFlavor</code> of transferable <code>VisualObjects</code>.
*/
public static final DataFlavor transferableVisualObjectsFlavor = new DataFlavor(VisualObject[].class, "Visual Objects");
/**
* Constructs a <code>TransferableVisualObjects</code> object that wraps the given <code>VisualObjects</code> as
* a <code>Transferable</code> object.
* <p>Note: the transfer data of the <code>StringSelection</code> flavors is the text "Visual Objects".
* @param vos the <code>VisualObjects</code> to wrap as a <code>Transferable</code> object.
*/
public TransferableVisualObjects(VisualObject[] vos) {
this(vos, ((vos.length == 1) ? vos[0].toString() : "Visual Objects"));
}
/**
* Constructs a <code>TransferableVisualObjects</code> object that wraps the given <code>VisualObject</code> as
* a <code>Transferable</code> object.
* <p>Note: the transfer data of the <code>StringSelection</code> flavors is the text "Visual Objects".
* @param vo the <code>VisualObject</code> to wrap as a <code>Transferable</code> object.
*/
public TransferableVisualObjects(VisualObject vo) {
this(vo, vo.toString());
}
/**
* Constructs a <code>TransferableVisualObjects</code> object that wraps the given <code>VisualObject</code> as
* a <code>Transferable</code> object.
* @param vo the <code>VisualObject</code> to wrap as a <code>Transferable</code> object.
* @param textValue the <code>String</code> to use for the transfer data of the <code>StringSelection</code> flavors.
*/
public TransferableVisualObjects(VisualObject vo, String textValue) {
this(new VisualObject[]{vo}, textValue);
}
/**
* Constructs a <code>TransferableVisualObjects</code> object that wraps the given <code>VisualObjects</code> as
* a <code>Transferable</code> object.
* @param vos the <code>VisualObjects</code> to wrap as a <code>Transferable</code> object.
* @param textValue the <code>String</code> to use for the transfer data of the <code>StringSelection</code> flavors.
*/
public TransferableVisualObjects(VisualObject[] vos, String textValue) {
super(textValue);
visualObjects = vos;
//
// Determine the flavor of the VisualObjects.
// If all of the VisualObjects are of the same type, we can
// register a specific flavor for them, so clients can query on it
//
String flavorClassName = vos[0].getClassName();
for (int i = 1; i<vos.length; i++) {
if (!flavorClassName.equals(vos[i].getClassName())) {
flavorClassName = null;
break;
}
}
if (flavorClassName != null) {
try {
visualObjectsFlavor = new DataFlavor(Class.forName(flavorClassName), flavorClassName);
} catch (ClassNotFoundException cnfe) {}
}
}
/**
* Gets the transferable <code>VisualObjects</code>.
* @return an array of the <code>VisualObjects</code> being transferred.
*/
public VisualObject[] getVisualObjects() {
return visualObjects;
}
/**
* 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[] sFlavors = super.getTransferDataFlavors();
DataFlavor[] flavors = new DataFlavor[sFlavors.length + 1];
flavors[0] = transferableVisualObjectsFlavor;
int f = 1;
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 flavor.equals(transferableVisualObjectsFlavor) ||
(visualObjectsFlavor != null && flavor.equals(visualObjectsFlavor)) ||
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 (flavor.equals(transferableVisualObjectsFlavor))
return (Object) visualObjects;
if (visualObjectsFlavor != null && flavor.equals(visualObjectsFlavor))
return (Object) visualObjects;
return super.getTransferData(flavor);
}
private VisualObject[] visualObjects;
private DataFlavor visualObjectsFlavor = null; // If all visualObjects are the same type
}