package editor.gui.ccp.handler;

import java.awt.datatransfer.DataFlavor;
import java.util.Arrays;
import java.util.LinkedHashMap;
import java.util.List;

import javax.swing.TransferHandler;

@SuppressWarnings("serial")
public class EditorTransferHandler extends TransferHandler
{
    private LinkedHashMap<DataFlavor, ImportHandler> handlers;

    public EditorTransferHandler(List<ImportHandler> importers) throws IllegalArgumentException
    {
        for (ImportHandler a : importers)
            for (ImportHandler b : importers)
                if (a != b && a.supportedFlavor().equals(b.supportedFlavor()))
                    throw new IllegalArgumentException("Import handlers both support data flavor " + a.supportedFlavor());

        handlers = new LinkedHashMap<>();
        for (ImportHandler importer : importers)
            handlers.put(importer.supportedFlavor(), importer);
    }

    public EditorTransferHandler(ImportHandler... importers) throws IllegalArgumentException
    {
        this(Arrays.asList(importers));
    }

    @Override
    public boolean canImport(TransferSupport supp)
    {
        for (var e : handlers.entrySet())
            if (supp.isDataFlavorSupported(e.getKey()))
                return e.getValue().canImport(supp);
        return false;
    }

    @Override
    public boolean importData(TransferSupport supp)
    {
        for (var e : handlers.entrySet())
            if (supp.isDataFlavorSupported(e.getKey()))
                return e.getValue().importData(supp);
        return false;
    }
}
@@ -189,160 +189,909 @@
 r;%0A%0A
-@SuppressWarnings(%22serial%22)%0Apublic class EditorTransferHandler extends TransferHandler%0A%7B%0A    private LinkedHashMap%3CDataFlavor, ImportHandler%3E handlers;%0A
+/**%0A * Handler for importing and exporting data between components in the editor.%0A * By default, only importing is supported based on a list of provided handlers.%0A * Each handler must only support one data flavor and they must all supporte%0A * differnet flavors. The list indicates the priority of each supported data%0A * flavor; if a flavor is supported, its handler will be used even if it can't%0A * import the data.%0A */%0A@SuppressWarnings(%22serial%22)%0Apublic class EditorTransferHandler extends TransferHandler%0A%7B%0A    /** import handlers telling the handler how to import different kinds of data. */%0A    private LinkedHashMap%3CDataFlavor, ImportHandler%3E handlers;%0A%0A    /**%0A     * Create a new editor transfer handler with the given importers that tell it%0A     * how to import supported data.%0A     * %0A     * @param importers list of handlers for importing data%0A     * @throws IllegalArgumentException%0A     */
 %0A   
@@ -1638,24 +1638,291 @@
 er);%0A    %7D%0A%0A
+    /**%0A     * Convenience constructor allowing the use of an array of import handlers or%0A     * just specifying them in-line without having to create a List.%0A     * %0A     * @param importers handlers for importing data%0A     * @throws IllegalArgumentException%0A     */%0A
     public E

Add documentation to editor transfer handler