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


Java SystemFlavorMap.getFlavorsForNative方法代码示例

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


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

示例1: doTest

import java.awt.datatransfer.SystemFlavorMap; //导入方法依赖的package包/类
public void doTest() throws Exception {
    // Initialize DataFlavors and arrays used for test data
    initMappings();

    boolean passed = true;
    flavorMap = (SystemFlavorMap)SystemFlavorMap.getDefaultFlavorMap();

    // Get all the native strings and preferred DataFlavor mappings
    hash = new Hashtable(flavorMap.getFlavorsForNatives(null));
    hashSize = hash.size();

    // GetNativesForFlavor using unknown DataFlavor (verify 2-way mapping)
    //
    // If a new DataFlavor is specified, the method should establish a mapping
    // in both directions between specified DataFlavor and an encoded
    // version of its MIME type as its native.
    System.out.println("GetNativesForFlavor using new DataFlavor");

    comp1 = new Vector(Arrays.asList(test_natives_set));
    comp2 = new Vector(flavorMap.getNativesForFlavor(test_flavor1));

    comp3 = new Vector(Arrays.asList(test_flavors_set));
    comp4 = new Vector(flavorMap.getFlavorsForNative(test_encoded));

    if ( !comp1.equals(comp2) || !comp3.equals(comp4) ) {
        throw new RuntimeException("\n*** After passing a new DataFlavor" +
            "\nwith getNativesForFlavor(DataFlavor flav)" +
            "\nthe mapping in both directions was not established.");
    }
    else
       System.out.println("GetNativesForFlavor using new DataFlavor: Test Passes");
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:33,代码来源:GetNativesForNewFlavorTest.java

示例2: 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

示例3: doTest

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

    // Test addFlavorForUnencodedNative(String nat, DataFlavor flav);
    //
    // Enumerate through all the system defined String natives,
    // and for each String native, define it again to the SystemFlavorMap
    // with a slightly modified String native (name).
    //
    // As a list of DataFlavors will be returned for each String native,
    // the method addFlavorForUnencodedNative will be called for each
    // DataFlavor in the list.
    hashVerify = new Hashtable();

    for (String key : flavorMap.getFlavorsForNatives(null).keySet()) {
        Set<DataFlavor> flavorsSet = new HashSet<>(flavorMap.getFlavorsForNative(key));
        // construct a unique String native
        key = key.concat("TEST");

        for (DataFlavor element : flavorsSet) {
            flavorMap.addFlavorForUnencodedNative(key, element);
        }
        hashVerify.put(key, new Vector(flavorsSet));
    }

    // Assertions: After establishing "new" mappings, verify that the defined
    //             DataFlavors can be retrieved and that the List is preserved.
    verifyNewMappings();
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:30,代码来源:AddFlavorTest.java

示例4: 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);

    // Assertion: Verify getNativesForFlavors(null) is returning the full list
    //            of String Native entries
    List listNatives = flavorMap.getNativesForFlavor(null);
    verifyListAllNativeEntries(listNatives);

    // Assertion: Verify getFlavorsForNatives(null) is returning the full list
    //            of DataFlavor entries
    List listFlavors = flavorMap.getFlavorsForNative(null);
    verifyListAllDataFlavorEntries(listFlavors);

    // Assertion: Verify getNativesForFlavor(DataFlavor flav) is returning the list
    //            of Native Strings (for all supported DataFlavors)
    //
    //            Verify that the first list item is the most preferred Native
    verifyListNativeEntries();

    // Assertion: Verify getFlavorsForNative(String nat) is returning the list
    //            of DataFlavors(for all supported natives)
    //
    //            Verify that the first list item is the most preferred DataFlavor
    verifyListDataFlavorEntries();
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:33,代码来源:ManyFlavorMapTest.java

