1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.xnap.gui.util;
21
22 import java.awt.datatransfer.DataFlavor;
23 import java.awt.datatransfer.Transferable;
24 import java.awt.datatransfer.UnsupportedFlavorException;
25 import java.io.File;
26 import java.io.IOException;
27
28 /***
29 * TransferableFile contains the files which are dragged by DragFilesSupport
30 * and received by for instance a DroppableTree.
31 */
32 public class TransferableFile implements Transferable
33 {
34
35
36
37 public static final DataFlavor FILE_FLAVOR =
38 new DataFlavor(TransferableFile.class, "File Transferable");
39
40
41
42 protected FileArray fileArray;
43 protected static DataFlavor flavors[] = { FILE_FLAVOR };
44
45
46
47 public TransferableFile(File files[])
48 {
49 fileArray = new FileArray(files);
50 }
51
52
53
54 public Object getTransferData(DataFlavor flavor)
55 throws UnsupportedFlavorException, IOException
56 {
57 if (isDataFlavorSupported(flavor)) {
58 return fileArray;
59 }
60 else {
61 throw new UnsupportedFlavorException(flavor);
62 }
63 }
64
65
66 public DataFlavor[] getTransferDataFlavors()
67 {
68 return flavors;
69 }
70
71 public boolean isDataFlavorSupported(DataFlavor flavor)
72 {
73 return flavor.equals(FILE_FLAVOR);
74 }
75 }