本文整理汇总了Java中java.awt.datatransfer.SystemFlavorMap.getNativesForFlavor方法的典型用法代码示例。如果您正苦于以下问题:Java SystemFlavorMap.getNativesForFlavor方法的具体用法?Java SystemFlavorMap.getNativesForFlavor怎么用?Java SystemFlavorMap.getNativesForFlavor使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.awt.datatransfer.SystemFlavorMap
的用法示例。
在下文中一共展示了SystemFlavorMap.getNativesForFlavor方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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");
}
示例2: getNativesForFlavors
import java.awt.datatransfer.SystemFlavorMap; //导入方法依赖的package包/类
private static List<String> getNativesForFlavors(DataFlavor[] flavors) {
ArrayList<String> natives = new ArrayList<String>();
SystemFlavorMap flavorMap =
(SystemFlavorMap)SystemFlavorMap.getDefaultFlavorMap();
for (int i = 0; i < flavors.length; i++) {
List<String> list = flavorMap.getNativesForFlavor(flavors[i]);
for (Iterator<String> it = list.iterator(); it.hasNext(); ) {
String nativeFormat = it.next();
if (!natives.contains(nativeFormat)) {
natives.add(nativeFormat);
}
}
}
return natives;
}
示例3: retrieveFormatsToTest
import java.awt.datatransfer.SystemFlavorMap; //导入方法依赖的package包/类
static String[] retrieveFormatsToTest() {
SystemFlavorMap sfm = (SystemFlavorMap) SystemFlavorMap.getDefaultFlavorMap();
java.util.List<String> ln = sfm.getNativesForFlavor(DataFlavor.imageFlavor);
if (OSInfo.OSType.WINDOWS.equals(OSInfo.getOSType()) && !ln.contains("METAFILEPICT")) {
// for test failing on JDK without this fix
ln.add("METAFILEPICT");
}
return ln.toArray(new String[ln.size()]);
}
示例4: 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);
}
}
示例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);
// 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();
}
示例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);
}
}
示例7: 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 addUnencodedNativeForFlavor(DataFlavor flav, String nat);
//
// Enumerate through all the system defined DataFlavors,
// and for each DataFlavor, define it again to the SystemFlavorMap
// with a slightly modified Mime Type.
//
// As a list of String natives will be returned for each DataFlavor,
// the method addUnencodedNativeForFlavor will be called for each
// String native in the list.
//
// For verification, a seperate Hashtable (Map) will be maintained with changes.
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);
// 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 testFlavor = new DataFlavor(mimeType.toString(), "Test DataFlavor");
for (ListIterator i = vectorNatives.listIterator() ; i.hasNext() ;) {
String element = (String)i.next();
flavorMap.addUnencodedNativeForFlavor(testFlavor, element);
}
//Added following 4 lines - Aruna Samji - 07/22/2003
Vector existingNatives = new Vector(flavorMap.getNativesForFlavor(testFlavor));
existingNatives.addAll(vectorNatives);
vectorNatives = existingNatives;
hashVerify.put(testFlavor, vectorNatives);
}
// Assertions: After establishing "new" mappings, verify that the defined
// DataFlavors can be retrieved.
verifyNewMappings();
}
示例8: 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();
}
示例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.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");
}
示例10: 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");
}
示例11: 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");
}