FileDocCategorySizeDatePackage
ImageTransferHandler.javaAPI DocAndroid 1.5 API3216Wed May 06 22:41:10 BST 2009com.android.draw9patch.ui

ImageTransferHandler

public class ImageTransferHandler extends TransferHandler

Fields Summary
private final MainFrame
mainFrame
Constructors Summary
ImageTransferHandler(MainFrame mainFrame)

        this.mainFrame = mainFrame;
    
Methods Summary
public booleancanImport(javax.swing.JComponent component, java.awt.datatransfer.DataFlavor[] dataFlavors)

        for (DataFlavor flavor : dataFlavors) {
            if (flavor.isFlavorJavaFileListType() || flavor.isFlavorTextType()) {
                return true;
            }
        }
        return false;
    
private static java.lang.StringconvertPath(java.lang.String path)

        if (path.startsWith("file://")) path = path.substring("file://".length());
        if (path.indexOf('\n") != -1) path = path.substring(0, path.indexOf('\n"));
        if (path.indexOf('\r") != -1) path = path.substring(0, path.indexOf('\r"));
        return path;
    
public booleanimportData(javax.swing.JComponent component, java.awt.datatransfer.Transferable transferable)

        try {
            for (DataFlavor flavor : transferable.getTransferDataFlavors()) {
                if (flavor.isFlavorJavaFileListType()) {
                    Object data = transferable.getTransferData(DataFlavor.javaFileListFlavor);
                    //noinspection unchecked
                    final File file = ((List<File>) data).get(0);
                    mainFrame.open(file).execute();
                    return true;
                } else if (flavor.isFlavorTextType()) {
                    if (flavor.getRepresentationClass() == String.class) {
                        String mime = flavor.getMimeType();
                        DataFlavor flave = new DataFlavor(mime);
                        Object data = transferable.getTransferData(flave);
                        final String path = convertPath(data.toString());
                        mainFrame.open(new File(path)).execute();
                        return true;
                    }
                }
            }
        } catch (UnsupportedFlavorException e) {
            // Ignore
        } catch (MalformedURLException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } catch (Exception e) {
            e.printStackTrace();
        }

        return false;