View Javadoc

1   /*
2    * @(#) ContextTransferable.java Oct 25, 2003
3    * 
4    * Copyright (c) 2003 Delft University of Technology Jaffalaan 5, 2628 BX Delft,
5    * the Netherlands All rights reserved.
6    * 
7    * This software is proprietary information of Delft University of Technology
8    * The code is published under the General Public License
9    */
10  package nl.tudelft.simulation.naming.context;
11  
12  import java.awt.datatransfer.DataFlavor;
13  import java.awt.datatransfer.Transferable;
14  
15  import javax.naming.NamingException;
16  
17  /***
18   * The ContextTransferable class transfers keys in DropNDrag Operations.
19   * <p>
20   * (c) copyright 2003 <a href="http://www.simulation.tudelft.nl">Delft
21   * University of Technology </a>, the Netherlands. <br>
22   * See for project information <a href="http://www.simulation.tudelft.nl">
23   * www.simulation.tudelft.nl </a> <br>
24   * License of use: <a href="http://www.gnu.org/copyleft/gpl.html">General Public
25   * License (GPL) </a>, no warranty <br>
26   * 
27   * @author <a href="http://www.simulation.tudelft.nl/people/jacobs.html">Peter
28   *         Jacobs </a>
29   * @version 1.2 2004-03-24
30   * @since 1.0
31   */
32  public class ContextTransferable implements Transferable
33  {
34  	/*** the name under which the object can be found in the context */
35  	private String name = null;
36  
37  	/***
38  	 * constructs a new ContextTransferable
39  	 * 
40  	 * @param object the object to send
41  	 * @throws NamingException whenever the object cannot be found in the
42  	 *         context
43  	 */
44  	public ContextTransferable(final Object object) throws NamingException
45  	{
46  		super();
47  		this.name = ContextUtil.resolveKey(object);
48  	}
49  
50  	/***
51  	 * @see java.awt.datatransfer.Transferable#getTransferDataFlavors()
52  	 */
53  	public DataFlavor[] getTransferDataFlavors()
54  	{
55  		return new DataFlavor[]{DataFlavor.stringFlavor};
56  	}
57  
58  	/***
59  	 * @see java.awt.datatransfer.Transferable
60  	 *      #isDataFlavorSupported(java.awt.datatransfer.DataFlavor)
61  	 */
62  	public boolean isDataFlavorSupported(final DataFlavor flavor)
63  	{
64  		if (flavor.equals(DataFlavor.stringFlavor))
65  		{
66  			return true;
67  		}
68  		return false;
69  	}
70  
71  	/***
72  	 * @see java.awt.datatransfer.Transferable
73  	 *      #getTransferData(java.awt.datatransfer.DataFlavor)
74  	 */
75  	public Object getTransferData(final DataFlavor flavor)
76  	{
77  		if (flavor.equals(DataFlavor.stringFlavor))
78  		{
79  			return this.name;
80  		}
81  		return null;
82  	}
83  }