Main Page   Packages   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members  

TransferableTreeNode.java

00001 package edu.ksu.cis.bandera.pdgslicer.dependency;
00002 
00003 import javax.swing.tree.*;
00004 import java.awt.dnd.*;
00005 import java.awt.datatransfer.*;
00006 import java.io.*;
00007 
00008 public class TransferableTreeNode extends DefaultMutableTreeNode implements Transferable {
00009   final static int TREE = 0;
00010   final static int STRING = 1;
00011   final static int PLAIN_TEXT = 2;
00012 
00013   final public static DataFlavor DEFAULT_MUTABLE_TREENODE_FLAVOR = 
00014     new DataFlavor(DefaultMutableTreeNode.class, "Default Mutable Tree Node");
00015 
00016   static DataFlavor flavors[] = {DEFAULT_MUTABLE_TREENODE_FLAVOR, DataFlavor.stringFlavor, DataFlavor.plainTextFlavor};
00017 //  static DataFlavor flavors[] = {DEFAULT_MUTABLE_TREENODE_FLAVOR}; // works fine
00018 
00019   private DefaultMutableTreeNode data;
00020                            
00021   public TransferableTreeNode(DefaultMutableTreeNode data) {
00022     this.data = data;
00023   }  
00024 public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException, IOException {
00025     Object returnObject;
00026     if (flavor.equals(flavors[TREE])) {
00027         Object userObject = data.getUserObject();
00028         if (userObject == null) {
00029             returnObject = data;
00030         } else {
00031             returnObject = userObject;
00032         }
00033     } else
00034         if (flavor.equals(flavors[STRING])) {
00035             Object userObject = data.getUserObject();
00036             if (userObject == null) {
00037                 returnObject = data.toString();
00038             } else {
00039                 returnObject = userObject.toString();
00040             }
00041         } else
00042             if (flavor.equals(flavors[PLAIN_TEXT])) {
00043                 Object userObject = data.getUserObject();
00044                 String string;
00045                 if (userObject == null) {
00046                     string = data.toString();
00047                 } else {
00048                     string = userObject.toString();
00049                 }
00050                 returnObject = new ByteArrayInputStream(string.getBytes());
00051             } else {
00052                 throw new UnsupportedFlavorException(flavor);
00053             }
00054     return returnObject;
00055 }
00056   public DataFlavor[] getTransferDataFlavors() {
00057    return flavors;
00058   }  
00059   public boolean isDataFlavorSupported(DataFlavor flavor) {
00060     boolean returnValue = false;
00061     for (int i=0, n=flavors.length; i<n; i++) {
00062       if (flavor.equals(flavors[i])) {
00063         returnValue = true;
00064         break;
00065       }
00066     }
00067     return returnValue;
00068   }  
00069 /**
00070  * Insert the method's description here.
00071  * Creation date: (00-11-21 10:24:54)
00072  * @return java.lang.String
00073  */
00074 public String toString() {
00075     return data.toString();
00076 }
00077 }

Generated at Thu Feb 7 06:57:55 2002 for Bandera by doxygen1.2.10 written by Dimitri van Heesch, © 1997-2001