001    /*
002      Copyright (C) 2003 Renaud Pawlak
003      
004      This program is free software; you can redistribute it and/or modify
005      it under the terms of the GNU Lesser General Public License as
006      published by the Free Software Foundation; either version 2 of the
007      License, or (at your option) any later version.
008    
009      This program is distributed in the hope that it will be useful, but
010      WITHOUT ANY WARRANTY; without even the implied warranty of
011      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
012      Lesser General Public License for more details.
013    
014      You should have received a copy of the GNU Lesser General Public
015      License along with this program; if not, write to the Free Software
016      Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
017      USA */
018    
019    package org.objectweb.jac.aspects.gui;
020    
021    import org.objectweb.jac.core.NameRepository;
022    import org.objectweb.jac.core.Wrappee;
023    
024    import java.util.List;
025    import java.util.Vector;
026    import java.util.StringTokenizer;
027    import java.awt.datatransfer.*;
028    
029    /**
030     * This class defines JAC objects data tranfer utilities.
031     */
032    
033    public class Transfer
034    {
035    
036       /**
037        * Gets the transferable representation of a set of JAC
038        * objects. */
039    
040       public static Transferable getJACTransfer(Wrappee[] wrappees) {
041          String names="";
042          for(int i=0;i<wrappees.length;i++) {
043             names=names+NameRepository.get().getName(wrappees[i]);
044             if(i+1<wrappees.length)
045                names=names+",";
046          }
047          return new StringSelection(names);
048       }
049    
050       /**
051        * Retrieves a list of JAC objects from a transferable
052        * representation made by <code>getJACTransfert</code>. */
053    
054       public static List getTransferedWrappees(Transferable transferable) {
055          Vector ret=new Vector();
056          try {
057             String names="";
058             StringTokenizer st=new StringTokenizer(
059                (String)transferable.getTransferData(DataFlavor.stringFlavor),",");
060             while(st.hasMoreTokens()) {
061                String s=st.nextToken();
062                ret.add(NameRepository.get().getObject(s));
063             }
064          } catch(Exception ex) {
065             ex.printStackTrace();
066          }
067          return ret;
068       }
069          
070    }
071