本文整理汇总了Java中java.awt.datatransfer.SystemFlavorMap.setFlavorsForNative方法的典型用法代码示例。如果您正苦于以下问题:Java SystemFlavorMap.setFlavorsForNative方法的具体用法?Java SystemFlavorMap.setFlavorsForNative怎么用?Java SystemFlavorMap.setFlavorsForNative使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.awt.datatransfer.SystemFlavorMap
的用法示例。
在下文中一共展示了SystemFlavorMap.setFlavorsForNative方法的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);
}
}
示例2: 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();
}
示例3: 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});
}