1 package snow.utils.gui; 2 3 import java.util.*; 4 import java.io.*; 5 import java.awt.*; 6 import java.awt.event.*; 7 import java.awt.datatransfer.*; 8 import java.awt.dnd.*; 9 import javax.swing.*; 10 11 13 public class VectorTransferable implements Transferable 14 { 15 16 public static DataFlavor localVectorFlavor, serialVectorFlavor; 17 public static String localVectorType = DataFlavor.javaJVMLocalObjectMimeType + ";class=java.util.Vector"; 18 19 20 static 21 { 22 try { 23 localVectorFlavor = new DataFlavor(localVectorType); 24 } catch (ClassNotFoundException e) { 25 System.out.println( 26 "VectorTransferable: unable to create data flavor"); 27 } 28 serialVectorFlavor = new DataFlavor(Vector.class, "Vector"); 29 30 } 31 32 public Vector v; 34 public DataFlavor transferedDataFlavor; 35 36 37 public VectorTransferable(Vector v) 38 { 39 this.v = v; 40 } 41 42 public Object getTransferData(DataFlavor flavor) 43 throws UnsupportedFlavorException { 44 if (!isDataFlavorSupported(flavor)) 45 { 46 throw new UnsupportedFlavorException(flavor); 47 } 48 49 if( flavor.equals( DataFlavor.stringFlavor )) 51 { 52 transferedDataFlavor = DataFlavor.stringFlavor; 53 return ""+v; 54 } 55 56 transferedDataFlavor = flavor; 57 return v; 58 } 59 60 public DataFlavor[] getTransferDataFlavors() { 61 return new DataFlavor[] { localVectorFlavor, 62 serialVectorFlavor, 63 DataFlavor.stringFlavor 64 }; 65 } 66 67 public boolean isDataFlavorSupported(DataFlavor flavor) { 68 if (localVectorFlavor.equals(flavor)) return true; 69 if (serialVectorFlavor.equals(flavor)) return true; 70 if (DataFlavor.stringFlavor.equals(flavor)) return true; 71 return false; 72 } 73 74 75 public static void main( String [] arguments ) 76 { 77 } 80 81 } | Popular Tags |