001    /**
002     * planningtool - A Planning Tool with Critiquing Support.
003     * 
004     * Copyright (C) 2006 olale
005    
006     * This program is free software; you can redistribute it and/or
007     * modify it under the terms of the GNU General Public License
008     * as published by the Free Software Foundation; either version 2
009     * of the License, or (at your option) any later version.
010    
011     * This program is distributed in the hope that it will be useful,
012     * but WITHOUT ANY WARRANTY; without even the implied warranty of
013     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
014     * GNU General Public License for more details.
015    
016     * You should have received a copy of the GNU General Public License
017     * along with this program; if not, write to the Free Software
018     * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
019    
020     * Contact information: 
021     * E-mail: olale@ida.liu.se
022     *         olale@lysator.liu.se
023     */
024    package se.liu.ida.critiquer.gui;
025    
026    import java.awt.datatransfer.DataFlavor;
027    import java.awt.datatransfer.Transferable;
028    import java.awt.datatransfer.UnsupportedFlavorException;
029    import java.io.IOException;
030    
031    import se.liu.ida.critiquer.activities.parameters.AgentParameter;
032    import se.liu.ida.critiquer.resources.Agent;
033    
034    public class AgentSelection implements Transferable {
035    
036            public static DataFlavor agentFlavor;
037            public static DataFlavor agentParameterFlavor;
038            
039            static {
040                    try {
041                            agentFlavor=new DataFlavor(DataFlavor.javaJVMLocalObjectMimeType+
042                                            ";class=se.liu.ida.critiquer.resources.Agent");
043                            agentParameterFlavor=new DataFlavor(DataFlavor.javaJVMLocalObjectMimeType+
044                            ";class=se.liu.ida.critiquer.activities.parameters.AgentParameter");
045                    } catch (ClassNotFoundException e) {
046                            // TODO Auto-generated catch block
047                            e.printStackTrace();
048                    }
049            }
050    
051            private Agent agent;
052            private AgentParameter param;
053            
054            public AgentSelection(Agent agent,AgentParameter param) {
055                    this.agent=agent;
056                    this.param=param;
057            }
058    
059                    
060            public DataFlavor[] getTransferDataFlavors() {
061                    return new DataFlavor[] {agentFlavor};
062            }
063    
064            public boolean isDataFlavorSupported(DataFlavor flavor) {
065                    return flavor.equals(agentFlavor);
066            }
067    
068            public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException, IOException {
069                    if (flavor.equals(agentFlavor)) {
070                            return agent;   
071                    } else if (flavor.equals(agentParameterFlavor)) {
072                            return param;
073                    } else {
074                            throw new UnsupportedFlavorException(flavor);
075                    }
076                    
077            }
078    
079    
080    }