01: //The contents of this file are subject to the Mozilla Public License Version 1.1
02: //(the "License"); you may not use this file except in compliance with the
03: //License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
04: //
05: //Software distributed under the License is distributed on an "AS IS" basis,
06: //WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
07: //for the specific language governing rights and
08: //limitations under the License.
09: //
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: * @version 1.0
20: * @author
21: */
22: import java.awt.datatransfer.DataFlavor;
23: import java.awt.datatransfer.Transferable;
24: import java.awt.datatransfer.UnsupportedFlavorException;
25:
26: import javax.swing.tree.TreePath;
27:
28: /**
29: * This represents a TreePath (a node in a JTree) that can be transferred between a drag source and a drop target.
30: */
31: public class CTransferableTreePath implements Transferable {
32: // The type of DnD object being dragged...
33: public static final DataFlavor TREEPATH_FLAVOR = new DataFlavor(
34: DataFlavor.javaJVMLocalObjectMimeType, "TreePath");
35: private TreePath _path;
36: private DataFlavor[] _flavors = { TREEPATH_FLAVOR };
37:
38: /**
39: * Constructs a transferrable tree path object for the specified path.
40: */
41: public CTransferableTreePath(TreePath path) {
42: _path = path;
43: }
44:
45: // Transferable interface methods...
46: public DataFlavor[] getTransferDataFlavors() {
47: return _flavors;
48: }
49:
50: public boolean isDataFlavorSupported(DataFlavor flavor) {
51: return java.util.Arrays.asList(_flavors).contains(flavor);
52: }
53:
54: public synchronized Object getTransferData(DataFlavor flavor)
55: throws UnsupportedFlavorException {
56: if (flavor.isMimeTypeEqual(TREEPATH_FLAVOR.getMimeType())) {
57: // DataFlavor.javaJVMLocalObjectMimeType))
58: return _path;
59: } else {
60: throw new UnsupportedFlavorException(flavor);
61: }
62: }
63: }
|