示例5: 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 setFlavorsForNative(String nat, DataFlavors[] flavors);
    //
    // Enumerate through all the system defined String natives,
    // and for each String native, define it again to the SystemFlavorMap
    // with a slightly modified String native (name).
    //
    // For verification, a seperate Hashtable will be maintained of the additions.
    String key;
    hashVerify = new Hashtable();

    for (Enumeration e = hashNatives.keys() ; e.hasMoreElements() ;) {
        key = (String)e.nextElement();

        java.util.List listFlavors = flavorMap.getFlavorsForNative(key);
        Vector vectorFlavors = new Vector(listFlavors);
        DataFlavor[] arrayFlavors = (DataFlavor[])vectorFlavors.toArray(new DataFlavor[0]);

        key = key.concat("TEST");   // construct a unique String native
                                    // define the new String native entry
        flavorMap.setFlavorsForNative(key, arrayFlavors);
                                    // keep track of this new native entry
        hashVerify.put(key, vectorFlavors);
    }

    // After establishing "new" mappings, verify that the defined
    // DataFlavors can be retrieved and that the List (order) is preserved.
    verifyNewMappings();
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:40,代码来源:SetNativesTest.java

示例6: main

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

        final String nativeString = "NATIVE";
        final DataFlavor dataFlavor = new DataFlavor();

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

        fm.addUnencodedNativeForFlavor(dataFlavor, nativeString);
        fm.addUnencodedNativeForFlavor(dataFlavor, nativeString);

        final java.util.List natives =
                fm.getNativesForFlavor(dataFlavor);
        boolean found = false;

        for (final Iterator i = natives.iterator(); i.hasNext(); ) {
            if (nativeString.equals(i.next())) {
                if (found) {
                    throw new RuntimeException("getNativesForFlavor() returns:" +
                            natives);
                } else {
                    found = true;
                }
            }
        }

        if (!found) {
            throw new RuntimeException("getNativesForFlavor() returns:" +
                    natives);
        }

        fm.addFlavorForUnencodedNative(nativeString, dataFlavor);
        fm.addFlavorForUnencodedNative(nativeString, dataFlavor);

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

        for (final Iterator i = flavors.iterator(); i.hasNext(); ) {
            if (dataFlavor.equals(i.next())) {
                if (found) {
                    throw new RuntimeException("getFlavorsForNative() returns:" +
                            flavors);
                } else {
                    found = true;
                }
            }
        }

        if (!found) {
            throw new RuntimeException("getFlavorsForNative() returns:" +
                    natives);
        }
    }
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:55,代码来源:DuplicateMappingTest.java

示例7: doTest

