View Javadoc

1   /*
2    *  XNap - A P2P framework and client.
3    *
4    *  See the file AUTHORS for copyright information.
5    *
6    *  This program is free software; you can redistribute it and/or modify
7    *  it under the terms of the GNU General Public License as published by
8    *  the Free Software Foundation.
9    *
10   *  This program is distributed in the hope that it will be useful,
11   *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12   *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13   *  GNU General Public License for more details.
14   *
15   *  You should have received a copy of the GNU General Public License
16   *  along with this program; if not, write to the Free Software
17   *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
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      //--- Constant(s) ---
36  
37      public static final DataFlavor FILE_FLAVOR =
38  	new DataFlavor(TransferableFile.class, "File Transferable");
39      
40      //--- Data field(s) ---
41  
42      protected FileArray fileArray;
43      protected static DataFlavor flavors[] = { FILE_FLAVOR };
44  
45      //--- Constructor(s) ---
46  
47      public TransferableFile(File files[])
48      {
49  	fileArray = new FileArray(files);
50      }
51  
52      //--- Method(s) ---
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  }