1 /*
2 * jcurl java curling software framework https://JCurl.mro.name
3 * Copyright (C) 2005-2009 M. Rohrmoser
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; either version 2 of the License, or (at your
8 * option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
13 * Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */
19 package org.jcurl.demo.jtree;
20
21 import java.awt.datatransfer.DataFlavor;
22 import java.awt.datatransfer.Transferable;
23 import java.awt.datatransfer.UnsupportedFlavorException;
24 import java.util.Arrays;
25
26 import javax.swing.tree.DefaultMutableTreeNode;
27
28 /**
29 * http://forum.java.sun.com/thread.jspa?threadID=296255&start=0
30 *
31 * @author <a href="http://forum.java.sun.com/profile.jspa?userID=82795">Deudeu</a>
32 * @version $Id: TransferableNode.java 1031 2009-07-23 15:06:05Z mro $
33 */
34 public class TransferableNode implements Transferable {
35 public static final DataFlavor NODE_FLAVOR = new DataFlavor(
36 DataFlavor.javaJVMLocalObjectMimeType, "Node");
37 private final DataFlavor[] flavors = { NODE_FLAVOR };
38 private final DefaultMutableTreeNode node;
39
40 public TransferableNode(final DefaultMutableTreeNode nd) {
41 node = nd;
42 }
43
44 public synchronized Object getTransferData(final DataFlavor flavor)
45 throws UnsupportedFlavorException {
46 if (flavor == NODE_FLAVOR)
47 return node;
48 else
49 throw new UnsupportedFlavorException(flavor);
50 }
51
52 public DataFlavor[] getTransferDataFlavors() {
53 return flavors;
54 }
55
56 public boolean isDataFlavorSupported(final DataFlavor flavor) {
57 return Arrays.asList(flavors).contains(flavor);
58 }
59 }