KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > util > explorer > core > dnd > lib > EntryTransferable


1 /*====================================================================
2
3 Objectweb Explorer framework
4 Copyright (C) 2000-2005 INRIA & USTL - LIFL - GOAL
5 Contact: openccm@objectweb.org
6
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 2.1 of the License, or any later version.
11
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public
18 License along with this library; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
20 USA
21
22 Initial developer(s): Jerome Moroy.
23 Contributor(s): ______________________________________.
24
25 ====================================================================
26 $Id: EntryTransferable.java,v 1.2 2005/07/06 15:36:00 moroy Exp $
27 ====================================================================*/

28
29 package org.objectweb.util.explorer.core.dnd.lib;
30
31 import java.awt.datatransfer.Clipboard JavaDoc;
32 import java.awt.datatransfer.ClipboardOwner JavaDoc;
33 import java.awt.datatransfer.DataFlavor JavaDoc;
34 import java.awt.datatransfer.Transferable JavaDoc;
35 import java.awt.datatransfer.UnsupportedFlavorException JavaDoc;
36 import java.io.IOException JavaDoc;
37 import java.util.Arrays JavaDoc;
38 import java.util.List JavaDoc;
39
40 import org.objectweb.util.explorer.api.Entry;
41 import org.objectweb.util.trace.TraceSystem;
42
43 /**
44  *
45  *
46  * @author <a HREF="mailto:Jerome.Moroy@lifl.fr">Jerome Moroy</a>
47  *
48  * @version 0.1
49  */

50 public class EntryTransferable
51     implements Transferable JavaDoc, ClipboardOwner JavaDoc {
52
53     //==================================================================
54
//
55
// Internal states.
56
//
57
//==================================================================
58

59     /** The flavors representing the TreeView class */
60     //
61
// new DataFlavor(TreeView.class,"treeView")
62
public static final DataFlavor JavaDoc[] flavors_ = getDataFlavor();
63     
64     /** A list representing the flavors of the TreeView class */
65     protected final List JavaDoc flavorList_ = Arrays.asList(flavors_);
66     
67     /** The Entry to transfer */
68     protected Entry entryView_;
69
70     //==================================================================
71
//
72
// No constructor.
73
//
74
//==================================================================
75

76     public EntryTransferable(Entry entryView){
77         entryView_ = entryView;
78     }
79
80     //==================================================================
81
//
82
// Internal methods.
83
//
84
//==================================================================
85

86     protected static DataFlavor JavaDoc[] getDataFlavor(){
87         try{
88             return new DataFlavor JavaDoc[]{new DataFlavor JavaDoc(DataFlavor.javaJVMLocalObjectMimeType + ";class=org.objectweb.util.explorer.api.Entry")};
89         } catch(ClassNotFoundException JavaDoc e){
90             TraceSystem.get("explorer").warn("[EntryTransferable] org.objectweb.util.explorer.api.Entry: Class Not Found!");
91             return null;
92         }
93     }
94
95     //==================================================================
96
//
97
// Public methods for Transferable.
98
//
99
//==================================================================
100

101     /*
102      * @see java.awt.datatransfer.Transferable#getTransferDataFlavors()
103      */

104     public DataFlavor JavaDoc[] getTransferDataFlavors() {
105         return flavors_;
106     }
107
108     /*
109      * @see java.awt.datatransfer.Transferable#isDataFlavorSupported(java.awt.datatransfer.DataFlavor)
110      */

111     public boolean isDataFlavorSupported(DataFlavor JavaDoc flavor) {
112         return flavorList_.contains(flavor);
113     }
114
115     /*
116      * @see java.awt.datatransfer.Transferable#getTransferData(java.awt.datatransfer.DataFlavor)
117      */

118     public Object JavaDoc getTransferData(DataFlavor JavaDoc flavor) throws UnsupportedFlavorException JavaDoc, IOException JavaDoc {
119         return entryView_;
120     }
121
122     //==================================================================
123
//
124
// Public methods for ClipboardOwner.
125
//
126
//==================================================================
127

128     /*
129      * @see java.awt.datatransfer.ClipboardOwner#lostOwnership(java.awt.datatransfer.Clipboard, java.awt.datatransfer.Transferable)
130      */

131     public void lostOwnership(Clipboard JavaDoc clipboard, Transferable JavaDoc contents) {
132         System.out.println ("EntryTransferable losts ownership of " + clipboard.getName());
133         System.out.println ("data: " + contents);
134     }
135
136 }
Popular Tags