import java.awt.datatransfer.SystemFlavorMap; //导入方法依赖的package包/类
public void doTest() throws Exception {
    // Initialize DataFlavors and arrays used for test data
    initMappings();

    flavorMap = (SystemFlavorMap)SystemFlavorMap.getDefaultFlavorMap();

    // Get all the native strings and preferred DataFlavor mappings
    hash = new Hashtable(flavorMap.getFlavorsForNatives(null));
    hashSize = hash.size();

    // Setup One-way Mappings
    System.out.println("One-way Mappings Test");
    flavorMap.addFlavorForUnencodedNative(test_native, test_flavor1);
    flavorMap.addFlavorForUnencodedNative(test_native, test_flavor2);

    // Confirm mapping with getFlavorsForNative
    comp1 = new Vector(Arrays.asList(test_flavors_set1));
    comp2 = new Vector(flavorMap.getFlavorsForNative(test_native));

    if ( !comp1.equals(comp2)) {
        throw new RuntimeException("\n*** After setting up one-way mapping" +
            "\nwith addFlavorForUnencodedNative(String nat, DataFlavor flav)" +
            "\nthe mappings returned from getFlavorsForNative() do not match" +
            "\noriginal mappings.");
    }
    else
       System.out.println("One-way: Test Passes");

    // Setup Two-way Mapping
    System.out.println("Two-way Mappings Test");
    flavorMap.addUnencodedNativeForFlavor(test_flavor1, test_native);
    flavorMap.addUnencodedNativeForFlavor(test_flavor2, test_native);

    // Confirm mapping with getNativesForFlavor
    comp1 = new Vector(Arrays.asList(test_natives_set));
    comp2 = new Vector(flavorMap.getNativesForFlavor(test_flavor1));
    comp3 = new Vector(flavorMap.getNativesForFlavor(test_flavor2));

    if ( !(comp1.equals(comp2)) || !(comp1.equals(comp3))) {
        throw new RuntimeException("\n*** After setting up two-way mapping" +
            "\nwith addUnencodedNativeForFlavor(DataFlavor flav, String nat)" +
            "\nthe mappings returned from getNativesForFlavor() do not match" +
            "\noriginal mappings.");
    }
    else
       System.out.println("Two-way (String native): Test Passes");

    // Check first native mapping
    comp1 = new Vector(Arrays.asList(test_flavors_set1));
    comp2 = new Vector(flavorMap.getFlavorsForNative(test_native));

    if ( !comp1.equals(comp2)) {
        throw new RuntimeException("\n*** After setting up two-way mapping" +
            "\nwith addFlavorForUnencodedNative(String nat, DataFlavor flav)" +
            "\nthe mappings returned from getFlavorsForNative() do not match" +
            "\noriginal mappings.");
    }
    else
       System.out.println("Two-way (DataFlavor): Test Passes");

    // Modify an existing mapping test
    System.out.println("Modify Existing Mappings Test");
    flavorMap.addFlavorForUnencodedNative(test_native, test_flavor3);
    flavorMap.addFlavorForUnencodedNative(test_native, test_flavor4);

    // Confirm mapping with getFlavorsForNative
    comp1 = new Vector(Arrays.asList(test_flavors_set2));
    comp2 = new Vector(flavorMap.getFlavorsForNative(test_native));

    if ( !comp1.equals(comp2)) {
        throw new RuntimeException("\n*** After modifying an existing mapping" +
            "\nwith addFlavorForUnencodedNative(String nat, DataFlavor flav)" +
            "\nthe mappings returned from getFlavorsForNative() do not match" +
            "\nupdated mappings.");
    } else
       System.out.println("Modify Existing Mappings: Test Passes");
}
 
开发者ID:campolake,项目名称:openjdk9,代码行数:78,代码来源:AddFlavorForNativeTest.java

示例8: doTest

import java.awt.datatransfer.SystemFlavorMap; //导入方法依赖的package包/类
public void doTest() throws Exception {
    // Initialize DataFlavors and arrays used for test data
    initMappings();

    flavorMap = (SystemFlavorMap) SystemFlavorMap.getDefaultFlavorMap();

    // Get all the native strings and preferred DataFlavor mappings
    hash = new Hashtable(flavorMap.getFlavorsForNatives(null));
    hashSize = hash.size();

    // GetFlavorsForNative using Unencoded Native
    //
    // If a new Unencoded native is specified as a parameter, the String
    // native should be ignored and no mapping established.
    System.out.println("GetFlavorsForNative using Unencoded Native Test");

    comp1 = new Vector(flavorMap.getFlavorsForNative(test_native1));

    if (comp1.size() != 0) {
        throw new RuntimeException("\n*** After passing a new Unencoded native" +
                "\nwith getFlavorsForNative(String nat)" +
                "\nthe String native should be ignored and no mapping established.");
    } else
        System.out.println("GetFlavorsForNative using Unencoded Native Test: Test Passes");


    // GetFlavorsForNative using Encoded Native (verify 2-way mapping)
    //
    // If a new Encoded native is specified, the method should establish a mapping
    // in both directions between specified native and DataFlavor whose MIME type
    // is a decoded version of the native.
    System.out.println("GetFlavorsForNative using Encoded Native Test");

    comp1 = new Vector(Arrays.asList(test_flavors_set));
    comp2 = new Vector(flavorMap.getFlavorsForNative(test_encoded));

    comp3 = new Vector(Arrays.asList(test_natives_set));
    comp4 = new Vector(flavorMap.getNativesForFlavor(test_flavor2));

    if (!comp1.equals(comp2) || !comp3.equals(comp4)) {
        throw new RuntimeException("\n*** After passing a new Encoded native" +
                "\nwith getFlavorsForNative(String nat)" +
                "\nthe mapping in both directions was not established.");
    } else
        System.out.println("GetFlavorsForNative using Encoded Native: Test Passes");
}
 
