01: /*
02: * Copyright (C) 2004 Giuseppe MANNA
03: *
04: * This file is part of FreeReportBuilder
05: *
06: * FreeReportBuilder is free software; you can redistribute it and/or
07: * modify it under the terms of the GNU General Public License
08: * as published by the Free Software Foundation; either version 2
09: * of the License, or (at your option) any later version.
10: *
11: * This program is distributed in the hope that it will be useful,
12: * but WITHOUT ANY WARRANTY; without even the implied warranty of
13: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14: * GNU General Public License for more details.
15: *
16: * You should have received a copy of the GNU General Public License
17: * along with this program; if not, write to the Free Software
18: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19: *
20: */
21:
22: package it.frb.tree.drag;
23:
24: import java.awt.datatransfer.DataFlavor;
25:
26: /**
27: * This represents a TreePath (a node in a JTree) that can be transferred between a drag source and a drop target.
28: */
29: public class CTransferableTreePath implements
30: java.awt.datatransfer.Transferable {
31: // The type of DnD object being dragged...
32: public static final DataFlavor TREEPATH_FLAVOR = new DataFlavor(
33: DataFlavor.javaJVMLocalObjectMimeType, "TreePath");
34:
35: private javax.swing.tree.TreePath path;
36:
37: private DataFlavor[] flavors = { TREEPATH_FLAVOR };
38:
39: /**
40: * Constructs a transferrable tree path object for the specified path.
41: */
42: public CTransferableTreePath(javax.swing.tree.TreePath path) {
43: this .path = path;
44: }
45:
46: // Transferable interface methods...
47: public DataFlavor[] getTransferDataFlavors() {
48: return flavors;
49: }
50:
51: public boolean isDataFlavorSupported(DataFlavor flavor) {
52: return java.util.Arrays.asList(flavors).contains(flavor);
53: }
54:
55: public synchronized Object getTransferData(DataFlavor flavor)
56: throws java.awt.datatransfer.UnsupportedFlavorException {
57: if (flavor.isMimeTypeEqual(TREEPATH_FLAVOR.getMimeType())) // DataFlavor.javaJVMLocalObjectMimeType))
58: return path;
59: else
60: throw new java.awt.datatransfer.UnsupportedFlavorException(
61: flavor);
62: }
63: }
|