久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

JDK1.6和JDK1.7的拖放區(qū)別

Drag and drop differences between JDK1.6 and JDK1.7(JDK1.6和JDK1.7的拖放區(qū)別)
本文介紹了JDK1.6和JDK1.7的拖放區(qū)別的處理方法,對(duì)大家解決問(wèn)題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!

問(wèn)題描述

限時(shí)送ChatGPT賬號(hào)..

有人知道 JDK1.6 和 JDK1.7 之間拖放行為的差異嗎?在將 URL 從瀏覽器拖放到需要支持 JDK1.5、JDK1.6 和 JDK1.7 的應(yīng)用程序上時(shí),我遇到了一個(gè)差異(如下所示).我現(xiàn)在想知道是否存在其他差異,以及它們是否記錄在某處.

Does anybody know about differences in the drag-and-drop behavior between JDK1.6 and JDK1.7 ? I encountered a difference (illustrated below) when drag-and-dropping an URL from a browser onto an application which needs to support JDK1.5, JDK1.6 and JDK1.7 . I am now wondering whether other differences exists and if they are documented somewhere.

我遇到的不同行為是通過(guò)單擊并將 URL 從瀏覽器(不是從地址欄而是從頁(yè)面)拖放到 Java 應(yīng)用程序上來(lái)拖放 URL.在 JDK1.6 上,Transferable 不支持 DataFlavor.javaFileListFlavor 而在 JDK1.7 上它支持(盡管在請(qǐng)求其傳輸數(shù)據(jù)時(shí)會(huì)得到一個(gè)空列表).下面的代碼說(shuō)明了這個(gè)問(wèn)題.它會(huì)打開(kāi)一個(gè) JFrame,您可以在其中拖放一個(gè) URL,例如 http://www.google.com 并打印出它是使用文件列表風(fēng)格還是 URI 列表風(fēng)格

The different behavior I encountered is when drag-and-drop an URL from a browser (not from the address bar but from the page) by click-and-drag the URL onto the Java application. On JDK1.6, the Transferable does not support the DataFlavor.javaFileListFlavor and on JDK1.7 it does (although when requesting for its transfer data you get an empty list). The following code illustrates the issue. It opens a JFrame on which you can drag-and-drop an URL like http://www.google.com and which prints out whether it uses the file list flavor or the URI-list flavor

import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.TransferHandler;
import java.awt.BorderLayout;
import java.awt.EventQueue;
import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.Transferable;
import java.awt.datatransfer.UnsupportedFlavorException;
import java.io.File;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.util.List;

public class DragAndDropTester {
  private static DataFlavor URI_LIST_FLAVOR = null;

  static {
    try {
      URI_LIST_FLAVOR = new DataFlavor( "text/uri-list;class=java.lang.String" );
    }
    catch ( ClassNotFoundException ignore ) {
    }
  }
  public static void main( String[] args ) {
    try {
      EventQueue.invokeAndWait( new Runnable() {
        public void run() {

          JFrame testFrame = new JFrame( "Test" );

          JPanel contents = new JPanel( new BorderLayout() );
          contents.add( new JLabel( "TestLabel" ), BorderLayout.CENTER );

          contents.setTransferHandler( createTransferHandler() );

          testFrame.getContentPane().add( contents );
          testFrame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
          testFrame.setSize( 200, 200 );
          testFrame.setVisible( true );
        }
      } );
    } catch ( InterruptedException e ) {
      throw new RuntimeException( e );
    } catch ( InvocationTargetException e ) {
      throw new RuntimeException( e );
    }
  }