开发者ID:campolake,项目名称:openjdk9,代码行数:47,代码来源:GetFlavorsForNewNativeTest.java

示例9: doTest

import java.awt.datatransfer.SystemFlavorMap; //导入方法依赖的package包/类
public void doTest() throws Exception {
    // Initialize DataFlavors and arrays used for test data
    initMappings();

    flavorMap = (SystemFlavorMap)SystemFlavorMap.getDefaultFlavorMap();

    // Get all the native strings and preferred DataFlavor mappings
    hash = new Hashtable(flavorMap.getFlavorsForNatives(null));
    hashSize = hash.size();

    // Setup One-way Mappings
    System.out.println("One-way Mappings Test");
    flavorMap.addUnencodedNativeForFlavor(test_flav, test_native1);
    flavorMap.addUnencodedNativeForFlavor(test_flav, test_native2);

    // Confirm mapping with getNativesForFlavor
    comp1 = new Vector(Arrays.asList(test_natives_set1));
    comp2 = new Vector(flavorMap.getNativesForFlavor(test_flav));

    if ( !comp1.equals(comp2)) {
        throw new RuntimeException("\n*** After setting up one-way mapping" +
            "\nwith addUnencodedNativeForFlavor(DataFlavor flav, String nat)" +
            "\nthe mappings returned from getNativesForFlavor() do not match" +
            "\noriginal mappings.");
    }
    else
       System.out.println("One-way: Test Passes");

    // Setup Two-way Mapping
    System.out.println("Two-way Mappings Test");
    flavorMap.addFlavorForUnencodedNative(test_native1, test_flav);
    flavorMap.addFlavorForUnencodedNative(test_native2, test_flav);

    // Confirm mapping with getFlavorsForNative
    comp1 = new Vector(Arrays.asList(test_flavors_set));
    comp2 = new Vector(flavorMap.getFlavorsForNative(test_native1));
    comp3 = new Vector(flavorMap.getFlavorsForNative(test_native2));

    if ( !(comp1.equals(comp2)) || !(comp1.equals(comp3))) {
        throw new RuntimeException("\n*** After setting up two-way mapping" +
            "\nwith addFlavorForUnencodedNative(String nat, DataFlavor flav)" +
            "\nthe mappings returned from getFlavorsForNative() do not match" +
            "\noriginal mappings.");
    }
    else
       System.out.println("Two-way (DataFlavor): Test Passes");

    // Check first native mapping
    comp1 = new Vector(Arrays.asList(test_natives_set1));
    comp2 = new Vector(flavorMap.getNativesForFlavor(test_flav));

    if ( !comp1.equals(comp2)) {
        throw new RuntimeException("\n*** After setting up two-way mapping" +
            "\nwith addUnencodedNativeForFlavor(DataFlavor flav, String nat)" +
            "\nthe mappings returned from getNativesForFlavor() do not match" +
            "\noriginal mappings.");
    }
    else
       System.out.println("Two-way (String native): Test Passes");

    // Modify an existing mapping test
    System.out.println("Modify Existing Mappings Test");
    flavorMap.addUnencodedNativeForFlavor(test_flav, test_native3);
    flavorMap.addUnencodedNativeForFlavor(test_flav, test_native4);

    // Confirm mapping with getNativesForFlavor
    comp1 = new Vector(Arrays.asList(test_natives_set2));
    comp2 = new Vector(flavorMap.getNativesForFlavor(test_flav));

    if ( !comp1.equals(comp2)) {
        throw new RuntimeException("\n*** After modifying an existing mapping" +
            "\nwith addUnencodedNativeForFlavor(DataFlavor flav, String nat)" +
            "\nthe mappings returned from getNativesForFlavor() do not match" +
            "\nupdated mappings.");
    }
    else
       System.out.println("Modify Existing Mappings: Test Passes");

}
 
开发者ID:campolake,项目名称:openjdk9,代码行数:80,代码来源:AddNativeForFlavorTest.java


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