@@ -0,0 +1,3431 @@
+//----------------------------------------------------------------------------//%0A//                                                                            //%0A//                       F i l e D r o p H a n d l e r                        //%0A//                                                                            //%0A//  Copyright (C) Herve Bitteur 2000-2007. All rights reserved.               //%0A//  This software is released under the GNU General Public License.           //%0A//  Contact author at herve.bitteur@laposte.net to report bugs & suggestions. //%0A//----------------------------------------------------------------------------//%0Apackage omr.ui;%0A%0Aimport omr.log.Logger;%0A%0Aimport omr.sheet.ui.SheetActions;%0A%0Aimport java.awt.datatransfer.DataFlavor;%0Aimport java.awt.datatransfer.Transferable;%0Aimport java.awt.datatransfer.UnsupportedFlavorException;%0Aimport java.io.File;%0Aimport java.io.IOException;%0A%0Aimport javax.swing.TransferHandler;%0Aimport javax.swing.TransferHandler.TransferSupport;%0A%0A/**%0A * Class %3Ccode%3EFileDropHandler%3C/code%3E handles the dropping of files onto the%0A * Audiveris GUI%0A *%0A * @author Herv&eacute Bitteur%0A * @version $Id$%0A */%0Aclass FileDropHandler%0A    extends TransferHandler%0A%7B%0A    //~ Static fields/initializers ---------------------------------------------%0A%0A    /** Usual logger utility */%0A    private static final Logger logger = Logger.getLogger(%0A        FileDropHandler.class);%0A%0A    //~ Methods ----------------------------------------------------------------%0A%0A    //-----------//%0A    // canImport //%0A    //-----------//%0A    @Override%0A    public boolean canImport (TransferSupport support)%0A    %7B%0A        /* For the time being, only support drops (not clipboard paste) */%0A        if (!support.isDrop()) %7B%0A            return false;%0A        %7D%0A%0A        /* Check that the drop contains a list of files */%0A        if (!support.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) %7B%0A            return false;%0A        %7D%0A%0A        /* Check to see if the source actions contains the COPY action%0A         */%0A        boolean copySupported = (COPY & support.getSourceDropActions()) == COPY;%0A%0A        /* If COPY is supported, choose COPY and accept the transfer */%0A        if (copySupported) %7B%0A            support.setDropAction(COPY);%0A%0A            return true;%0A        %7D%0A%0A        /* COPY isn't supported, so reject the transfer */%0A        return false;%0A    %7D%0A%0A    //------------//%0A    // importData //%0A    //------------//%0A    @Override%0A    public boolean importData (TransferSupport support)%0A    %7B%0A        if (!canImport(support)) %7B%0A            return false;%0A        %7D%0A%0A        /* fetch the Transferable */%0A        Transferable trsf = support.getTransferable();%0A%0A        try %7B%0A            /* Fetch data */%0A            Object data = trsf.getTransferData(DataFlavor.javaFileListFlavor);%0A            java.util.List fileList = (java.util.List) data;%0A%0A            /* Loop through the files */%0A            for (Object obj : fileList) %7B%0A                File file = (File) obj;%0A                logger.info(%22Dropping file %22 + file);%0A                new SheetActions.OpenTask(file).execute();%0A            %7D%0A        %7D catch (UnsupportedFlavorException ex) %7B%0A            logger.warning(%22Unsupported flavor in drag & drop%22, ex);%0A%0A            return false;%0A        %7D catch (IOException ex) %7B%0A            logger.warning(%22IO Exception in drag & drop%22, ex);%0A%0A            return false;%0A        %7D%0A%0A        return true;%0A    %7D%0A%7D%0A

Support for dropping files to the GUI