pbootcms网站模板|日韩1区2区|织梦模板||网站源码|日韩1区2区|jquery建站特效-html5模板网

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ì)大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

限時(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.

我遇到的不同行為是通過單擊并將 URL 從瀏覽器(不是從地址欄而是從頁面)拖放到 Java 應(yīng)用程序上來拖放 URL.在 JDK1.6 上,Transferable 不支持 DataFlavor.javaFileListFlavor 而在 JDK1.7 上它支持(盡管在請(qǐng)求其傳輸數(shù)據(jù)時(shí)會(huì)得到一個(gè)空列表).下面的代碼說明了這個(gè)問題.它會(huì)打開一個(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è)問題創(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)于 類似問題的討論,包含以下引用

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)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(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)前星期幾的值)
主站蜘蛛池模板: 不锈钢反应釜,不锈钢反应釜厂家-价格-威海鑫泰化工机械有限公司 不干胶标签-不干胶贴纸-不干胶标签定制-不干胶标签印刷厂-弗雷曼纸业(苏州)有限公司 | 阜阳在线-阜阳综合门户 | 桥架-槽式电缆桥架-镀锌桥架-托盘式桥架 - 上海亮族电缆桥架制造有限公司 | 北京易通慧公司从事北京网站优化,北京网络推广、网站建设一站式服务商-北京网站优化公司 | 工业用品一站式采购平台|南创工品汇-官网|广州南创 | 环比机械| 电动手术床,医用护理床,led手术无影灯-曲阜明辉医疗设备有限公司 | 穿线管|波纹穿线管|包塑金属软管|蛇皮管?闵彬专注弱电工程? | 济南冷库安装-山东冷库设计|建造|冷库维修-山东齐雪制冷设备有限公司 | 消防泵-XBD单级卧式/立式消防泵-上海塑泉泵阀(集团)有限公司 | 环氧乙烷灭菌器_压力蒸汽灭菌器_低温等离子过氧化氢灭菌器 _低温蒸汽甲醛灭菌器_清洗工作站_医用干燥柜_灭菌耗材-环氧乙烷灭菌器_脉动真空压力蒸汽灭菌器_低温等离子灭菌设备_河南省三强医疗器械有限责任公司 | 沙盘模型公司_沙盘模型制作公司_建筑模型公司_工业机械模型制作厂家 | ge超声波测厚仪-电动涂膜机-电动划格仪-上海洪富 | 今日热点_实时热点_奇闻异事_趣闻趣事_灵异事件 - 奇闻事件 | 四探针电阻率测试仪-振实密度仪-粉末流动性测定仪-宁波瑞柯微智能 | 首页|专注深圳注册公司,代理记账报税,注册商标代理,工商变更,企业400电话等企业一站式服务-慧用心 | 深圳美安可自动化设备有限公司,喷码机,定制喷码机,二维码喷码机,深圳喷码机,纸箱喷码机,东莞喷码机 UV喷码机,日期喷码机,鸡蛋喷码机,管芯喷码机,管内壁喷码机,喷码机厂家 | 特材真空腔体_哈氏合金/镍基合金/纯镍腔体-无锡国德机械制造有限公司 | 华夏医界网_民营医疗产业信息平台_民营医院营销管理培训 | 抓斗式清污机|螺杆式|卷扬式启闭机|底轴驱动钢坝|污水处理闸门-方源水利机械 | 钢结构厂房造价_钢结构厂房预算_轻钢结构厂房_山东三维钢结构公司 | 旗帜网络笔记-免费领取《旗帜网络笔记》电子书 | 拉力机-拉力试验机-万能试验机-电子拉力机-拉伸试验机-剥离强度试验机-苏州皖仪实验仪器有限公司 | 深圳展厅设计_企业展馆设计_展厅设计公司_数字展厅设计_深圳百艺堂 | 成都软件开发_OA|ERP|CRM|管理系统定制开发_成都码邻蜀科技 | 光伏家 - 太阳能光伏发电_分布式光伏发电_太阳能光伏网 | 建筑消防设施检测系统检测箱-电梯**检测仪器箱-北京宇成伟业科技有限责任公司 | 不干胶标签-不干胶贴纸-不干胶标签定制-不干胶标签印刷厂-弗雷曼纸业(苏州)有限公司 | 恒压供水控制柜|无负压|一体化泵站控制柜|PLC远程调试|MCGS触摸屏|自动控制方案-联致自控设备 | 浙江工业冷却塔-菱电冷却塔厂家 - 浙江菱电冷却设备有限公司 | 成都亚克力制品,PVC板,双色板雕刻加工,亚克力门牌,亚克力标牌,水晶字雕刻制作-零贰捌广告 | 螺旋丝杆升降机-SWL蜗轮-滚珠丝杆升降机厂家-山东明泰传动机械有限公司 | 制冷采购电子商务平台——制冷大市场| 粘弹体防腐胶带,聚丙烯防腐胶带-全民塑胶 | 陶瓷砂磨机,盘式砂磨机,棒销式砂磨机-无锡市少宏粉体科技有限公司 | PVC快速门-硬质快速门-洁净室快速门品牌厂家-苏州西朗门业 | 雄松华章(广州华章MBA)官网-专注MBA/MPA/MPAcc/MEM辅导培训 | [品牌官网]贵州遵义双宁口腔连锁_贵州遵义牙科医院哪家好_种植牙_牙齿矫正_原华美口腔 | 周口风机|周风风机|河南省周口通用风机厂 | 北京企业宣传片拍摄_公司宣传片制作-广告短视频制作_北京宣传片拍摄公司 | 电销卡_北京电销卡_包月电话卡-豪付网络 |