Example usage for java.awt.datatransfer DataFlavor javaFileListFlavor

List of usage examples for java.awt.datatransfer DataFlavor javaFileListFlavor

Introduction

In this page you can find the example usage for java.awt.datatransfer DataFlavor javaFileListFlavor.

Prototype

DataFlavor javaFileListFlavor

To view the source code for java.awt.datatransfer DataFlavor javaFileListFlavor.

Click Source Link

Document

To transfer a list of files to/from Java (and the underlying platform) a DataFlavor of this type/subtype and representation class of java.util.List is used.

Usage

From source file:Main.java

public static void main(String[] args) {

    DataFlavor df = DataFlavor.javaFileListFlavor;

    System.out.println(df.toString());
}

From source file:MainClass.java

public static void main(String[] args) {

    DataFlavor df = DataFlavor.stringFlavor;

    System.out.println("Mime type: " + df.getMimeType());
    System.out.println("Primary type: " + df.getPrimaryType());
    System.out.println("Subtype: " + df.getSubType());
    System.out.println("Name: " + df.getHumanPresentableName());
    String s = df.getRepresentationClass().toString();
    System.out.println("Representation class: " + s + "\n");

    df = DataFlavor.javaFileListFlavor;

    System.out.println("Mime type: " + df.getMimeType());
    System.out.println("Primary type: " + df.getPrimaryType());
    System.out.println("Subtype: " + df.getSubType());
    System.out.println("Name: " + df.getHumanPresentableName());
    s = df.getRepresentationClass().toString();
    System.out.println("Representation class: " + s);
}

From source file:Main.java

/**
 * Returns a list of files from a given transferable.
 *///from ww w .ja  v a2 s. co m
public static List<File> getFiles(Transferable aTrans) {
    // Handle JavaFileListFlavor
    if (aTrans.isDataFlavorSupported(DataFlavor.javaFileListFlavor))
        try {
            return (List) aTrans.getTransferData(DataFlavor.javaFileListFlavor);
        } catch (Exception e) {
            System.err.println(e);
            return null;
        }

    // Otherwise return null
    return null;
}

From source file:MyTree.java

