Java Code Examples for java.awt.datatransfer.SystemFlavorMap#getFlavorsForNatives()

The following examples show how to use java.awt.datatransfer.SystemFlavorMap#getFlavorsForNatives() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GetNativesForNewFlavorTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
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");
}
 
Example 2
Source File: ManyFlavorMapTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
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();
}
 
Example 3
Source File: SetNativesTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
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();
}