  private static TransferHandler createTransferHandler(){
    return new TransferHandler(  ){
      @Override
      public boolean importData( JComponent comp, Transferable aTransferable ) {
        try {
          if ( aTransferable.isDataFlavorSupported( DataFlavor.javaFileListFlavor ) ) {
            System.out.println("File list flavor");
            List<File> file_list = ( List<File> ) aTransferable.getTransferData( DataFlavor.javaFileListFlavor );
            System.out.println( "file_list = " + file_list );
          }
              if ( URI_LIST_FLAVOR != null && aTransferable.isDataFlavorSupported( URI_LIST_FLAVOR ) ){
            System.out.println("URI list flavor");
            String uri_list = ( String ) aTransferable.getTransferData( URI_LIST_FLAVOR );
            System.out.println( "uri_list = " + uri_list );
          }
        } catch ( UnsupportedFlavorException e ) {
          throw new RuntimeException( e );
        } catch ( IOException e ) {
          throw new RuntimeException( e );
        }
        return true;
      }

      @Override
      public boolean canImport( JComponent comp, DataFlavor[] transferFlavors ) {
        return true;
      }
    };
  }
}

JDK 1.7.01 上的結(jié)果輸出

Resulting output on JDK 1.7.01

File list flavor
file_list = []
URI list flavor
uri_list = http://www.google.com

JDK1.6.0.18 上的結(jié)果輸出

Resulting output on JDK1.6.0.18

URI list flavor
uri_list = http://www.google.com

我可以輕松地為這個(gè)問(wèn)題創(chuàng)建一個(gè)解決方法,但我對(duì)更多已知的差異和/或關(guān)于這些差異的文檔更感興趣.

I can easily create a workaround for this issue, but I am more interested in any more know differences and/or documentation about those differences.

編輯

一些進(jìn)一步的調(diào)查/谷歌搜索讓我認(rèn)為 JDK7 上的行為是創(chuàng)建 URI 和文件列表數(shù)據(jù)風(fēng)格,并在可傳輸中提供它們.然后文件列表只包含代表文件的 URI.因此,僅拖放 URL 時(shí),文件列表為空.我在 JDK 源代碼中找不到這個(gè),因?yàn)樗坪蹩蓚鬏?傳輸數(shù)據(jù)是用本機(jī)代碼創(chuàng)建的(或者至少是我找不到源代碼的代碼).在 OpenJDK 郵件列表上有一個(gè)關(guān)于 類(lèi)似問(wèn)題的討論,包含以下引用

Some further investigation/googling makes me think the behavior on JDK7 is to create both the URI and filelist data flavor and offering them both in the transferable. The filelist then only contains the URI's which represent a file. Hence when only drag-and-dropping an URL, the file list is empty. I cannot find this in the JDK source code as it seems the transferable/transferdata is created in native code (or at least code for which I do not find the sources). On the OpenJDK mailing list there was a discussion about a similar issue, containing the following quote

如果您將文件列表從本機(jī)拖到 Java 中,應(yīng)用程序會(huì)同時(shí)看到 URI 列表和文件列表.如果你拖入一個(gè) URI 列表,它會(huì)看到一個(gè) URI 列表,如果所有 URI 都是文件,那么它也是一個(gè)非空文件列表,否則只是一個(gè)空文件列表.

If you drag a file list from native into Java, the application sees both a URI list and a file list. If you drag in a URI list it sees a URI list, and if all URIs are files also a non-empty file list, otherwise just an empty file list.

編輯2

根據(jù) serg.nechaev 的回答,我在 32/64 位 Linux 系統(tǒng)和幾個(gè) Windows 系統(tǒng)(從 XP 到 Windows7)上進(jìn)行了更多測(cè)試.在帶有 JDK7 的 Linux 上,我總是得到 URI 數(shù)據(jù)風(fēng)格,以及空文件列表風(fēng)格.在 Windows 上,我得到一個(gè) URI 數(shù)據(jù)風(fēng)格和一個(gè)非空文件列表數(shù)據(jù)風(fēng)格.似乎在臨時(shí)目錄中創(chuàng)建了一個(gè) .URL 文件,并且這也是在文件列表數(shù)據(jù)風(fēng)格中傳遞的,這在 JDK 6 上不是這種情況.

