本文整理汇总了Java中java.awt.datatransfer.SystemFlavorMap.addFlavorForUnencodedNative方法的典型用法代码示例。如果您正苦于以下问题:Java SystemFlavorMap.addFlavorForUnencodedNative方法的具体用法?Java SystemFlavorMap.addFlavorForUnencodedNative怎么用?Java SystemFlavorMap.addFlavorForUnencodedNative使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.awt.datatransfer.SystemFlavorMap
的用法示例。
在下文中一共展示了SystemFlavorMap.addFlavorForUnencodedNative方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import java.awt.datatransfer.SystemFlavorMap; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
final DataFlavor dataFlavor = new DataFlavor(TEST_MIME_TYPE);
SystemFlavorMap systemFlavorMap = (SystemFlavorMap) SystemFlavorMap.
getDefaultFlavorMap();
systemFlavorMap.addUnencodedNativeForFlavor(dataFlavor, "TEXT");
systemFlavorMap.addFlavorForUnencodedNative("TEXT", dataFlavor);
TransferHandler transferHandler = new TransferHandler("Test Handler");
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
transferHandler.exportToClipboard(new JLabel("Test"), clipboard,
TransferHandler.COPY);
Object clipboardData = clipboard.getData(dataFlavor);
if (!(clipboardData instanceof MyStringReader)) {
throw new RuntimeException("Wrong clipboard data!");
}
}
示例2: SwingClipboard
import java.awt.datatransfer.SystemFlavorMap; //导入方法依赖的package包/类
public SwingClipboard() {
super(SwingOptions.getClipbaordPollingMillis());
if (!SwingUtilities.isEventDispatchThread()) {
throw new IllegalStateException("The clipboard must be created in the event dispatcher thread");
}
this.systemClipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
final FlavorMap map = SystemFlavorMap.getDefaultFlavorMap();
if (map instanceof SystemFlavorMap) {
final SystemFlavorMap systemMap = (SystemFlavorMap) map;
systemMap.addFlavorForUnencodedNative(TransferContainer.MIME_TYPE, TRANSFER_CONTAINER_FLAVOR);
systemMap.addUnencodedNativeForFlavor(TRANSFER_CONTAINER_FLAVOR, TransferContainer.MIME_TYPE);
}
checkContentChanged();
}
示例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();
}
示例4: addUnicodeClasses
import java.awt.datatransfer.SystemFlavorMap; //导入方法依赖的package包/类
public static void addUnicodeClasses(SystemFlavorMap fm,
String nat,
String subType) {
for (int i = 0; i < unicodeTextClasses.length; i++) {
String type = "text/" + subType; //$NON-NLS-1$
String params = ";class=\"" + //$NON-NLS-1$
unicodeTextClasses[i].getName() + "\""; //$NON-NLS-1$
DataFlavor f = new DataFlavor(type + params, type);
fm.addFlavorForUnencodedNative(nat, f);
fm.addUnencodedNativeForFlavor(f, nat);
}
}
示例5: addCharsetClasses
import java.awt.datatransfer.SystemFlavorMap; //导入方法依赖的package包/类
public static void addCharsetClasses(SystemFlavorMap fm,
String nat,
String subType,
String charset) {
for (int i = 0; i < charsetTextClasses.length; i++) {
String type = "text/" + subType; //$NON-NLS-1$
String params = ";class=\"" + //$NON-NLS-1$
charsetTextClasses[i].getName() + "\"" + //$NON-NLS-1$
";charset=\"" + charset + "\""; //$NON-NLS-1$ //$NON-NLS-2$
DataFlavor f = new DataFlavor(type + params, type);
fm.addFlavorForUnencodedNative(nat, f);
fm.addUnencodedNativeForFlavor(f, nat);
}
}
示例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() 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");
}
示例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();
// 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");
}
示例9: appendSystemFlavorMap
import java.awt.datatransfer.SystemFlavorMap; //导入方法依赖的package包/类
protected void appendSystemFlavorMap(SystemFlavorMap fm,
DataFlavor flav,
String nat) {
fm.addFlavorForUnencodedNative(nat, flav);
fm.addUnencodedNativeForFlavor(flav, nat);
}