KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jac > aspects > gui > Transfer


1 /*
2   Copyright (C) 2003 Renaud Pawlak <renaud@aopsys.com>
3   
4   This program is free software; you can redistribute it and/or modify
5   it under the terms of the GNU Lesser General Public License as
6   published by the Free Software Foundation; either version 2 of the
7   License, or (at your option) any later version.
8
9   This program is distributed in the hope that it will be useful, but
10   WITHOUT ANY WARRANTY; without even the implied warranty of
11   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12   Lesser General Public License for more details.
13
14   You should have received a copy of the GNU Lesser General Public
15   License along with this program; if not, write to the Free Software
16   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
17   USA */

18
19 package org.objectweb.jac.aspects.gui;
20
21 import java.awt.datatransfer.DataFlavor JavaDoc;
22 import java.awt.datatransfer.StringSelection JavaDoc;
23 import java.awt.datatransfer.Transferable JavaDoc;
24 import java.util.List JavaDoc;
25 import java.util.StringTokenizer JavaDoc;
26 import java.util.Vector JavaDoc;
27 import org.apache.log4j.Logger;
28 import org.objectweb.jac.core.NameRepository;
29 import org.objectweb.jac.core.Wrappee;
30
31 /**
32  * This class defines JAC objects data tranfer utilities.
33  */

34
35 public class Transfer
36 {
37     static final Logger logger = Logger.getLogger("gui.dnd");
38
39     /**
40      * Gets the transferable representation of a set of JAC
41      * objects.
42      */

43     public static Transferable JavaDoc getJACTransfer(Wrappee[] wrappees) {
44         String JavaDoc names="";
45         for(int i=0;i<wrappees.length;i++) {
46             names=names+NameRepository.get().getName(wrappees[i]);
47             if(i+1<wrappees.length)
48                 names=names+",";
49         }
50         return new StringSelection JavaDoc(names);
51     }
52
53     /**
54      * Retrieves a list of JAC objects from a transferable
55      * representation made by <code>getJACTransfert</code>.
56      */

57     public static List JavaDoc getTransferedWrappees(Transferable JavaDoc transferable) {
58         Vector JavaDoc ret = new Vector JavaDoc();
59         try {
60             String JavaDoc names = "";
61             StringTokenizer JavaDoc st = new StringTokenizer JavaDoc(
62                 (String JavaDoc)transferable.getTransferData(DataFlavor.stringFlavor),",");
63             while(st.hasMoreTokens()) {
64                 String JavaDoc s = st.nextToken();
65                 ret.add(NameRepository.get().getObject(s));
66             }
67         } catch(Exception JavaDoc e) {
68             logger.error("getTransferedWrappees "+transferable,e);
69         }
70         return ret;
71     }
72       
73 }
74
75
Popular Tags