当前位置: 首页>>代码示例>>Java>>正文


Java SystemFlavorMap.setNativesForFlavor方法代码示例

本文整理汇总了Java中java.awt.datatransfer.SystemFlavorMap.setNativesForFlavor方法的典型用法代码示例。如果您正苦于以下问题:Java SystemFlavorMap.setNativesForFlavor方法的具体用法?Java SystemFlavorMap.setNativesForFlavor怎么用?Java SystemFlavorMap.setNativesForFlavor使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.awt.datatransfer.SystemFlavorMap的用法示例。


在下文中一共展示了SystemFlavorMap.setNativesForFlavor方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: main

import java.awt.datatransfer.SystemFlavorMap; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
        final String nativeString = "NATIVE";

        final SystemFlavorMap fm =
            (SystemFlavorMap)SystemFlavorMap.getDefaultFlavorMap();

        fm.setNativesForFlavor(DataFlavor.plainTextFlavor,
                               new String[] { nativeString });

        final java.util.List natives =
            fm.getNativesForFlavor(DataFlavor.plainTextFlavor);

        if (natives.size() != 1 || !natives.contains(nativeString)) {
            throw new RuntimeException("getNativesForFlavor() returns:" +
                                       natives);
        }

        final DataFlavor dataFlavor =
            new DataFlavor("text/unknown; class=java.lang.String");

        fm.setFlavorsForNative(nativeString, new DataFlavor[] { dataFlavor });

        final java.util.List flavors = fm.getFlavorsForNative(nativeString);

        if (flavors.size() != 1 || !flavors.contains(dataFlavor)) {
            throw new RuntimeException("getFlavorsForNative() returns:" +
                                       flavors);
        }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:30,代码来源:SetNativesForFlavorTest.java

示例2: leaveFormat

import java.awt.datatransfer.SystemFlavorMap; //导入方法依赖的package包/类
static void leaveFormat(String format) {
    SystemFlavorMap sfm = (SystemFlavorMap) SystemFlavorMap.getDefaultFlavorMap();
    sfm.setFlavorsForNative(format, new DataFlavor[]{DataFlavor.imageFlavor});
    sfm.setNativesForFlavor(DataFlavor.imageFlavor, new String[]{format});
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:6,代码来源:ImageTransferTest.java

示例3: doTest

import java.awt.datatransfer.SystemFlavorMap; //导入方法依赖的package包/类
public void doTest() {
    flavorMap = (SystemFlavorMap)SystemFlavorMap.getDefaultFlavorMap();

    // Get SystemFlavorMap Maps of String Natives and DataFlavors
    mapFlavors = flavorMap.getNativesForFlavors(null);
    mapNatives = flavorMap.getFlavorsForNatives(null);

    hashFlavors = new Hashtable(mapFlavors);
    hashNatives = new Hashtable(mapNatives);


    // Test setNativesForFlavor(DataFlavors flav, String[] natives);
    //
    // Enumerate through all the system defined DataFlavors,
    // and for each DataFlavor, define it again to the SystemFlavorMap
    // with a slightly modified MimeType.
    //
    // For verification, a seperate Hashtable will be maintained of the additions.
    DataFlavor key;
    hashVerify = new Hashtable();

    for (Enumeration e = hashFlavors.keys() ; e.hasMoreElements() ;) {
        key = (DataFlavor)e.nextElement();

        java.util.List listNatives = flavorMap.getNativesForFlavor(key);
        Vector vectorNatives = new Vector(listNatives);
        String[] arrayNatives = (String[])vectorNatives.toArray(new String[0]);

        // Construct a new DataFlavor from an existing DataFlavor's MimeType
        // Example:
        // Original MimeType: "text/plain; class=java.io.Reader; charset=Unicode"
        // Modified MimeType: "text/plain-TEST; class=java.io.Reader; charset=Unicode"

        StringBuffer mimeType = new StringBuffer(key.getMimeType());
        mimeType.insert(mimeType.indexOf(";"),"-TEST");

        DataFlavor testFlav = new DataFlavor(mimeType.toString(), "Test DataFlavor");

                                    // define the new String native entry
        flavorMap.setNativesForFlavor(testFlav, arrayNatives);
                                    // keep track of this new native entry
        hashVerify.put(testFlav, vectorNatives);
    }

    // After establishing "new" mappings, verify that the defined
    // Natives can be retrieved and that the List (order) is preserved.
    verifyNewMappings();
}
 
开发者ID:campolake,项目名称:openjdk9,代码行数:49,代码来源:SetDataFlavorsTest.java


注:本文中的java.awt.datatransfer.SystemFlavorMap.setNativesForFlavor方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。