Outils pour utilisateurs

Outils du site


informatique:java:tips:drag_drop

Java Drag & Drop

Essais

Dans la méthode canImport() du javax.swing.TransferHandler voici les DataFlavor obtenus (support.getDataFlavors()):

for (java.awt.datatransfer.DataFlavor df : support.getDataFlavors()) {
 System.out.println(df.getHumanPresentableName() + " - " + df.getMimeType()+" - "+df.getSubType() + " - " + df.getDefaultRepresentationClassAsString());
}

Linux XUbuntu

Avec Linux XUbuntu: Drag d'un fichier depuis le gestionnaire de fichier Thunar vers un JTextField. Quelque soit le type de fichier (“Text”, “Png”) l'appel à support.getDataFlavors() donne :

text/uri-list - text/uri-list; class=java.io.Reader; charset=Unicode - uri-list - java.io.InputStream
text/uri-list - text/uri-list; class=java.lang.String; charset=Unicode - uri-list - java.io.InputStream
text/uri-list - text/uri-list; class=java.nio.CharBuffer; charset=Unicode - uri-list - java.io.InputStream
text/uri-list - text/uri-list; class="[C"; charset=Unicode - uri-list - java.io.InputStream
text/uri-list - text/uri-list; class=java.io.InputStream; charset=UTF-16 - uri-list - java.io.InputStream
text/uri-list - text/uri-list; class=java.nio.ByteBuffer; charset=UTF-16 - uri-list - java.io.InputStream
text/uri-list - text/uri-list; class="[B"; charset=UTF-16 - uri-list - java.io.InputStream
text/uri-list - text/uri-list; class=java.io.InputStream; charset=UTF-8 - uri-list - java.io.InputStream
text/uri-list - text/uri-list; class=java.nio.ByteBuffer; charset=UTF-8 - uri-list - java.io.InputStream
text/uri-list - text/uri-list; class="[B"; charset=UTF-8 - uri-list - java.io.InputStream
text/uri-list - text/uri-list; class=java.io.InputStream; charset=UTF-16BE - uri-list - java.io.InputStream
text/uri-list - text/uri-list; class=java.nio.ByteBuffer; charset=UTF-16BE - uri-list - java.io.InputStream
text/uri-list - text/uri-list; class="[B"; charset=UTF-16BE - uri-list - java.io.InputStream
text/uri-list - text/uri-list; class=java.io.InputStream; charset=UTF-16LE - uri-list - java.io.InputStream
text/uri-list - text/uri-list; class=java.nio.ByteBuffer; charset=UTF-16LE - uri-list - java.io.InputStream
text/uri-list - text/uri-list; class="[B"; charset=UTF-16LE - uri-list - java.io.InputStream
text/uri-list - text/uri-list; class=java.io.InputStream; charset=ISO-8859-1 - uri-list - java.io.InputStream
text/uri-list - text/uri-list; class=java.nio.ByteBuffer; charset=ISO-8859-1 - uri-list - java.io.InputStream
text/uri-list - text/uri-list; class="[B"; charset=ISO-8859-1 - uri-list - java.io.InputStream
text/uri-list - text/uri-list; class=java.io.InputStream; charset=US-ASCII - uri-list - java.io.InputStream
text/uri-list - text/uri-list; class=java.nio.ByteBuffer; charset=US-ASCII - uri-list - java.io.InputStream
text/uri-list - text/uri-list; class="[B"; charset=US-ASCII - uri-list - java.io.InputStream

Et l'appel à DataFlavor.selectBestTextFlavor()

java.awt.datatransfer.DataFlavor df = java.awt.datatransfer.DataFlavor.selectBestTextFlavor(support.getDataFlavors()) ;
System.out.println(df.getHumanPresentableName() + " - " + df.getMimeType()+" - "+df.getSubType() + " - " + df.getDefaultRepresentationClassAsString());

donne:

text/uri-list - text/uri-list; class=java.io.Reader; charset=Unicode - uri-list - java.io.InputStream

Windows XP

Avec Windows l'appel à support.getDataFlavors() donne:

application/x-java-file-list - application/x-java-file-list; class=java.util.List - x-java-file-list - java.io.InputStream

Et l'appel ) DataFlavor.selectBestTextFlavor() donne:

NULL
informatique/java/tips/drag_drop.txt · Dernière modification: 19/05/2012 00:19 (modification externe)