Major cleanup of Utils class.
[trakem2.git] / ini / trakem2 / tree / TransferableNode.java
blob2b6b1ae0643781bc20783f15eb82cd1cc563f202
1 /**
3 TrakEM2 plugin for ImageJ(C).
4 Copyright (C) 2005,2006 Albert Cardona and Rodney Douglas.
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 (http://www.gnu.org/licenses/gpl.txt )
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.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 You may contact Albert Cardona at acardona at ini.phys.ethz.ch
20 Institute of Neuroinformatics, University of Zurich / ETH, Switzerland.
21 **/
23 package ini.trakem2.tree;
26 import java.awt.datatransfer.*;
27 import javax.swing.tree.*;
28 import java.util.*;
30 /** Adapted from freely available code by DeuDeu from http://forum.java.sun.com/thread.jspa?threadID=296255&start=0&tstart=0 */
31 public class TransferableNode implements Transferable {
33 public static final DataFlavor NODE_FLAVOR = new DataFlavor(DataFlavor.javaJVMLocalObjectMimeType, "Node");
35 private DefaultMutableTreeNode node;
37 private DataFlavor[] flavors = { NODE_FLAVOR };
39 public TransferableNode(DefaultMutableTreeNode nd) {
40 node = nd;
43 public synchronized Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException {
44 if (flavor == NODE_FLAVOR) {
45 return node;
46 } else {
47 throw new UnsupportedFlavorException(flavor);
51 public DataFlavor[] getTransferDataFlavors() {
52 return flavors;
55 public boolean isDataFlavorSupported(DataFlavor flavor) {
56 return Arrays.asList(flavors).contains(flavor);