Based on the answer of serg.nechaev I performed some more tests on 32/64 bit Linux systems and several Windows system (ranging from XP to Windows7). On Linux with JDK7 I always get the URI dataflavor, combined with an empty filelist flavor. On Windows, I get a URI dataflavor and a non-empty filelist data flavor. It seems a .URL file gets created in the temp dir, and this is passed in the filelist data flavor as well, which wasn't the case on JDK 6.

所有這些情況的解決方案是首先檢查 URI 數(shù)據(jù)風(fēng)格,然后使用文件列表數(shù)據(jù)風(fēng)格作為后備

Solution in all these cases is to check for the URI dataflavor first, and use the file list data flavor as fall-back

推薦答案

我認(rèn)為導(dǎo)致此行為的更改在 $(JDK)/jre/lib/flavormap.properties:

I think the change that caused this behaviour is in $(JDK)/jre/lib/flavormap.properties:

http://hg.openjdk.java.net/jdk7/hotspot-gc/jdk/diff/fd5bf5955e37/src/windows/lib/flavormap.properties

但是,使用您的示例并從您的帖子中拖動(dòng)到 Google 的鏈接,我得到了文件列表和WinXP、FireFox 8 上 JDK 1.7.0 上的 uri 列表:

However, using your sample and dragging a link to Google from your post, I am getting both file list & uri list on JDK 1.7.0 on WinXP, FireFox 8:

File list flavor
file_list = [C:DOCUME~1SERGNLOCALS~1Temphttpwww.google.com.URL]
URI list flavor
uri_list = http://www.google.com/

這可能是 JDK 1.7.01 的特定于平臺(tái)的錯(cuò)誤,您可能需要進(jìn)一步調(diào)查,并可能向 Oracle 提交錯(cuò)誤.

That could be a platform-specific bug for JDK 1.7.01, you might want to investigate it further and maybe submit a bug to Oracle.

這篇關(guān)于JDK1.6和JDK1.7的拖放區(qū)別的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來(lái)源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問(wèn)題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

Parsing an ISO 8601 string local date-time as if in UTC(解析 ISO 8601 字符串本地日期時(shí)間,就像在 UTC 中一樣)
How to convert Gregorian string to Gregorian Calendar?(如何將公歷字符串轉(zhuǎn)換為公歷?)
Java: What/where are the maximum and minimum values of a GregorianCalendar?(Java:GregorianCalendar 的最大值和最小值是什么/在哪里?)
Calendar to Date conversion for dates before 15 Oct 1582. Gregorian to Julian calendar switch(1582 年 10 月 15 日之前日期的日歷到日期轉(zhuǎn)換.公歷到儒略歷切換)
java Calendar setFirstDayOfWeek not working(java日歷setFirstDayOfWeek不起作用)
Java: getting current Day of the Week value(Java:獲取當(dāng)前星期幾的值)
主站蜘蛛池模板: 九九久久精品视频 | 密室大逃脱第六季大神版在线观看 | 成人精品视频在线观看 | 国产精品视频免费观看 | 国产高清精品一区二区三区 | 久久久精品网站 | 国产精品久久久乱弄 | 欧美视频三级 | 精品九九| 一区福利视频 | 黄色网址免费在线观看 | 九九九国产 | 中文字幕一区二区三区精彩视频 | 欧美精品一区二区三区在线播放 | 国产在线观看网站 | 国产精品久久久久久中文字 | 极品电影院 | 黄色网址大全在线观看 | 国产成人自拍av | 日韩成人一区 | 国产97碰免费视频 | 午夜精品久久久久久久久久久久 | 久久久国产精品视频 | 亚洲毛片| 精品一区二区视频 | 在线视频a | 一级黄a视频| 国产精品一区在线播放 | 国产69精品久久久久777 | 久久国产精品一区二区三区 | 91天堂| 国产欧美日韩久久久 | 午夜三级在线观看 | 香蕉视频黄色 | 亚洲视频在线观看 | 天天av综合 | 一区二区成人在线 | 国产美女在线播放 | 精品99久久久久久 | 久久剧场 | 欧美成人一区二区三区 |