Example usage for java.awt.datatransfer DataFlavor DataFlavor

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

Introduction

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

Prototype

public DataFlavor(String mimeType, String humanPresentableName) 

Source Link

Document

Constructs a DataFlavor that represents a MimeType .

Usage

From source file:Main.java

public static void main(String[] args) {

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

}

From source file:Main.java

public static void main(String[] args) {

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

}

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 equals df2: " + df1.isMimeTypeEqual("Plain ASCII text"));
}

From source file:Main.java

public static void main(String[] args) {

    DataFlavor df1 = new DataFlavor("text/plain; charset=ASCII", "Plain ASCII text");
    df1.selectBestTextFlavor(new DataFlavor[] { DataFlavor.stringFlavor });

}

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:Main.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("df1 equals df2: " + df1.match(df2));
}

From source file:Main.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("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: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:Main.java

public static String getClipboardData() {
    String result = "";
    Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();

    Transferable contents = clipboard.getContents(null);
    DataFlavor dfRTF = new DataFlavor("text/rtf", "Rich Formatted Text");
    DataFlavor dfTxt = DataFlavor.stringFlavor;

    boolean hasTransferableRTFText = (contents != null) && contents.isDataFlavorSupported(dfRTF);

    boolean hasTransferableTxtText = (contents != null) && contents.isDataFlavorSupported(dfTxt);

    if (hasTransferableRTFText) {
        try {/*w  w  w .jav a  2s . c  o  m*/
            result = streamToString((InputStream) contents.getTransferData(dfRTF));
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    } else if (hasTransferableTxtText) {
        try {
            result = (String) contents.getTransferData(dfTxt);
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
    return result;
}