view src/MPipeline/src/mpipeline/MElementSelection.java @ 46:ca0b8d4dcdb6 database-connection-manager

Fix
author Daniele Nicolodi <nicolodi@science.unitn.it>
date Tue, 06 Dec 2011 19:07:27 +0100
parents f0afece42f48
children
line wrap: on
line source

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package mpipeline;

import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.ClipboardOwner;
import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.Transferable;
import java.awt.datatransfer.UnsupportedFlavorException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;

/**
 * A class that implements elements that can be transferred over the clipboard.
 * 
 * @author hewitson
 */
public class MElementSelection implements Transferable, ClipboardOwner {

    /**
     *
     */
    public DataFlavor elementFlavor;
    private DataFlavor[] supportedFlavors = {elementFlavor};
    private ArrayList<MElement> elements = new ArrayList<MElement>();
    private ArrayList<MBlock> blocks = new ArrayList<MBlock>();

    /**
     * Create a new element selection object
     */
    public MElementSelection() {
        try {
            elementFlavor = new DataFlavor(Class.forName("mpipeline.MElement"), "Elements");
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
    }

    /**
     * Return a list of the elements
     * @return
     */
    public ArrayList<MElement> getElements(){
        return elements;
    }
    
        
    /**
     * Set the elements in this selection
     * @param els
     */
    public void setElements(Object els){
        elements.clear();
        elements.addAll((Collection<? extends MElement>) els);
    }
    
    
    
    /**
     * Add the given elements to the selection.
     * @param els
     */
    public void addElements(Object els){
        elements.addAll((Collection<? extends MElement>) els);
    }
        
    public DataFlavor[] getTransferDataFlavors() {
        return (supportedFlavors);
    }

    public boolean isDataFlavorSupported(DataFlavor flavor) {
        return (flavor.equals(elementFlavor));
    }

    public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException, IOException {
        if (flavor.equals(elementFlavor)) {
            return (elements);
        } else {
            throw new UnsupportedFlavorException(elementFlavor);
        }
    }

    public void lostOwnership(Clipboard clipboard, Transferable contents) {
        System.out.println("Lost clipboard ownership.");
    }

    /**
     *
     * @return
     */
    public ArrayList<MBlock> getBlocks() {
        return blocks;
    }

    /**
     *
     * @param blocks
     */
    public void setBlocks(ArrayList<MBlock> blocks) {
        this.blocks = blocks;
    }

    /**
     *
     * @return
     */
    public DataFlavor getElementFlavor() {
        return elementFlavor;
    }

    /**
     *
     * @param elementFlavor
     */
    public void setElementFlavor(DataFlavor elementFlavor) {
        this.elementFlavor = elementFlavor;
    }

    /**
     *
     * @return
     */
    public DataFlavor[] getSupportedFlavors() {
        return supportedFlavors;
    }

    /**
     * 
     * @param supportedFlavors
     */
    public void setSupportedFlavors(DataFlavor[] supportedFlavors) {
        this.supportedFlavors = supportedFlavors;
    }
    
    
    
}