Example usage for java.awt.datatransfer DataFlavor getHumanPresentableName

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

Introduction

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

Prototype

public String getHumanPresentableName() 

Source Link

Document

Returns the human presentable name for the data format that this DataFlavor represents.

Usage

From source file:Main.java

public static void main(String[] args) {

    DataFlavor df = DataFlavor.stringFlavor;

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

From source file:Main.java

public static void main(String[] args) {

    DataFlavor df1 = new DataFlavor("text/plain; charset=ASCII", "Plain ASCII text");
    System.out.println(df1.getParameter(df1.getHumanPresentableName()));

}

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:MainClass.java

public static void main(String[] args) {

    DataFlavor df1 = new DataFlavor("text/plain; charset=ASCII", "Plain ASCII text");

    DataFlavor df2 = new DataFlavor(java.awt.Button.class, "AWT Button");

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

    System.out.println("df1 equals df2: " + df1.isMimeTypeEqual(df2));
}

From source file:MainClass.java

public static void main(String[] args) {

    DataFlavor df = new DataFlavor("text/plain; charset=ASCII", "Plain ASCII text");

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

}

From source file:net.sf.jabref.external.TransferableFileLinkSelection.java

@Override
public boolean isDataFlavorSupported(DataFlavor dataFlavor) {
    LOGGER.debug("Query: " + dataFlavor.getHumanPresentableName() + " , "
            + dataFlavor.getDefaultRepresentationClass() + " , " + dataFlavor.getMimeType());
    return dataFlavor.equals(DataFlavor.javaFileListFlavor) || dataFlavor.equals(DataFlavor.stringFlavor);
}

From source file:edu.ku.brc.specify.tasks.subpane.wb.ImageTransferable.java

@Override
public boolean canImport(TransferSupport support) {
    Transferable trans = support.getTransferable();
    DataFlavor[] flavors = trans.getTransferDataFlavors();
    for (DataFlavor df : flavors) {
        if (df.getHumanPresentableName().equals(MIME_TYPE) && df.getRepresentationClass() == String.class) {
            return true;
            /*try/*from ww w. j a va2 s. c  o m*/
            {
            String uris = (String)trans.getTransferData(df);
                    
            String[] filePaths = StringUtils.split(uris, "\r\n");
            for (String path : filePaths)
            {
                System.out.println("canImport2: "+filter.isImageFile(path));
                return filter.isImageFile(path);
            }
            } catch (UnsupportedFlavorException e)
            {
            e.printStackTrace();
            } catch (IOException e)
            {
            e.printStackTrace();
            }*/
        }
    }
    return false;
}

From source file:edu.ku.brc.specify.tasks.subpane.wb.ImageTransferable.java

@Override
public boolean canImport(JComponent comp, DataFlavor[] transferFlavors) {
    for (DataFlavor df : transferFlavors) {
        if (df.getHumanPresentableName().equals(MIME_TYPE) && df.getRepresentationClass() == String.class) {
            return true;
            /*try/*  w  ww  .  ja  v a 2 s.  c  o  m*/
            {
                       
            String uris = (String)trans.getTransferData(df);
            String[] filePaths = StringUtils.split(uris, "\r\n");
            for (String path : filePaths)
            {
                return filter.isImageFile(path);
            }
            } catch (UnsupportedFlavorException e)
            {
            e.printStackTrace();
            } catch (IOException e)
            {
            e.printStackTrace();
            }*/
        }
    }
    System.out.println("canImport1: false");
    return false;
}

From source file:edu.ku.brc.specify.tasks.subpane.wb.ImageTransferable.java

@Override
public boolean importData(TransferSupport support) {
    Vector<File> fileList = new Vector<File>();

    try {//w  w w  .  j  a  v  a 2s.c o m
        Transferable trans = support.getTransferable();
        DataFlavor[] flavors = trans.getTransferDataFlavors();
        for (DataFlavor df : flavors) {
            if (df.getHumanPresentableName().equals("text/uri-list")
                    && df.getRepresentationClass() == String.class) {
                String uris = (String) trans.getTransferData(df);
                String[] filePaths = StringUtils.split(uris, "\r\n");
                for (String path : filePaths) {
                    URI uri = URI.create(path);
                    File f = new File(uri);
                    if (filter.isImageFile(path)) {
                        fileList.add(f);
                    }
                }
                break;
            }
        }

    } catch (UnsupportedFlavorException e) {
        e.printStackTrace();

    } catch (IOException e) {
        e.printStackTrace();
    }

    if (fileList.size() > 0) {
        processImages(fileList);
        return true;
    }

    return false;
}

From source file:EditorDropTarget2.java

protected boolean dropContent(Transferable transferable, DropTargetDropEvent dtde) {
    if (!pane.isEditable()) {
        // Can't drop content on a read-only text control
        return false;
    }/*from w  ww . ja  va 2  s .  c  o  m*/

    try {
        // Check for a match with the current content type
        DataFlavor[] flavors = dtde.getCurrentDataFlavors();

        DataFlavor selectedFlavor = null;

        // Look for either plain text or a String.
        for (int i = 0; i < flavors.length; i++) {
            DataFlavor flavor = flavors[i];

            if (flavor.equals(DataFlavor.plainTextFlavor) || flavor.equals(DataFlavor.stringFlavor)) {
                selectedFlavor = flavor;
                break;
            }
        }

        if (selectedFlavor == null) {
            // No compatible flavor - should never happen
            return false;

        }

        DnDUtils.debugPrintln("Selected flavor is " + selectedFlavor.getHumanPresentableName());

        // Get the transferable and then obtain the data
        Object data = transferable.getTransferData(selectedFlavor);

        DnDUtils.debugPrintln("Transfer data type is " + data.getClass().getName());

        String insertData = null;
        if (data instanceof InputStream) {
            // Plain text flavor
            String charSet = selectedFlavor.getParameter("charset");
            InputStream is = (InputStream) data;
            byte[] bytes = new byte[is.available()];
            is.read(bytes);
            try {
                insertData = new String(bytes, charSet);
            } catch (UnsupportedEncodingException e) {
                // Use the platform default encoding
                insertData = new String(bytes);
            }
        } else if (data instanceof String) {
            // String flavor
            insertData = (String) data;
        }

        if (insertData != null) {
            int selectionStart = pane.getCaretPosition();
            pane.replaceSelection(insertData);
            pane.select(selectionStart, selectionStart + insertData.length());
            return true;
        }
        return false;
    } catch (Exception e) {
        return false;
    }
}