KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > columba > mail > gui > tree > util > CTransferableTreePath


1 //The contents of this file are subject to the Mozilla Public License Version 1.1
2
//(the "License"); you may not use this file except in compliance with the
3
//License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
4
//
5
//Software distributed under the License is distributed on an "AS IS" basis,
6
//WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
7
//for the specific language governing rights and
8
//limitations under the License.
9
//
10
//The Original Code is "The Columba Project"
11
//
12
//The Initial Developers of the Original Code are Frederik Dietz and Timo Stich.
13
//Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
14
//
15
//All Rights Reserved.
16
package org.columba.mail.gui.tree.util;
17
18
19 /**
20  * @version 1.0
21  * @author
22  */

23 import java.awt.datatransfer.DataFlavor JavaDoc;
24 import java.awt.datatransfer.Transferable JavaDoc;
25 import java.awt.datatransfer.UnsupportedFlavorException JavaDoc;
26
27 import javax.swing.tree.TreePath JavaDoc;
28
29
30 /**
31 * This represents a TreePath (a node in a JTree) that can be transferred between a drag source and a drop target.
32 */

33 public class CTransferableTreePath implements Transferable JavaDoc {
34     // The type of DnD object being dragged...
35
public static final DataFlavor JavaDoc TREEPATH_FLAVOR = new DataFlavor JavaDoc(DataFlavor.javaJVMLocalObjectMimeType,
36             "TreePath");
37     private TreePath JavaDoc _path;
38     private DataFlavor JavaDoc[] _flavors = { TREEPATH_FLAVOR };
39
40     /**
41 * Constructs a transferrable tree path object for the specified path.
42 */

43     public CTransferableTreePath(TreePath JavaDoc path) {
44         _path = path;
45     }
46
47     // Transferable interface methods...
48
public DataFlavor JavaDoc[] getTransferDataFlavors() {
49         return _flavors;
50     }
51
52     public boolean isDataFlavorSupported(DataFlavor JavaDoc flavor) {
53         return java.util.Arrays.asList(_flavors).contains(flavor);
54     }
55
56     public synchronized Object JavaDoc getTransferData(DataFlavor JavaDoc flavor)
57         throws UnsupportedFlavorException JavaDoc {
58         if (flavor.isMimeTypeEqual(TREEPATH_FLAVOR.getMimeType())) {
59             // DataFlavor.javaJVMLocalObjectMimeType))
60
return _path;
61         } else {
62             throw new UnsupportedFlavorException JavaDoc(flavor);
63         }
64     }
65 }
66
Popular Tags