--- /dev/null
+// TransferableResourceCell.java\r
+// $Id: TransferableResourceCell.java,v 1.1 2010/06/15 12:25:53 smhuang Exp $\r
+// (c) COPYRIGHT MIT, INRIA and Keio, 1999.\r
+// Please first read the full copyright statement in file COPYRIGHT.html\r
+\r
+package org.w3c.jigadmin.editors;\r
+\r
+import java.awt.datatransfer.Transferable;\r
+import java.awt.datatransfer.DataFlavor;\r
+import java.awt.datatransfer.UnsupportedFlavorException;\r
+\r
+import java.io.ByteArrayInputStream;\r
+import java.io.IOException;\r
+\r
+/**\r
+ * The transferable ResourceCell\r
+ * @see org.w3c.jigadmin.editors.ResourceCell\r
+ * @version $Revision: 1.1 $\r
+ * @author Benoît Mahé (bmahe@w3.org)\r
+ */\r
+public class TransferableResourceCell implements Transferable {\r
+\r
+ final static int CELL = 0;\r
+ final static int STRING = 1;\r
+ final static int PLAIN_TEXT = 2;\r
+\r
+ final public static DataFlavor RESOURCE_CELL_FLAVOR =\r
+ new DataFlavor(ResourceCell.class, "Resource Cell");\r
+\r
+ static DataFlavor flavors[] = { RESOURCE_CELL_FLAVOR,\r
+ DataFlavor.stringFlavor, \r
+ DataFlavor.plainTextFlavor };\r
+\r
+ private ResourceCell data = null;\r
+\r
+ /**\r
+ * Constructor\r
+ * @param data The ResourceCell\r
+ */\r
+ public TransferableResourceCell(ResourceCell data) {\r
+ this.data = data;\r
+ }\r
+\r
+ /**\r
+ * Returns an array of DataFlavor objects indicating the flavors the\r
+ * data can be provided in. The array should be ordered according to \r
+ * preference for providing the data (from most richly descriptive to \r
+ * least descriptive).\r
+ * @return an array of data flavors in which this data can be transferred\r
+ */\r
+ public DataFlavor[] getTransferDataFlavors() {\r
+ return flavors;\r
+ }\r
+\r
+ /**\r
+ * Returns whether or not the specified data flavor is supported for \r
+ * this object.\r
+ * @param flavor the requested flavor for the data \r
+ * @return boolean indicating wether or not the data flavor is supported\r
+ */\r
+ public boolean isDataFlavorSupported(DataFlavor flavor) {\r
+ boolean returnValue = false;\r
+ for (int i=0, n=flavors.length; i<n; i++) {\r
+ if (flavor.equals(flavors[i])) {\r
+ returnValue = true;\r
+ break;\r
+ }\r
+ }\r
+ return returnValue;\r
+ }\r
+\r
+ /**\r
+ * Returns an object which represents the data to be transferred. \r
+ * The class of the object returned is defined by the representation \r
+ * class of the flavor.\r
+ * @param flavor the requested flavor for the data\r
+ * @return an object which represents the data to be transferred\r
+ * @exception IOException if the data is no longer available in the \r
+ * requested flavor.\r
+ * @exception UnsupportedFlavorException if the requested data flavor \r
+ * is not supported.\r
+ */\r
+ public Object getTransferData(DataFlavor flavor)\r
+ throws UnsupportedFlavorException, IOException \r
+ {\r
+ Object returnObject;\r
+ if (flavor.equals(flavors[CELL])) {\r
+ returnObject = data;\r
+ } else if (flavor.equals(flavors[STRING])) {\r
+ returnObject = data.toString();\r
+ } else if (flavor.equals(flavors[PLAIN_TEXT])) {\r
+ String string = data.toString();\r
+ returnObject = new ByteArrayInputStream(string.getBytes());\r
+ } else {\r
+ throw new UnsupportedFlavorException(flavor);\r
+ }\r
+ return returnObject;\r
+ }\r
+\r
+}\r