KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sshtools > ui > swing > dnd > FileSelection


1 /*
2  * SSL-Explorer
3  *
4  * Copyright (C) 2003-2006 3SP LTD. All Rights Reserved
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2 of
9  * the License, or (at your option) any later version.
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
16  * License along with this program; if not, write to the Free Software
17  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18  */

19             
20 package com.sshtools.ui.swing.dnd;
21
22 import java.awt.datatransfer.DataFlavor JavaDoc;
23 import java.awt.datatransfer.Transferable JavaDoc;
24 import java.awt.datatransfer.UnsupportedFlavorException JavaDoc;
25 import java.io.File JavaDoc;
26 import java.io.IOException JavaDoc;
27 import java.util.Iterator JavaDoc;
28 import java.util.Vector JavaDoc;
29
30 public class FileSelection extends Vector JavaDoc implements Transferable JavaDoc {
31     public static DataFlavor JavaDoc FILE_SELECTION_FLAVOR = new DataFlavor JavaDoc(DataFlavor.javaJVMLocalObjectMimeType, "FileSelection");
32
33     public FileSelection() {
34         super();
35     }
36
37     /* Returns the array of flavors in which it can provide the data. */
38     public synchronized DataFlavor JavaDoc[] getTransferDataFlavors() {
39         return new DataFlavor JavaDoc[] { FILE_SELECTION_FLAVOR };
40     }
41
42     /* Returns whether the requested flavor is supported by this object. */
43     public boolean isDataFlavorSupported(DataFlavor JavaDoc flavor) {
44         return FILE_SELECTION_FLAVOR == flavor;
45     }
46
47     /**
48      * If the data was requested in the "java.lang.String" flavor, return the
49      * String representing the selection.
50      */

51     public synchronized Object JavaDoc getTransferData(DataFlavor JavaDoc flavor) throws UnsupportedFlavorException JavaDoc, IOException JavaDoc {
52         if (flavor.equals(FILE_SELECTION_FLAVOR)) {
53             return this;
54         } else {
55             throw new UnsupportedFlavorException JavaDoc(flavor);
56         }
57     }
58
59     public String JavaDoc toString() {
60         StringBuffer JavaDoc buf = new StringBuffer JavaDoc("File selection of");
61         buf.append(size());
62         for (Iterator JavaDoc i = iterator(); i.hasNext();) {
63             buf.append("\n");
64             File JavaDoc file = (File JavaDoc) i.next();
65             buf.append(" ");
66             buf.append(file.getAbsolutePath());
67             buf.append(" (");
68             try {
69                 buf.append(file.length());
70             } catch (Exception JavaDoc ioe0) {
71             }
72             buf.append(")");
73         }
74         return buf.toString();
75     }
76 }
Popular Tags