public boolean importData(JComponent comp, Transferable t) {
    if (!(comp instanceof MyTree)) {
        return false;
    }//from w  ww  .  ja  v a  2s. com
    if (!t.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {
        return false;
    }
    MyTree tree = (MyTree) comp;
    DefaultTreeModel model = (DefaultTreeModel) tree.getModel();
    DefaultMutableTreeNode root = (DefaultMutableTreeNode) model.getRoot();
    try {
        List data = (List) t.getTransferData(DataFlavor.javaFileListFlavor);
        Iterator i = data.iterator();
        while (i.hasNext()) {
            File f = (File) i.next();
            root.add(new DefaultMutableTreeNode(f.getName()));
        }
        model.reload();
        return true;
    } catch (Exception ioe) {
        System.out.println(ioe);
    }
    return false;
}

From source file:Main.java

public boolean canImport(JComponent com, DataFlavor[] dataFlavors) {
    for (int i = 0; i < dataFlavors.length; i++) {
        DataFlavor flavor = dataFlavors[i];
        if (flavor.equals(DataFlavor.javaFileListFlavor)) {
            System.out.println("canImport: JavaFileList FLAVOR: " + flavor);
            return true;
        }//w ww .  j  a  v  a  2  s . c o m
        if (flavor.equals(DataFlavor.stringFlavor)) {
            System.out.println("canImport: String FLAVOR: " + flavor);
            return true;
        }
        System.err.println("canImport: Rejected Flavor: " + flavor);
    }
    return false;
}

From source file:de.drop_converter.plugins.binary_convert.Hex2Data.java

@Override
public boolean importData(TransferSupport support) throws ConverterException {
    try {/*  w  w w  .  ja v  a  2s .  c o m*/
        if (support.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {
            List<File> files = (List<File>) support.getTransferable()
                    .getTransferData(DataFlavor.javaFileListFlavor);
            for (File file : files) {
                FileInputStream fis = null;
                OutputStream out = null;
                try {
                    out = getOutputStream(file, ".hex");
                    fis = new FileInputStream(file);
                    byte[] buffer = new byte[bufferSize];
                    int count = 0;
                    while (-1 != (count = fis.read(buffer))) {
                        if (count == bufferSize) {
                            out.write(Hex.decodeHex(new String(buffer).toCharArray()));
                        } else {
                            byte[] tmp = Arrays.copyOf(Hex.decodeHex(new String(buffer).toCharArray()), count);
                            out.write(tmp);
                        }
                    }
                } catch (Exception e) {
                    throw new ConverterException(e);
                } finally {
                    IOUtils.closeQuietly(out);
                    IOUtils.closeQuietly(fis);
                }
            }
            return true;
        } else if (support.isDataFlavorSupported(DataFlavor.stringFlavor)) {
            String data = (String) support.getTransferable().getTransferData(DataFlavor.stringFlavor);
            OutputStream out = null;
            try {
                byte[] encode = Hex.decodeHex(data.toCharArray());
                out = getOutputStream(null, ".hex");
                out.write(encode);
            } catch (Exception e) {
                throw new ConverterException(e);
            } finally {
                IOUtils.closeQuietly(out);
            }
        }
    } catch (Exception e) {
        throw new ConverterException(e);
    }

    return false;
}

From source file:de.drop_converter.plugins.binary_convert.Base642Data.java

@Override
public boolean importData(TransferSupport support) throws ConverterException {
    try {/*from ww w .ja v a 2  s. c  o  m*/
        if (support.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {
            List<File> files = (List<File>) support.getTransferable()
                    .getTransferData(DataFlavor.javaFileListFlavor);
            for (File file : files) {
                FileInputStream fis = null;
                Base64InputStream base64IS = null;
                OutputStream out = null;
                try {
                    fis = new FileInputStream(file);
                    base64IS = new Base64InputStream(fis, false);
                    out = getOutputStream(file, ".bin");
                    IOUtils.copy(base64IS, out);
                } catch (Exception e) {
                    throw new ConverterException(e);
                } finally {
                    IOUtils.closeQuietly(out);
                    IOUtils.closeQuietly(base64IS);
                    IOUtils.closeQuietly(fis);
                }
            }
            return true;
        } else if (support.isDataFlavorSupported(DataFlavor.stringFlavor)) {
            String data = (String) support.getTransferable().getTransferData(DataFlavor.stringFlavor);
            OutputStream out = null;
            try {
                byte[] encode = new Base64().decode(data.getBytes());
                out = getOutputStream(null, ".bin");
                out.write(encode);
            } catch (Exception e) {
                throw new ConverterException(e);
            } finally {
                IOUtils.closeQuietly(out);
            }
        }
    } catch (Exception e) {
        throw new ConverterException(e);
    }

    return false;
}

From source file:de.drop_converter.plugins.binary_convert.Data2Base64.java

@Override
public boolean importData(TransferSupport support) throws ConverterException {
    try {//from w  ww.j  a v a 2s . c o m
        if (support.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {
            List<File> files = (List<File>) support.getTransferable()
                    .getTransferData(DataFlavor.javaFileListFlavor);
            for (File file : files) {
                FileInputStream fis = null;
                Base64InputStream base64IS = null;
                OutputStream out = null;
                try {
                    fis = new FileInputStream(file);
                    base64IS = new Base64InputStream(fis, true);
                    out = getOutputStream(file, ".base64");
                    IOUtils.copy(base64IS, out);
                } catch (Exception e) {
                    throw new ConverterException(e);
                } finally {
                    IOUtils.closeQuietly(out);
                    IOUtils.closeQuietly(base64IS);
                    IOUtils.closeQuietly(fis);
                }
            }
            return true;
        } else if (support.isDataFlavorSupported(DataFlavor.stringFlavor)) {
            String data = (String) support.getTransferable().getTransferData(DataFlavor.stringFlavor);
            OutputStream out = null;
            try {
                byte[] encode = new Base64().encode(data.getBytes());
                out = getOutputStream(null, ".base64");
                out.write(encode);
            } catch (Exception e) {
                throw new ConverterException(e);
            } finally {
                IOUtils.closeQuietly(out);
            }

        }
    } catch (Exception e) {
        throw new ConverterException(e);
    }

    return false;
}

From source file:de.drop_converter.plugins.binary_convert.Data2Hex.java

@Override
public boolean importData(TransferSupport support) throws ConverterException {
    try {/*from  w  w w.j  a va2 s  .c o m*/
        if (support.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {
            List<File> files = (List<File>) support.getTransferable()
                    .getTransferData(DataFlavor.javaFileListFlavor);
            for (File file : files) {
                FileInputStream fis = null;
                OutputStream out = null;
                try {
                    out = getOutputStream(file, ".hex");
                    fis = new FileInputStream(file);
                    byte[] buffer = new byte[bufferSize];
                    int count = 0;
                    while (-1 != (count = fis.read(buffer))) {
                        if (count == bufferSize) {
                            out.write(Hex.encodeHexString(buffer).getBytes("UTF-8"));
                        } else {
                            byte[] tmp = Arrays.copyOf(Hex.encodeHexString(buffer).getBytes("UTF-8"), count);
                            out.write(tmp);
                        }
                    }
                } catch (Exception e) {
                    throw new ConverterException(e);
                } finally {
                    IOUtils.closeQuietly(out);
                    IOUtils.closeQuietly(fis);
                }
            }
            return true;
        } else if (support.isDataFlavorSupported(DataFlavor.stringFlavor)) {
            String data = (String) support.getTransferable().getTransferData(DataFlavor.stringFlavor);
            OutputStream out = null;
            try {
                byte[] encode = Hex.encodeHexString(data.getBytes()).getBytes();
                out = getOutputStream(null, ".hex");
                out.write(encode);
            } catch (Exception e) {
                throw new ConverterException(e);
            } finally {
                IOUtils.closeQuietly(out);
            }

        }
    } catch (Exception e) {
        throw new ConverterException(e);
    }

    return false;
}

From source file:com.codecrate.shard.ui.dragdrop.FileTransferHandler.java

public FileTransferHandler() {
    fileDataFlavor = DataFlavor.javaFileListFlavor;
    try {//w  w w  . j  a  va 2s  .c  o m
        uriListFlavor = new DataFlavor("text/uri-list;class=java.lang.String");
    } catch (ClassNotFoundException e) {
        throw new RuntimeException(e);
    }
}